ac6db50cd028ace2bb950a6e4eb471f9957ed1cb
[public/netxms.git] / src / java / netxms-eclipse / EventManager / src / org / netxms / ui / eclipse / eventmanager / actions / OpenSyslogMonitor.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.eventmanager.actions;
20
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.viewers.ISelection;
24 import org.eclipse.ui.IWorkbenchWindow;
25 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
26 import org.eclipse.ui.PartInitException;
27 import org.netxms.client.NXCSession;
28 import org.netxms.ui.eclipse.eventmanager.Activator;
29 import org.netxms.ui.eclipse.eventmanager.Messages;
30 import org.netxms.ui.eclipse.eventmanager.views.SyslogMonitor;
31 import org.netxms.ui.eclipse.jobs.ConsoleJob;
32 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
33 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
34
35 /**
36 * Open syslog monitor view
37 */
38 public class OpenSyslogMonitor implements IWorkbenchWindowActionDelegate
39 {
40 private IWorkbenchWindow window;
41
42 /* (non-Javadoc)
43 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
44 */
45 @Override
46 public void dispose()
47 {
48 }
49
50 /* (non-Javadoc)
51 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
52 */
53 @Override
54 public void init(IWorkbenchWindow window)
55 {
56 this.window = window;
57 }
58
59 /* (non-Javadoc)
60 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
61 */
62 @Override
63 public void run(IAction action)
64 {
65 if(window == null)
66 return;
67
68 final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
69 new ConsoleJob(Messages.get().OpenSyslogMonitor_JobTitle, null, Activator.PLUGIN_ID, null) {
70 @Override
71 protected void runInternal(IProgressMonitor monitor) throws Exception
72 {
73 session.subscribe(NXCSession.CHANNEL_SYSLOG);
74 runInUIThread(new Runnable() {
75 @Override
76 public void run()
77 {
78 try
79 {
80 window.getActivePage().showView(SyslogMonitor.ID);
81 }
82 catch (PartInitException e)
83 {
84 MessageDialogHelper.openError(window.getShell(), Messages.get().OpenSyslogMonitor_Error, Messages.get().OpenSyslogMonitor_ErrorText + e.getMessage());
85 }
86 }
87 });
88 }
89
90 @Override
91 protected String getErrorMessage()
92 {
93 return Messages.get().OpenSyslogMonitor_JobError;
94 }
95 }.start();
96 }
97
98 /* (non-Javadoc)
99 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
100 */
101 @Override
102 public void selectionChanged(IAction action, ISelection selection)
103 {
104 }
105 }