File: gqbBrowser.cpp

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (139 lines) | stat: -rw-r--r-- 4,226 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// gqbBrowser.cpp - Tables Tree of GQB.
//
//////////////////////////////////////////////////////////////////////////

#include "pgAdmin3.h"

// wxWindows headers
#include <wx/wx.h>
#include <wx/regex.h>
#include <wx/imaglist.h>

// App headers
#include "gqb/gqbBrowser.h"
#include "gqb/gqbEvents.h"
#include "gqb/gqbSchema.h"
#include "gqb/gqbDatabase.h"
#include "gqb/gqbViewController.h"

// Images
#include "images/table-sm.pngc"
#include "images/view-sm.pngc"
#include "images/namespace-sm.pngc"
#include "images/namespaces.pngc"
#include "images/database-sm.pngc"
#include "images/catalog-sm.pngc"
#include "images/catalogs.pngc"
#include "images/catalogobject-sm.pngc"
#include "images/exttable-sm.pngc"	// Greenplum external tables

BEGIN_EVENT_TABLE(gqbBrowser, wxTreeCtrl)
	EVT_TREE_ITEM_ACTIVATED(GQB_BROWSER, gqbBrowser::OnItemActivated)
	EVT_TREE_BEGIN_DRAG(GQB_BROWSER, gqbBrowser::OnBeginDrag)
END_EVENT_TABLE()

gqbBrowser::gqbBrowser(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style, gqbController *_controller)
	: wxTreeCtrl(parent, id, pos, size, style)
{
	controller = _controller;
	rootNode = (wxTreeItemId *)NULL;

	// Create normal images list of browser
	// Remember to update enum gqbImages in gqbBrowser.h if changing the images!!
	imageList = new wxImageList(16, 16);
	imageList->Add(*database_sm_png_ico);
	imageList->Add(*namespace_sm_png_ico);
	imageList->Add(*table_sm_png_ico);
	imageList->Add(*namespaces_png_ico);
	imageList->Add(*catalogs_png_ico);
	imageList->Add(*catalog_sm_png_ico);
	imageList->Add(*catalogobject_sm_png_ico);
	imageList->Add(*view_sm_png_ico);
	imageList->Add(*exttable_sm_png_ico);
	this->AssignImageList(imageList);
}


// Destructor
gqbBrowser::~gqbBrowser()
{
	this->DeleteAllItems();        // This remove and delete data inside tree's node
}


// Create root node
wxTreeItemId &gqbBrowser::createRoot(wxString &Name)
{
	rootNode = this->AddRoot(Name, 0, 0);
	catalogsNode = this->AppendItem(rootNode, _("Catalogs"), GQB_IMG_CATALOGS, GQB_IMG_CATALOGS, NULL);
	schemasNode = this->AppendItem(rootNode, _("Schemas"), GQB_IMG_NAMESPACES, GQB_IMG_NAMESPACES, NULL);
	return rootNode;
}


// Event activated when user double click on a item of tree
void gqbBrowser::OnItemActivated(wxTreeEvent &event)
{
	wxTreeItemId itemId = event.GetItem();
	gqbObject *object = (gqbObject *) GetItemData(itemId);
	if(object)
	{
		if (object->getType() == GQB_TABLE || object->getType() == GQB_VIEW)
		{
			gqbTable *item = (gqbTable *)  object;
			controller->addTableToModel(item, wxPoint(10, 10));
			controller->getView()->Refresh();
		}
		else if (GetChildrenCount(itemId) == 0 && object->getType() == GQB_SCHEMA)
		{
			gqbSchema *schema = (gqbSchema *)object;
			schema->createObjects(this, schema->getOid(), itemId, GQB_IMG_TABLE, GQB_IMG_VIEW, GQB_IMG_EXTTABLE);
		}
	}

}

void gqbBrowser::refreshTables(pgConn *connection)
{
	controller->emptyModel();
	this->DeleteAllItems();
	gqbDatabase *Data = new gqbDatabase(wxEmptyString, connection);
	Data->createObjects(this);
	this->Expand(rootNode);
}


void gqbBrowser::OnBeginDrag(wxTreeEvent &event)
{
	wxTreeItemId itemId = event.GetItem();

	// Simplest solution, simulate DnD but actually don't do it
	gqbObject *object = (gqbObject *) GetItemData(itemId);
	if(object != NULL && (object->getType() == GQB_TABLE || object->getType() == GQB_VIEW))
	{
		gqbTable *item = (gqbTable *) object;
		wxString tableName = item->getName();
		wxTextDataObject textData(tableName);
		wxDropSource dragSource(this);
		dragSource.SetData(textData);
		wxDragResult result = dragSource.DoDragDrop(wxDrag_CopyOnly);
		if(result == wxDragCopy)
		{
			controller->getView()->CalcUnscrolledPosition(xx, yy, &xx, &yy);
			gqbQueryObject *queryObj = controller->addTableToModel(item, wxPoint(xx, yy));
			controller->getView()->Refresh();
			if (queryObj)
			{
				controller->getView()->Update();
				controller->getView()->updateModelSize(queryObj, false);
			}
		}
	}
}