KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.ltk.internal.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  * @since 3.2
32  */

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

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

69     public void dispose() {
70         // Do nothing
71
}
72
73     /**
74      * {@inheritDoc}
75      */

76     public void init(final IWorkbenchWindow window) {
77         fWindow= window;
78     }
79
80     /**
81      * {@inheritDoc}
82      */

83     public void run(final IAction action) {
84         if (fWindow != null) {
85             showApplyScriptWizard(fWindow);
86         }
87     }
88
89     /**
90      * {@inheritDoc}
91      */

92     public void selectionChanged(final IAction action, final ISelection selection) {
93         // Do nothing
94
}
95 }
96
Popular Tags