KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
12 package org.eclipse.ltk.internal.ui.refactoring;
13
14 import org.eclipse.core.runtime.Assert;
15
16 import org.eclipse.ltk.core.refactoring.Change;
17 import org.eclipse.ltk.core.refactoring.CreateChangeOperation;
18 import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
19 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
20
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.widgets.Composite;
23
24 import org.eclipse.jface.action.LegacyActionTools;
25 import org.eclipse.jface.dialogs.Dialog;
26 import org.eclipse.jface.dialogs.IDialogConstants;
27 import org.eclipse.jface.dialogs.MessageDialog;
28 import org.eclipse.jface.wizard.IWizardPage;
29
30 import org.eclipse.ui.PlatformUI;
31
32 import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
33 import org.eclipse.ltk.ui.refactoring.RefactoringWizardPage;
34
35 /**
36  * Presents the list of failed preconditions to the user
37  */

38 public class ErrorWizardPage extends RefactoringWizardPage implements IErrorWizardPage {
39         
40     protected RefactoringStatus fStatus;
41     protected RefactoringStatusViewer fViewer;
42     
43     /**
44      * Creates a new error wizard page.
45      */

46     public ErrorWizardPage() {
47         super(PAGE_NAME);
48     }
49     
50     /**
51      * Creates a new error wizard page.
52      *
53      * @param wizard
54      * <code>true</code> if the page belongs to a conventional
55      * wizard, <code>false</code> otherwise
56      */

57     public ErrorWizardPage(boolean wizard) {
58         super(PAGE_NAME, wizard);
59     }
60     
61     /**
62      * {@inheritDoc}
63      */

64     public void setStatus(RefactoringStatus status) {
65         fStatus= status;
66         if (fStatus != null) {
67             final int severity= fStatus.getSeverity();
68             setPageComplete(severity < RefactoringStatus.FATAL);
69             if (severity >= RefactoringStatus.FATAL) {
70                 setDescription(RefactoringUIMessages.ErrorWizardPage_cannot_proceed);
71             } else if (severity >= RefactoringStatus.INFO) {
72                 setDescription(Messages.format(RefactoringUIMessages.ErrorWizardPage_confirm, new String JavaDoc[] {getLabelAsText(IDialogConstants.NEXT_LABEL), getLabelAsText(IDialogConstants.FINISH_LABEL)}));
73             } else {
74                 setDescription(""); //$NON-NLS-1$
75
}
76         } else {
77             setPageComplete(true);
78             setDescription(""); //$NON-NLS-1$
79
}
80     }
81
82     protected String JavaDoc getLabelAsText(String JavaDoc label) {
83         Assert.isNotNull(label);
84         return LegacyActionTools.removeMnemonics(label);
85     }
86
87     /**
88      * {@inheritDoc}
89      */

90     public RefactoringStatus getStatus() {
91         return fStatus;
92     }
93     
94     //---- UI creation ----------------------------------------------------------------------
95

96     /* (non-Javadoc)
97      * Method declared in IWizardPage.
98      */

99     public void createControl(Composite parent) {
100         initializeDialogUnits(parent);
101         setControl(fViewer= new RefactoringStatusViewer(parent, SWT.NONE));
102         Dialog.applyDialogFont(fViewer);
103         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IRefactoringHelpContextIds.REFACTORING_ERROR_WIZARD_PAGE);
104     }
105     
106     //---- Reimplementation of WizardPage methods ------------------------------------------
107

108     /* (non-Javadoc)
109      * Method declared on IDialog.
110      */

111     public void setVisible(boolean visible) {
112         if (visible) {
113             fViewer.setStatus(fStatus);
114         } else {
115             // the page was not complete if we show a fatal error. In this
116
// case we can finish anyway. To enable the OK and Preview button
117
// on the user input page we have to mark the page as complete again.
118
if (!isPageComplete() && fStatus.hasFatalError())
119                 setPageComplete(true);
120         }
121         super.setVisible(visible);
122     }
123     
124     /* (non-Javadoc)
125      * Method declared in IWizardPage.
126      */

127     public boolean canFlipToNextPage() {
128         // We have to call super.getNextPage since computing the next
129
// page is expensive. So we avoid it as long as possible.
130
return fStatus != null && fStatus.getSeverity() < RefactoringStatus.FATAL &&
131                isPageComplete() && super.getNextPage() != null;
132     }
133     
134     /* (non-Javadoc)
135      * Method declared in IWizardPage.
136      */

137     public IWizardPage getNextPage() {
138         RefactoringWizard wizard= getRefactoringWizard();
139         Change change= wizard.getChange();
140         if (change == null) {
141             change= wizard.internalCreateChange(InternalAPI.INSTANCE, new CreateChangeOperation(getRefactoring()), false);
142             wizard.internalSetChange(InternalAPI.INSTANCE, change);
143         }
144         if (change == null)
145             return this;
146             
147         return super.getNextPage();
148     }
149     
150     /* (non-JavaDoc)
151      * Method defined in RefactoringWizardPage
152      */

153     protected boolean performFinish() {
154         RefactoringWizard wizard= getRefactoringWizard();
155         Change change= wizard.getChange();
156         PerformChangeOperation operation= null;
157         if (change != null) {
158             operation= new UIPerformChangeOperation(getShell().getDisplay(), change, getContainer());
159         } else {
160             CreateChangeOperation ccop= new CreateChangeOperation(getRefactoring());
161             operation= new UIPerformChangeOperation(getShell().getDisplay(), ccop, getContainer());
162         }
163         FinishResult result= wizard.internalPerformFinish(InternalAPI.INSTANCE, operation);
164         if (result.isException())
165             return true;
166         if (result.isInterrupted())
167             return false;
168         RefactoringStatus fValidationStatus= operation.getValidationStatus();
169         if (fValidationStatus != null && fValidationStatus.hasFatalError()) {
170             MessageDialog.openError(wizard.getShell(), wizard.getWindowTitle(),
171                 Messages.format(
172                     RefactoringUIMessages.RefactoringUI_cannot_execute,
173                     fValidationStatus.getMessageMatchingSeverity(RefactoringStatus.FATAL)));
174             return true;
175         }
176         return true;
177     }
178 }
179
Popular Tags