~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to pgadmin/gqb/gqbGridOrderTable.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pgAdmin III - PostgreSQL Tools
 
4
// RCS-ID:      $Id: gqbGridOrderTable.cpp 7758 2009-03-26 20:49:59Z dpage $
 
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
 
6
// This software is released under the BSD Licence
 
7
//
 
8
// gqbGridOrderTable.cpp - Table implementation for Order By Panel Grid
 
9
//
 
10
//////////////////////////////////////////////////////////////////////////
 
11
 
 
12
// App headers
 
13
#include "pgAdmin3.h"
 
14
 
 
15
// wxWindows headers
 
16
#include <wx/wx.h>
 
17
 
 
18
// App headers
 
19
#include "gqb/gqbGridOrderTable.h"
 
20
#include "gqb/gqbColumn.h"
 
21
#include "gqb/gqbArrayCollection.h"
 
22
#include "gqb/gqbModel.h"
 
23
 
 
24
gqbGridOrderTable::gqbGridOrderTable(int numColumns, gqbObjsArray* cols, gqbObjsArray* parent, charArray* orderBy)
 
25
{
 
26
    numberColumns=numColumns;
 
27
    columns=cols;
 
28
    colsParents=parent;
 
29
    kindOfOrder=orderBy;
 
30
}
 
31
 
 
32
 
 
33
gqbGridOrderTable::~gqbGridOrderTable()
 
34
{
 
35
}
 
36
 
 
37
 
 
38
int gqbGridOrderTable::GetNumberRows()
 
39
{
 
40
    return (columns->GetCount());
 
41
}
 
42
 
 
43
 
 
44
int gqbGridOrderTable::GetNumberCols()
 
45
{
 
46
    return numberColumns;
 
47
}
 
48
 
 
49
 
 
50
bool gqbGridOrderTable::IsEmptyCell( int row, int col )
 
51
{
 
52
    int count=columns->GetCount();
 
53
    if(row+1 <= count)
 
54
        return false;
 
55
    else
 
56
        return true;
 
57
}
 
58
 
 
59
 
 
60
wxString gqbGridOrderTable::GetValue( int row, int col )
 
61
{
 
62
    if(col==0)
 
63
    {
 
64
        wxString col = wxT("");
 
65
        if(((gqbQueryObject *)colsParents->Item(row))->getAlias().length()>0)
 
66
        {
 
67
            col+=((gqbQueryObject *)colsParents->Item(row))->getAlias()+wxT(".");
 
68
        }
 
69
        else
 
70
        {
 
71
            col+=((gqbQueryObject *)colsParents->Item(row))->getName()+wxT(".");
 
72
        }
 
73
        col+=((gqbColumn *)columns->Item(row))->getName();
 
74
        return col;
 
75
    }
 
76
 
 
77
    if(numberColumns==2)
 
78
    {
 
79
        if(col==1)
 
80
        {
 
81
            wxString ord = wxT("");
 
82
            if(kindOfOrder->Item(row)=='A')
 
83
                ord+=wxT("ASC");
 
84
            else
 
85
                ord+=wxT("DESC");
 
86
 
 
87
            return ord;
 
88
        }
 
89
    }
 
90
    return wxT("");
 
91
}
 
92
 
 
93
 
 
94
wxString gqbGridOrderTable::GetColLabelValue(int col)
 
95
{
 
96
    switch(col)
 
97
    {
 
98
        case 0:
 
99
            if(numberColumns==2)
 
100
            {
 
101
                return _("Column");
 
102
            }
 
103
            else
 
104
            {
 
105
                return _("Available Columns");
 
106
            }
 
107
            break;
 
108
        case 1:
 
109
            return _("Order");
 
110
            break;
 
111
    };
 
112
    return wxT("");
 
113
}
 
114
 
 
115
 
 
116
void gqbGridOrderTable::SetValue( int row, int col, const wxString& value )
 
117
{
 
118
    if(col==1 && numberColumns==2)
 
119
    {
 
120
        if(value.Contains(wxT("ASC")))
 
121
        {
 
122
            kindOfOrder->Item(row)='A';
 
123
        }
 
124
        else
 
125
        {
 
126
            kindOfOrder->Item(row)='D';
 
127
        }
 
128
    }
 
129
}
 
130
 
 
131
 
 
132
void gqbGridOrderTable::AppendItem(gqbColumn *column, gqbQueryObject *parent, char kindOrder)
 
133
{
 
134
    columns->Add(column);
 
135
    colsParents->Add(parent);
 
136
    if(numberColumns==2)
 
137
    {
 
138
        kindOfOrder->Add(kindOrder);
 
139
    }
 
140
 
 
141
    if (GetView() )
 
142
    {
 
143
        wxGridTableMessage msg( this,
 
144
            wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
 
145
            (columns->GetCount()-1),
 
146
            1 );
 
147
        GetView()->ProcessTableMessage( msg );
 
148
    }
 
149
}
 
150
 
 
151
 
 
152
bool gqbGridOrderTable::removeFirstRow(gqbObject *itemTable)
 
