dc3454eb2bcac1734e8578d309618d0b5b43aff8
[public/netxms.git] / webui / webapp / DataCollection / src / org / netxms / ui / eclipse / datacollection / propertypages / helpers / TableThresholdLabelProvider.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2013 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.ui.eclipse.datacollection.propertypages.helpers;
20
21 import org.eclipse.jface.viewers.ITableLabelProvider;
22 import org.eclipse.jface.viewers.LabelProvider;
23 import org.eclipse.swt.graphics.Image;
24 import org.eclipse.ui.model.WorkbenchLabelProvider;
25 import org.netxms.client.NXCSession;
26 import org.netxms.client.constants.Severity;
27 import org.netxms.client.datacollection.TableThreshold;
28 import org.netxms.client.events.EventTemplate;
29 import org.netxms.ui.eclipse.console.resources.StatusDisplayInfo;
30 import org.netxms.ui.eclipse.datacollection.Activator;
31 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
32
33 /**
34 * Label provider for list of table column definitions
35 */
36 public class TableThresholdLabelProvider extends LabelProvider implements ITableLabelProvider
37 {
38 private NXCSession session = (NXCSession)ConsoleSharedData.getSession();
39 private WorkbenchLabelProvider eventLabelProvider = new WorkbenchLabelProvider();
40 private Image thresholdIcon = Activator.getImageDescriptor("icons/threshold.png").createImage(); //$NON-NLS-1$
41
42 /* (non-Javadoc)
43 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
44 */
45 @Override
46 public Image getColumnImage(Object element, int columnIndex)
47 {
48 switch(columnIndex)
49 {
50 case 0:
51 return thresholdIcon;
52 case 1:
53 {
54 final EventTemplate event = session.findEventTemplateByCode(((TableThreshold)element).getActivationEvent());
55 return StatusDisplayInfo.getStatusImage((event != null) ? event.getSeverity() : Severity.UNKNOWN);
56 }
57 case 2:
58 {
59 final EventTemplate event = session.findEventTemplateByCode(((TableThreshold)element).getDeactivationEvent());
60 return StatusDisplayInfo.getStatusImage((event != null) ? event.getSeverity() : Severity.UNKNOWN);
61 }
62 }
63 return null;
64 }
65
66 /* (non-Javadoc)
67 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
68 */
69 @Override
70 public String getColumnText(Object element, int columnIndex)
71 {
72 switch(columnIndex)
73 {
74 case 0:
75 return ((TableThreshold)element).getConditionAsText();
76 case 1:
77 {
78 final EventTemplate event = session.findEventTemplateByCode(((TableThreshold)element).getActivationEvent());
79 return eventLabelProvider.getText(event);
80 }
81 case 2:
82 {
83 final EventTemplate event = session.findEventTemplateByCode(((TableThreshold)element).getDeactivationEvent());
84 return eventLabelProvider.getText(event);
85 }
86 }
87 return null;
88 }
89
90 /* (non-Javadoc)
91 * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose()
92 */
93 @Override
94 public void dispose()
95 {
96 thresholdIcon.dispose();
97 eventLabelProvider.dispose();
98 super.dispose();
99 }
100 }