~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to src/schema/pgCollection.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Enrici
  • Date: 2004-12-14 23:46:39 UTC
  • Revision ID: james.westby@ubuntu.com-20041214234639-tve0i5l49fq13jli
Tags: upstream-1.2.0
ImportĀ upstreamĀ versionĀ 1.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pgAdmin III - PostgreSQL Tools
 
4
// RCS-ID:      $Id: pgCollection.cpp,v 1.35 2004/07/25 20:33:51 andreas Exp $
 
5
// Copyright (C) 2002 - 2004, The pgAdmin Development Team
 
6
// This software is released under the Artistic Licence
 
7
//
 
8
// pgCollection.cpp - Simple object for use with 'collection' nodes
 
9
//
 
10
//////////////////////////////////////////////////////////////////////////
 
11
 
 
12
// wxWindows headers
 
13
#include <wx/wx.h>
 
14
 
 
15
// App headers
 
16
#include "pgAdmin3.h"
 
17
#include "misc.h"
 
18
#include "pgCollection.h"
 
19
#include "pgServer.h"
 
20
#include "pgGroup.h"
 
21
#include "pgUser.h"
 
22
#include "pgLanguage.h"
 
23
#include "pgTablespace.h"
 
24
#include "pgAggregate.h"
 
25
#include "pgCast.h"
 
26
#include "pgConversion.h"
 
27
#include "pgDomain.h"
 
28
#include "pgFunction.h"
 
29
#include "pgOperator.h"
 
30
#include "pgOperatorClass.h"
 
31
#include "pgSequence.h"
 
32
#include "pgTable.h"
 
33
#include "pgType.h"
 
34
#include "pgView.h"
 
35
#include "pgColumn.h"
 
36
#include "pgIndex.h"
 
37
#include "pgRule.h"
 
38
#include "pgTrigger.h"
 
39
 
 
40
 
 
41
 
 
42
pgCollection::pgCollection(int newType, pgServer *sv)
 
43
: pgObject(newType, typesList[newType].typName)
 
44
 
45
    wxLogInfo(wxT("Creating a pgCollection object")); 
 
46
    schema=0;
 
47
    database=0;
 
48
    server= sv;
 
49
}
 
50
 
 
51
 
 
52
pgCollection::pgCollection(int newType, pgDatabase *db)
 
53
: pgObject(newType, typesList[newType].typName)
 
54
 
55
    wxLogInfo(wxT("Creating a pgCollection object")); 
 
56
    schema=0;
 
57
    database=db;
 
58
    server= database->GetServer();
 
59
}
 
60
 
 
61
 
 
62
pgCollection::pgCollection(int newType, pgSchema *sch)
 
63
: pgObject(newType, typesList[newType].typName)
 
64
 
65
    wxLogInfo(wxT("Creating a pgCollection object")); 
 
66
    schema = sch;
 
67
    database = sch->GetDatabase();
 
68
    server= database->GetServer();
 
69
}
 
70
 
 
71
 
 
72
pgCollection::~pgCollection()
 
73
{
 
74
    wxLogInfo(wxT("Destroying a pgCollection object"));
 
75
}
 
76
 
 
77
 
 
78
void pgCollection::ShowList(const wxString& name, wxTreeCtrl *browser, ctlListView *properties)
 
79
{
 
80
    if (properties)
 
81
    {
 
82
        // Display the properties.
 
83
        wxCookieType cookie;
 
84
        pgObject *data;
 
85
 
 
86
        // Setup listview
 
87
        CreateListColumns(properties, wxGetTranslation(name), _("Comment"));
 
88
 
 
89
        wxTreeItemId item = browser->GetFirstChild(GetId(), cookie);
 
90
        long pos=0;
 
91
        while (item)
 
92
        {
 
93
            data = (pgObject *)browser->GetItemData(item);
 
94
            if (IsCollectionForType(data->GetType()))
 
95
            {
 
96
                properties->InsertItem(pos, data->GetFullName(), data->GetIcon());
 
97
                properties->SetItem(pos, 1, data->GetComment());
 
98
            }
 
99
            // Get the next item
 
100
            item = browser->GetNextChild(GetId(), cookie);
 
101
            pos++;
 
102
        }
 
103
    }
 
104
}
 
