00001 #ifndef MediaTable_TableFilter_h 00002 #define MediaTable_TableFilter_h 00003 00004 #include "TableFilterUpdateListener.h" 00005 00006 namespace Impala { 00007 namespace Application { 00008 namespace MediaTable { 00009 00010 class TableFilter 00011 { 00012 public: 00013 00014 TableFilter(TableFilterUpdateListener *source, String column) 00015 { 00016 mColumn = column; 00017 mSource = source; 00018 mType = 0; 00019 } 00020 00021 void SetTextFilter(String substring) 00022 { 00023 if (substring == "") 00024 { 00025 Disable(true); 00026 return; 00027 } 00028 ILOG_SYSTEM("SetTextFilter for "<< mColumn << ": " << substring); 00029 mType = 1; 00030 mSubstring = substring; 00031 mSource->ApplyFilters(); 00032 } 00033 00034 std::string GetTextFilter() 00035 { 00036 return mSubstring; 00037 } 00038 00039 void SetValueFilter(double value, bool greaterThen=true) 00040 { 00041 ILOG_SYSTEM("SetValueFilter: " << value << "(gt=" << greaterThen << ")"); 00042 mType = 2; 00043 mValue = value; 00044 mGreaterThen = greaterThen; 00045 mSource->ApplyFilters(); 00046 } 00047 00048 void Disable(bool callApply=true) 00049 { 00050 ILOG_SYSTEM("Filter for "<< mColumn << " disabled"); 00051 mType = 0; 00052 if (callApply) 00053 mSource->ApplyFilters(); 00054 } 00055 00056 bool IsDisabled() 00057 { 00058 return (mType==0); 00059 } 00060 00061 bool IsFilteredByText(String data) 00062 { 00063 if (mType==1) 00064 return data.find(mSubstring,0)==String::npos; 00065 return false; 00066 } 00067 00068 bool IsFilteredByValue(double data) 00069 { 00070 if (mType==2) 00071 { 00072 if (mGreaterThen) 00073 return data > mValue; 00074 else 00075 return data < mValue; 00076 } 00077 return false; 00078 } 00079 00080 String GetColumn() 00081 { 00082 return mColumn; 00083 } 00084 00085 int GetType() 00086 { 00087 return mType; 00088 } 00089 00090 private: 00091 00092 bool mGreaterThen; 00093 int mType; 00094 double mValue; // type 2: lt or gt a value 00095 String mSubstring; // type 1: textual substring search 00096 String mColumn; 00097 00098 TableFilterUpdateListener* mSource; 00099 00100 ILOG_VAR_DEC; 00101 }; 00102 00103 ILOG_VAR_INIT(TableFilter, Application.MediaTable); 00104 00105 } // namespace MediaTable 00106 } // namespace Application 00107 } // namespace Impala 00108 00109 #endif // TableFilter_h