00001
00002
00003
00004
00005
00006
00007
00008 #ifndef CONFIGWINDOWMODULE_H
00009 #define CONFIGWINDOWMODULE_H
00010
00011 #include "Module.h"
00012
00013 #include "../TableDataStore.h"
00014
00015 #include "OglGui/Button.h"
00016 #include "OglGui/TitledWindow.h"
00017 #include "OglGui/Strut.h"
00018 #include "OglGui/StringSelector.h"
00019 #include "OglGui/TextField.h"
00020
00021 namespace Impala { namespace Application { namespace MediaTable {
00022
00023 class ConfigWindowModule;
00024
00025 class ConfigWindowModuleListener : public ModuleListener {
00026 public:
00027 ConfigWindowModuleListener(std::string type) : ModuleListener(type) {}
00028
00029 virtual void ReleaseConfigWindow() {}
00030 };
00031
00032 class ConfigWindowModule : public Module, public OglGui::CloseWindowListener {
00033 public:
00034 ConfigWindowModule(std::string type, std::string name) : Module(type, name) {
00035 mErrorMessage = 0;
00036 }
00037
00038 void DrawConfigWindow() {
00039 OglGui::TitledWindow* nConfigWindow;
00040 nConfigWindow = new OglGui::TitledWindow(mConfigWindow->GetParent(),
00041 mConfigWindow->GetParent()->W()/2-260,
00042 mConfigWindow->GetParent()->H()/2-195, 520, 390,
00043 "Add new "+GetName(), OglGui::TitledWindow::BtnClose);
00044 nConfigWindow->SetCloseWindowListener(this, 0);
00045 nConfigWindow->SetRoundness(3, 3, 3 ,3);
00046 nConfigWindow->SetBackground(mConfigWindow->GetBackground());
00047 new OglGui::Strut(nConfigWindow, nConfigWindow->W(), 24);
00048
00049 delete mConfigWindow;
00050 mConfigWindow = nConfigWindow;
00051 }
00052
00053 void SetErrorMessage(OglGui::Window* wnd, std::string msg)
00054 {
00055 if(!mErrorMessage)
00056 {
00057 mErrorMessage = new OglGui::StaticText(wnd, wnd->W(), 20, msg);
00058 mErrorMessage->SetForeground(oglRED);
00059 } else {
00060 mErrorMessage->SetText(msg);
00061 }
00062 }
00063
00064 void AddTextField(OglGui::Window* wnd, std::string label, std::string value = "") {
00065 new OglGui::StaticText(wnd, wnd->W(), 20, label);
00066
00067 OglGui::TextField* txtField;
00068 txtField = new OglGui::TextField(wnd, wnd->W(), 24, value);
00069 mTextFields[label] = txtField;
00070 }
00071
00072 void AddSelectorWithTableDataViews(OglGui::Window* wnd, std::string label, std::string view = "", int h = 80)
00073 {
00074 new OglGui::StaticText(wnd, wnd->W(), 20, label);
00075 OglGui::StringSelector* strSel;
00076 strSel = new OglGui::StringSelector(wnd, wnd->W(), h);
00077
00078
00079 int valuesAdded = 0;
00080 std::map<std::string, std::vector<std::string> > contents;
00081 contents = TableDataStore::GetInstance()->GetContents();
00082 for(std::map<std::string, std::vector<std::string> >::iterator it = contents.begin(); it != contents.end(); it++) {
00083 if(view != "") {
00084 strSel->AddString(it->first + ":" + view);
00085 valuesAdded++;
00086 }
00087 for(std::vector<std::string>::iterator itv = it->second.begin(); itv != it->second.end(); itv++) {
00088 strSel->AddString(it->first + ":" + *itv);
00089 valuesAdded++;
00090 }
00091 if(!it->second.size()) {
00092 strSel->AddString(it->first + ":Default");
00093 valuesAdded++;
00094 }
00095 }
00096 if(valuesAdded) {
00097 mStringSelectors[label] = strSel;
00098 } else {
00099 mStringValues[label] = "";
00100 }
00101 }
00102
00103 void AddSelectorWithColumnsOfType(OglGui::Window* wnd, std::string label,
00104 std::string view, int type, bool typeIsFlag = false)
00105 {
00106 std::vector<TableColumn*> mColumnNames = TableDataStore::GetInstance()->GetTableDataView(view)->GetColumns(true, true);
00107 OglGui::StringSelector* strSel;
00108 new OglGui::StaticText(wnd, wnd->W(), 24, label);
00109 strSel = new OglGui::StringSelector(wnd, wnd->W(), 78);
00110 int valuesAdded = 0;
00111 for (std::vector<TableColumn*>::iterator it=mColumnNames.begin(); it!=mColumnNames.end(); ++it) {
00112 if(!typeIsFlag && (*it)->GetType() == type ||
00113 typeIsFlag && (*it)->GetType() & type) {
00114 strSel->AddString((*it)->GetName());
00115 valuesAdded++;
00116 }
00117 }
00118 if(valuesAdded) {
00119 mStringSelectors[label] = strSel;
00120 } else {
00121 mStringValues[label] = "";
00122 }
00123 }
00124
00125 void StoreConfigWindowValues() {
00126 std::map<std::string,OglGui::StringSelector*>::iterator itss;
00127 for(itss = mStringSelectors.begin(); itss != mStringSelectors.end(); ++itss ) {
00128 mStringValues[itss->first] = itss->second->GetCurrentString();
00129 }
00130 std::map<std::string,OglGui::TextField*>::iterator ittf;
00131 for( ittf = mTextFields.begin(); ittf != mTextFields.end(); ++ittf ) {
00132 mStringValues[ittf->first] = ittf->second->GetText();
00133 }
00134 }
00135
00136 void ClearConfigWindowValues()
00137 {
00138 mStringSelectors.clear();
00139 mTextFields.clear();
00140 }
00141
00142 void DoReleaseConfigWindow() {
00143 for (std::vector<ModuleListener*>::iterator it=mListeners.begin() ; it != mListeners.end(); it++ )
00144 ((ConfigWindowModuleListener*) (*it))->ReleaseConfigWindow();
00145 }
00146
00147 bool OnCloseWindow(OglGui::Window *src, void* userData) {
00148 DoReleaseConfigWindow();
00149 return true;
00150 }
00151
00152 OglGui::Window* mConfigWindow;
00153 OglGui::StaticText* mErrorMessage;
00154 std::map<std::string, OglGui::StringSelector*> mStringSelectors;
00155 std::map<std::string, OglGui::TextField*> mTextFields;
00156 std::map<std::string, std::string> mStringValues;
00157 };
00158
00159 } } }
00160
00161 #endif