00001 #ifndef MediaTable_TableWindowColumn_h
00002 #define MediaTable_TableWindowColumn_h
00003
00004 #include "TableDataView.h"
00005 #include "TableWindowCell.h"
00006 #include "ColumnListener.h"
00007
00008 #include "OglGui/DirectionButton.h"
00009 #include "OglGui/TextField.h"
00010 #include "OglGui/StaticText.h"
00011 #include "OglGui/MenuOnButton.h"
00012 #include "OglGui/TitledWindow.h"
00013 #include "OglGui/CheckBox.h"
00014 #include "OglGui/StaticText.h"
00015
00016 namespace Impala {
00017 namespace Application {
00018 namespace MediaTable {
00019
00020
00021
00022 class TableWindowColumn : public OglGui::SizableWindow,
00023 OglGui::TextFieldListener,
00024 OglGui::ButtonListener,
00025 OglGui::MenuListener,
00026 OglGui::WindowListener,
00027 OglGui::CloseWindowListener,
00028 OglGui::CheckBoxListener,
00029 TableDataViewListener
00030 {
00031 public:
00032 typedef OglGui::SizableWindow SizableWindow;
00033 typedef OglGui::TitledWindow TitledWindow;
00034 typedef OglGui::Window Window;
00035 typedef OglGui::Button Button;
00036 typedef OglGui::DirectionButton DirectionButton;
00037 typedef OglGui::CheckBox CheckBox;
00038 typedef OglGui::TextField TextField;
00039 typedef OglGui::MenuOnButton MenuOnButton;
00040 typedef OglGui::MenuTopPane MenuTopPane;
00041 typedef OglGui::Menu Menu;
00042 typedef OglGui::StaticText StaticText;
00043
00044
00045 const static int BTN_CONFIGURE = 1;
00046 const static int BTN_SORT = 2;
00047 const static int BTN_APPLY_FILTER = 3;
00048 const static int BTN_REMOVE_FILTER = 4;
00049
00050 TableWindowColumn(Window *parent, ColumnListener *l, TableDataView *source,
00051 CString name, int width=120) :
00052 SizableWindow(parent, width, parent->H())
00053 {
00054 ConnectTo(parent, OglGui::T2T | OglGui::B2B);
00055 Init(name, parent, l, source, width, parent->H());
00056 }
00057
00058 void SetDisplayMode(int mode, int attr=TableWindowCell::NONE)
00059 {
00060 ILOG_DEBUG("SetDisplayMode: " << mode);
00061 mDisplayMode = mode;
00062 mDisplayAttr = attr;
00063 switch (mode)
00064 {
00065 case TableWindowCell::DISPLAY_TEXT:
00066
00067
00068 break;
00069 case TableWindowCell::DISPLAY_NUMBER:
00070
00071
00072 break;
00073 case TableWindowCell::DISPLAY_IMAGE:
00074 if (!mCache)
00075 mCache = new TableViewCache(this, mSource);
00076
00077
00078 mSortButton->SetVisible(false);
00079 break;
00080 case TableWindowCell::DISPLAY_DOT:
00081 case TableWindowCell::DISPLAY_FILLED:
00082
00083
00084 break;
00085 }
00086 mSource->DoUpdateRowsEvent();
00087 }
00088
00089 int GetDisplayMode() {
00090 return mDisplayMode;
00091 }
00092
00093 void SetSortType(int type) {
00094 mSortType = type;
00095 }
00096
00097 TableViewCache* GetViewCache()
00098 {
00099 return mCache;
00100 }
00101
00102 virtual void DisplayFunc()
00103 {
00104 if (mCache && mCache->ProcessDelayLoad())
00105 {
00106 mSource->DoUpdateRowsEvent();
00107 }
00108 Window::DisplayFunc();
00109 }
00110
00111 virtual void ButtonSelectionEvent(Button *src, void* userData)
00112 {
00113 switch ((long long) userData)
00114 {
00115 case BTN_CONFIGURE:
00116 OpenConfigWindow();
00117 break;
00118 case BTN_SORT:
00119 DoSort();
00120 break;
00121 case BTN_APPLY_FILTER:
00122 mConfigWindow->OnCloseButton();
00123 break;
00124 case BTN_REMOVE_FILTER:
00125 mFilter->Disable();
00126 mConfigWindow->OnCloseButton();
00127 break;
00128 }
00129 }
00130
00131 void
00132 DoSort()
00133 {
00134 int t = 0;
00135 if (mDisplayMode == TableWindowCell::DISPLAY_TEXT ||
00136 mDisplayMode == TableWindowCell::DISPLAY_NUMBER)
00137 t = TableDataSource::TYPE_TEXT;
00138 if (mDisplayMode == TableWindowCell::DISPLAY_DOT ||
00139 mDisplayMode == TableWindowCell::DISPLAY_FILLED)
00140 t = TableDataSource::TYPE_NORMALIZEDVALUE;
00141 if (mSortType > 0)
00142 t = mSortType;
00143 if (t == 0) return;
00144
00145 if (mSource->GetSortColumn() == mColumnName)
00146 mSource->SetSortColumn(mColumnName,!mSource->GetSortAscending());
00147 else
00148 mSource->SetSortColumn(mColumnName);
00149 }
00150
00151 virtual bool OnCloseWindow(Window *src, void* userData)
00152 {
00153 ReleaseConfigWindow();
00154 return true;
00155 }
00156
00157
00158 static int GetHeaderHeight()
00159 {
00160 return sHeaderHeight;
00161 }
00162
00163 static bool GetUpdatingColumnWidths()
00164 {
00165 return sUpdatingColumnWidths;
00166 }
00167
00168 static void SetUpdatingColumnWidths(bool value)
00169 {
00170 sUpdatingColumnWidths = value;
00171 }
00172
00173 int GetColumnWidth()
00174 {
00175 return mColWidth;
00176 }
00177
00178 void SetColumnWidthDynamic(bool value)
00179 {
00180 mColWidthDynamic = value;
00181 }
00182
00183 bool GetColumnWidthDynamic()
00184 {
00185 return mColWidthDynamic;
00186 }
00187
00188 void ResetFilter(bool callEvents=true)
00189 {
00190 switch (mDisplayMode)
00191 {
00192 case TableWindowCell::DISPLAY_TEXT:
00193 if(mFilterTextField && mMenuTopPane && mMenuTopPane->GetVisible())
00194 mFilterTextField->SetText("");
00195 mFilter->Disable(callEvents);
00196 break;
00197 case TableWindowCell::DISPLAY_DOT:
00198 case TableWindowCell::DISPLAY_FILLED:
00199 if(mFilterValueButton && mMenuTopPane && mMenuTopPane->GetVisible())
00200 mFilterValueButton->SetText("Filter");
00201 mFilter->Disable(callEvents);
00202 break;
00203 }
00204
00205 UpdateHeader();
00206 }
00207
00208 TableWindowCell *GetCell(int index)
00209 {
00210 if (index >= mCellCache.size())
00211 {
00212 TableWindowCell *c = new TableWindowCell(this, mSource, mCache, mColumnName);
00213 oglSys.SetNoMouseInput(c->GetOGLWND(),1);
00214 mCellCache.push_back(c);
00215 return c;
00216 }
00217 return mCellCache[index];
00218 }
00219
00220 void HideCellsFrom(int index) {
00221
00222 for (int i=index; i<mCellCache.size(); i++)
00223 mCellCache[i]->SetVisible(false);
00224 }
00225
00226 private:
00227
00228 virtual void UpdateSortEvent(String col, bool ascending)
00229 {
00230
00231 if (mColumnName == col)
00232 {
00233 ILOG_SYSTEM("sorting on " << col << " asc: " << ascending);
00234 mSortButton->SetFilled(true);
00235 mColumnHeaderButton->SetPressed(true);
00236 mSortButton->SetDirection(ascending ? 3 : 1);
00237 mSortButton->SetVisible(true);
00238 mIsActiveSortColumn = true;
00239 }
00240 else
00241 {
00242 mSortButton->SetFilled(false);
00243 mColumnHeaderButton->SetPressed(false);
00244 mSortButton->SetDirection(3);
00245 mSortButton->SetVisible(false);
00246 mIsActiveSortColumn = false;
00247 }
00248 }
00249
00250
00251
00252
00253 void OpenConfigWindow()
00254 {
00255
00256 int zx = 0;
00257 int zy = 6;
00258
00259 if (mMenuTopPane)
00260
00261 delete mMenuTopPane;
00262 MenuTopPane* top = mMenuTopPane = new MenuTopPane(this);
00263
00264 oglSys.VPToTopWndI(mColumnHeader->GetOGLWND(),&zx,&zy);
00265 oglSys.TopWndToVPI(top->GetOGLWND(),&zx,&zy);
00266
00267 if(zx+320 > GetParent()->W())
00268 zx = GetParent()->W()-320;
00269
00270 mConfigWindow = new TitledWindow(top, zx, zy-120, 320, 120,
00271 "Filter on column " + mColumnName,
00272 TitledWindow::BtnClose);
00273
00274 mConfigWindow->SetAllowMoveDirections(TitledWindow::AllDir,false);
00275 mConfigWindow->SetAllowSizeDirections(TitledWindow::AllDir,false);
00276 mConfigWindow->SetToFrontOnMouseDown(false);
00277 mConfigWindow->SetBackground(0xddffffff);
00278 mConfigWindow->SetRoundness(0, 0, 0 ,0);
00279 mConfigWindow->SetCloseWindowListener(this, 0);
00280 top->Open();
00281
00282 mFilterTextField = new TextField(mConfigWindow, 10, 50, 280, 20, "");
00283 mFilterTextField->SetTextFieldListener(this, 0);
00284 mFilterTextField->ConnectTo(mConfigWindow, OglGui::TOTOP | OglGui::TOLEFTRIGHT);
00285
00286 mFilterHelpAsc = new StaticText(mConfigWindow, 10, 70, 280, 20, "Enter lowest number to show");
00287 mFilterAscButton = new CheckBox(mConfigWindow,280-120, 30, 120, 20, "invert filter", false);
00288 mFilterAscButton->ConnectTo(mConfigWindow,OglGui::TOTOP | OglGui::TOLEFTRIGHT);
00289 mFilterAscButton->SetVisible(false);
00290 mFilterAscButton->SetCheckBoxListener(this, 0);
00291
00292 Menu *filterMenu = new Menu(top, 1, 120);
00293 filterMenu->AddItem("filter " + mColumnName, 0);
00294 filterMenu->SetOptions(0, Menu::SEPARATOR, true);
00295 filterMenu->AddItem("strong match", 2);
00296 filterMenu->AddItem("less strong", 3);
00297 filterMenu->AddItem("weak match", 4);
00298 filterMenu->AddItem("very weak match", 5);
00299 filterMenu->AddItem("everything", 9);
00300
00301 filterMenu->SetMenuListener(this, 0);
00302
00303 mFilterValueButton =
00304 new MenuOnButton(mConfigWindow, 10, 60, 280, 20, "Filter", filterMenu);
00305 mFilterValueButton->ConnectTo(mConfigWindow, OglGui::TOTOP|OglGui::TOLEFTRIGHT);
00306
00307 Button *apply = new Button(mConfigWindow, 200, 10, 100, 20, "Apply filter");
00308 Button *disable = new Button(mConfigWindow, 80, 10, 100, 20, "Remove filter");
00309 apply->SetButtonListener(this, BTN_APPLY_FILTER);
00310 disable->SetButtonListener(this, BTN_REMOVE_FILTER);
00311
00312
00313 mFilterHelpAsc->SetVisible(false);
00314 mFilterAscButton->SetVisible(false);
00315 switch (mDisplayMode)
00316 {
00317 case TableWindowCell::DISPLAY_TEXT:
00318 mFilterTextField->SetVisible(true);
00319 mFilterTextField->SetText(mFilter->GetTextFilter());
00320 mFilter->SetTextFilter(mFilterTextField->GetText());
00321 mFilterValueButton->SetVisible(false);
00322 break;
00323 case TableWindowCell::DISPLAY_NUMBER:
00324 mFilterTextField->SetVisible(true);
00325 mFilterTextField->SetText(mFilter->GetTextFilter());
00326 mFilter->SetTextFilter(mFilterTextField->GetText());
00327 mFilterValueButton->SetVisible(false);
00328 mFilterHelpAsc->SetVisible(true);
00329 mFilterAscButton->SetVisible(true);
00330 break;
00331 case TableWindowCell::DISPLAY_IMAGE:
00332 mFilterTextField->SetVisible(false);
00333 mFilterValueButton->SetVisible(false);
00334 break;
00335 case TableWindowCell::DISPLAY_DOT:
00336 case TableWindowCell::DISPLAY_FILLED:
00337 mFilterTextField->SetVisible(false);
00338 mFilterValueButton->SetVisible(true);
00339 break;
00340 }
00341 if (mFilterTextField->GetVisible())
00342 oglFocusWnd = mFilterTextField->GetOGLWND();
00343
00344
00345
00346
00347
00348
00349 return;
00350 }
00351
00352 void ReleaseConfigWindow()
00353 {
00354
00355 if (mMenuTopPane)
00356 mMenuTopPane->Hide();
00357
00358 UpdateHeader();
00359
00360
00361
00362 }
00363
00364
00365
00366
00367
00368
00369
00370 virtual void
00371 TextFieldChangedEvent(TextField *src, void* userData)
00372 {
00373
00374 if (mDisplayMode == TableWindowCell::DISPLAY_TEXT)
00375 mFilter->SetTextFilter(src->GetText());
00376
00377 if (mDisplayMode == TableWindowCell::DISPLAY_NUMBER)
00378 {
00379 bool asc = mFilterAscButton->GetSelected();
00380 int number = atoi(src->GetText());
00381 ILOG_DEBUG("number = " << number << " asc= " << asc);
00382 mFilter->SetValueFilter(number, asc);
00383 }
00384
00385 UpdateHeader();
00386 }
00387
00388
00389 virtual void CheckBoxEvent(CheckBox *src, bool checked, void* userData)
00390 {
00391 if (src == mFilterAscButton)
00392 TextFieldChangedEvent(mFilterTextField, 0);
00393 }
00394
00395
00396 virtual void OnMenuItem(Menu *src, int menuIdx, String itemName,
00397 int itemIdx, void *userData)
00398 {
00399 ILOG_DEBUG("Selected option " << itemIdx << " menuIdx " << menuIdx <<
00400 " itemName " << itemName);
00401
00402 switch (itemIdx)
00403 {
00404 case 1:
00405 mFilter->SetValueFilter(0.95, false);
00406
00407 break;
00408 case 2:
00409 mFilter->SetValueFilter(0.90, false);
00410
00411 break;
00412 case 3:
00413 mFilter->SetValueFilter(0.80, false);
00414
00415 break;
00416 case 4:
00417 mFilter->SetValueFilter(0.70, false);
00418
00419 break;
00420 case 5:
00421 mFilter->SetValueFilter(0.50, false);
00422
00423 break;
00424 case 6:
00425 mFilter->SetValueFilter(0.50, true);
00426
00427 break;
00428 case 7:
00429 mFilter->SetValueFilter(0.20, false);
00430
00431 break;
00432 case 8:
00433 mFilter->SetValueFilter(0.10, false);
00434
00435 break;
00436 case 9:
00437 mFilter->Disable();
00438
00439 break;
00440 }
00441 UpdateHeader();
00442 }
00443
00444 virtual void
00445 WindowReshapeEvent(Window *source, int w, int h, void *userData)
00446 {
00447 if (userData == (void*) 2 && !GetUpdatingColumnWidths())
00448 {
00449 ILOG_USER("Manual reshape of column " << mColumnName << ": " << w << " x " << h);
00450 if (w < 20)
00451 mColWidthDynamic = true;
00452 else
00453 mColWidthDynamic = false;
00454 SetDimensions(RETAIN, RETAIN, w, RETAIN);
00455 mColumnListener->ColumnWidthUpdated();
00456 }
00457 }
00458
00459
00460 virtual void
00461 WindowMouseEvent(Window *src, int msg, int but, int state,
00462 int x, int y, void *userData )
00463 {
00464 if (userData == (void*) 2 && (x < mColumnHeaderButton->W()-2))
00465 mColumnHeaderButton->MouseFunc(msg, but, state, x, y);
00466 if (userData == (void*) 1)
00467 {
00468 if (msg == oglMouseEnter)
00469 mSortButton->SetVisible(true);
00470 if (msg == oglMouseLeave)
00471 {
00472 if (!mIsActiveSortColumn)
00473 mSortButton->SetVisible(false);
00474 }
00475 }
00476 }
00477
00478 void
00479 UpdateHeader()
00480 {
00481 if (mFilter->IsDisabled())
00482 {
00483 mColumnHeaderButton->SetBackground(0xffffddee);
00484 }
00485 else
00486 {
00487 mColumnHeaderButton->SetBackground(0xffbbbbff);
00488 }
00489 }
00490
00491 void
00492 Init(String name, Window *parent, ColumnListener *l, TableDataView *source, int w, int h)
00493 {
00494 mSource = source;
00495 mColumnName = name;
00496 mCache = 0;
00497 mDisplayMode = TableWindowCell::DISPLAY_TEXT;
00498 mDisplayAttr = TableWindowCell::NONE;
00499 mColumnListener = l;
00500 mIsActiveSortColumn = false;
00501
00502
00503 mSource->AddTableDataViewListener(this);
00504
00505
00506 oglSys.SetNoMouseInput(GetOGLWND(),1);
00507
00508 mColumnHeader = new SizableWindow(this, 0, h-20, w, 20);
00509 mColumnHeader->ConnectTo(this, OglGui::TOTOP| OglGui::TOLEFTRIGHT);
00510
00511 mColumnHeader->SetAllowMoveDirections(SizableWindow::AllDir, false);
00512 mColumnHeader->SetAllowSizeDirections(SizableWindow::AllDir, false);
00513 mColumnHeader->SetAllowSizeDirections(SizableWindow::East, true);
00514 mColumnHeader->SetMoveCursor(oglCursorE);
00515 mColumnHeader->SetMoveFeedback(false);
00516 mColumnHeader->SetDoStateFeedback(false);
00517 mColumnHeader->SetBorderType(0);
00518 mColumnHeader->SetMinMaxSizes(10, 600, RETAIN, RETAIN);
00519 mColumnHeader->SetWindowListener(this, 2);
00520
00521 mColumnHeaderButton = new Button(mColumnHeader,0,0,w,20,name,4,true);
00522 mColumnHeaderButton->SetAlign(oglLeftAlign);
00523 mColumnHeaderButton->SetAlignOffsets(4,0);
00524 mColumnHeaderButton->ConnectTo(mColumnHeader, OglGui::TOTOP| OglGui::TOLEFTRIGHT);
00525 mColumnHeaderButton->SetButtonListener(this, BTN_CONFIGURE);
00526 mColumnHeaderButton->SetBackground(0xffffddee);
00527 mColumnHeaderButton->SetWindowListener(this, 1);
00528 mColumnHeaderButton->SetNoMouseInput(true);
00529
00530 mSortButton = new DirectionButton(mColumnHeaderButton,w-18,2,16,16,3,-1);
00531 mSortButton->SetBackground(0xffffddee);
00532 mSortButton->ConnectTo(mColumnHeaderButton,OglGui::TORIGHT);
00533 mSortButton->SetButtonListener(this, BTN_SORT);
00534 mSortButton->SetWindowListener(this, 1);
00535 mSortButton->SetVisible(false);
00536
00537
00538
00539 mFilterTextField = 0;
00540 mFilterValueButton = 0;
00541
00542 mFilter = new TableFilter(mSource, mColumnName);
00543 mSource->RegisterFilter(mFilter);
00544
00545 mColWidth = w;
00546 mColWidthDynamic = false;
00547 mMenuTopPane = 0;
00548
00549 }
00550
00551 public:
00552 static bool sUpdatingColumnWidths;
00553 static int sHeaderHeight;
00554 int mDisplayMode;
00555 int mDisplayAttr;
00556
00557 private:
00558 bool mColWidthDynamic;
00559 int mSortType;
00560 int mColWidth;
00561 bool mIsActiveSortColumn;
00562
00563 String mColumnName;
00564
00565 TableDataView* mSource;
00566 TableViewCache* mCache;
00567 TableFilter* mFilter;
00568 std::vector<TableWindowCell*> mCellCache;
00569
00570 SizableWindow* mColumnHeader;
00571 Button* mColumnHeaderButton;
00572
00573 TitledWindow* mConfigWindow;
00574 DirectionButton* mSortButton;
00575 TextField* mFilterTextField;
00576 MenuTopPane* mMenuTopPane;
00577 MenuOnButton* mFilterValueButton;
00578 StaticText* mFilterHelpAsc;
00579 CheckBox* mFilterAscButton;
00580
00581 ColumnListener* mColumnListener;
00582
00583 ILOG_VAR_DEC;
00584 };
00585
00586 ILOG_VAR_INIT(TableWindowColumn, Application.MediaTable);
00587
00588 int TableWindowColumn::sHeaderHeight = 20;
00589 bool TableWindowColumn::sUpdatingColumnWidths = false;
00590
00591 }
00592 }
00593 }
00594
00595 #endif // TableWindowColumn_h