On Mon, Dec 1, 2008 at 6:41 AM, Ashesh D Vashi <
[EMAIL PROTECTED]> wrote:
> Hi All,
>
> As per my discussion with Dave Page:
> - Replace the generic dialog box that the graphical query builder uses when
> you right-click a join, and select the join type option. It currently
> uses
> an ugly standard dialog. Create a more compact and purpose built one -
> like
> the one you get when you add criteria, and click on the 'restricted
> value'
> button.
>
Good improvement, yeah it was my foul :(
>
> Modifications and addition are as follows:
> * Introduced couple of new classes for handling operations:
> + gqbJoinsPanel - Panel for handling the joins in the tab - container for
>
>
criteria, order & columns panels
>
Good add-on
> + gqbJoinsPopUp - Pop up window, when selecting a column from the table
> list,
> derived from the gqbColsPopUp
>
> + gqbGridJoinTable - Table for handling all the joins data. It handles
> three
> columns Source, Join-Type & Destination
> * Added new images gqbAdd.xpm & gqbRemove.xpm
> * Renamed wxRestrictionGrid to gqbCustomGrid as we're using the same Grid
> for
> handling the criteria(s) and join(s) in the gqbCriteriaPanel and
> gqbJoinsPanel
> respectively.
>
Good change, I notice this item probably will be use in the future for
others panels but at that moment I hadn't enough time to think in a good
name ;)
>
> * Added one operator [] in gqbArrayCollection for accessing the gqbObject
> object
> directory (replacement/accessibility of the object at particular index
> will be
> easy and fast).
>
A good way to access the vector, but allowing the code to access directly
the objects based on the index probably decrease the independece of the
subyacent structured inside the collection. If I decided to change the
vector for a hash map in a future this operator probably difficult the
change by example, because now we have hard code access directly to the
structure inside the collection.
>
> * Removed the context menu "Set Type" removed for join, as this operation
> will be
> handled from the joins-panel now onwards.
>
I'm not really sure about remove the Set type from context menu, because
this was the fastest way to do this task, I think it can be change but for a
faster one way (like click on the type =,<,> etc and change in a circular
way the type), and consequence of forcing the user to use a panel to change
some properties in a diagram probably is it can hurt usability.
>
>
> Regards,
> Ashesh Vashi
>
>
>
> --
> Sent via pgadmin-hackers mailing list ([email protected])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>
>
About Last Dave commentaries:
I don't see any difference on Windows - I still need to click on the
> canvas before the label changes. Changing to a difference cell, or
> hitting return doesn't help.
>
I fixed this in a very rudimentary way this you can try to find a new and
more elegant one solution Ashesh. I included the patch here
the only change was made on gqbGridJoinTable class and affected ones).
About the the two patches:
I have something to tell about the patches: I tried the second patch first
but doesn't works, tried the first and works Revert svn and apply second
patch and works, there is any file missing in the second patch?
Regards, Luis.
Index: gqb/gqbGridJoinTable.cpp
===================================================================
--- gqb/gqbGridJoinTable.cpp (revision 0)
+++ gqb/gqbGridJoinTable.cpp (revision 0)
@@ -0,0 +1,288 @@
+//////////////////////////////////////////////////////////////////////////
+//
+// pgAdmin III - PostgreSQL Tools
+// RCS-ID: $Id$
+// Copyright (C) 2002 - 2008, The pgAdmin Development Team
+// This software is released under the Artistic Licence
+//
+// gqbGridJoinTable.cpp - Table implementation for Joins Panel Grid
+//
+//////////////////////////////////////////////////////////////////////////
+
+// App headers
+#include "pgAdmin3.h"
+
+// wxWindows headers
+#include <wx/wx.h>
+#include <wx/settings.h>
+#include <wx/utils.h>
+#include <wx/notebook.h>
+#include <wx/regex.h>
+
+// App headers
+#include "gqb/gqbGridJoinTable.h"
+#include "gqb/gqbGridRestTable.h"
+#include "gqb/gqbColumn.h"
+#include "gqb/gqbQueryObjs.h"
+#include "gqb/gqbEvents.h"
+#include "gqb/gqbViewController.h"
+
+gqbGridJoinTable::gqbGridJoinTable(gqbController *_controller):
+wxGridTableBase()
+{
+ controller=_controller;
+}
+
+
+gqbGridJoinTable::~gqbGridJoinTable()
+{
+ emptyTableData();
+}
+
+
+int gqbGridJoinTable::GetNumberRows()
+{
+ return joins.count();
+}
+
+
+int gqbGridJoinTable::GetNumberCols()
+{
+ return 3;
+}
+
+
+bool gqbGridJoinTable::IsEmptyCell( int row, int col )
+{
+ if (joins.count() == 0)
+ return true;
+ return false;
+}
+
+
+wxString gqbGridJoinTable::GetValue( int row, int col )
+{
+ if (row >= joins.count())
+ return wxEmptyString;
+ gqbQueryJoin* obj = (gqbQueryJoin *)joins.getItemAt(row);
+
+ switch(col)
+ {
+ case 0:
+ {
+ gqbQueryObject* srcTbl = obj->getSourceQTable();
+ wxString sStr = srcTbl ? (srcTbl->getAlias().IsEmpty() ? qtIdent(srcTbl->getName()) : qtIdent(srcTbl->getAlias())) : wxString(wxEmptyString);
+ if ( !sStr.IsEmpty() )
+ sStr += wxT(".") + qtIdent(obj->getSourceCol());
+ return sStr;
+ }
+ case 1:
+ switch(obj->getKindofJoin())
+ {
+ case _equally:
+ return wxT("=");
+ case _lesser:
+ return wxT("<");
+ case _greater:
+ return wxT(">");
+ case _equlesser:
+ return wxT("<=");
+ case _equgreater:
+ return wxT(">=");
+ }
+ return wxEmptyString;
+ case 2:
+ {
+ gqbQueryObject* destTbl = obj->getDestQTable();
+ wxString dStr = destTbl ? (destTbl->getAlias().IsEmpty() ? qtIdent(destTbl->getName()) : qtIdent(destTbl->getAlias())) : wxString(wxEmptyString);
+ if ( !dStr.IsEmpty() )
+ dStr += wxT(".") + obj->getDestCol();
+ return dStr;
+ }
+ break;
+ };
+ return wxT("");
+}
+
+
+void gqbGridJoinTable::SetValue( int row, int col, const wxString& value )
+{
+ if (col == 1)
+ {
+ gqbQueryJoin *join = (gqbQueryJoin *)joins.getItemAt(row);
+ if (value == wxT("="))
+ join->setKindofJoin(_equally);
+ else if (value == wxT("<"))
+ join->setKindofJoin(_lesser);
+ else if (value == wxT(">"))
+ join->setKindofJoin(_greater);
+ else if (value == wxT("<="))
+ join->setKindofJoin(_equlesser);
+ else if (value == wxT(">="))
+ join->setKindofJoin(_equgreater);
+ controller->getView()->Refresh();
+ }
+}
+
+bool gqbGridJoinTable::ReplaceJoin( gqbQueryJoin *orig, gqbQueryJoin *newVal )
+{
+ int rowCount = joins.count();
+ for ( int index = 0; index < rowCount; index++ )
+ {
+ if ( joins[ index ] == orig )
+ {
+ joins[ index ] = newVal;
+ return true;
+ }
+ }
+ return false;
+}
+
+gqbQueryJoin* gqbGridJoinTable::GetJoin( int row )
+{
+ if (row >= joins.count())
+ return NULL;
+ return (gqbQueryJoin *)joins.getItemAt(row);
+}
+
+
+void gqbGridJoinTable::removeJoin(gqbQueryJoin *item)
+{
+ if (item == NULL || this->joins.count() == 0)
+ return;
+ int index = joins.getIndex( item );
+ if (index == -1)
+ return;
+ joins.removeItem( item );
+ if (GetView())
+ {
+ wxGridTableMessage msg( this,
+ wxGRIDTABLE_NOTIFY_ROWS_DELETED,
+ index + 1,
+ 1 );
+ GetView()->ProcessTableMessage( msg );
+ }
+}
+
+void gqbGridJoinTable::removeJoins(gqbQueryObject *obj)
+{
+ if (!obj)
+ return;
+
+ if (obj->getHaveJoins())
+ {
+ gqbIteratorBase *itrJoins = obj->createJoinsIterator();
+ if (itrJoins)
+ {
+ while (itrJoins->HasNext())
+ {
+ gqbQueryJoin *tmp = (gqbQueryJoin *)itrJoins->Next();
+ removeJoin(tmp);
+ }
+ }
+ }
+
+ if (obj->getHaveRegJoins())
+ {
+ gqbIteratorBase *itrRegJoins = obj->createRegJoinsIterator();
+ if (itrRegJoins)
+ {
+ while (itrRegJoins->HasNext())
+ {
+ gqbQueryJoin *tmp = (gqbQueryJoin *)itrRegJoins->Next();
+ removeJoin(tmp);
+ }
+ }
+ }
+}
+
+void gqbGridJoinTable::AppendJoin(gqbQueryJoin *item)
+{
+ bool notify = true;
+ if ( item == NULL )
+ {
+ item = new gqbQueryJoin(NULL, NULL, NULL, NULL, _equally);
+ }
+ joins.addItem( item );
+ if (notify && GetView() )
+ {
+ wxGridTableMessage msg( this,
+ wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
+ joins.count(),
+ 1 );
+ GetView()->ProcessTableMessage( msg );
+
+ int row = GetView()->GetNumberRows() -1;
+
+ wxString strChoices[] = {wxT("="), wxT("<"),wxT("<="),wxT(">"),wxT(">=")};
+
+ GetView()->SetCellRenderer(row, 0, new wxGridCellButtonRenderer);
+ GetView()->SetCellRenderer(row, 1, new wxGridCellComboBoxRenderer);
+ GetView()->SetCellEditor(row, 1, new dxGridCellSizedChoiceEditor(WXSIZEOF(strChoices),strChoices));
+ GetView()->SetCellRenderer(row, 2, new wxGridCellButtonRenderer);
+
+ GetView()->SetReadOnly( row, 0 );
+ GetView()->SetReadOnly( row, 2 );
+ }
+}
+
+
+// Removes all items from gqbGridJoinTable
+void gqbGridJoinTable::emptyTableData()
+{
+ for (int index = joins.count() - 1; index >= 0; index--)
+ {
+ gqbQueryJoin* join = (gqbQueryJoin *)joins[index];
+ joins.removeItem(join);
+
+ // Join with either source or destination not present needs to be removed here
+ if (!(join->getSourceQTable() && join->getDestQTable()))
+ {
+ delete join;
+ join = NULL;
+ }
+ }
+}
+
+gqbQueryObject *gqbGridJoinTable::DeleteRow(size_t pos)
+{
+ gqbQueryJoin *join = (gqbQueryJoin *)joins.getItemAt(pos);
+ gqbQueryObject* srcTbl = NULL;
+ if (join)
+ {
+ this->removeJoin(join);
+ if (join->getSourceQTable() && join->getDestQTable())
+ {
+ srcTbl = join->getSourceQTable();
+ srcTbl->removeJoin(join, true);
+ }
+ }
+
+ return srcTbl;
+}
+
+wxString gqbGridJoinTable::GetColLabelValue(int col)
+{
+ switch(col)
+ {
+ case 0:
+ return wxT("Source");
+ case 1:
+ return wxT("Join Type");
+ case 2:
+ return wxT("Destination");
+ }
+ return wxEmptyString;
+}
+
+
+void gqbGridJoinTable::selectJoin(gqbQueryJoin *join)
+{
+ int indexRow = joins.getIndex(join);
+ if (indexRow != -1 && GetView())
+ {
+ GetView()->ClearSelection();
+ GetView()->SelectRow(indexRow, true);
+ }
+}
+
Index: gqb/gqbViewPanels.cpp
===================================================================
--- gqb/gqbViewPanels.cpp (revision 7506)
+++ gqb/gqbViewPanels.cpp (working copy)
@@ -25,6 +25,7 @@
#include "gqb/gqbGridProjTable.h"
#include "gqb/gqbGridRestTable.h"
#include "gqb/gqbGridOrderTable.h"
+#include "gqb/gqbGridJoinTable.h"
// Images
#include "images/gqbUp.xpm"
@@ -41,7 +42,13 @@
#include "images/table-sm.xpm"
#include "images/column-sm.xpm"
#include "images/view-sm.xpm"
+#include "images/gqbAdd.xpm"
+#include "images/gqbRemove.xpm"
+// Get available ID for Criteria & Joins Panel
+long CRITERIA_PANEL_RESTRICTION_GRID_ID = ::wxNewId();
+long JOINS_PANEL_GRID_ID = ::wxNewId();
+
//
// View Columns Grid Panel Class.
//
@@ -383,10 +390,50 @@
}
-void gqbColsTree::refreshTree(gqbModel * model)
+// Override the DeleteAllItems virtual function
+// Needs to set null as item-data, otherwise they will delete
+// the gqbQueryObject(s) and gqbColumn(s), while deleting these
+// items
+void gqbColsTree::DeleteAllItems()
{
+ wxTreeItemId tableId;
+ wxTreeItemIdValue tableCookie;
+ wxTreeItemId rootId = this->GetRootItem();
+
+ if ( this->GetChildrenCount(rootId, false) != 0 )
+ {
+ wxTreeItemId lastTableId = this->GetLastChild(rootId);
+ tableId = this->GetFirstChild(rootId, tableCookie);
+ while ( true )
+ {
+ this->SetItemData(tableId, NULL);
+ wxTreeItemIdValue colCookie;
+ wxTreeItemId colId = this->GetFirstChild(tableId, colCookie);
+ wxTreeItemId lastColId = this->GetLastChild(tableId);
+ if ( this->GetChildrenCount(tableId, false) != 0 )
+ {
+ while ( true )
+ {
+ this->SetItemData(colId, NULL);
+ if ( colId != lastColId )
+ colId = this->GetNextSibling(colId);
+ else
+ break;
+ }
+ }
+ if ( lastTableId != tableId )
+ tableId = this->GetNextSibling(tableId);
+ else
+ break;
+ }
+ }
+ wxTreeCtrl::DeleteAllItems();
+}
+
+void gqbColsTree::refreshTree(gqbModel * model, gqbQueryObject *doNotInclude)
+{
// This remove and delete data inside tree's node
- this->DeleteAllItems();
+ this->DeleteAllItems();
wxString a=_("Select column");
createRoot(a);
this->Expand(rootNode);
@@ -396,26 +443,29 @@
while(iterator->HasNext())
{
gqbQueryObject *tmpTable= (gqbQueryObject *)iterator->Next();
+
+ if (doNotInclude && tmpTable == doNotInclude)
+ continue;
- int iconIndex;
- if (tmpTable->parent->getType() == GQB_TABLE)
- iconIndex = 1;
- else // Must be a view
- iconIndex = 3;
+ int iconIndex;
+ if (tmpTable->parent->getType() == GQB_TABLE)
+ iconIndex = 1;
+ else // Must be a view
+ iconIndex = 3;
if(tmpTable->getAlias().length()>0)
{
- parent=this->AppendItem(rootNode, tmpTable->getAlias() , iconIndex, iconIndex, NULL);
+ parent=this->AppendItem(rootNode, tmpTable->getAlias() , iconIndex, iconIndex, tmpTable);
}
else
{
- parent=this->AppendItem(rootNode, tmpTable->getName() , iconIndex, iconIndex, NULL);
+ parent=this->AppendItem(rootNode, tmpTable->getName() , iconIndex, iconIndex, tmpTable);
}
gqbIteratorBase *colsIterator = tmpTable->parent->createColumnsIterator();
while(colsIterator->HasNext())
{
gqbColumn *tmpColumn= (gqbColumn *)colsIterator->Next();
- this->AppendItem(parent, tmpColumn->getName() , 2, 2,NULL);
+ this->AppendItem(parent, tmpColumn->getName() , 2, 2, tmpColumn);
}
delete colsIterator;
}
@@ -546,13 +596,11 @@
gModel=gridModel;
colsPopUp=NULL;
- // GQB-TODO: add real ID not 321
- // wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_DONTWRAP,wxT(""));
- this->restrictionsGrid = new wxRestrictionGrid(this, 321);
+ this->restrictionsGrid = new gqbCustomGrid(this, CRITERIA_PANEL_RESTRICTION_GRID_ID);
restrictionsGrid->SetTable(gModel, true, wxGrid::wxGridSelectCells);
this->restrictionsGrid->SetSelectionMode(wxGrid::wxGridSelectRows);
- this->Connect(321, wxEVT_GRID_CELL_LEFT_CLICK, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &gqbCriteriaPanel::OnCellLeftClick);
+ this->Connect(CRITERIA_PANEL_RESTRICTION_GRID_ID, wxEVT_GRID_CELL_LEFT_CLICK, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &gqbCriteriaPanel::OnCellLeftClick);
// GQB-TODO: in a future implement OnMouseWheel
addBitmap= wxBitmap(gqbAddRest_xpm);
@@ -633,7 +681,7 @@
void gqbCriteriaPanel::OnCellLeftClick(wxGridEvent& event)
{
wxObject *object = event.GetEventObject();
- wxRestrictionGrid *grid = wxDynamicCast( object, wxRestrictionGrid );
+ gqbCustomGrid *grid = wxDynamicCast( object, gqbCustomGrid );
// Only show editor y case of column 1
if(event.GetCol()==1)
@@ -718,7 +766,7 @@
//
// View Selection Criteria Panel Class's Grid.
//
-wxRestrictionGrid::wxRestrictionGrid(wxWindow* parent, wxWindowID id):
+gqbCustomGrid::gqbCustomGrid(wxWindow* parent, wxWindowID id):
wxGrid(parent, id, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_BESTWRAP,wxT("")),
m_selTemp(NULL)
{
@@ -737,7 +785,7 @@
}
-void wxRestrictionGrid::RevertSel()
+void gqbCustomGrid::RevertSel()
{
if (m_selTemp)
{
@@ -748,7 +796,7 @@
}
-void wxRestrictionGrid::ComboBoxEvent(wxGridEvent& event)
+void gqbCustomGrid::ComboBoxEvent(wxGridEvent& event)
{
// This forces the cell to go into edit mode directly
@@ -772,7 +820,7 @@
}
// hack to prevent selection from being lost when click combobox
- if (event.GetCol() == 0 && this->IsInSelection(event.GetRow(), event.GetCol()))
+ if (this->IsInSelection(event.GetRow(), event.GetCol()))
{
this->m_selTemp = this->m_selection;
this->m_selection = NULL;
@@ -1266,3 +1314,310 @@
}
event.Skip();
}
+
+// Popup window for gqbJoinsPanel
+//
+gqbJoinsPopUp::gqbJoinsPopUp(
+ gqbJoinsPanel* parent, wxWindowID id, wxString title,
+ wxPoint pos, const wxSize size, gqbQueryJoin *_join,
+ bool isSource, gqbGridJoinTable* _gmodel)
+:gqbColsPopUp(parent, id, title, pos, size)
+{
+ this->editTree->SetEditable(false);
+
+ // Handles different events for Ok button, single mouse click, double mouse click
+ this->Connect(QR_TREE_OK, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &gqbJoinsPopUp::OnPopUpOKClick);
+ this->Connect(QR_TREE, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) &gqbJoinsPopUp::OnPopUpTreeDoubleClick);
+ this->Connect(QR_TREE, wxEVT_COMMAND_TREE_SEL_CHANGED, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) &gqbJoinsPopUp::OnPopUpTreeClick);
+
+ this->selectedTbl = NULL;
+ this->selectedCol = NULL;
+ this->join = _join;
+ this->isSource = isSource;
+ this->gModel = _gmodel;
+}
+
+void gqbJoinsPopUp::refreshTree(gqbModel *_model)
+{
+ model=_model;
+ if(colsTree && _model)
+ {
+ // Do not include already included Table
+ // For self join, other entity for the same table should be used with alias
+ if ( join )
+ colsTree->refreshTree(model, isSource ? join->getDestQTable() : join->getSourceQTable());
+ else
+ colsTree->refreshTree(model);
+ }
+}
+
+// single mouse click on tree
+void gqbJoinsPopUp::OnPopUpTreeClick(wxTreeEvent& event)
+{
+ if( colsTree )
+ {
+ wxTreeItemId itemId = event.GetItem();
+ wxTreeItemId itemIdParent = colsTree->GetItemParent(itemId);
+
+ if(!colsTree->ItemHasChildren(itemId) && (colsTree->GetRootItem()!=itemId))
+ {
+ selectedCol = (gqbColumn *)colsTree->GetItemData(itemId);
+ selectedTbl = (gqbQueryObject *)colsTree->GetItemData(itemIdParent);
+ this->editTree->SetValue(qtIdent(colsTree->GetItemText(itemIdParent)) + wxT(".") + qtIdent(colsTree->GetItemText(itemId)));
+ }
+ else
+ {
+ selectedCol = NULL;
+ selectedTbl = NULL;
+ }
+ }
+}
+
+
+void gqbJoinsPopUp::OnPopUpOKClick(wxCommandEvent& event)
+{
+ if( colsTree && selectedCol && selectedTbl )
+ {
+ // This should update the selected Join with the new values.
+ updateJoin();
+ }
+
+ this->MakeModal(false);
+ this->Hide();
+ this->GetParent()->Refresh();
+ this->join = NULL;
+ this->selectedCol = NULL;
+ this->selectedTbl = NULL;
+}
+
+
+// Update the view fo this query table, involved in
+// the whole operation
+void gqbJoinsPanel::updateView(gqbQueryObject *table)
+{
+ if (table)
+ controller->getView()->updateTable(table);
+}
+
+void gqbJoinsPopUp::updateJoin()
+{
+ if ((isSource ? join->getSCol() : join->getDCol()) != selectedCol)
+ {
+ // Create a new join with the existing data
+ // Replace it in the gqbJoinTable with the existing one
+ // Unregister the join, if exists
+ gqbQueryObject *srcTbl = ( isSource ? selectedTbl : join->getSourceQTable() );
+ gqbQueryObject *destTbl = ( isSource ? join->getDestQTable() : selectedTbl );
+ gqbColumn *srcCol = ( isSource ? selectedCol : join->getSCol() );
+ gqbColumn *destCol = ( isSource ? join->getDCol() : selectedCol );
+ type_Join joinType = join->getKindofJoin();
+
+ gqbQueryJoin *newJoin = NULL;
+ if( srcTbl && destTbl )
+ {
+ newJoin = srcTbl->addJoin(srcTbl, destTbl, srcCol, destCol, joinType);
+ ((gqbJoinsPanel *)GetParent())->updateView(newJoin->getSourceQTable());
+ }
+ else
+ newJoin = new gqbQueryJoin(srcTbl, destTbl, srcCol, destCol, joinType);
+
+ gModel->ReplaceJoin(join, newJoin);
+
+ if (join->getSourceQTable() && join->getDestQTable())
+ {
+ // This will remove the join object too
+ gqbQueryObject* srcObj = join->getSourceQTable();
+ srcObj->removeJoin(join, true);
+ }
+ else
+ {
+ delete join;
+ }
+ join = newJoin;
+ }
+}
+
+
+void gqbJoinsPopUp::OnPopUpTreeDoubleClick(wxTreeEvent& event)
+{
+ if(colsTree)
+ {
+ wxTreeItemId itemId = event.GetItem();
+ wxTreeItemId itemIdParent = colsTree->GetItemParent(itemId);
+ if(!colsTree->ItemHasChildren(itemId) && (colsTree->GetRootItem()!=itemId))
+ {
+ selectedCol = (gqbColumn *)colsTree->GetItemData(itemId);
+ selectedTbl = (gqbQueryObject *)colsTree->GetItemData(itemIdParent);
+
+ updateJoin();
+
+ this->MakeModal(false);
+ this->Hide();
+ this->GetParent()->Refresh();
+ this->join = NULL;
+ this->selectedCol = NULL;
+ this->selectedTbl = NULL;
+ }
+ }
+}
+
+//
+// View Selection Joins Panel Class.
+//
+
+BEGIN_EVENT_TABLE(gqbJoinsPanel, wxPanel)
+EVT_BUTTON(GQB_JOIN_COLS_ADD_BUTTON_ID, gqbJoinsPanel::OnButtonAdd)
+EVT_BUTTON(GQB_JOIN_COLS_DELETE_BUTTON_ID, gqbJoinsPanel::OnButtonDrop)
+END_EVENT_TABLE()
+
+gqbJoinsPanel::gqbJoinsPanel(wxWindow* parent, gqbModel *_model, gqbGridJoinTable* _gmodel, gqbController *_controller):
+wxPanel(parent, wxID_ANY)
+{
+ model=_model;
+ gModel=_gmodel;
+ controller=_controller;
+ joinsPopUp=NULL;
+
+ this->joinsGrid = new gqbCustomGrid(this, JOINS_PANEL_GRID_ID);
+ joinsGrid->CreateGrid(0, 5, wxGrid::wxGridSelectRows);
+ joinsGrid->SetTable(gModel, true, wxGrid::wxGridSelectCells);
+ this->joinsGrid->SetSelectionMode(wxGrid::wxGridSelectRows);
+
+ this->Connect(JOINS_PANEL_GRID_ID, wxEVT_GRID_CELL_LEFT_CLICK, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &gqbJoinsPanel::OnCellLeftClick);
+ // GQB-TODO: in a future implement OnMouseWheel
+
+ addBitmap= wxBitmap(gqbAdd_xpm);
+ dropBitmap= wxBitmap(gqbRemove_xpm);
+ buttonAdd= new wxBitmapButton( this, GQB_JOIN_COLS_ADD_BUTTON_ID, addBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, wxT("Add"));
+ buttonDrop= new wxBitmapButton( this, GQB_JOIN_COLS_DELETE_BUTTON_ID, dropBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, wxT("Remove"));
+
+ wxBoxSizer *horizontalSizer = new wxBoxSizer( wxHORIZONTAL );
+ horizontalSizer->Add(joinsGrid,
+ 1, // make vertically stretchable
+ wxEXPAND | // make horizontally stretchable
+ wxALL, // and make border all around
+ 3 ); // set border width to 10
+
+ wxBoxSizer *buttonsSizer = new wxBoxSizer( wxVERTICAL );
+
+ buttonsSizer->Add(
+ this->buttonAdd,
+ 0, // make horizontally unstretchable
+ wxALL, // make border all around (implicit top alignment)
+ 10 ); // set border width to 10
+
+ buttonsSizer->Add(
+ this->buttonDrop,
+ 0, // make horizontally unstretchable
+ wxALL, // make border all around (implicit top alignment)
+ 10 ); // set border width to 10
+
+ horizontalSizer->Add(
+ buttonsSizer,
+ 0, // make vertically unstretchable
+ wxALIGN_CENTER ); // no border and centre horizontally
+
+ this->SetSizer(horizontalSizer);
+}
+
+
+void gqbJoinsPanel::showColsPopUp(int row, int col, wxPoint pos)
+{
+ if( joinsPopUp )
+ {
+ joinsPopUp->Destroy();
+ joinsPopUp = NULL;
+ }
+ joinsPopUp = new gqbJoinsPopUp(this,-1,wxT("Select Column"),wxDefaultPosition,wxDefaultSize, this->gModel->GetJoin(row), ( col == 0 ? true : false ), this->gModel);
+
+ refreshTree(model);
+
+ // Set initial Value
+ joinsPopUp->setEditText(joinsGrid->GetCellValue(row,col));
+
+ // Set Position for Pop Up Tree
+ // Position of wxNotebook
+ wxPoint p=this->GetParent()->GetPosition();
+ p.x+=pos.x;
+ p.y+=pos.y;
+ wxPoint p2=this->GetPosition();
+
+ // Position of panel inside wxNotebook
+ p.x+=p2.x;
+ p.y+=p2.y+40;
+ joinsPopUp->SetPosition(p);
+ joinsPopUp->Show();
+ joinsPopUp->MakeModal(true);
+ joinsPopUp->focus();
+ joinsPopUp->setUsedCell(joinsGrid,row,col);
+}
+
+
+void gqbJoinsPanel::refreshTree(gqbModel *_model)
+{
+ model=_model;
+ if(joinsPopUp && model)
+ joinsPopUp->refreshTree(model);
+}
+
+
+void gqbJoinsPanel::OnCellLeftClick(wxGridEvent& event)
+{
+ wxObject *object = event.GetEventObject();
+ gqbCustomGrid *grid = wxDynamicCast( object, gqbCustomGrid );
+
+ // Only show editor y case of column 1
+ if(event.GetCol()==1)
+ {
+ grid->ComboBoxEvent(event);
+ } else if(event.GetCol()==0 || event.GetCol()==2)
+ {
+ // Allow mini browser frame to be visible to user
+ wxRect cellSize=grid->CellToRect(event.GetRow(), event.GetCol());
+ wxPoint p = event.GetPosition();
+ joinsGrid->CalcUnscrolledPosition(p.x,p.y,&p.x,&p.y);
+
+ // Number 17 is button's width at cellRender function [nButtonWidth]
+ if((grid->GetRowLabelSize()+cellSize.GetRight())-(p.x) <= 17 )
+ {
+ p = event.GetPosition();
+ showColsPopUp(event.GetRow(), event.GetCol(),p);
+ }
+ }
+ event.Skip();
+}
+
+
+void gqbJoinsPanel::OnButtonAdd(wxCommandEvent&)
+{
+ this->gModel->AppendJoin( NULL );
+}
+
+
+void gqbJoinsPanel::OnButtonDrop(wxCommandEvent&)
+{
+ if(joinsGrid->GetGridCursorRow()>=0)
+ {
+ gqbQueryObject *updateTbl = gModel->DeleteRow(joinsGrid->GetGridCursorRow());
+ if (updateTbl)
+ controller->getView()->updateTable(updateTbl);
+ }
+ joinsGrid->Refresh();
+}
+
+
+void gqbJoinsPanel::SetGridColsSize()
+{
+ // After sizers determine the width of Grid then calculate the % space for each column about 33% each one
+ int size=(int)((joinsGrid->GetSize().GetWidth() - joinsGrid->GetRowLabelSize())*0.3);
+ joinsGrid->SetColSize(0,size);
+ joinsGrid->SetColSize(1,size);
+ joinsGrid->SetColSize(2,size);
+}
+
+void gqbJoinsPanel::updatedJoinType(gqbQueryJoin *join)
+{
+ controller->getView()->updateJoin(join);
+}
+
+
Index: include/gqb/gqbGridJoinTable.h
===================================================================
--- include/gqb/gqbGridJoinTable.h (revision 0)
+++ include/gqb/gqbGridJoinTable.h (revision 0)
@@ -0,0 +1,49 @@
+//////////////////////////////////////////////////////////////////////////
+//
+// pgAdmin III - PostgreSQL Tools
+// RCS-ID: $Id$
+// Copyright (C) 2002 - 2008, The pgAdmin Development Team
+// This software is released under the Artistic Licence
+//
+// gqbGridJoinTable.h - Table implementation for Join Panel Grid
+//
+//////////////////////////////////////////////////////////////////////////
+
+#ifndef GQBGRIDJOINTABLE_H
+#define GQBGRIDJOINTABLE_H
+
+#include <wx/grid.h>
+#include <wx/laywin.h>
+
+// App headers
+#include "gqb/gqbViewController.h"
+#include "gqb/gqbQueryObjs.h"
+#include "gqb/gqbArrayCollection.h"
+
+class gqbGridJoinTable : public wxGridTableBase
+{
+public:
+ gqbGridJoinTable(gqbController* _controller);
+ ~gqbGridJoinTable();
+ int GetNumberRows();
+ int GetNumberCols();
+ bool IsEmptyCell(int row, int col);
+ wxString GetValue(int row, int col);
+ wxString GetColLabelValue( int col);
+ void SetValue(int row, int col, const wxString& value);
+ void AppendJoin(gqbQueryJoin *item);
+ void removeJoin(gqbQueryJoin *item);
+ void removeJoins(gqbQueryObject *obj);
+ void emptyTableData();
+ gqbQueryObject *DeleteRow(size_t pos);
+ bool ReplaceJoin(gqbQueryJoin *orig, gqbQueryJoin *newVal);
+ gqbQueryJoin* GetJoin(int row);
+ void selectJoin(gqbQueryJoin *join);
+
+private:
+ gqbController *controller;
+ gqbArrayCollection joins;
+};
+
+#endif
+
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers