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.ShowRefactoringHistoryWizard; 24 25 import org.eclipse.swt.widgets.Composite; 26 27 import org.eclipse.jface.action.IAction; 28 import org.eclipse.jface.dialogs.IDialogConstants; 29 import org.eclipse.jface.operation.IRunnableContext; 30 import org.eclipse.jface.operation.IRunnableWithProgress; 31 import org.eclipse.jface.viewers.ISelection; 32 import org.eclipse.jface.wizard.WizardDialog; 33 34 import org.eclipse.ui.IWorkbenchWindow; 35 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 36 import org.eclipse.ui.PlatformUI; 37 38 47 public final class ShowRefactoringHistoryAction implements IWorkbenchWindowActionDelegate { 48 49 50 private static final int SIZING_WIZARD_HEIGHT= 560; 51 52 53 private static final int SIZING_WIZARD_WIDTH= 480; 54 55 61 private static void showRefactoringHistoryWizard(final IWorkbenchWindow window) { 62 Assert.isNotNull(window); 63 final ShowRefactoringHistoryWizard wizard= new ShowRefactoringHistoryWizard(); 64 IRunnableContext context= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 65 if (context == null) 66 context= PlatformUI.getWorkbench().getProgressService(); 67 try { 68 context.run(false, true, new IRunnableWithProgress() { 69 70 public void run(final IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 71 final IRefactoringHistoryService service= RefactoringCore.getHistoryService(); 72 try { 73 service.connect(); 74 wizard.setRefactoringHistory(service.getWorkspaceHistory(monitor)); 75 } finally { 76 service.disconnect(); 77 } 78 } 79 }); 80 } catch (InvocationTargetException exception) { 81 RefactoringUIPlugin.log(exception); 82 } catch (InterruptedException exception) { 83 return; 84 } 85 final WizardDialog dialog= new WizardDialog(window.getShell(), wizard) { 86 87 protected final void createButtonsForButtonBar(final Composite parent) { 88 super.createButtonsForButtonBar(parent); 89 getButton(IDialogConstants.FINISH_ID).setText(IDialogConstants.OK_LABEL); 90 } 91 }; 92 dialog.create(); 93 dialog.getShell().setSize(Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), SIZING_WIZARD_HEIGHT); 94 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IRefactoringHelpContextIds.REFACTORING_SHOW_HISTORY_PAGE); 95 dialog.open(); 96 } 97 98 99 private IWorkbenchWindow fWindow= null; 100 101 104 public void dispose() { 105 } 107 108 111 public void init(final IWorkbenchWindow window) { 112 fWindow= window; 113 } 114 115 118 public void run(final IAction action) { 119 if (fWindow != null) { 120 showRefactoringHistoryWizard(fWindow); 121 } 122 } 123 124 127 public void selectionChanged(final IAction action, final ISelection selection) { 128 } 130 } 131 | Popular Tags |