01: /*******************************************************************************
02: * Copyright (c) 2004, 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 - Initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.ide.actions;
11:
12: import org.eclipse.jface.action.IAction;
13: import org.eclipse.ui.actions.RetargetAction;
14:
15: /**
16: * A specialization of RetargetAction that allows for specification of a default
17: * handler when the active part does not supply one. Enablement of this
18: * action is based on enablement of the handler, or enablement of the default
19: * handler if no explicit handler is available.
20: *
21: * @since 3.1
22: */
23: public class RetargetActionWithDefault extends RetargetAction {
24:
25: private IAction defaultHandler;
26:
27: /**
28: * Constructs a RetargetActionWithDefault with the given action id and text.
29: *
30: * @param actionID the retargetable action id
31: * @param text the action's text, or <code>null</code> if there is no text
32: */
33: public RetargetActionWithDefault(String actionID, String text) {
34: super (actionID, text);
35: }
36:
37: /* (non-Javadoc)
38: * Method declared on RetargetAction.
39: */
40: protected void setActionHandler(IAction newHandler) {
41: super .setActionHandler(newHandler);
42: // Only set the default handler after clearing the old handler above.
43: // This triggers enablement updating on the default handler which
44: // might be needed since the active part has changed.
45: if (newHandler == null) {
46: super .setActionHandler(defaultHandler);
47: }
48: }
49:
50: /**
51: * Sets the default handler for this action.
52: * @param handler An action handler, or <code>null</code>
53: */
54: public void setDefaultHandler(IAction handler) {
55: this.defaultHandler = handler;
56: if (getActionHandler() == null && handler != null) {
57: super.setActionHandler(handler);
58: }
59: }
60: }
|