Removed
Link Here
|
1 |
/****************************************************************************** |
2 |
* Copyright (c) 2002, 2003 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
****************************************************************************/ |
11 |
|
12 |
package org.eclipse.gmf.runtime.common.ui.action.actions; |
13 |
|
14 |
import org.eclipse.core.runtime.IProgressMonitor; |
15 |
import org.eclipse.core.runtime.NullProgressMonitor; |
16 |
import org.eclipse.swt.widgets.Event; |
17 |
import org.eclipse.ui.IWorkbenchPart; |
18 |
|
19 |
import org.eclipse.gmf.runtime.common.ui.action.ActionManagerChangeEvent; |
20 |
import org.eclipse.gmf.runtime.common.ui.action.IActionManagerChangeListener; |
21 |
import org.eclipse.gmf.runtime.common.ui.action.internal.actions.CommandManagerActionHandler; |
22 |
|
23 |
/** |
24 |
* Represents an action handler that could be registered with a retargetable |
25 |
* (global) repeat action to repeat the last command that was run. This class |
26 |
* implements the <code>IActionManagerChangeListener</code> interface; hence its |
27 |
* instances will automatically refresh themselves when an action manager change |
28 |
* notification is received. Repeat action handlers would update the label |
29 |
* for a Repeat menu item based on the label for the action that was last run. |
30 |
* |
31 |
* @author khussey |
32 |
* |
33 |
* @see org.eclipse.gmf.runtime.common.ui.action.IActionManagerChangeListener |
34 |
*/ |
35 |
public class RepeatActionHandler |
36 |
extends CommandManagerActionHandler |
37 |
implements IActionManagerChangeListener { |
38 |
|
39 |
/** |
40 |
* Constructs a new repeat action handler for the specified workbench part. |
41 |
* |
42 |
* @param workbenchPart The workbench part to which this repeat action |
43 |
* handler applies. |
44 |
*/ |
45 |
public RepeatActionHandler(IWorkbenchPart workbenchPart) { |
46 |
super(workbenchPart); |
47 |
} |
48 |
|
49 |
/* (non-Javadoc) |
50 |
* @see org.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler#setWorkbenchPart(org.eclipse.ui.IWorkbenchPart) |
51 |
*/ |
52 |
protected void setWorkbenchPart(IWorkbenchPart workbenchPart) { |
53 |
if (getWorkbenchPart() != null){ |
54 |
getActionManager().removeActionManagerChangeListener(this); |
55 |
} |
56 |
super.setWorkbenchPart(workbenchPart); |
57 |
if (getWorkbenchPart() != null){ |
58 |
getActionManager().addActionManagerChangeListener(this); |
59 |
} |
60 |
} |
61 |
|
62 |
/** |
63 |
* Handles an event indicating that an action manager has changed. |
64 |
* |
65 |
* @param event The action manager change event to be handled. |
66 |
* |
67 |
**/ |
68 |
public void actionManagerChanged(ActionManagerChangeEvent event) { |
69 |
refresh(); |
70 |
} |
71 |
|
72 |
/** |
73 |
* Runs this repeat action handler, passing the triggering SWT event. |
74 |
* |
75 |
* @param event The SWT event which triggered this action being run. |
76 |
* |
77 |
*/ |
78 |
public final void runWithEvent(Event event) { |
79 |
run(); |
80 |
} |
81 |
|
82 |
/** |
83 |
* Refreshes the label and enabled state of this repeat action handler. |
84 |
*/ |
85 |
public void refresh() { |
86 |
setEnabled(getActionManager().canRepeat()); |
87 |
setText(getActionManager().getRepeatLabel()); |
88 |
} |
89 |
|
90 |
/* (non-Javadoc) |
91 |
* @see org.eclipse.jface.action.IAction#run() |
92 |
*/ |
93 |
public void run() { |
94 |
doRun(new NullProgressMonitor()); |
95 |
} |
96 |
|
97 |
/** |
98 |
* Performs the actual work when this repeat action handler is run by asking |
99 |
* the action manager to repeat the last action that was run. |
100 |
*/ |
101 |
protected void doRun(IProgressMonitor progressMonitor) { |
102 |
getActionManager().repeat(); |
103 |
} |
104 |
|
105 |
/* (non-Javadoc) |
106 |
* @see org.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler#isSelectionListener() |
107 |
*/ |
108 |
protected boolean isSelectionListener() { |
109 |
return true; |
110 |
} |
111 |
|
112 |
} |