blob: 4a6c2f414273b62d7c711ff83d4c9d036254993b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
*******************************************************************************/
package org.eclipse.dltk.internal.ui.refactoring.actions;
import org.eclipse.dltk.core.ModelException;
import org.eclipse.dltk.internal.ui.refactoring.RefactoringSaveHelper;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
import org.eclipse.swt.widgets.Shell;
/**
* A helper class to activate the UI of a refactoring
*/
public class RefactoringStarter {
private RefactoringSaveHelper fSaveHelper= new RefactoringSaveHelper();
private RefactoringStatus fStatus;
public void activate(Refactoring refactoring, RefactoringWizard wizard, Shell parent, String dialogTitle, boolean mustSaveEditors) throws ModelException {
if (! canActivate(mustSaveEditors, parent))
return;
try {
RefactoringWizardOpenOperation op= new RefactoringWizardOpenOperation(wizard);
int result= op.run(parent, dialogTitle);
fStatus= op.getInitialConditionCheckingStatus();
if (result == IDialogConstants.CANCEL_ID || result == RefactoringWizardOpenOperation.INITIAL_CONDITION_CHECKING_FAILED)
fSaveHelper.triggerBuild();
} catch (InterruptedException e) {
// do nothing. User action got cancelled
}
}
public RefactoringStatus getInitialConditionCheckingStatus() {
return fStatus;
}
private boolean canActivate(boolean mustSaveEditors, Shell shell) {
return ! mustSaveEditors || fSaveHelper.saveEditors(shell);
}
}