105
 
 
106
 
 
107
 
 
108
void pgCollection::UpdateChildCount(wxTreeCtrl *browser, int substract)
 
109
{
 
110
    wxString label;
 
111
    label.Printf(wxString(wxGetTranslation(GetName())) + wxT(" (%d)"), browser->GetChildrenCount(GetId(), FALSE) -substract);
 
112
    browser->SetItemText(GetId(), label);
 
113
}
 
114
 
 
115
 
 
116
bool pgCollection::CanCreate()
 
117
{
 
118
    switch (GetType())
 
119
    {
 
120
        case PG_USERS:
 
121
        case PG_GROUPS:
 
122
        case PG_TABLESPACES:
 
123
            return GetServer()->GetSuperUser();
 
124
        case PG_DATABASES:
 
125
            return GetServer()->GetCreatePrivilege();
 
126
        case PG_CASTS:
 
127
        case PG_LANGUAGES:
 
128
        case PG_SCHEMAS:
 
129
            return GetDatabase()->GetCreatePrivilege();
 
130
        case PG_AGGREGATES:
 
131
        case PG_CONVERSIONS:
 
132
        case PG_DOMAINS:
 
133
        case PG_FUNCTIONS:
 
134
        case PG_TRIGGERFUNCTIONS:
 
135
        case PG_OPERATORS:
 
136
        case PG_SEQUENCES:
 
137
        case PG_TABLES:
 
138
        case PG_TYPES:
 
139
        case PG_VIEWS:
 
140
        case PG_COLUMNS:
 
141
        case PG_INDEXES:
 
142
        case PG_RULES:
 
143
        case PG_TRIGGERS:
 
144
            return GetSchema()->GetCreatePrivilege();
 
145
        case PG_OPERATORCLASSES:
 
146
        default:
 
147
            return false;
 
148
    }
 
149
}
 
150
 
 
151
 
 
152
int pgCollection::GetIcon()
 
153
{
 
154
    switch (GetType())
 
155
    {
 
156
        case PG_SERVERS:            return PGICON_SERVER;
 
157
        case PG_USERS:              return PGICON_USER;
 
158
        case PG_GROUPS:             return PGICON_GROUP;
 
159
        case PG_DATABASES:          return PGICON_DATABASE;
 
160
        case PG_CASTS:              return PGICON_CAST;
 
161
        case PG_LANGUAGES:          return PGICON_LANGUAGE;
 
162
        case PG_SCHEMAS:            return PGICON_SCHEMA;
 
163
        case PG_TABLESPACES:        return PGICON_TABLESPACE;
 
164
        case PG_AGGREGATES:         return PGICON_AGGREGATE;
 
165
        case PG_CONVERSIONS:        return PGICON_CONVERSION;
 
166
        case PG_DOMAINS:            return PGICON_DOMAIN;
 
167
        case PG_FUNCTIONS:          return PGICON_FUNCTION;
 
168
        case PG_TRIGGERFUNCTIONS:   return PGICON_TRIGGERFUNCTION;
 
169
        case PG_OPERATORS:          return PGICON_OPERATOR;
 
170
        case PG_OPERATORCLASSES:    return PGICON_OPERATORCLASS;
 
171
        case PG_SEQUENCES:          return PGICON_SEQUENCE;
 
172
        case PG_TABLES:             return PGICON_TABLE;
 
173
        case PG_TYPES:              return PGICON_TYPE;
 
174
        case PG_VIEWS:              return PGICON_VIEW;
 
175
        case PG_COLUMNS:            return PGICON_COLUMN;
 
176
        case PG_INDEXES:            return PGICON_INDEX;
 
177
        case PG_RULES:              return PGICON_RULE;
 
178
        case PG_TRIGGERS:           return PGICON_TRIGGER;
 
179
        default:    return 0;
 
180
    }
 
181
}
 
182
 
 
183
 
 
184
pgObject *pgCollection::FindChild(wxTreeCtrl *browser, int index)
 
185
{
 
186
    wxCookieType cookie;
 
187
    pgObject *data;
 
188
 
 
189
    wxTreeItemId item = browser->GetFirstChild(GetId(), cookie);
 
190
    long pos=0;
 
191
    while (item && index >= 0)
 
192
    {
 
193
        data = (pgObject *)browser->GetItemData(item);
 
194
        if (data && IsCollectionForType(data->GetType()))
 
195
        {
 
196
            if (index == pos)
 
197
                return data;
 
198
 
 
199
            pos++;
 
200
        }
 
201
        item = browser->GetNextChild(GetId(), cookie);
 
202
    }
 
203
    return 0;
 
204
}
 
