+/*
+# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+# pour la Sant�)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+# This software is governed by the CeCILL-B license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/ or redistribute the software under the terms of the CeCILL-B
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+# or in the file LICENSE.txt.
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------
+ */
+
+/*
+ * wxCDMPackageManagerPanel.cpp
+ *
+ * Created on: Dec 10, 2012
+ * Author: Daniel Felipe Gonzalez Obando
+ */
+
+#include "wxCDMPackageManagerPanel.h"
+
+#include "wxCDMMainFrame.h"
+#include "wxCDMNewPackageDialog.h"
+
+#include "creaDevManagerIds.h"
+#include "images/PkIcon64.xpm"
+
+BEGIN_EVENT_TABLE(wxCDMPackageManagerPanel, wxPanel)
+EVT_BUTTON(ID_BUTTON_PREV, wxCDMPackageManagerPanel::OnBtnReturn)
+EVT_HYPERLINK(ID_LINK_SELECT_PACKAGE, wxCDMPackageManagerPanel::OnLnkPackageSelect)
+EVT_BUTTON(ID_BUTTON_CREATE_PACKAGE, wxCDMPackageManagerPanel::OnBtnCreatePackage)
+EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageManagerPanel::OnBtnEditCMakeLists)
+END_EVENT_TABLE()
+
+wxCDMPackageManagerPanel::wxCDMPackageManagerPanel(
+ wxWindow* parent,
+ modelCDMProject* project,
+ wxWindowID id,
+ const wxString& caption,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style
+)
+{
+ wxCDMPackageManagerPanel::Create(parent, project, id, caption, pos, size, style);
+}
+
+wxCDMPackageManagerPanel::~wxCDMPackageManagerPanel()
+{
+}
+
+bool wxCDMPackageManagerPanel::Create(
+ wxWindow* parent,
+ modelCDMProject* project,
+ wxWindowID id,
+ const wxString& caption,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style
+)
+{
+ wxPanel::Create(parent, id, pos, size, style);
+ this->project = project;
+ CreateControls();
+ return TRUE;
+}
+
+void wxCDMPackageManagerPanel::CreateControls()
+{
+ wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+ //Link to return
+ sizer->Add(new wxButton(this, ID_BUTTON_PREV, wxT("Return to project")), 0, wxALIGN_CENTER | wxALL, 5);
+
+ //Title
+ sizer->Add(new wxStaticText(this, -1, _("Package Management")),0, wxALIGN_CENTER, 0);
+
+ //Image
+ sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
+
+ //Packages
+ wxStaticBox* propertiesBox = new wxStaticBox(this, -1, _T("&Available Packages"));
+ wxStaticBoxSizer* propertiesBoxInnerSizer = new wxStaticBoxSizer(propertiesBox, wxVERTICAL);
+
+ std::vector<modelCDMPackage*> packages = this->project->GetPackages();
+ for (int i = 0; i < packages.size(); i++)
+ {
+ wxHyperlinkCtrl* pPackagelk = new wxHyperlinkCtrl(this,ID_LINK_SELECT_PACKAGE, crea::std2wx(packages[i]->GetName().c_str()), crea::std2wx(packages[i]->GetName().c_str()));
+ propertiesBoxInnerSizer -> Add(pPackagelk, 0, wxALIGN_LEFT | wxALL, 5);
+ }
+
+ sizer -> Add(propertiesBoxInnerSizer, 0, wxEXPAND | wxALL, 10);
+
+ //Actions
+ wxStaticBox* actionsBox = new wxStaticBox(this, -1, _T("&Actions"));
+ wxStaticBoxSizer* actionsBoxInnerSizer = new wxStaticBoxSizer(actionsBox, wxHORIZONTAL);
+ sizer -> Add(actionsBoxInnerSizer, 0, wxEXPAND | wxALL, 10);
+
+ actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_CREATE_PACKAGE, _T("Create Package")), 0, wxALL, 5);
+ actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")), 0, wxALL, 5);
+
+ //Assign sizer
+ actionsBoxInnerSizer->SetSizeHints(this);
+
+ SetSizer(sizer);
+ sizer->SetSizeHints(this);
+}
+
+void wxCDMPackageManagerPanel::OnBtnCreatePackage(wxCommandEvent& event)
+{
+ std::string* result;
+
+ wxCDMNewPackageDialog* dialog = new wxCDMNewPackageDialog(this);
+ long userResponse;
+ userResponse = dialog->ShowModal();
+
+ if(userResponse == wxID_FORWARD)
+ {
+ modelCDMIProjectTreeNode* package = this->project->CreatePackage(
+ crea::wx2std(dialog->GetPackageName()),
+ result,
+ crea::wx2std(dialog->GetPackageAuthor()),
+ crea::wx2std(dialog->GetPackageAuthorEmail()),
+ crea::wx2std(dialog->GetPackageDescription())
+ );
+ if(package == NULL)
+ {
+ std::cout << "error creating package: " << *result << std::endl;
+ wxMessageBox(crea::std2wx(*result),_T("New Package - Error!"),wxOK | wxICON_ERROR);
+ event.Skip();
+ return;
+ }
+ wxMessageBox(crea::std2wx("Package successfully created."),_T("New Package - Success!"),wxOK | wxICON_INFORMATION);
+
+ //refreshing tree and description
+ //send event instead of calling parent to avoid crashing
+
+ ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
+
+ wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
+ newEvent->SetInt(package->GetId());
+ newEvent->SetId(0);
+ wxPostEvent(this->GetParent(), *newEvent);
+ event.Skip();
+ }
+
+ event.Skip();
+}
+
+void wxCDMPackageManagerPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
+{
+ //TODO: implement method
+ std::cerr << "Event OnBtnCreatePackage not implemented" << std::endl;
+ event.Skip();
+}
+
+void wxCDMPackageManagerPanel::OnLnkPackageSelect(wxHyperlinkEvent& event)
+{
+ int packageId = 0;
+ std::vector<modelCDMPackage*> packages = this->project->GetPackages();
+ for (int i = 0; i < packages.size(); i++)
+ {
+ if(packages[i]->GetName() == crea::wx2std(event.GetURL()))
+ {
+ packageId = packages[i]->GetId();
+ break;
+ }
+ }
+
+ wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
+ newEvent->SetInt(packageId);
+ newEvent->SetId(0);
+ wxPostEvent(this->GetParent(), *newEvent);
+
+}
+
+void wxCDMPackageManagerPanel::OnBtnReturn(wxCommandEvent& event)
+{
+ wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
+ newEvent->SetInt(project->GetId());
+ newEvent->SetId(0);
+ wxPostEvent(this->GetParent(), *newEvent);
+}