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.ui.examples.readmetool;
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: /**
18: * This class shows how <code>IActionDelegate</code> implementations
19: * should be used for global action registration for menu
20: * and tool bars. Action proxy object is created in the
21: * workbench based on presentation information in the plugin.xml
22: * file. Delegate is not loaded until the first time the user
23: * presses the button or selects the menu. Based on the action
24: * availability, it is possible that the button will disable
25: * instead of executing.
26: */
27: public class WindowActionDelegate implements
28: IWorkbenchWindowActionDelegate {
29: private IWorkbenchWindow window;
30:
31: private ISelection selection;
32:
33: /* (non-Javadoc)
34: * Method declared on IWorkbenchActionDelegate
35: */
36: public void dispose() {
37: // do nothing
38: }
39:
40: /* (non-Javadoc)
41: * Method declared on IWorkbenchActionDelegate
42: */
43: public void init(IWorkbenchWindow window) {
44: this .window = window;
45: }
46:
47: /**
48: * The <code>WindowActionDelegate</code> implementation of this
49: * <code>IActionDelegate</code> method
50: * launches a stand-alone dialog that contains a list of sections for
51: * the selected readme file in the navigator.
52: */
53: public void run(IAction action) {
54: SectionsDialog dialog = new SectionsDialog(window.getShell(),
55: ReadmeModelFactory.getInstance().getSections(selection));
56: dialog.open();
57: }
58:
59: /**
60: * The <code>WindowActionDelegate</code> implementation of this
61: * <code>IActionDelegate</code> method
62: * does nothing - we will let simple rules in the XML
63: * config file react to selections.
64: */
65: public void selectionChanged(IAction action, ISelection selection) {
66: this.selection = selection;
67: }
68: }
|