1 /******************************************************************************* 2 * Copyright (c) 2000, 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 Corporation - initial API and implementation 10 *******************************************************************************/ 11 package org.eclipse.ui; 12 13 import org.eclipse.jface.action.IAction; 14 import org.eclipse.jface.viewers.ISelection; 15 16 /** 17 * Interface for actions contributed via an extension point. 18 * <p> 19 * This interface should be implemented by clients who need to contribute actions 20 * via an extension point. The workbench will generate a <b>proxy action</b> 21 * object on behalf of the plug-in to avoid having to activate the plug-in until 22 * the user needs it. If the action is performed the workbench will load the class 23 * that implements this interface and create what is called an <b>action 24 * delegate</b> object. Then the request, and all subsequent ones, are 25 * forwarded through the proxy action to the action delegate, which does the 26 * real work. 27 * </p><p> 28 * The proxy action is the one that appears in the UI, so the action delegate 29 * will need to talk to the proxy action in order to keep up an appropriate 30 * appearance. Once the action delegate has been created, it will be 31 * notified of all selection changes, allowing it to enable or disable the 32 * proxy action appropriately. 33 * </p><p> 34 * An action delegate cannot be consulted about selection changes before the 35 * action is performed because it does not exist. For this reason, control of 36 * the action's enable state should also be exercised through simple XML rules 37 * contained in the extension. These rules allow enable state control before 38 * the action delegate's plug-in is loaded. 39 * </p><p> 40 * Clients can choose to subclass the provided abstract implementation 41 * <code>org.eclipse.ui.actions.ActionDelegate</code> or implement the 42 * interface directly. 43 * </p> 44 * 45 * @see org.eclipse.ui.actions.ActionDelegate 46 * @see org.eclipse.ui.IActionDelegate2 47 */ 48 public interface IActionDelegate { 49 /** 50 * Performs this action. 51 * <p> 52 * This method is called by the proxy action when the action has been 53 * triggered. Implement this method to do the actual work. 54 * </p><p> 55 * <b>Note:</b> If the action delegate also implements 56 * <code>IActionDelegate2</code>, then this method is not invoked but 57 * instead the <code>runWithEvent(IAction, Event)</code> method is called. 58 * </p> 59 * 60 * @param action the action proxy that handles the presentation portion of the 61 * action 62 */ 63 public void run(IAction action); 64 65 /** 66 * Notifies this action delegate that the selection in the workbench has changed. 67 * <p> 68 * Implementers can use this opportunity to change the availability of the 69 * action or to modify other presentation properties. 70 * </p><p> 71 * When the selection changes, the action enablement state is updated based on 72 * the criteria specified in the plugin.xml file. Then the delegate is notified 73 * of the selection change regardless of whether the enablement criteria in the 74 * plugin.xml file is met. 75 * </p> 76 * 77 * @param action the action proxy that handles presentation portion of 78 * the action 79 * @param selection the current selection, or <code>null</code> if there 80 * is no selection. 81 */ 82 public void selectionChanged(IAction action, ISelection selection); 83 } 84