KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > RefactoringHistoryPreviewPage


1 /*******************************************************************************
2  * Copyright (c) 2005, 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;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.ltk.core.refactoring.Refactoring;
16 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
17 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
18 import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
19
20 import org.eclipse.ltk.internal.ui.refactoring.history.RefactoringHistoryErrorPage;
21
22 import org.eclipse.jface.wizard.IWizard;
23 import org.eclipse.jface.wizard.IWizardPage;
24
25 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryWizard;
26
27 /**
28  * Preview page for refactoring history wizards.
29  *
30  * @since 3.2
31  */

32 public final class RefactoringHistoryPreviewPage extends PreviewWizardPage {
33
34     /** The preview change filter */
35     private RefactoringPreviewChangeFilter fFilter= new RefactoringPreviewChangeFilter();
36
37     /** Is the next wizard page disabled? */
38     private boolean fNextPageDisabled= false;
39
40     /** The current refactoring, or <code>null</code> */
41     private Refactoring fRefactoring;
42
43     /** The refactoring status */
44     private RefactoringStatus fStatus= new RefactoringStatus();
45
46     /**
47      * Creates a new refactoring history preview page.
48      */

49     public RefactoringHistoryPreviewPage() {
50         super(true);
51         setTitle(RefactoringUIMessages.RefactoringHistoryOverviewPage_title);
52         setDescription(RefactoringUIMessages.RefactoringHistoryPreviewPage_description);
53     }
54
55     /**
56      * {@inheritDoc}
57      */

58     public boolean canFlipToNextPage() {
59         return !fNextPageDisabled;
60     }
61
62     /**
63      * {@inheritDoc}
64      */

65     public IWizardPage getNextPage() {
66         if (fChange != null && fRefactoring != null && !fStatus.hasFatalError()) {
67             final RefactoringHistoryWizard result= getRefactoringHistoryWizard();
68             if (result != null) {
69                 final RefactoringStatus status= result.performPreviewChange(fChange, fRefactoring);
70                 if (!status.isOK()) {
71                     final RefactoringStatusEntry entry= status.getEntryWithHighestSeverity();
72                     if (entry != null) {
73                         if (entry.getSeverity() == RefactoringStatus.INFO && entry.getCode() == RefactoringHistoryWizard.STATUS_CODE_INTERRUPTED)
74                             return this;
75                         final IErrorWizardPage page= result.getErrorPage();
76                         if (page instanceof RefactoringHistoryErrorPage) {
77                             final RefactoringHistoryErrorPage extended= (RefactoringHistoryErrorPage) page;
78                             extended.setStatus(status);
79                             extended.setNextPageDisabled(fNextPageDisabled);
80                             extended.setTitle(RefactoringUIMessages.RefactoringHistoryPreviewPage_apply_error_title);
81                             extended.setDescription(RefactoringUIMessages.RefactoringHistoryPreviewPage_apply_error);
82                             return extended;
83                         }
84                     }
85                 }
86             }
87         }
88         return getWizard().getNextPage(this);
89     }
90
91     /**
92      * {@inheritDoc}
93      */

94     public IWizardPage getPreviousPage() {
95         return getWizard().getPreviousPage(this);
96     }
97
98     /**
99      * Returns the current refactoring.
100      *
101      * @return the current refactoring
102      */

103     public Refactoring getRefactoring() {
104         return fRefactoring;
105     }
106
107     /**
108      * Returns the refactoring history wizard.
109      *
110      * @return the refactoring history wizard
111      */

112     protected RefactoringHistoryWizard getRefactoringHistoryWizard() {
113         final IWizard result= getWizard();
114         if (result instanceof RefactoringHistoryWizard)
115             return (RefactoringHistoryWizard) result;
116         return null;
117     }
118
119     /**
120      * Is the next wizard page disabled?
121      *
122      * @return <code>true</code> if disabled, <code>false</code> otherwise
123      */

124     public boolean isNextPageDisabled() {
125         return fNextPageDisabled;
126     }
127
128     /**
129      * {@inheritDoc}
130      */

131     protected boolean performFinish() {
132         return true;
133     }
134
135     /**
136      * Sets the preview change filter.
137      *
138      * @param filter
139      * the preview change filter to set
140      */

141     public void setFilter(final RefactoringPreviewChangeFilter filter) {
142         Assert.isNotNull(filter);
143         fFilter= filter;
144     }
145
146     /**
147      * Determines whether the next wizard page is disabled.
148      *
149      * @param disable
150      * <code>true</code> to disable, <code>false</code> otherwise
151      */

152     public void setNextPageDisabled(final boolean disable) {
153         fNextPageDisabled= disable;
154     }
155
156     /**
157      * {@inheritDoc}
158      */

159     public void setPageComplete(final boolean complete) {
160         super.setPageComplete(!fNextPageDisabled);
161     }
162
163     /**
164      * Sets the current refactoring.
165      *
166      * @param refactoring
167      * the current refactoring, or <code>null</code>
168      */

169     public void setRefactoring(final Refactoring refactoring) {
170         fRefactoring= refactoring;
171     }
172
173     /**
174      * Sets the status of the change generation.
175      *
176      * @param status
177      * the status
178      */

179     public void setStatus(final RefactoringStatus status) {
180         Assert.isNotNull(status);
181         fStatus= status;
182     }
183
184     /**
185      * Sets the title of the page according to the refactoring.
186      *
187      * @param descriptor
188      * the refactoring descriptor, or <code>null</code>
189      * @param current
190      * the non-zero based index of the current refactoring
191      * @param total
192      * the total number of refactorings
193      */

194     public void setTitle(final RefactoringDescriptorProxy descriptor, final int current, final int total) {
195         final String JavaDoc message;
196         if (descriptor != null)
197             message= descriptor.getDescription();
198         else
199             message= RefactoringUIMessages.RefactoringHistoryOverviewPage_title;
200         if (total > 1)
201             setTitle(Messages.format(RefactoringUIMessages.RefactoringHistoryPreviewPage_refactoring_pattern, new String JavaDoc[] { message, String.valueOf(current + 1), String.valueOf(total)}));
202         else
203             setTitle(message);
204     }
205
206     /**
207      * {@inheritDoc}
208      */

209     protected void setTreeViewerInput() {
210         if (fTreeViewer == null)
211             return;
212         PreviewNode input= null;
213         if (fTreeViewerInputChange != null) {
214             input= AbstractChangeNode.createNode(null, fFilter, fTreeViewerInputChange);
215         }
216         if (input instanceof CompositeChangeNode) {
217             final CompositeChangeNode node= (CompositeChangeNode) input;
218             final PreviewNode[] nodes= node.getChildren();
219             if (nodes == null || nodes.length == 0) {
220                 fTreeViewerPane.setText(RefactoringUIMessages.RefactoringHistoryPreviewPage_no_changes);
221                 fNextAction.setEnabled(false);
222                 fPreviousAction.setEnabled(false);
223                 fFilterDropDownAction.setEnabled(false);
224                 fTreeViewer.setInput(null);
225                 return;
226             }
227         }
228         fTreeViewerPane.setText(RefactoringUIMessages.PreviewWizardPage_changes);
229         fNextAction.setEnabled(true);
230         fPreviousAction.setEnabled(true);
231         fFilterDropDownAction.setEnabled(true);
232         fTreeViewer.setInput(input);
233     }
234
235     /**
236      * {@inheritDoc}
237      */

238     public void setVisible(final boolean visible) {
239         super.setVisible(visible);
240         if (fTreeViewer.getInput() == null)
241             fFilterDropDownAction.setEnabled(false);
242     }
243
244     /**
245      * {@inheritDoc}
246      */

247     public void setWizard(final IWizard newWizard) {
248         Assert.isTrue(newWizard instanceof RefactoringHistoryWizard);
249         super.setWizard(newWizard);
250     }
251 }
252
Popular Tags