8153dafe1ecc8d99c6c591483a39478aae0fa24b
[public/netxms.git] / src / java / netxms-eclipse / DataCollection / src / org / netxms / ui / eclipse / datacollection / objecttabs / LastValues.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2015 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.objecttabs;
20
21 import org.eclipse.core.commands.Command;
22 import org.eclipse.core.commands.State;
23 import org.eclipse.jface.action.Action;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.ui.PlatformUI;
27 import org.eclipse.ui.commands.ICommandService;
28 import org.eclipse.ui.contexts.IContextService;
29 import org.netxms.client.objects.AbstractObject;
30 import org.netxms.client.objects.DataCollectionTarget;
31 import org.netxms.ui.eclipse.datacollection.widgets.LastValuesWidget;
32 import org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab;
33 import org.netxms.ui.eclipse.tools.VisibilityValidator;
34
35 /**
36 * Last values tab
37 */
38 public class LastValues extends ObjectTab
39 {
40 private LastValuesWidget dataView;
41
42 /* (non-Javadoc)
43 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#createTabContent(org.eclipse.swt.widgets.Composite)
44 */
45 @Override
46 protected void createTabContent(Composite parent)
47 {
48 dataView = new LastValuesWidget(getViewPart(), parent, SWT.NONE, getObject(), "LastValuesTab", new VisibilityValidator() { //$NON-NLS-1$
49 @Override
50 public boolean isVisible()
51 {
52 return isActive();
53 }
54 });
55 dataView.setAutoRefreshEnabled(true);
56 dataView.setFilterCloseAction(new Action() {
57 @Override
58 public void run()
59 {
60 dataView.enableFilter(false);
61 ICommandService service = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
62 Command command = service.getCommand("org.netxms.ui.eclipse.datacollection.commands.show_dci_filter"); //$NON-NLS-1$
63 State state = command.getState("org.netxms.ui.eclipse.datacollection.commands.show_dci_filter.state"); //$NON-NLS-1$
64 state.setValue(false);
65 service.refreshElements(command.getId(), null);
66 }
67 });
68 }
69
70 /* (non-Javadoc)
71 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#objectChanged(org.netxms.client.objects.AbstractObject)
72 */
73 @Override
74 public void objectChanged(AbstractObject object)
75 {
76 dataView.setDataCollectionTarget(object);
77 if (getViewPart().getSite().getPage().isPartVisible(getViewPart()) && isActive())
78 dataView.refresh();
79 }
80
81 /* (non-Javadoc)
82 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#showForObject(org.netxms.client.objects.AbstractObject)
83 */
84 @Override
85 public boolean showForObject(AbstractObject object)
86 {
87 return object instanceof DataCollectionTarget;
88 }
89
90 /* (non-Javadoc)
91 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#refresh()
92 */
93 @Override
94 public void refresh()
95 {
96 dataView.refresh();
97 }
98
99 /**
100 * @param enabled
101 */
102 public void setFilterEnabled(boolean enabled)
103 {
104 dataView.enableFilter(enabled);
105 }
106
107 /* (non-Javadoc)
108 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#selected()
109 */
110 @Override
111 public void selected()
112 {
113 super.selected();
114 IContextService contextService = (IContextService)getViewPart().getSite().getService(IContextService.class);
115 if (contextService != null)
116 {
117 contextService.activateContext("org.netxms.ui.eclipse.datacollection.context.LastValues"); //$NON-NLS-1$
118 }
119 refresh();
120 }
121 }