153
{
 
154
    bool found=false;
 
155
    int i,size=colsParents->GetCount();
 
156
 
 
157
    for(i=0;i<size;i++)
 
158
    {
 
159
        if (colsParents->Item(i)==itemTable)
 
160
        {
 
161
            found=true;
 
162
            break;
 
163
        }
 
164
    }
 
165
 
 
166
    if(found)
 
167
    {
 
168
        columns->RemoveAt(i);
 
169
        colsParents->RemoveAt(i);
 
170
        if(numberColumns==2)
 
171
        {
 
172
            kindOfOrder->RemoveAt(i);
 
173
        }
 
174
        if ( GetView() )                          // Notify Grid about the change
 
175
        {
 
176
            wxGridTableMessage msg( this,
 
177
                wxGRIDTABLE_NOTIFY_ROWS_DELETED,
 
178
                i+1,
 
179
                1 );
 
180
            GetView()->ProcessTableMessage( msg );
 
181
        }
 
182
    }
 
183
 
 
184
    return found;
 
185
}
 
186
 
 
187
 
 
188
void gqbGridOrderTable::emptyTableData(gqbQueryObject *object)
 
189
{
 
190
    // Because items positions on array changes when I delete one, I have to do the remove in this way
 
191
    while(removeFirstRow(object));
 
192
}
 
193
 
 
194
 
 
195
void gqbGridOrderTable::removeRowAt(int i)
 
196
{
 
197
    columns->RemoveAt(i);
 
198
    colsParents->RemoveAt(i);
 
199
    if(numberColumns==2)
 
200
    {
 
201
        kindOfOrder->RemoveAt(i);
 
202
    }
 
203
    // Notify Grid about the change
 
204
        if ( GetView() )                              
 
205
    {
 
206
        wxGridTableMessage msg( this,
 
207
            wxGRIDTABLE_NOTIFY_ROWS_DELETED,
 
208
            i+1,
 
209
            1 );
 
210
        GetView()->ProcessTableMessage( msg );
 
211
    }
 
212
}
 
213
 
 
214
 
 
215
gqbObject* gqbGridOrderTable::getObjectAt(int pos, int col)
 
216
{
 
217
    gqbObject *value = NULL;
 
218
    switch(col)
 
219
    {
 
220
        case 0:
 
221
            value=columns->Item(pos);
 
222
            break;
 
223
        case 1:
 
224
            value=colsParents->Item(pos);
 
225
            break;
 
226
    };
 
227
    return value;
 
228
}
 
229
 
 
230
 
 
231
void gqbGridOrderTable::changesPositions(int sPos, int dPos)
 
232
{
 
233
 
 
234
    int size=columns->GetCount();
 
235
    gqbObject *tmpTable=NULL, *tmpColumn=NULL;
 
236
    char tmpKind = 'N';
 
237
 
 
238
    if( (sPos>=0 && sPos < size) && (dPos>=0 && dPos < size) )
 
239
    {
 
240
        tmpTable=colsParents->Item(sPos);
 
241
        tmpColumn=columns->Item(sPos);
 
242
        tmpKind=kindOfOrder->Item(sPos);
 
243
 
 
244
        colsParents->Item(sPos)=colsParents->Item(dPos);
 
245
        columns->Item(sPos)=columns->Item(dPos);
 
246
        kindOfOrder->Item(sPos)=kindOfOrder->Item(dPos);
 
247
        colsParents->Item(dPos)=tmpTable;
 
248
        columns->Item(dPos)=tmpColumn;
 
249
        kindOfOrder->Item(dPos)=tmpKind;
 
250
    }
 
251
 
 
252
    wxGridTableMessage msg( this,
 
253
        wxGRIDTABLE_REQUEST_VIEW_GET_VALUES,
 
254
        sPos,
 
255
        1 );
 
256
    GetView()->ProcessTableMessage( msg );
 
257
 
 
258
}
 
259
 
 
260
 
 
261
// GQB-TODO: optimize this functions & related buttons events at gqbView because works but are a mess.
 
262
// Change a single row or a range to one pos up or down (but no more than one position)
 
263
void gqbGridOrderTable::changesRangeOnePos(int topPos, int bottomPos, int newTop)
 
264
{
 
265
    // Eliminate side effect of zero base array on calculations, but carefull newTop still it's zero based
 
266
    topPos++;
 
267
    bottomPos++;
 
268
    int sizeRange=bottomPos-(topPos-1), size=GetNumberRows();
 
269
    if(topPos>newTop)                             // Go Down
 
270
    {
 
271
        // Only if the movement don't create an overflow
 
272
        if( (topPos > 1) && ((newTop+sizeRange) <  size)  )
 
273
        {
 
274
            for(int i=newTop ; i < (newTop+sizeRange) ; i++)
 
275
            {
 
276
                changesPositions(i,i+1);
 
277
            }
 
278
        }
 
279
 
 
280
    }                                             // Go Up
 
281
    else
 
282
    {
 
283
        // Only if the movement don't create an overflow
 
284
        if( (bottomPos < size) && ((newTop+sizeRange) <=  size)  )
 
285
        {
 
286
                                                  // Go Up Down
 
287
            for(int i=(newTop+sizeRange-1) ; i >= newTop  ; i--)
 
288
            {
 
289
                changesPositions(i-1,i);
 
290
            }
 
291
        }
 
292
    }
 
293
}