KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.IProgressMonitor;
17
18 import org.eclipse.ltk.core.refactoring.RefactoringCore;
19 import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService;
20
21 import org.eclipse.ltk.internal.ui.refactoring.IRefactoringHelpContextIds;
22 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIPlugin;
23 import org.eclipse.ltk.internal.ui.refactoring.scripting.CreateRefactoringScriptWizard;
24 import org.eclipse.ltk.internal.ui.refactoring.scripting.ScriptingMessages;
25
26 import org.eclipse.swt.widgets.Composite;
27
28 import org.eclipse.jface.action.IAction;
29 import org.eclipse.jface.dialogs.IDialogConstants;
30 import org.eclipse.jface.operation.IRunnableContext;
31 import org.eclipse.jface.operation.IRunnableWithProgress;
32 import org.eclipse.jface.viewers.ISelection;
33 import org.eclipse.jface.wizard.WizardDialog;
34
35 import org.eclipse.ui.IWorkbenchWindow;
36 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
37 import org.eclipse.ui.PlatformUI;
38
39 /**
40  * Action to open the dialog to create a refactoring script from the refactoring history.
41  *
42  * <p>
43  * This class may be instantiated; it is not intended to be subclassed.
44  * </p>
45  *
46  * @since 3.3
47  */

48 public final class CreateRefactoringScriptAction implements IWorkbenchWindowActionDelegate {
49
50     /** The wizard height */
51     private static final int SIZING_WIZARD_HEIGHT= 610;
52
53     /** The wizard width */
54     private static final int SIZING_WIZARD_WIDTH= 500;
55
56     /**
57      * Shows the create script wizard.
58      *
59      * @param window
60      * the workbench window
61      */

62     private static void showCreateScriptWizard(final IWorkbenchWindow window) {
63         Assert.isNotNull(window);
64         final CreateRefactoringScriptWizard wizard= new CreateRefactoringScriptWizard();
65         try {
66             IRunnableContext context= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
67             if (context == null)
68                 context= PlatformUI.getWorkbench().getProgressService();
69             context.run(false, true, new IRunnableWithProgress() {
70
71                 public void run(final IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
72                     final IRefactoringHistoryService service= RefactoringCore.getHistoryService();
73                     try {
74                         service.connect();
75                         wizard.setRefactoringHistory(service.getWorkspaceHistory(monitor));
76                     } finally {
77                         service.disconnect();
78                     }
79                 }
80             });
81         } catch (InvocationTargetException JavaDoc exception) {
82             RefactoringUIPlugin.log(exception);
83         } catch (InterruptedException JavaDoc exception) {
84             return;
85         }
86         final WizardDialog dialog= new WizardDialog(window.getShell(), wizard) {
87
88             protected final void createButtonsForButtonBar(final Composite parent) {
89                 super.createButtonsForButtonBar(parent);
90                 getButton(IDialogConstants.FINISH_ID).setText(ScriptingMessages.CreateRefactoringScriptAction_finish_button_label);
91             }
92         };
93         dialog.create();
94         dialog.getShell().setSize(Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), SIZING_WIZARD_HEIGHT);
95         PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IRefactoringHelpContextIds.REFACTORING_CREATE_SCRIPT_PAGE);
96         dialog.open();
97     }
98
99     /** The workbench window, or <code>null</code> */
100     private IWorkbenchWindow fWindow= null;
101
102     /**
103      * {@inheritDoc}
104      */

105     public void dispose() {
106         // Do nothing
107
}
108
109     /**
110      * {@inheritDoc}
111      */

112     public void init(final IWorkbenchWindow window) {
113         fWindow= window;
114     }
115
116     /**
117      * {@inheritDoc}
118      */

119     public void run(final IAction action) {
120         if (fWindow != null) {
121             showCreateScriptWizard(fWindow);
122         }
123     }
124
125     /**
126      * {@inheritDoc}
127      */

128     public void selectionChanged(final IAction action, final ISelection selection) {
129         // Do nothing
130
}
131 }
132
Popular Tags