1 //////////////////////////////////////////////////////////////////////////
2 //
3 // pgAdmin III - PostgreSQL Tools
4 //
5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team
6 // This software is released under the PostgreSQL Licence
7 //
8 // pgConstraint.cpp - Constraint collection
9 //
10 //////////////////////////////////////////////////////////////////////////
11
12 // wxWindows headers
13 #include <wx/wx.h>
14
15
16 #include "pgAdmin3.h"
17 #include "schema/pgTable.h"
18 #include "schema/pgDomain.h"
19 #include "schema/pgConstraints.h"
20 #include "schema/pgIndexConstraint.h"
21 #include "schema/pgCheck.h"
22 #include "schema/pgForeignKey.h"
23
24
pgConstraintCollection(pgaFactory * factory,pgSchema * schema)25 pgConstraintCollection::pgConstraintCollection(pgaFactory *factory, pgSchema *schema)
26 : pgSchemaObjCollection(factory, schema)
27 {
28 }
29
GetNewMenu()30 wxMenu *pgConstraintCollection::GetNewMenu()
31 {
32 if ((table && !table->CanCreate()) || (domain && !domain->CanCreate()))
33 return 0;
34
35 wxMenu *menu = new wxMenu();
36 if (table)
37 {
38 if (table->GetPrimaryKey().IsEmpty())
39 primaryKeyFactory.AppendMenu(menu);
40 foreignKeyFactory.AppendMenu(menu);
41 excludeFactory.AppendMenu(menu);
42 uniqueFactory.AppendMenu(menu);
43 }
44 checkFactory.AppendMenu(menu);
45 return menu;
46 }
47
48
ShowTreeDetail(ctlTree * browser,frmMain * form,ctlListView * properties,ctlSQLBox * sqlPane)49 void pgConstraintCollection::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
50 {
51 if (browser->GetChildrenCount(GetId(), false) == 0)
52 {
53 browser->RemoveDummyChild(this);
54
55 wxTreeItemId id = browser->GetItemParent(GetId());
56 wxASSERT(id);
57 table = NULL;
58 domain = NULL;
59 if (browser->GetObject(id)->IsCreatedBy(tableFactory))
60 {
61 table = (pgTable *)browser->GetObject(id);
62 }
63 if (browser->GetObject(id)->IsCreatedBy(domainFactory))
64 {
65 domain = (pgDomain *)browser->GetObject(id);
66 }
67
68 if (table)
69 {
70 primaryKeyFactory.CreateObjects(this, browser);
71 foreignKeyFactory.CreateObjects(this, browser);
72 excludeFactory.CreateObjects(this, browser);
73 uniqueFactory.CreateObjects(this, browser);
74 }
75 checkFactory.CreateObjects(this, browser);
76 }
77 UpdateChildCount(browser);
78 if (properties)
79 ShowList(_("Constraints"), browser, properties);
80 }
81
82
GetTranslatedMessage(int kindOfMessage) const83 wxString pgConstraintCollection::GetTranslatedMessage(int kindOfMessage) const
84 {
85 wxString message = wxEmptyString;
86
87 switch (kindOfMessage)
88 {
89 case RETRIEVINGDETAILS:
90 message = _("Retrieving details on constraints");
91 break;
92 case REFRESHINGDETAILS:
93 message = _("Refreshing constraints");
94 break;
95 case OBJECTSLISTREPORT:
96 message = _("Constraints list report");
97 break;
98 }
99
100 return message;
101 }
102
103
104 /////////////////////////////
105
106 #include "images/constraints.pngc"
107
pgConstraintFactory()108 pgConstraintFactory::pgConstraintFactory()
109 : pgSchemaObjFactory(__("Constraint"), 0, 0, 0)
110 {
111 metaType = PGM_CONSTRAINT;
112 }
113
CreateCollection(pgObject * obj)114 pgCollection *pgConstraintFactory::CreateCollection(pgObject *obj)
115 {
116 return new pgConstraintCollection(GetCollectionFactory(), (pgSchema *)obj);
117 }
118
119
120 pgConstraintFactory constraintFactory;
121 pgaCollectionFactory constraintCollectionFactory(&constraintFactory, __("Constraints"), constraints_png_img);
122
123
124