KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > ui > refactoring > actions > ApplyRefactoringScriptAction


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.ltk.ui.refactoring.actions;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.ltk.internal.ui.refactoring.IRefactoringHelpContextIds;
16 import org.eclipse.ltk.internal.ui.refactoring.scripting.ApplyRefactoringScriptWizard;
17
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.jface.wizard.WizardDialog;
22
23 import org.eclipse.ui.IWorkbenchWindow;
24 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
25 import org.eclipse.ui.IWorkbenchWizard;
26 import org.eclipse.ui.PlatformUI;
27
28 /**
29  * Action to apply a refactoring script to the workspace.
30  *
31  * <p>
32  * This class may be instantiated; it is not intended to be subclassed.
33  * </p>
34  *
35  * @since 3.3
36  */

37 public final class ApplyRefactoringScriptAction implements IWorkbenchWindowActionDelegate {
38
39     /** The wizard height */
40     private static final int SIZING_WIZARD_HEIGHT= 520;
41
42     /** The wizard width */
43     private static final int SIZING_WIZARD_WIDTH= 470;
44
45     /**
46      * Shows the apply script wizard.
47      *
48      * @param window
49      * the workbench window
50      */

51     private static void showApplyScriptWizard(final IWorkbenchWindow window) {
52         Assert.isNotNull(window);
53         final IWorkbenchWizard wizard= new ApplyRefactoringScriptWizard();
54         final ISelection selection= window.getSelectionService().getSelection();
55         if (selection instanceof IStructuredSelection) {
56             final IStructuredSelection structured= (IStructuredSelection) selection;
57             wizard.init(window.getWorkbench(), structured);
58         } else
59             wizard.init(window.getWorkbench(), null);
60         final WizardDialog dialog= new WizardDialog(window.getShell(), wizard);
61         dialog.create();
62         dialog.getShell().setSize(Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), SIZING_WIZARD_HEIGHT);
63         PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IRefactoringHelpContextIds.REFACTORING_APPLY_SCRIPT_PAGE);
64         dialog.open();
65     }
66
67     /** The workbench window, or <code>null</code> */
68     private IWorkbenchWindow fWindow= null;
69
70     /**
71      * {@inheritDoc}
72      */

73     public void dispose() {
74         // Do nothing
75
}
76
77     /**
78      * {@inheritDoc}
79      */

80     public void init(final IWorkbenchWindow window) {
81         fWindow= window;
82     }
83
84     /**
85      * {@inheritDoc}
86      */

87     public void run(final IAction action) {
88         if (fWindow != null) {
89             showApplyScriptWizard(fWindow);
90         }
91     }
92
93     /**
94      * {@inheritDoc}
95      */

96     public void selectionChanged(final IAction action, final ISelection selection) {
97         // Do nothing
98
}
99 }
100
Popular Tags