1
//////////////////////////////////////////////////////////////////////////
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
8
// gqbGridOrderTable.cpp - Table implementation for Order By Panel Grid
10
//////////////////////////////////////////////////////////////////////////
19
#include "gqb/gqbGridOrderTable.h"
20
#include "gqb/gqbColumn.h"
21
#include "gqb/gqbArrayCollection.h"
22
#include "gqb/gqbModel.h"
24
gqbGridOrderTable::gqbGridOrderTable(int numColumns, gqbObjsArray* cols, gqbObjsArray* parent, charArray* orderBy)
26
numberColumns=numColumns;
33
gqbGridOrderTable::~gqbGridOrderTable()
38
int gqbGridOrderTable::GetNumberRows()
40
return (columns->GetCount());
44
int gqbGridOrderTable::GetNumberCols()
50
bool gqbGridOrderTable::IsEmptyCell( int row, int col )
52
int count=columns->GetCount();
60
wxString gqbGridOrderTable::GetValue( int row, int col )
64
wxString col = wxT("");
65
if(((gqbQueryObject *)colsParents->Item(row))->getAlias().length()>0)
67
col+=((gqbQueryObject *)colsParents->Item(row))->getAlias()+wxT(".");
71
col+=((gqbQueryObject *)colsParents->Item(row))->getName()+wxT(".");
73
col+=((gqbColumn *)columns->Item(row))->getName();
81
wxString ord = wxT("");
82
if(kindOfOrder->Item(row)=='A')
94
wxString gqbGridOrderTable::GetColLabelValue(int col)
105
return _("Available Columns");
116
void gqbGridOrderTable::SetValue( int row, int col, const wxString& value )
118
if(col==1 && numberColumns==2)
120
if(value.Contains(wxT("ASC")))
122
kindOfOrder->Item(row)='A';
126
kindOfOrder->Item(row)='D';
132
void gqbGridOrderTable::AppendItem(gqbColumn *column, gqbQueryObject *parent, char kindOrder)
134
columns->Add(column);
135
colsParents->Add(parent);
138
kindOfOrder->Add(kindOrder);
143
wxGridTableMessage msg( this,
144
wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
145
(columns->GetCount()-1),
147
GetView()->ProcessTableMessage( msg );
152
bool gqbGridOrderTable::removeFirstRow(gqbObject *itemTable)
155
int i,size=colsParents->GetCount();
159
if (colsParents->Item(i)==itemTable)
168
columns->RemoveAt(i);
169
colsParents->RemoveAt(i);
172
kindOfOrder->RemoveAt(i);
174
if ( GetView() ) // Notify Grid about the change
176
wxGridTableMessage msg( this,
177
wxGRIDTABLE_NOTIFY_ROWS_DELETED,
180
GetView()->ProcessTableMessage( msg );
188
void gqbGridOrderTable::emptyTableData(gqbQueryObject *object)
190
// Because items positions on array changes when I delete one, I have to do the remove in this way
191
while(removeFirstRow(object));
195
void gqbGridOrderTable::removeRowAt(int i)
197
columns->RemoveAt(i);
198
colsParents->RemoveAt(i);
201
kindOfOrder->RemoveAt(i);
203
// Notify Grid about the change
206
wxGridTableMessage msg( this,
207
wxGRIDTABLE_NOTIFY_ROWS_DELETED,
210
GetView()->ProcessTableMessage( msg );
215
gqbObject* gqbGridOrderTable::getObjectAt(int pos, int col)
217
gqbObject *value = NULL;
221
value=columns->Item(pos);
224
value=colsParents->Item(pos);
231
void gqbGridOrderTable::changesPositions(int sPos, int dPos)
234
int size=columns->GetCount();
235
gqbObject *tmpTable=NULL, *tmpColumn=NULL;
238
if( (sPos>=0 && sPos < size) && (dPos>=0 && dPos < size) )
240
tmpTable=colsParents->Item(sPos);
241
tmpColumn=columns->Item(sPos);
242
tmpKind=kindOfOrder->Item(sPos);
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;
252
wxGridTableMessage msg( this,
253
wxGRIDTABLE_REQUEST_VIEW_GET_VALUES,
256
GetView()->ProcessTableMessage( msg );
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)
265
// Eliminate side effect of zero base array on calculations, but carefull newTop still it's zero based
268
int sizeRange=bottomPos-(topPos-1), size=GetNumberRows();
269
if(topPos>newTop) // Go Down
271
// Only if the movement don't create an overflow
272
if( (topPos > 1) && ((newTop+sizeRange) < size) )
274
for(int i=newTop ; i < (newTop+sizeRange) ; i++)
276
changesPositions(i,i+1);
283
// Only if the movement don't create an overflow
284
if( (bottomPos < size) && ((newTop+sizeRange) <= size) )
287
for(int i=(newTop+sizeRange-1) ; i >= newTop ; i--)
289
changesPositions(i-1,i);