205
 
 
206
 
 
207
 
 
208
void pgCollection::ShowTreeDetail(wxTreeCtrl *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
 
209
{
 
210
    if (browser->GetChildrenCount(GetId(), FALSE) == 0)
 
211
    {
 
212
        switch (GetType())
 
213
        {
 
214
            case PG_DATABASES:
 
215
                pgDatabase::ReadObjects(this, browser);
 
216
                break;
 
217
            case PG_GROUPS:
 
218
                pgGroup::ReadObjects(this, browser);
 
219
                break;
 
220
            case PG_USERS:
 
221
                pgUser::ReadObjects(this, browser);
 
222
                break;
 
223
            case PG_LANGUAGES:
 
224
                pgLanguage::ReadObjects(this, browser);
 
225
                break;
 
226
            case PG_SCHEMAS:
 
227
                pgSchema::ReadObjects(this, browser);
 
228
                break;
 
229
            case PG_TABLESPACES:
 
230
                pgTablespace::ReadObjects(this, browser);
 
231
                break;
 
232
            case PG_AGGREGATES:
 
233
                pgAggregate::ReadObjects(this, browser);
 
234
                break;
 
235
            case PG_CASTS:
 
236
                pgCast::ReadObjects(this, browser);
 
237
                break;
 
238
            case PG_CONVERSIONS:
 
239
                pgConversion::ReadObjects(this, browser);
 
240
                break;
 
241
            case PG_DOMAINS:
 
242
                pgDomain::ReadObjects(this, browser);
 
243
                break;
 
244
            case PG_FUNCTIONS:
 
245
                pgFunction::ReadObjects(this, browser);
 
246
                break;
 
247
            case PG_TRIGGERFUNCTIONS:
 
248
                pgTriggerFunction::ReadObjects(this, browser);
 
249
                break;
 
250
            case PG_OPERATORS:
 
251
                pgOperator::ReadObjects(this, browser);
 
252
                break;
 
253
            case PG_OPERATORCLASSES:
 
254
                pgOperatorClass::ReadObjects(this, browser);
 
255
                break;
 
256
            case PG_SEQUENCES:
 
257
                pgSequence::ReadObjects(this, browser);
 
258
                break;
 
259
            case PG_TABLES:
 
260
                pgTable::ReadObjects(this, browser);
 
261
                break;
 
262
            case PG_TYPES:
 
263
                pgType::ReadObjects(this, browser);
 
264
                break;
 
265
            case PG_VIEWS:
 
266
                pgView::ReadObjects(this, browser);
 
267
                break;
 
268
            case PG_COLUMNS:
 
269
                pgColumn::ReadObjects(this, browser);
 
270
                break;
 
271
            case PG_INDEXES:
 
272
                pgIndex::ReadObjects(this, browser);
 
273
                break;
 
274
            case PG_RULES:
 
275
                pgRule::ReadObjects(this, browser);
 
276
                break;
 
277
            case PG_TRIGGERS:
 
278
                pgTrigger::ReadObjects(this, browser);
 
279
                break;
 
280
            default:
 
281
                return;
 
282
        }
 
283
    }
 
284
 
 
285
    UpdateChildCount(browser);
 
286
    if (properties)
 
287
        ShowList(typesList[GetType()+1].typName, browser, properties);
 
288
}
 
289
 
 
290
 
 
291
void pgCollection::ShowStatistics(frmMain *form, ctlListView *statistics)
 
292
{
 
293
    switch (GetType())
 
294
    {
 
295
        case PG_DATABASES:
 
296
            pgDatabase::ShowStatistics(this, statistics);
 
297
            break;
 
298
        case PG_TABLES:
 
299
            pgTable::ShowStatistics(this, statistics);
 
300
            break;
 
301
        case PG_TABLESPACES:
 
302
            pgTablespace::ShowStatistics(this, statistics);
 
303
            break;
 
304
        default:
 
305
            break;
 
306
    }
 
307
}
 
 
b'\\ No newline at end of file'