update
[public/netxms.git] / src / client / console / plugins / ObjectBrowser / overview.cpp
CommitLineData
f2a439ef
VK
1/*
2** NetXMS - Network Management System
3** Portable management console - Object 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: overview.cpp
21**
22**/
23
24#include "object_browser.h"
25
26
27//
28// Header's event table
29//
30
31BEGIN_EVENT_TABLE(nxObjOverviewHeader, wxWindow)
32 EVT_PAINT(nxObjOverviewHeader::OnPaint)
33END_EVENT_TABLE()
34
35
36//
37// Header's constructor
38//
39
40nxObjOverviewHeader::nxObjOverviewHeader(wxWindow *parent)
41 : wxWindow(parent, wxID_ANY, wxDefaultPosition, wxSize(100, 40))
42{
43 m_object = NULL;
44}
45
46
47//
48// Set current object
49//
50
51void nxObjOverviewHeader::SetObject(NXC_OBJECT *object)
52{
53 m_object = object;
54 Refresh();
55}
56
57
58//
59// Paint header
60//
61
62void nxObjOverviewHeader::OnPaint(wxPaintEvent &event)
63{
64 wxPaintDC dc(this);
65
66 dc.DrawText(m_object->szName, 40, 3);
67}
68
69
70//
71// Constructor
72//
73
74nxObjectOverview::nxObjectOverview(wxWindow *parent)
75 : wxPanel(parent, wxID_ANY)
76{
77 wxBoxSizer *sizer;
78
79 Hide();
80 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
81
82 m_object = NULL;
83
84 m_header = new nxObjOverviewHeader(this);
85
86 sizer = new wxBoxSizer(wxVERTICAL);
87 sizer->Add(m_header, 0, wxALL | wxEXPAND, 7);
88 sizer->Add(new nxHeading(this, _T("Attributes"), wxDefaultPosition, wxSize(500, 20)), 0, wxALL | wxEXPAND, 7);
89
90 m_attrList = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER);
91 m_attrList->InsertColumn(0, _T("Name"), wxLIST_FORMAT_LEFT, 100);
92 m_attrList->InsertColumn(1, _T("Value"), wxLIST_FORMAT_LEFT, -1);
93 sizer->Add(m_attrList, 1, wxALL | wxEXPAND, 7);
94
95 SetSizer(sizer);
96 sizer->SetSizeHints(this);
97}
98
99
100//
101// Set current object
102//
103
104void nxObjectOverview::SetObject(NXC_OBJECT *object)
105{
106 TCHAR temp[32];
107
108 m_object = object;
109 m_header->SetObject(object);
110
111 m_attrList->DeleteAllItems();
112 InsertItem(_T("ID"), m_object->dwId);
113 InsertItem(_T("Class"), NXMCGetClassName(m_object->iClass));
114 if (m_object->dwIpAddr != 0)
115 InsertItem(_T("IP Address"), IpToStr(m_object->dwIpAddr, temp));
116
117 // Class-specific information
118 switch(m_object->iClass)
119 {
120 case OBJECT_SUBNET:
121 InsertItem(_T("Network Mask"), IpToStr(m_object->subnet.dwIpNetMask, temp));
122 break;
123 case OBJECT_NODE:
124 if (m_object->node.dwFlags & NF_IS_NATIVE_AGENT)
125 {
126 InsertItem(_T("NetXMS Agent"), _T("Active"));
127 InsertItem(_T("Agent Version"), m_object->node.szAgentVersion);
128 InsertItem(_T("Platform Name"), m_object->node.szPlatformName);
129 }
130 else
131 {
132 InsertItem(_T("NetXMS Agent"), _T("Inactive"));
133 }
134 if (m_object->node.dwFlags & NF_IS_SNMP)
135 {
136 InsertItem(_T("SNMP Agent"), _T("Active"));
137 InsertItem(_T("SNMP OID"), m_object->node.szObjectId);
138 }
139 else
140 {
141 InsertItem(_T("SNMP Agent"), _T("Inactive"));
142 }
143 InsertItem(_T("Node Type"), NXMCGetNodeTypeName(m_object->node.dwNodeType));
144 break;
145 case OBJECT_INTERFACE:
146 if (m_object->dwIpAddr != 0)
147 InsertItem(_T("IP Netmask"), IpToStr(m_object->iface.dwIpNetMask, temp));
148 InsertItem(_T("Index"), m_object->iface.dwIfIndex);
149 InsertItem(_T("Type"), NXMCGetIfTypeName((int)m_object->iface.dwIfType));
150 BinToStr(m_object->iface.bMacAddr, MAC_ADDR_LENGTH, temp);
151 InsertItem(_T("MAC Address"), temp);
152 break;
153 default:
154 break;
155 }
156}
157
158
159//
160// Insert item into attributes list
161//
162
163void nxObjectOverview::InsertItem(const TCHAR *name, const TCHAR *value)
164{
165 long item;
166
167 item = m_attrList->InsertItem(0x7FFFFFFF, name);
168 m_attrList->SetItem(item, 1, value);
169}
170
171void nxObjectOverview::InsertItem(const TCHAR *name, DWORD value)
172{
173 TCHAR buffer[32];
174
175 _stprintf(buffer, _T("%d"), value);
176 InsertItem(name, buffer);
177}