1 11 package org.eclipse.ltk.ui.refactoring.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 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 48 public final class CreateRefactoringScriptAction implements IWorkbenchWindowActionDelegate { 49 50 51 private static final int SIZING_WIZARD_HEIGHT= 610; 52 53 54 private static final int SIZING_WIZARD_WIDTH= 500; 55 56 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 , InterruptedException { 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 exception) { 82 RefactoringUIPlugin.log(exception); 83 } catch (InterruptedException 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 100 private IWorkbenchWindow fWindow= null; 101 102 105 public void dispose() { 106 } 108 109 112 public void init(final IWorkbenchWindow window) { 113 fWindow= window; 114 } 115 116 119 public void run(final IAction action) { 120 if (fWindow != null) { 121 showCreateScriptWizard(fWindow); 122 } 123 } 124 125 128 public void selectionChanged(final IAction action, final ISelection selection) { 129 } 131 } 132 | Popular Tags |