|
1 /* |
|
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Start External Filter Application Action |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.action; |
|
20 |
|
21 import java.net.URL; |
|
22 |
|
23 import org.eclipse.jface.resource.ImageDescriptor; |
|
24 import org.eclipse.ui.PlatformUI; |
|
25 |
|
26 import com.nokia.traceviewer.TraceViewerHelpContextIDs; |
|
27 import com.nokia.traceviewer.TraceViewerPlugin; |
|
28 import com.nokia.traceviewer.engine.TraceViewerGlobals; |
|
29 import com.nokia.traceviewer.engine.TraceViewerDialogInterface.TVPreferencePage; |
|
30 import com.nokia.traceviewer.engine.dataprocessor.ExternalFilterProcessor; |
|
31 import com.nokia.traceviewer.engine.preferences.PreferenceConstants; |
|
32 |
|
33 /** |
|
34 * Start External Filter Application Action |
|
35 */ |
|
36 public class StartExternalFilterAction extends TraceViewerAction { |
|
37 |
|
38 /** |
|
39 * Image for the start action |
|
40 */ |
|
41 private static ImageDescriptor startImage; |
|
42 |
|
43 /** |
|
44 * Image for the stop action |
|
45 */ |
|
46 private static ImageDescriptor stopImage; |
|
47 |
|
48 static { |
|
49 URL url = null; |
|
50 URL url2 = null; |
|
51 url = TraceViewerPlugin.getDefault().getBundle().getEntry( |
|
52 "/icons/startexternal.gif"); //$NON-NLS-1$ |
|
53 url2 = TraceViewerPlugin.getDefault().getBundle().getEntry( |
|
54 "/icons/stopexternal.gif"); //$NON-NLS-1$ |
|
55 startImage = ImageDescriptor.createFromURL(url); |
|
56 stopImage = ImageDescriptor.createFromURL(url2); |
|
57 } |
|
58 |
|
59 /** |
|
60 * Constructor |
|
61 */ |
|
62 public StartExternalFilterAction() { |
|
63 setText(Messages.getString("StartExternalFilterAction.Title")); //$NON-NLS-1$ |
|
64 setToolTipText(Messages.getString("StartExternalFilterAction.Tooltip")); //$NON-NLS-1$ |
|
65 setImageDescriptor(startImage); |
|
66 |
|
67 // Set help |
|
68 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, |
|
69 TraceViewerHelpContextIDs.ACTIONS); |
|
70 } |
|
71 |
|
72 /* |
|
73 * (non-Javadoc) |
|
74 * |
|
75 * @see com.nokia.traceviewer.action.TraceViewerAction#doRun() |
|
76 */ |
|
77 @Override |
|
78 protected void doRun() { |
|
79 TraceViewerGlobals.postUiEvent("StartExternalFilterButton", "1"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
80 |
|
81 // If external filter is not defined, open the preference page |
|
82 boolean externalFilterIsDefined = TraceViewerPlugin.getDefault() |
|
83 .getPreferenceStore().getBoolean( |
|
84 PreferenceConstants.EXTERNAL_FILTER_CHECKBOX); |
|
85 |
|
86 if (!externalFilterIsDefined) { |
|
87 TraceViewerGlobals.getTraceViewer().getDialogs() |
|
88 .openPreferencePage(TVPreferencePage.ADVANCED); |
|
89 |
|
90 // If defined but not using, set as using |
|
91 } else if (!TraceViewerGlobals.getTraceViewer() |
|
92 .getDataProcessorAccess().getFilterProcessor() |
|
93 .isUsingExternalFilter()) { |
|
94 TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
95 .getFilterProcessor().setUsingExternalFilter(true); |
|
96 } |
|
97 |
|
98 // Check checkbox again |
|
99 externalFilterIsDefined = TraceViewerPlugin.getDefault() |
|
100 .getPreferenceStore().getBoolean( |
|
101 PreferenceConstants.EXTERNAL_FILTER_CHECKBOX); |
|
102 |
|
103 // Start external application and show stop image |
|
104 if (externalFilterIsDefined |
|
105 && !TraceViewerGlobals.getTraceViewer() |
|
106 .getDataProcessorAccess().getFilterProcessor() |
|
107 .isUsingExternalFilter()) { |
|
108 boolean success = TraceViewerGlobals.getTraceViewer() |
|
109 .getDataProcessorAccess().getFilterProcessor() |
|
110 .getExternalFilterProcessor().startExternalApplication(); |
|
111 |
|
112 if (success) { |
|
113 setImageDescriptor(stopImage); |
|
114 setText(Messages.getString("StopExternalFilterAction.Title")); //$NON-NLS-1$ |
|
115 setToolTipText(Messages |
|
116 .getString("StopExternalFilterAction.Tooltip")); //$NON-NLS-1$ |
|
117 } |
|
118 // Stop external application and show start image |
|
119 } else { |
|
120 setImageDescriptor(startImage); |
|
121 setText(Messages.getString("StartExternalFilterAction.Title")); //$NON-NLS-1$ |
|
122 setToolTipText(Messages |
|
123 .getString("StartExternalFilterAction.Tooltip")); //$NON-NLS-1$ |
|
124 |
|
125 // Get the processor and stop it if it exists |
|
126 ExternalFilterProcessor extProcessor = TraceViewerGlobals |
|
127 .getTraceViewer().getDataProcessorAccess() |
|
128 .getFilterProcessor().getExternalFilterProcessor(); |
|
129 |
|
130 if (extProcessor != null) { |
|
131 extProcessor.stopExternalApplication(); |
|
132 } |
|
133 } |
|
134 TraceViewerGlobals.postUiEvent("StartExternalFilterButton", "0"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
135 } |
|
136 } |