- Alarm browser added to wx console
[public/netxms.git] / src / client / console / plugins / AlarmBrowser / view.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Portable management console - Alarm Browser plugin
4 ** Copyright (C) 2007 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** File: view.cpp
21 **
22 **/
23
24 #include "alarm_browser.h"
25
26
27 //
28 // Event table
29 //
30
31 BEGIN_EVENT_TABLE(nxAlarmView, wxWindow)
32 EVT_SIZE(nxAlarmView::OnSize)
33 EVT_LIST_ITEM_RIGHT_CLICK(wxID_LIST_CTRL, nxAlarmView::OnListItemRightClick)
34 END_EVENT_TABLE()
35
36
37 //
38 // Constructor
39 //
40
41 nxAlarmView::nxAlarmView(wxWindow *parent)
42 : wxWindow(parent, wxID_ANY)
43 {
44 m_wndListCtrl = new wxListCtrl(this, wxID_LIST_CTRL, wxDefaultPosition, wxDefaultSize,
45 wxLC_REPORT | wxLC_HRULES | wxLC_VRULES);
46 m_wndListCtrl->InsertColumn(0, _T("Severity"), wxLIST_FORMAT_LEFT, 70);
47 m_wndListCtrl->InsertColumn(1, _T("State"), wxLIST_FORMAT_LEFT, 70);
48 m_wndListCtrl->InsertColumn(2, _T("Source"), wxLIST_FORMAT_LEFT, 120);
49 m_wndListCtrl->InsertColumn(3, _T("Message"), wxLIST_FORMAT_LEFT, 200);
50 m_wndListCtrl->InsertColumn(4, _T("Count"), wxLIST_FORMAT_LEFT, 40);
51 m_wndListCtrl->InsertColumn(5, _T("Created"), wxLIST_FORMAT_LEFT, 70);
52 m_wndListCtrl->InsertColumn(6, _T("Last Change"), wxLIST_FORMAT_LEFT, 70);
53 wxImageList *imgList = NXMCGetImageListCopy(IMAGE_LIST_STATUS_SMALL);
54 imgList->Add(wxXmlResource::Get()->LoadIcon(_T("icoSmallOutstanding")));
55 imgList->Add(wxXmlResource::Get()->LoadIcon(_T("icoSmallAcknowledged")));
56 imgList->Add(wxXmlResource::Get()->LoadIcon(_T("icoSmallTerminated")));
57 m_wndListCtrl->AssignImageList(imgList, wxIMAGE_LIST_SMALL);
58 }
59
60
61 //
62 // Resize handler
63 //
64
65 void nxAlarmView::OnSize(wxSizeEvent &event)
66 {
67 wxSize size = GetClientSize();
68 m_wndListCtrl->SetSize(0, 0, size.x, size.y);
69 }
70
71
72 //
73 // Refresh view
74 //
75
76 void nxAlarmView::RefreshView()
77 {
78 nxArrayOfAlarms *list;
79 size_t i;
80
81 m_wndListCtrl->DeleteAllItems();
82 list = NXMCGetAlarmList();
83
84 for(i = 0; i < list->GetCount(); i++)
85 {
86 AddAlarm((*list)[i]);
87 }
88
89 NXMCUnlockAlarmList();
90 }
91
92
93 //
94 // Add alarm to view
95 //
96
97 void nxAlarmView::AddAlarm(NXC_ALARM *alarm)
98 {
99 long item;
100
101 item = m_wndListCtrl->InsertItem(0x7FFFFFFF, NXMCGetStatusTextSmall(alarm->nCurrentSeverity), alarm->nCurrentSeverity);
102 if (item != -1)
103 {
104 m_wndListCtrl->SetItemData(item, alarm->dwAlarmId);
105 UpdateAlarm(item, alarm);
106 }
107 }
108
109
110 //
111 // Update alarm in view
112 //
113
114 void nxAlarmView::UpdateAlarm(long item, NXC_ALARM *alarm)
115 {
116 NXC_OBJECT *object;
117 TCHAR temp[64];
118
119 m_wndListCtrl->SetItem(item, 0, NXMCGetStatusTextSmall(alarm->nCurrentSeverity), alarm->nCurrentSeverity);
120 m_wndListCtrl->SetItem(item, 1, NXMCGetAlarmStateName(alarm->nState), alarm->nState + STATUS_TESTING + 1);
121
122 object = NXCFindObjectById(NXMCGetSession(), alarm->dwSourceObject);
123 if (object != NULL)
124 {
125 m_wndListCtrl->SetItem(item, 2, object->szName);
126 }
127 else
128 {
129 m_wndListCtrl->SetItem(item, 2, _T("<unknown>"));
130 }
131
132 m_wndListCtrl->SetItem(item, 3, alarm->szMessage);
133
134 _stprintf(temp, _T("%d"), alarm->dwRepeatCount);
135 m_wndListCtrl->SetItem(item, 4, temp);
136
137 m_wndListCtrl->SetItem(item, 5, NXMCFormatTimeStamp(alarm->dwCreationTime, temp, TS_LONG_DATE_TIME));
138 m_wndListCtrl->SetItem(item, 6, NXMCFormatTimeStamp(alarm->dwLastChangeTime, temp, TS_LONG_DATE_TIME));
139 }
140
141
142 //
143 // Handler for right click on item
144 //
145
146 void nxAlarmView::OnListItemRightClick(wxListEvent &event)
147 {
148 wxMenu *menu;
149
150 menu = wxXmlResource::Get()->LoadMenu(_T("menuCtxAlarm"));
151 if (menu != NULL)
152 {
153 PopupMenu(menu);
154 delete menu;
155 }
156 }