KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > history > RefactoringHistoryErrorPage


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.history;
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
19 import org.eclipse.ltk.internal.ui.refactoring.ErrorWizardPage;
20 import org.eclipse.ltk.internal.ui.refactoring.Messages;
21 import org.eclipse.ltk.internal.ui.refactoring.RefactoringStatusEntryFilter;
22 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages;
23
24 import org.eclipse.swt.widgets.Composite;
25
26 import org.eclipse.jface.dialogs.IDialogConstants;
27 import org.eclipse.jface.wizard.IWizard;
28 import org.eclipse.jface.wizard.IWizardPage;
29
30 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryWizard;
31
32 /**
33  * Error page for refactoring history wizards.
34  *
35  * @since 3.2
36  */

37 public final class RefactoringHistoryErrorPage extends ErrorWizardPage {
38
39     /** The status entry filter */
40     private RefactoringStatusEntryFilter fFilter= new RefactoringStatusEntryFilter();
41
42     /** Is the next wizard page disabled? */
43     private boolean fNextPageDisabled= false;
44
45     /** The current refactoring, or <code>null</code> */
46     private Refactoring fRefactoring;
47
48     /**
49      * Creates a new refactoring history error page.
50      */

51     public RefactoringHistoryErrorPage() {
52         super(true);
53         setTitle(RefactoringUIMessages.RefactoringHistoryOverviewPage_title);
54         setDescription(Messages.format(RefactoringUIMessages.RefactoringHistoryErrorPage_description, new String JavaDoc[] { getLabelAsText(IDialogConstants.NEXT_LABEL), getLabelAsText(IDialogConstants.FINISH_LABEL) }));
55     }
56
57     /**
58      * {@inheritDoc}
59      */

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

67     public void createControl(final Composite parent) {
68         super.createControl(parent);
69         fViewer.setFilter(fFilter);
70     }
71
72     /**
73      * {@inheritDoc}
74      */

75     public IWizardPage getNextPage() {
76         return getWizard().getNextPage(this);
77     }
78
79     /**
80      * {@inheritDoc}
81      */

82     public IWizardPage getPreviousPage() {
83         return getWizard().getPreviousPage(this);
84     }
85
86     /**
87      * Returns the current refactoring.
88      *
89      * @return the current refactoring
90      */

91     public Refactoring getRefactoring() {
92         return fRefactoring;
93     }
94
95     /**
96      * Returns the refactoring history wizard.
97      *
98      * @return the refactoring history wizard
99      */

100     protected RefactoringHistoryWizard getRefactoringHistoryWizard() {
101         final IWizard result= getWizard();
102         if (result instanceof RefactoringHistoryWizard)
103             return (RefactoringHistoryWizard) result;
104         return null;
105     }
106
107     /**
108      * Is the next wizard page disabled?
109      *
110      * @return <code>true</code> if disabled, <code>false</code> otherwise
111      */

112     public boolean isNextPageDisabled() {
113         return fNextPageDisabled;
114     }
115
116     /**
117      * {@inheritDoc}
118      */

119     protected boolean performFinish() {
120         return true;
121     }
122
123     /**
124      * Sets the status entry filter.
125      *
126      * @param filter
127      * the status entry filter to set
128      */

129     public void setFilter(final RefactoringStatusEntryFilter filter) {
130         Assert.isNotNull(filter);
131         fFilter= filter;
132     }
133
134     /**
135      * Determines whether the next wizard page is disabled.
136      *
137      * @param disable
138      * <code>true</code> to disable, <code>false</code> otherwise
139      */

140     public void setNextPageDisabled(final boolean disable) {
141         fNextPageDisabled= disable;
142     }
143
144     /**
145      * {@inheritDoc}
146      */

147     public void setPageComplete(final boolean complete) {
148         super.setPageComplete(true);
149     }
150
151     /**
152      * Sets the current refactoring.
153      *
154      * @param refactoring
155      * the current refactoring, or <code>null</code>
156      */

157     public void setRefactoring(final Refactoring refactoring) {
158         fRefactoring= refactoring;
159     }
160
161     /**
162      * {@inheritDoc}
163      */

164     public void setStatus(final RefactoringStatus status) {
165         super.setStatus(status);
166         if (status != null) {
167             final int severity= status.getSeverity();
168             if (severity >= RefactoringStatus.FATAL)
169                 setDescription(RefactoringUIMessages.RefactoringHistoryErrorPage_fatal_error);
170             else if (severity >= RefactoringStatus.INFO)
171                 setDescription(Messages.format(RefactoringUIMessages.RefactoringHistoryErrorPage_info_error, new String JavaDoc[] { getLabelAsText(IDialogConstants.NEXT_LABEL), getLabelAsText(IDialogConstants.FINISH_LABEL) }));
172         }
173         if (fViewer != null)
174             fViewer.setStatus(status);
175     }
176
177     /**
178      * Sets the title of the page according to the refactoring.
179      *
180      * @param descriptor
181      * the refactoring descriptor, or <code>null</code>
182      * @param current
183      * the non-zero based index of the current refactoring
184      * @param total
185      * the total number of refactorings
186      */

187     public void setTitle(final RefactoringDescriptorProxy descriptor, final int current, final int total) {
188         final String JavaDoc message;
189         if (descriptor != null)
190             message= descriptor.getDescription();
191         else
192             message= RefactoringUIMessages.RefactoringHistoryOverviewPage_title;
193         if (total > 1)
194             setTitle(Messages.format(RefactoringUIMessages.RefactoringHistoryPreviewPage_refactoring_pattern, new String JavaDoc[] { message, String.valueOf(current + 1), String.valueOf(total) }));
195         else
196             setTitle(message);
197     }
198
199     /**
200      * {@inheritDoc}
201      */

202     public void setVisible(final boolean visible) {
203         if (visible) {
204             if (fViewer != null && fViewer.getStatus() != fStatus)
205                 fViewer.setStatus(fStatus);
206         } else
207             setPageComplete(!fNextPageDisabled);
208         getControl().setVisible(visible);
209     }
210
211     /**
212      * {@inheritDoc}
213      */

214     public void setWizard(final IWizard newWizard) {
215         Assert.isTrue(newWizard instanceof RefactoringHistoryWizard);
216         super.setWizard(newWizard);
217     }
218 }
219
Popular Tags