KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > actions > RefactoringStarter


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 package org.eclipse.jdt.internal.ui.refactoring.actions;
12
13 import org.eclipse.jdt.core.JavaModelException;
14
15 import org.eclipse.swt.widgets.Shell;
16
17 import org.eclipse.jface.dialogs.IDialogConstants;
18
19 import org.eclipse.jdt.internal.ui.refactoring.RefactoringSaveHelper;
20
21 import org.eclipse.ltk.core.refactoring.Refactoring;
22 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
23 import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
24 import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
25
26 /**
27  * A helper class to activate the UI of a refactoring
28  */

29 public class RefactoringStarter {
30     
31     private RefactoringStatus fStatus;
32
33     /**
34      * @param refactoring
35      * @param wizard
36      * @param parent
37      * @param dialogTitle
38      * @param saveMode a save mode from {@link RefactoringSaveHelper}
39      * @return <code>true</code> if the refactoring was executed, <code>false</code> otherwise
40      * @throws JavaModelException
41      */

42     public boolean activate(Refactoring refactoring, RefactoringWizard wizard, Shell parent, String JavaDoc dialogTitle, int saveMode) throws JavaModelException {
43         RefactoringSaveHelper saveHelper= new RefactoringSaveHelper(saveMode);
44         if (! canActivate(saveHelper, parent))
45             return false;
46
47         try {
48             RefactoringWizardOpenOperation op= new RefactoringWizardOpenOperation(wizard);
49             int result= op.run(parent, dialogTitle);
50             fStatus= op.getInitialConditionCheckingStatus();
51             if (result == IDialogConstants.CANCEL_ID || result == RefactoringWizardOpenOperation.INITIAL_CONDITION_CHECKING_FAILED) {
52                 saveHelper.triggerBuild();
53                 return false;
54             } else {
55                 return true;
56             }
57         } catch (InterruptedException JavaDoc e) {
58             return false; // User action got cancelled
59
}
60     }
61     
62     public RefactoringStatus getInitialConditionCheckingStatus() {
63         return fStatus;
64     }
65         
66     private boolean canActivate(RefactoringSaveHelper saveHelper, Shell shell) {
67         return saveHelper.saveEditors(shell);
68     }
69 }
70
Popular Tags