blob: 65262fbaf6050afa715b7cecf4472c640dc2b6a7 [file] [log] [blame]
package org.eclipse.epp.installer.internal.ui.steps;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.epp.installer.core.model.IInstallStep;
import org.eclipse.epp.installer.core.model.InstallOperation;
import org.eclipse.epp.installer.core.operations.UndoInstallOperation;
import org.eclipse.epp.installer.core.steps.RunOperationsStep;
import org.eclipse.epp.installer.internal.ui.WizardInstaller;
import org.eclipse.epp.installer.internal.ui.pages.InstallCodePage;
import org.eclipse.epp.installer.ui.WizardStep;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
/**
* <p>
* Copyright (c) 2006, Instantiations, Inc.<br>
* All Rights Reserved
*/
public class RunOperationsWizardStep extends WizardStep {
public RunOperationsWizardStep(IInstallStep step) {
super(step);
}
protected WizardPage createPage() {
return new InstallCodePage(this, "installCode");
}
public void aboutToShow() {
super.aboutToShow();
final IStatus[] status = new IStatus[1];
IWizardContainer dialog = getPage().getWizard().getContainer();
RunOperationsStep step = (RunOperationsStep) getInstallStep();
try {
dialog.run(true, true, getOperationRunnable(step.getRootOperation()));
status[0] = step.verifyStep();
} catch(Exception e) {
status[0] = new Status(IStatus.ERROR, WizardInstaller.PLUGIN_ID, 0,
"error running operations", e);
}
if(status[0].getSeverity() >= IStatus.ERROR) {
if(status[0].getSeverity() == IStatus.CANCEL ) {
/*updatePageComplete(new Status(IStatus.WARNING, WizardInstaller.PLUGIN_ID, 0,
"Install was canceled...", null));*/
IWizardPage page = this.getPage();
page.setDescription("Installing canceled.");
}
else {
updatePageComplete(status[0]);
}
if (step.canRollback()) {
InstallOperation rollback = new UndoInstallOperation(step.getInstaller().getInstallLog());
try {
dialog.run(true, false, getOperationRunnable(rollback));
}
catch (Exception e) {
updatePageComplete(new Status(IStatus.ERROR, WizardInstaller.PLUGIN_ID, 0,
"error running operations", e));
e.printStackTrace();
}
}
}
nextPage();
}
private void nextPage() {
IWizardContainer dialog = getPage().getWizard().getContainer();
if( dialog != null ) {
IWizardPage page = this.getPage();
if( page != null ) {
IWizardPage nextPage = page.getNextPage();
if( nextPage != null ) {
dialog.showPage(nextPage);
}
}
}
}
private IRunnableWithProgress getOperationRunnable(final InstallOperation operation) {
return new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
RunOperationsStep step = (RunOperationsStep) getInstallStep();
step.run(operation, monitor);
}
};
}
}