92a114f6b727d43a608e98b34e20dc784557c8ad
[public/netxms.git] / webui / webapp / AlarmViewer / src / org / netxms / ui / eclipse / alarmviewer / actions / ShowObjectAlarms.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2012 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.alarmviewer.actions;
20
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.jface.viewers.IStructuredSelection;
24 import org.eclipse.ui.IObjectActionDelegate;
25 import org.eclipse.ui.IWorkbenchPage;
26 import org.eclipse.ui.IWorkbenchPart;
27 import org.eclipse.ui.IWorkbenchWindow;
28 import org.eclipse.ui.PartInitException;
29 import org.netxms.client.objects.AbstractNode;
30 import org.netxms.client.objects.AbstractObject;
31 import org.netxms.client.objects.Cluster;
32 import org.netxms.client.objects.Container;
33 import org.netxms.client.objects.EntireNetwork;
34 import org.netxms.client.objects.ServiceRoot;
35 import org.netxms.client.objects.Subnet;
36 import org.netxms.client.objects.Zone;
37 import org.netxms.ui.eclipse.alarmviewer.Messages;
38 import org.netxms.ui.eclipse.alarmviewer.views.ObjectAlarmBrowser;
39 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
40
41 /**
42 * Show alarms for given object
43 */
44 public class ShowObjectAlarms implements IObjectActionDelegate
45 {
46 private IWorkbenchWindow window;
47 private AbstractObject object;
48
49 /* (non-Javadoc)
50 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
51 */
52 @Override
53 public void setActivePart(IAction action, IWorkbenchPart targetPart)
54 {
55 window = targetPart.getSite().getWorkbenchWindow();
56 }
57
58 /* (non-Javadoc)
59 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
60 */
61 @Override
62 public void run(IAction action)
63 {
64 if (object != null)
65 {
66 try
67 {
68 window.getActivePage().showView(ObjectAlarmBrowser.ID, Long.toString(object.getObjectId()), IWorkbenchPage.VIEW_ACTIVATE);
69 }
70 catch(PartInitException e)
71 {
72 MessageDialogHelper.openError(window.getShell(), Messages.get().ShowObjectAlarms_Error, Messages.get().ShowObjectAlarms_ErrorOpeningView + e.getMessage());
73 }
74 }
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
79 */
80 @Override
81 public void selectionChanged(IAction action, ISelection selection)
82 {
83 Object obj;
84 if ((selection instanceof IStructuredSelection) &&
85 (((IStructuredSelection)selection).size() == 1))
86 {
87 obj = ((IStructuredSelection)selection).getFirstElement();
88 if((obj instanceof AbstractNode) || (obj instanceof Container) ||
89 (obj instanceof Subnet) || (obj instanceof Cluster) ||
90 (obj instanceof EntireNetwork) || (obj instanceof ServiceRoot) ||
91 (obj instanceof Zone))
92 {
93 object = (AbstractObject)obj;
94 }
95 }
96 else
97 {
98 object = null;
99 }
100 action.setEnabled(object != null);
101 }
102 }