]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMPackageManagerPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMPackageManagerPanel.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sant�)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26  */
27
28 /*
29  * wxCDMPackageManagerPanel.cpp
30  *
31  *  Created on: Dec 10, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMPackageManagerPanel.h"
36
37 #include "wxCDMMainFrame.h"
38 #include "wxCDMNewPackageDialog.h"
39
40 #include "creaDevManagerIds.h"
41 #include "images/PkIcon64.xpm"
42
43 BEGIN_EVENT_TABLE(wxCDMPackageManagerPanel, wxPanel)
44 EVT_BUTTON(ID_BUTTON_PREV, wxCDMPackageManagerPanel::OnBtnReturn)
45 EVT_HYPERLINK(ID_LINK_SELECT_PACKAGE, wxCDMPackageManagerPanel::OnLnkPackageSelect)
46 EVT_BUTTON(ID_BUTTON_CREATE_PACKAGE, wxCDMPackageManagerPanel::OnBtnCreatePackage)
47 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageManagerPanel::OnBtnEditCMakeLists)
48 END_EVENT_TABLE()
49
50 wxCDMPackageManagerPanel::wxCDMPackageManagerPanel(
51     wxWindow* parent,
52     modelCDMProject* project,
53     wxWindowID id,
54     const wxString& caption,
55     const wxPoint& pos,
56     const wxSize& size,
57     long style
58 )
59 {
60   wxCDMPackageManagerPanel::Create(parent, project, id, caption, pos, size, style);
61 }
62
63 wxCDMPackageManagerPanel::~wxCDMPackageManagerPanel()
64 {
65 }
66
67 bool wxCDMPackageManagerPanel::Create(
68     wxWindow* parent,
69     modelCDMProject* project,
70     wxWindowID id,
71     const wxString& caption,
72     const wxPoint& pos,
73     const wxSize& size,
74     long style
75 )
76 {
77   wxPanel::Create(parent, id, pos, size, style);
78   this->project = project;
79   CreateControls();
80   return TRUE;
81 }
82
83 void wxCDMPackageManagerPanel::CreateControls()
84 {
85   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
86
87   //Link to return
88   sizer->Add(new wxButton(this, ID_BUTTON_PREV, wxT("Return to project")), 0, wxALIGN_CENTER | wxALL, 5);
89
90   //Title
91   sizer->Add(new wxStaticText(this, -1, _("Package Management")),0, wxALIGN_CENTER, 0);
92
93   //Image
94   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
95
96   //Packages
97   wxStaticBox* propertiesBox = new wxStaticBox(this, -1, _T("&Available Packages"));
98   wxStaticBoxSizer* propertiesBoxInnerSizer = new wxStaticBoxSizer(propertiesBox, wxVERTICAL);
99
100   std::vector<modelCDMPackage*> packages = this->project->GetPackages();
101   for (int i = 0; i < packages.size(); i++)
102     {
103       wxHyperlinkCtrl* pPackagelk = new wxHyperlinkCtrl(this,ID_LINK_SELECT_PACKAGE, crea::std2wx(packages[i]->GetName().c_str()), crea::std2wx(packages[i]->GetName().c_str()));
104       propertiesBoxInnerSizer -> Add(pPackagelk, 0, wxALIGN_LEFT | wxALL, 5);
105     }
106
107   sizer -> Add(propertiesBoxInnerSizer, 0, wxEXPAND | wxALL, 10);
108
109   //Actions
110   wxStaticBox* actionsBox = new wxStaticBox(this, -1, _T("&Actions"));
111   wxStaticBoxSizer* actionsBoxInnerSizer = new wxStaticBoxSizer(actionsBox, wxHORIZONTAL);
112   sizer -> Add(actionsBoxInnerSizer, 0, wxEXPAND | wxALL, 10);
113
114   actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_CREATE_PACKAGE, _T("Create Package")), 0, wxALL, 5);
115   actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")), 0, wxALL, 5);
116
117   //Assign sizer
118   actionsBoxInnerSizer->SetSizeHints(this);
119
120   SetSizer(sizer);
121   sizer->SetSizeHints(this);
122 }
123
124 void wxCDMPackageManagerPanel::OnBtnCreatePackage(wxCommandEvent& event)
125 {
126   std::string* result;
127
128   wxCDMNewPackageDialog* dialog = new wxCDMNewPackageDialog(this);
129   long userResponse;
130   userResponse = dialog->ShowModal();
131
132   if(userResponse == wxID_FORWARD)
133     {
134       modelCDMIProjectTreeNode* package = this->project->CreatePackage(
135           crea::wx2std(dialog->GetPackageName()),
136           result,
137           crea::wx2std(dialog->GetPackageAuthor()),
138           crea::wx2std(dialog->GetPackageAuthorEmail()),
139           crea::wx2std(dialog->GetPackageDescription())
140       );
141       if(package == NULL)
142         {
143           std::cout << "error creating package: " << *result << std::endl;
144           wxMessageBox(crea::std2wx(*result),_T("New Package - Error!"),wxOK | wxICON_ERROR);
145           event.Skip();
146           return;
147         }
148       wxMessageBox(crea::std2wx("Package successfully created."),_T("New Package - Success!"),wxOK | wxICON_INFORMATION);
149
150       //refreshing tree and description
151       //send event instead of calling parent to avoid crashing
152
153       ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
154
155       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
156       newEvent->SetInt(package->GetId());
157       newEvent->SetId(0);
158       wxPostEvent(this->GetParent(), *newEvent);
159       event.Skip();
160     }
161
162   event.Skip();
163 }
164
165 void wxCDMPackageManagerPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
166 {
167   //TODO: implement method
168   std::cerr << "Event OnBtnCreatePackage not implemented" << std::endl;
169   event.Skip();
170 }
171
172 void wxCDMPackageManagerPanel::OnLnkPackageSelect(wxHyperlinkEvent& event)
173 {
174   int packageId = 0;
175   std::vector<modelCDMPackage*> packages = this->project->GetPackages();
176   for (int i = 0; i < packages.size(); i++)
177     {
178       if(packages[i]->GetName() == crea::wx2std(event.GetURL()))
179         {
180           packageId = packages[i]->GetId();
181           break;
182         }
183     }
184
185   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
186   newEvent->SetInt(packageId);
187   newEvent->SetId(0);
188   wxPostEvent(this->GetParent(), *newEvent);
189
190 }
191
192 void wxCDMPackageManagerPanel::OnBtnReturn(wxCommandEvent& event)
193 {
194   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
195   newEvent->SetInt(project->GetId());
196   newEvent->SetId(0);
197   wxPostEvent(this->GetParent(), *newEvent);
198 }