KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
39  * Action to show the global refactoring history.
40  *
41  * <p>
42  * This class may be instantiated; it is not intended to be subclassed.
43  * </p>
44  *
45  * @since 3.3
46  */

47 public final class ShowRefactoringHistoryAction implements IWorkbenchWindowActionDelegate {
48
49     /** The wizard height */
50     private static final int SIZING_WIZARD_HEIGHT= 560;
51
52     /** The wizard width */
53     private static final int SIZING_WIZARD_WIDTH= 480;
54
55     /**
56      * Shows the refactoring history wizard.
57      *
58      * @param window
59      * the workbench window
60      */

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 JavaDoc, InterruptedException JavaDoc {
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 JavaDoc exception) {
81             RefactoringUIPlugin.log(exception);
82         } catch (InterruptedException JavaDoc 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     /** The workbench window, or <code>null</code> */
99     private IWorkbenchWindow fWindow= null;
100
101     /**
102      * {@inheritDoc}
103      */

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

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

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

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