01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.tests.macro;
11:
12: import org.eclipse.jface.action.IAction;
13: import org.eclipse.jface.viewers.ISelection;
14: import org.eclipse.ui.IWorkbenchWindow;
15: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
16:
17: public class StopAction implements IWorkbenchWindowActionDelegate,
18: IRecorderListener {
19: private IAction action;
20:
21: /**
22: * The constructor.
23: */
24: public StopAction() {
25: MacroManager recorder = MacroPlugin.getDefault()
26: .getMacroManager();
27: recorder.addRecorderListener(this );
28: }
29:
30: /**
31: * The action has been activated. The argument of the
32: * method represents the 'real' action sitting
33: * in the workbench UI.
34: * @see IWorkbenchWindowActionDelegate#run
35: */
36: public void run(IAction action) {
37: MacroManager recorder = MacroPlugin.getDefault()
38: .getMacroManager();
39: this .action = action;
40: if (!recorder.isRecording()) {
41: action.setEnabled(false);
42: return;
43: }
44: RecordBlock.getInstance().stopRecording();
45: }
46:
47: /**
48: * Selection in the workbench has been changed. We
49: * can change the state of the 'real' action here
50: * if we want, but this can only happen after
51: * the delegate has been created.
52: * @see IWorkbenchWindowActionDelegate#selectionChanged
53: */
54: public void selectionChanged(IAction action, ISelection selection) {
55: }
56:
57: public void recordingStarted() {
58: if (action != null)
59: action.setEnabled(true);
60: }
61:
62: public void recordingStopped() {
63: if (action != null)
64: action.setEnabled(false);
65: }
66:
67: public void recordingInterrupted(int type) {
68: }
69:
70: /**
71: * We can use this method to dispose of any system
72: * resources we previously allocated.
73: * @see IWorkbenchWindowActionDelegate#dispose
74: */
75: public void dispose() {
76: MacroManager recorder = MacroPlugin.getDefault()
77: .getMacroManager();
78: recorder.removeRecorderListener(this );
79: RecordBlock.dispose();
80: }
81:
82: /**
83: * We will cache window object in order to
84: * be able to provide parent shell for the message dialog.
85: * @see IWorkbenchWindowActionDelegate#init
86: */
87: public void init(IWorkbenchWindow window) {
88: RecordBlock.init(window);
89: }
90: }
|