cdbd3b245d16e3a9e4f351a4647302cdf4b7600a
[public/netxms.git] / src / java / netxms-eclipse / FileManager / src / org / netxms / ui / eclipse / filemanager / actions / OpenFileManager.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.filemanager.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.AbstractObject;
30 import org.netxms.ui.eclipse.filemanager.views.AgentFileManager;
31 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
32
33 /**
34 * Show alarms for given object
35 */
36 public class OpenFileManager implements IObjectActionDelegate
37 {
38 private IWorkbenchWindow window;
39 private AbstractObject object;
40
41 /* (non-Javadoc)
42 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
43 */
44 @Override
45 public void setActivePart(IAction action, IWorkbenchPart targetPart)
46 {
47 window = targetPart.getSite().getWorkbenchWindow();
48 }
49
50 /* (non-Javadoc)
51 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
52 */
53 @Override
54 public void run(IAction action)
55 {
56 if (object != null)
57 {
58 try
59 {
60 window.getActivePage().showView(AgentFileManager.ID, Long.toString(object.getObjectId()), IWorkbenchPage.VIEW_ACTIVATE);
61 }
62 catch(PartInitException e)
63 {
64 MessageDialogHelper.openError(window.getShell(), "Show node file list error", "Error: " + e.getMessage());
65 }
66 }
67 }
68
69 /* (non-Javadoc)
70 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
71 */
72 @Override
73 public void selectionChanged(IAction action, ISelection selection)
74 {
75 Object obj;
76 if ((selection instanceof IStructuredSelection) &&
77 (((IStructuredSelection)selection).size() == 1))
78 {
79 obj = ((IStructuredSelection)selection).getFirstElement();
80 if (obj instanceof AbstractObject)
81 {
82 object = (AbstractObject)obj;
83 }
84 }
85 else
86 {
87 object = null;
88 }
89 action.setEnabled(object != null);
90 }
91 }