KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > scripting > ShowRefactoringHistoryWizardPage


1 /*******************************************************************************
2  * Copyright (c) 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.scripting;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.IProgressMonitor;
15
16 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
17 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
18
19 import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService;
20 import org.eclipse.ltk.internal.ui.refactoring.IRefactoringHelpContextIds;
21 import org.eclipse.ltk.internal.ui.refactoring.history.RefactoringDescriptorDeleteQuery;
22 import org.eclipse.ltk.internal.ui.refactoring.history.RefactoringHistoryEditHelper;
23 import org.eclipse.ltk.internal.ui.refactoring.history.ShowRefactoringHistoryControl;
24 import org.eclipse.ltk.internal.ui.refactoring.history.RefactoringHistoryEditHelper.IRefactoringHistoryProvider;
25 import org.eclipse.ltk.internal.ui.refactoring.util.PixelConverter;
26
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.layout.GridLayout;
32 import org.eclipse.swt.widgets.Button;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Shell;
35
36 import org.eclipse.jface.dialogs.Dialog;
37 import org.eclipse.jface.dialogs.IDialogSettings;
38 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
39 import org.eclipse.jface.operation.IRunnableContext;
40 import org.eclipse.jface.wizard.WizardPage;
41
42 import org.eclipse.ui.PlatformUI;
43
44 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryControlConfiguration;
45
46 /**
47  * First page of the show refactoring history wizard.
48  *
49  * @since 3.2
50  */

51 public final class ShowRefactoringHistoryWizardPage extends WizardPage {
52
53     /** The show refactoring history wizard page name */
54     private static final String JavaDoc PAGE_NAME= "ShowRefactoringHistoryWizardPage"; //$NON-NLS-1$
55

56     /** The sort dialog setting */
57     private static final String JavaDoc SETTING_SORT= "org.eclipse.ltk.ui.refactoring.sortRefactorings"; //$NON-NLS-1$
58

59     /** The refactoring history control */
60     private ShowRefactoringHistoryControl fHistoryControl= null;
61
62     /** The show refactoring history wizard */
63     private final ShowRefactoringHistoryWizard fWizard;
64
65     /**
66      * Creates a new show refactoring history wizard page.
67      *
68      * @param wizard
69      * the associated wizard
70      */

71     public ShowRefactoringHistoryWizardPage(final ShowRefactoringHistoryWizard wizard) {
72         super(PAGE_NAME);
73         Assert.isNotNull(wizard);
74         fWizard= wizard;
75         setTitle(ScriptingMessages.ShowRefactoringHistoryWizard_caption);
76         setDescription(ScriptingMessages.ShowRefactoringHistoryWizard_description);
77     }
78
79     /**
80      * {@inheritDoc}
81      */

82     public void createControl(final Composite parent) {
83         initializeDialogUnits(parent);
84         final Composite composite= new Composite(parent, SWT.NULL);
85         final GridLayout layout= new GridLayout();
86         layout.marginWidth= 0;
87         layout.marginLeft= 5;
88         layout.marginRight= 5;
89         composite.setLayout(layout);
90         composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
91         final RefactoringHistoryControlConfiguration configuration= new RefactoringHistoryControlConfiguration(null, true, false) {
92
93             public final String JavaDoc getWorkspaceCaption() {
94                 return ScriptingMessages.ShowRefactoringHistoryWizard_workspace_caption;
95             }
96         };
97         fHistoryControl= new ShowRefactoringHistoryControl(composite, configuration) {
98
99             protected void createBottomButtonBar(final Composite control) {
100                 Assert.isNotNull(control);
101                 final Composite container= new Composite(control, SWT.NONE);
102                 final GridLayout grid= new GridLayout(1, false);
103                 grid.marginWidth= 0;
104                 grid.marginHeight= 0;
105                 container.setLayout(grid);
106
107                 final GridData data= new GridData();
108                 data.grabExcessHorizontalSpace= true;
109                 data.grabExcessVerticalSpace= false;
110                 data.horizontalAlignment= SWT.FILL;
111                 data.verticalAlignment= SWT.TOP;
112                 container.setLayoutData(data);
113
114                 createDeleteButton(container, GridData.END);
115             }
116
117             protected void createDeleteAllButton(final Composite control) {
118                 // No delete all button
119
}
120
121             protected void createEditButton(final Composite control) {
122                 // No edit button so far
123
}
124
125             protected void createRightButtonBar(final Composite control) {
126                 final Composite container= new Composite(control, SWT.NONE);
127                 container.setLayout(new GridLayout(1, false));
128             }
129
130             protected int getContainerColumns() {
131                 return 1;
132             }
133         };
134         fHistoryControl.createControl();
135         boolean sortProjects= true;
136         final IDialogSettings settings= fWizard.getDialogSettings();
137         if (settings != null)
138             sortProjects= settings.getBoolean(SETTING_SORT);
139         if (sortProjects)
140             fHistoryControl.sortByProjects();
141         else
142             fHistoryControl.sortByDate();
143
144         fHistoryControl.setInput(fWizard.getRefactoringHistory());
145
146         final GridData data= new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
147         data.heightHint= new PixelConverter(parent).convertHeightInCharsToPixels(24);
148         fHistoryControl.setLayoutData(data);
149         fHistoryControl.getDeleteButton().addSelectionListener(new SelectionAdapter() {
150
151             public final void widgetSelected(final SelectionEvent event) {
152                 final RefactoringDescriptorProxy[] selection= fHistoryControl.getCheckedDescriptors();
153                 if (selection.length > 0) {
154                     final Shell shell= getShell();
155                     final IRunnableContext context= new ProgressMonitorDialog(shell);
156                     RefactoringHistoryEditHelper.promptRefactoringDelete(shell, context, fHistoryControl, new RefactoringDescriptorDeleteQuery(shell, null, selection.length), new IRefactoringHistoryProvider() {
157
158                         public RefactoringHistory getRefactoringHistory(final IProgressMonitor monitor) {
159                             return RefactoringHistoryService.getInstance().getWorkspaceHistory(monitor);
160                         }
161                     }, selection);
162                 }
163             }
164         });
165         final Button button= fHistoryControl.getEditButton();
166         if (button != null) {
167             button.addSelectionListener(new SelectionAdapter() {
168
169                 public final void widgetSelected(final SelectionEvent event) {
170                     final RefactoringDescriptorProxy[] selection= fHistoryControl.getSelectedDescriptors();
171                     if (selection.length > 0)
172                         RefactoringHistoryEditHelper.promptRefactoringDetails(getContainer(), fHistoryControl, selection[0]);
173                 }
174             });
175         }
176         setPageComplete(false);
177         setControl(composite);
178         Dialog.applyDialogFont(parent);
179         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IRefactoringHelpContextIds.REFACTORING_SHOW_HISTORY_PAGE);
180     }
181
182     /**
183      * {@inheritDoc}
184      */

185     public boolean isPageComplete() {
186         return true;
187     }
188
189     /**
190      * Gets called if the wizard is finished.
191      */

192     public void performFinish() {
193         final IDialogSettings settings= fWizard.getDialogSettings();
194         if (settings != null)
195             settings.put(SETTING_SORT, fHistoryControl.isSortByProjects());
196     }
197 }
Popular Tags