|
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 * Handler for pause command |
|
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 |
|
30 /** |
|
31 * Handler for pause command |
|
32 */ |
|
33 public final class PauseAction extends TraceViewerAction { |
|
34 |
|
35 /** |
|
36 * Indicated if pause is on or off |
|
37 */ |
|
38 private boolean paused; |
|
39 |
|
40 /** |
|
41 * Image for the action showing pause button |
|
42 */ |
|
43 private static ImageDescriptor pauseImage; |
|
44 |
|
45 /** |
|
46 * Image for the action showing paused button |
|
47 */ |
|
48 private static ImageDescriptor pausedImage; |
|
49 |
|
50 static { |
|
51 URL url = null; |
|
52 URL url2 = null; |
|
53 url = TraceViewerPlugin.getDefault().getBundle().getEntry( |
|
54 "/icons/pause.gif"); //$NON-NLS-1$ |
|
55 url2 = TraceViewerPlugin.getDefault().getBundle().getEntry( |
|
56 "/icons/resume.gif"); //$NON-NLS-1$ |
|
57 pauseImage = ImageDescriptor.createFromURL(url); |
|
58 pausedImage = ImageDescriptor.createFromURL(url2); |
|
59 } |
|
60 |
|
61 /** |
|
62 * Constructor |
|
63 */ |
|
64 PauseAction() { |
|
65 setPauseImage(true); |
|
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("PauseButton", "1"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
80 setPauseImage(paused); |
|
81 if (TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
82 .getMainDataReader() != null) { |
|
83 TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
84 .getMainDataReader().pause(paused); |
|
85 } |
|
86 |
|
87 TraceViewerGlobals.getTraceViewer().getView().updateViewName(); |
|
88 TraceViewerGlobals.postUiEvent("PauseButton", "0"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
89 } |
|
90 |
|
91 /** |
|
92 * Sets pause image |
|
93 * |
|
94 * @param pause |
|
95 * true to set pause image |
|
96 */ |
|
97 public void setPauseImage(boolean pause) { |
|
98 if (!pause) { |
|
99 paused = true; |
|
100 setImageDescriptor(pausedImage); |
|
101 setText(Messages.getString("UnPauseAction.Title")); //$NON-NLS-1$ |
|
102 setToolTipText(Messages.getString("UnPauseAction.Tooltip")); //$NON-NLS-1$ |
|
103 } else { |
|
104 paused = false; |
|
105 setImageDescriptor(pauseImage); |
|
106 setText(Messages.getString("PauseAction.Title")); //$NON-NLS-1$ |
|
107 setToolTipText(Messages.getString("PauseAction.Tooltip")); //$NON-NLS-1$ |
|
108 } |
|
109 } |
|
110 |
|
111 /** |
|
112 * Sets paused |
|
113 * |
|
114 * @param paused |
|
115 * if true, pauses. If false, unpauses |
|
116 */ |
|
117 public void setPaused(boolean paused) { |
|
118 this.paused = !paused; |
|
119 doRun(); |
|
120 } |
|
121 } |