- Implemented possibility to use views provided by one plugin in another plugin
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 26 Jul 2007 17:15:21 +0000 (17:15 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 26 Jul 2007 17:15:21 +0000 (17:15 +0000)
- Alarm viewer integrated into object browser

src/client/console/include/nxmc_api.h
src/client/console/libnxmc/libnxmc.h
src/client/console/libnxmc/nxview.cpp
src/client/console/libnxmc/nxview.h
src/client/console/libnxmc/view.cpp
src/client/console/plugins/AlarmBrowser/alarm_browser.h
src/client/console/plugins/AlarmBrowser/main.cpp
src/client/console/plugins/AlarmBrowser/rc/AlarmBrowser.xrc
src/client/console/plugins/AlarmBrowser/view.cpp
src/client/console/plugins/ObjectBrowser/objview.cpp

index 570ccb0..5bee05d 100644 (file)
@@ -293,6 +293,13 @@ WX_DECLARE_HASH_MAP(DWORD, NXC_ALARM*, wxIntegerHash, wxIntegerEqual, nxAlarmLis
 #include "../libnxmc/heading.h"
 
 
+//
+// View creator callback type
+//
+
+typedef nxView* (*nxViewCreator)(wxWindow *, const TCHAR *, NXC_OBJECT *, void *);
+
+
 //
 // Functions
 //
@@ -319,6 +326,11 @@ void LIBNXMC_EXPORTABLE UnregisterUniqueView(const TCHAR *name);
 nxView LIBNXMC_EXPORTABLE *FindUniqueView(const TCHAR *name);
 void LIBNXMC_EXPORTABLE ActivateView(nxView *view);
 
+void LIBNXMC_EXPORTABLE NXMCRegisterViewCreator(const TCHAR *viewClass, nxViewCreator func);
+nxView LIBNXMC_EXPORTABLE *NXMCCreateViewByClass(const TCHAR *viewClass, wxWindow *parent,
+                                                 const TCHAR *context, NXC_OBJECT *object,
+                                                 void *userData);
+
 const TCHAR LIBNXMC_EXPORTABLE *NXMCCodeToText(int code, CODE_TO_TEXT *translator, const TCHAR *defaultText);
 const TCHAR LIBNXMC_EXPORTABLE *NXMCGetStatusText(int status);
 const TCHAR LIBNXMC_EXPORTABLE *NXMCGetStatusTextSmall(int status);
index 775f68a..5efeb4e 100644 (file)
@@ -57,6 +57,7 @@
 //
 
 WX_DECLARE_STRING_HASH_MAP(nxView*, nxViewHash);
+WX_DECLARE_STRING_HASH_MAP(nxViewCreator, nxViewCreatorsHash);
 
 
 //
index 1b5672f..6b807f4 100644 (file)
@@ -48,7 +48,7 @@ END_EVENT_TABLE()
 nxView::nxView(wxWindow *parent)
        : wxWindow(parent, wxID_ANY,  wxDefaultPosition, wxDefaultSize)
 {
-       m_icon = wxNullBitmap;
+       m_icon = wxNullIcon;
        m_timer = new wxTimer(this, RQ_TIMER_ID);
        m_activeRequestCount = 0;
        m_freeRqId = 0;
@@ -232,3 +232,12 @@ void nxView::RequestCompletionHandler(int rqId, DWORD rcc)
 {
 }
 
+
+//
+// Virtual refresh view method
+//
+
+void nxView::RefreshView()
+{
+}
+
index 47f0c23..13a3be7 100644 (file)
@@ -57,8 +57,8 @@ class LIBNXMC_EXPORTABLE nxView : public wxWindow
 {
 private:
        wxString m_label;
-       wxBitmap m_icon;        // Icon associated with this view
        wxTimer *m_timer;
+       wxIcon m_icon;  // Icon associated with this view
        int m_activeRequestCount;
        int m_freeRqId; // First free request id
        bool m_isBusy;
@@ -66,6 +66,7 @@ private:
        int DoRequest(RqData *data);
        
 protected:
+       
        int DoRequestArg1(void *func, wxUIntPtr arg1);
        int DoRequestArg2(void *func, wxUIntPtr arg1, wxUIntPtr arg2);
        int DoRequestArg3(void *func, wxUIntPtr arg1, wxUIntPtr arg2, wxUIntPtr arg3);
@@ -78,11 +79,14 @@ public:
 
        virtual void SetLabel(const wxString& label);
        virtual wxString GetLabel() const;
+       
+       virtual void RefreshView();
 
-       const wxBitmap& GetBitmap() { return m_icon; }
+       void SetIcon(const wxIcon &icon) { m_icon = icon; }
+       const wxIcon& GetIcon() { return m_icon; }
        
        bool IsBusy() { return m_isBusy; }
-
+       
        // Event handlers
 protected:
        void OnTimer(wxTimerEvent &event);
index b409ba1..8304d23 100644 (file)
 #include "libnxmc.h"
 
 
+//
+// Static data
+//
+
+static nxViewCreatorsHash s_viewCreators;
+
+
 //
 // Create view in given area
 //
@@ -37,7 +44,7 @@ bool LIBNXMC_EXPORTABLE NXMCCreateView(nxView *view, int area)
        {
                case VIEWAREA_MAIN:
                        view->Reparent(g_auiNotebook);
-                       g_auiNotebook->AddPage(view, view->GetLabel(), true, view->GetBitmap());
+                       g_auiNotebook->AddPage(view, view->GetLabel(), true, view->GetIcon());
                        break;
                case VIEWAREA_DOCKED:
                        g_auiManager->AddPane(view, wxAuiPaneInfo().Name(view->GetName()).Caption(view->GetLabel()));
@@ -53,3 +60,29 @@ bool LIBNXMC_EXPORTABLE NXMCCreateView(nxView *view, int area)
        }
        return true;
 }
+
+
+//
+// Register view creator
+//
+
+void LIBNXMC_EXPORTABLE NXMCRegisterViewCreator(const TCHAR *viewClass, nxViewCreator func)
+{
+       s_viewCreators[viewClass] = func;
+}
+
+
+//
+// Create view provided by plugin or main app by class name
+//
+
+nxView LIBNXMC_EXPORTABLE *NXMCCreateViewByClass(const TCHAR *viewClass, wxWindow *parent,
+                                                 const TCHAR *context, NXC_OBJECT *object,
+                                                 void *userData)
+{
+       nxViewCreatorsHash::iterator it;
+               
+       it = s_viewCreators.find(viewClass);
+       return (it == s_viewCreators.end()) ? NULL : it->second(parent, context, object, userData);
+}
+
index b8eab06..4397888 100644 (file)
@@ -41,16 +41,18 @@ private:
        long m_sortMode;
        long m_sortDir;
        wxString m_context;
+       NXC_OBJECT *m_object;
 
        void AddAlarm(NXC_ALARM *alarm);
        void UpdateAlarm(long item, NXC_ALARM *alarm);
        void SortAlarmList();
+       bool MatchAlarm(NXC_ALARM *pAlarm);
 
 public:
-       nxAlarmView(wxWindow *parent, const TCHAR *context);
+       nxAlarmView(wxWindow *parent, const TCHAR *context, NXC_OBJECT *object = NULL);
        virtual ~nxAlarmView();
 
-       void RefreshView();
+       virtual void RefreshView();
 
        // Event handlers
 protected:
index ef5e001..4dba4bd 100644 (file)
@@ -63,6 +63,16 @@ extern "C" void NXMC_PLUGIN_EXPORT nxmcCommandHandler(int cmd)
 NXMC_IMPLEMENT_PLUGIN_REGISTRATION(_T("AlarmBrowser"), NETXMS_VERSION_STRING, NXMC_IP_MAIN_MENU)
 
 
+//
+// Alarm view creator
+//
+
+static nxView *CreateAlarmView(wxWindow *parent, const TCHAR *context, NXC_OBJECT *object, void *userData)
+{
+       return new nxAlarmView(parent, context, object);
+}
+
+
 //
 // Initialization function
 //
@@ -72,6 +82,7 @@ extern "C" bool NXMC_PLUGIN_EXPORT nxmcInitializePlugin(NXMC_PLUGIN_HANDLE handl
        if (!NXMCLoadResources(_T("AlarmBrowser.xrs"), NXMC_LIB_INSTANCE_ARG(s_libInstance), wxMAKEINTRESOURCE(IDR_XRS)))
                wxLogWarning(_T("AlarmBrowser: cannot load resource file"));
        NXMCAddViewMenuItem(handle, _T("&Alarm Browser\tF8"), 0);
+       NXMCRegisterViewCreator(_T("AlarmView"), CreateAlarmView);
        return true;
 }
 
index c470eac..02ae9db 100644 (file)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 <resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
+       <object class="wxIcon" name="icoAlarmView">alarmview.xpm</object>
        <object class="wxMenu" name="menuCtxAlarm">
                <label>Alarm</label>
                <object class="wxMenuItem" name="menuAlarmAck">
index 014e658..c60b541 100644 (file)
@@ -42,13 +42,14 @@ END_EVENT_TABLE()
 // Constructor
 //
 
-nxAlarmView::nxAlarmView(wxWindow *parent, const TCHAR *context)
+nxAlarmView::nxAlarmView(wxWindow *parent, const TCHAR *context, NXC_OBJECT *object)
             : nxView(parent)
 {
        wxConfigBase *cfg = wxConfig::Get();
        wxString path = cfg->GetPath();
 
        m_context = context;
+       m_object = object;
 
        cfg->SetPath(m_context);
        cfg->Read(_T("AlarmView/SortMode"), &m_sortMode, 0);
@@ -73,6 +74,8 @@ nxAlarmView::nxAlarmView(wxWindow *parent, const TCHAR *context)
        NXMCLoadListCtrlColumns(cfg, *m_wndListCtrl, _T("AlarmView"));
 
        cfg->SetPath(path);
+       
+       SetIcon(wxXmlResource::Get()->LoadIcon(_T("icoAlarmView")));
 
        NXMCEvtConnect(nxEVT_NXC_ALARM_CHANGE, wxCommandEventHandler(nxAlarmView::OnAlarmChange), this);
 }
@@ -121,7 +124,8 @@ void nxAlarmView::RefreshView()
        
        for(it = list->begin(); it != list->end(); it++)
        {
-               AddAlarm(it->second);
+               if (MatchAlarm(it->second))
+                       AddAlarm(it->second);
        }
 
        NXMCUnlockAlarmList();
@@ -130,6 +134,21 @@ void nxAlarmView::RefreshView()
 }
 
 
+//
+// Check if alarm matched to current filter settings
+//
+
+bool nxAlarmView::MatchAlarm(NXC_ALARM *alarm)
+{
+       if (m_object == NULL)
+               return true;
+printf("MATCHING against %s\n", m_object->szName);             
+       if (m_object->dwId == alarm->dwSourceObject)
+               return true;
+       return NXCIsParent(NXMCGetSession(), m_object->dwId, alarm->dwSourceObject);
+}
+
+
 //
 // Add alarm to view
 //
@@ -296,25 +315,31 @@ void nxAlarmView::OnListColumnClick(wxListEvent &event)
 void nxAlarmView::OnAlarmChange(wxCommandEvent &event)
 {
        long item;
+       NXC_ALARM *alarm;
        
+       alarm = (NXC_ALARM *)event.GetClientData();
        switch(event.GetInt())
        {
                case NX_NOTIFY_NEW_ALARM:
                case NX_NOTIFY_ALARM_CHANGED:
-                       item = m_wndListCtrl->FindItem(-1, ((NXC_ALARM *)event.GetClientData())->dwAlarmId);
+                       item = m_wndListCtrl->FindItem(-1, alarm->dwAlarmId);
                        if (item != -1)
                        {
-                               UpdateAlarm(item, (NXC_ALARM *)event.GetClientData());
+                               if (MatchAlarm(alarm))
+                                       UpdateAlarm(item, (NXC_ALARM *)event.GetClientData());
+                               else
+                                       m_wndListCtrl->DeleteItem(item);                // Alarm no longer match filter
                        }
                        else
                        {
-                               AddAlarm((NXC_ALARM *)event.GetClientData());
+                               if (MatchAlarm(alarm))
+                                       AddAlarm(alarm);
                        }
                        SortAlarmList();
                        break;
                case NX_NOTIFY_ALARM_TERMINATED:
                case NX_NOTIFY_ALARM_DELETED:
-                       item = m_wndListCtrl->FindItem(-1, ((NXC_ALARM *)event.GetClientData())->dwAlarmId);
+                       item = m_wndListCtrl->FindItem(-1, alarm->dwAlarmId);
                        if (item != -1)
                                m_wndListCtrl->DeleteItem(item);
                        break;
index 484ef05..81a7afa 100644 (file)
@@ -94,6 +94,8 @@ void nxObjectView::OnPaint(wxPaintEvent &event)
 
 void nxObjectView::SetObject(NXC_OBJECT *object)
 {
+       nxView *view;
+       
        m_object = object;
        RefreshRect(wxRect(0, 0, GetClientSize().x, m_headerOffset), false);
 
@@ -105,5 +107,18 @@ void nxObjectView::SetObject(NXC_OBJECT *object)
        m_notebook->AddPage(new nxObjectOverview(m_notebook, object), _T("Overview"), false,
                            wxXmlResource::Get()->LoadIcon(_T("icoSmallInformation")));
 
+       if ((object->iClass == OBJECT_NETWORK) || (object->iClass == OBJECT_SUBNET) ||
+           (object->iClass == OBJECT_NODE) || (object->iClass == OBJECT_SERVICEROOT) ||
+           (object->iClass == OBJECT_CONTAINER) || (object->iClass == OBJECT_ZONE))
+       {
+               view = NXMCCreateViewByClass(_T("AlarmView"), m_notebook, _T("ObjectBrowser"), object, NULL);
+               if (view != NULL)
+               {
+                       m_notebook->AddPage(view, _T("Alarms"), false, view->GetIcon());
+                       view->RefreshView();
+               }
+       }
+
        Thaw();
 }
+