KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > actions > RetargetActionWithDefault


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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 - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.ide.actions;
12
13 import org.eclipse.jface.action.IAction;
14 import org.eclipse.ui.actions.RetargetAction;
15
16 /**
17  * A specialization of RetargetAction that allows for specification of a default
18  * handler when the active part does not supply one. Enablement of this
19  * action is based on enablement of the handler, or enablement of the default
20  * handler if no explicit handler is available.
21  *
22  * @since 3.1
23  */

24 public class RetargetActionWithDefault extends RetargetAction {
25
26     private IAction defaultHandler;
27
28     /**
29      * Constructs a RetargetActionWithDefault with the given action id and text.
30      *
31      * @param actionID the retargetable action id
32      * @param text the action's text, or <code>null</code> if there is no text
33      */

34     public RetargetActionWithDefault(String JavaDoc actionID, String JavaDoc text) {
35         super(actionID, text);
36     }
37
38     /* (non-Javadoc)
39      * Method declared on RetargetAction.
40      */

41     protected void setActionHandler(IAction newHandler) {
42         super.setActionHandler(newHandler);
43         // Only set the default handler after clearing the old handler above.
44
// This triggers enablement updating on the default handler which
45
// might be needed since the active part has changed.
46
if (newHandler == null) {
47             super.setActionHandler(defaultHandler);
48         }
49     }
50
51     /**
52      * Sets the default handler for this action.
53      * @param handler An action handler, or <code>null</code>
54      */

55     public void setDefaultHandler(IAction handler) {
56         this.defaultHandler = handler;
57         if (getActionHandler() == null && handler != null) {
58             super.setActionHandler(handler);
59         }
60     }
61 }
62
Popular Tags