1 //////////////////////////////////////////////////////////////////////////
2 //
3 // pgAdmin III - PostgreSQL Tools
4 //
5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team
6 // This software is released under the PostgreSQL Licence
7 //
8 // ddAddColButtonHandle.cpp - A handle for a table figure that allow to graphically add columns
9 //
10 //////////////////////////////////////////////////////////////////////////
11
12 #include "pgAdmin3.h"
13
14 // wxWindows headers
15 #include <wx/wx.h>
16
17 // App headers
18 #include "dd/dditems/handles/ddAddColButtonHandle.h"
19 #include "dd/dditems/figures/ddTableFigure.h"
20 #include "dd/dditems/utilities/ddDataType.h"
21 #include "hotdraw/main/hdDrawingView.h"
22
23 //Images
24 #include "images/ddAddColumnCursor.pngc"
25
ddAddColButtonHandle(hdIFigure * owner,hdILocator * buttonLocator,wxBitmap & buttonImage,wxSize & size)26 ddAddColButtonHandle::ddAddColButtonHandle(hdIFigure *owner, hdILocator *buttonLocator , wxBitmap &buttonImage, wxSize &size):
27 hdButtonHandle(owner, buttonLocator, buttonImage, size)
28 {
29 }
30
~ddAddColButtonHandle()31 ddAddColButtonHandle::~ddAddColButtonHandle()
32 {
33 }
34
invokeStart(hdMouseEvent & event,hdDrawingView * view)35 void ddAddColButtonHandle::invokeStart(hdMouseEvent &event, hdDrawingView *view)
36 {
37 ddTableFigure *table = (ddTableFigure *) getOwner();
38 wxTextEntryDialog nameDialog(view, wxT("New column name"), wxT("Add a column"));
39 bool again;
40 do
41 {
42 again = false;
43 int answer = nameDialog.ShowModal();
44 if (answer == wxID_OK)
45 {
46 wxString name = nameDialog.GetValue();
47 if(table->getColByName(name) == NULL)
48 {
49 table->addColumn(view->getIdx(), new ddColumnFigure(name, table));
50 view->notifyChanged();
51 }
52 else
53 {
54 wxString msg(wxT("Error trying to add new column '"));
55 msg.Append(name);
56 msg.Append(wxT("' column name already in use"));
57 wxMessageDialog info( view, msg ,
58 wxT("Column name already in use"),
59 wxNO_DEFAULT | wxOK | wxICON_EXCLAMATION);
60 again = true;
61 info.ShowModal();
62 }
63 }
64
65 }
66 while(again);
67 view->Refresh();
68 }
69
invokeStep(hdMouseEvent & event,hdDrawingView * view)70 void ddAddColButtonHandle::invokeStep(hdMouseEvent &event, hdDrawingView *view)
71 {
72 }
73
invokeEnd(hdMouseEvent & event,hdDrawingView * view)74 void ddAddColButtonHandle::invokeEnd(hdMouseEvent &event, hdDrawingView *view)
75 {
76 }
77