eclipse plugin: use a commong template for wizards
This commit is contained in:
parent
a6d98e46fc
commit
d3f0d46ddf
3 changed files with 44 additions and 56 deletions
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* @author Timotei Dolean
|
||||
*
|
||||
*/
|
||||
package wesnoth_eclipse_plugin.wizards;
|
||||
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.wizard.IWizardPage;
|
||||
import org.eclipse.jface.wizard.Wizard;
|
||||
import org.eclipse.ui.INewWizard;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
|
||||
public abstract class NewWizardTemplate extends Wizard implements INewWizard
|
||||
{
|
||||
protected ISelection selection_;
|
||||
protected int lastPageHashCode_ = 0;
|
||||
|
||||
@Override
|
||||
public void init(IWorkbench workbench, IStructuredSelection selection)
|
||||
{
|
||||
this.selection_ = selection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFinish()
|
||||
{
|
||||
IWizardPage page = getContainer().getCurrentPage();
|
||||
return super.canFinish() && page.hashCode() == lastPageHashCode_ && page.isPageComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPages()
|
||||
{
|
||||
lastPageHashCode_ = getPages()[getPageCount() - 1].hashCode();
|
||||
}
|
||||
}
|
|
@ -10,26 +10,20 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.wizard.IWizardPage;
|
||||
import org.eclipse.jface.wizard.Wizard;
|
||||
import org.eclipse.ui.INewWizard;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
|
||||
import wesnoth_eclipse_plugin.builder.WesnothProjectNature;
|
||||
import wesnoth_eclipse_plugin.utils.Pair;
|
||||
import wesnoth_eclipse_plugin.utils.ResourceUtils;
|
||||
import wesnoth_eclipse_plugin.wizards.NewWizardTemplate;
|
||||
import wesnoth_eclipse_plugin.wizards.ReplaceableParameter;
|
||||
import wesnoth_eclipse_plugin.wizards.TemplateProvider;
|
||||
|
||||
public class CampaignNewWizard extends Wizard implements INewWizard
|
||||
public class CampaignNewWizard extends NewWizardTemplate
|
||||
{
|
||||
protected CampaignPage0 page0_;
|
||||
protected CampaignPage1 page1_;
|
||||
protected CampaignPage2 page2_;
|
||||
|
||||
protected int lastPageHashCode_ = 0;
|
||||
|
||||
@Override
|
||||
public void addPages()
|
||||
{
|
||||
|
@ -42,7 +36,7 @@ public class CampaignNewWizard extends Wizard implements INewWizard
|
|||
page2_ = new CampaignPage2();
|
||||
addPage(page2_);
|
||||
|
||||
lastPageHashCode_ = getPages()[getPageCount() - 1].hashCode();
|
||||
super.addPages();
|
||||
}
|
||||
|
||||
public CampaignNewWizard() {
|
||||
|
@ -50,11 +44,6 @@ public class CampaignNewWizard extends Wizard implements INewWizard
|
|||
setNeedsProgressMonitor(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IWorkbench workbench, IStructuredSelection selection)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performFinish()
|
||||
{
|
||||
|
@ -150,11 +139,4 @@ public class CampaignNewWizard extends Wizard implements INewWizard
|
|||
|
||||
return TemplateProvider.getInstance().getProcessedTemplate(templateName, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFinish()
|
||||
{
|
||||
IWizardPage page = getContainer().getCurrentPage();
|
||||
return super.canFinish() && page.hashCode() == lastPageHashCode_ && page.isPageComplete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,20 +18,14 @@ import org.eclipse.core.runtime.Path;
|
|||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.wizard.IWizardPage;
|
||||
import org.eclipse.jface.wizard.Wizard;
|
||||
import org.eclipse.ui.INewWizard;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWizard;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
|
||||
import wesnoth_eclipse_plugin.utils.GUIUtils;
|
||||
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
|
||||
import wesnoth_eclipse_plugin.wizards.NewWizardTemplate;
|
||||
import wesnoth_eclipse_plugin.wizards.ReplaceableParameter;
|
||||
import wesnoth_eclipse_plugin.wizards.TemplateProvider;
|
||||
|
||||
|
@ -44,13 +38,10 @@ import wesnoth_eclipse_plugin.wizards.TemplateProvider;
|
|||
* same extension, it will be able to open it.
|
||||
*/
|
||||
|
||||
public class ScenarioNewWizard extends Wizard implements INewWizard
|
||||
public class ScenarioNewWizard extends NewWizardTemplate
|
||||
{
|
||||
private ScenarioPage0 page0_;
|
||||
private ScenarioPage1 page1_;
|
||||
private ISelection selection;
|
||||
|
||||
protected int lastPageHashCode_;
|
||||
|
||||
/**
|
||||
* Constructor for ScenarioNewWizard.
|
||||
|
@ -66,24 +57,13 @@ public class ScenarioNewWizard extends Wizard implements INewWizard
|
|||
@Override
|
||||
public void addPages()
|
||||
{
|
||||
page0_ = new ScenarioPage0(selection);
|
||||
page0_ = new ScenarioPage0(selection_);
|
||||
addPage(page0_);
|
||||
|
||||
page1_ = new ScenarioPage1();
|
||||
// addPage(page1_);
|
||||
|
||||
lastPageHashCode_ = getPages()[getPageCount() - 1].hashCode();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.jface.wizard.Wizard#canFinish()
|
||||
*/
|
||||
@Override
|
||||
public boolean canFinish()
|
||||
{
|
||||
IWizardPage page = getContainer().getCurrentPage();
|
||||
return super.canFinish() && page.hashCode() == lastPageHashCode_ && page.isPageComplete();
|
||||
super.addPages();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,15 +196,4 @@ public class ScenarioNewWizard extends Wizard implements INewWizard
|
|||
IStatus status = new Status(IStatus.ERROR, "Wesnoth_Eclipse_Plugin", IStatus.OK, message, null);
|
||||
throw new CoreException(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* We will accept the selection in the workbench to see if we can initialize
|
||||
* from it.
|
||||
* @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
|
||||
*/
|
||||
@Override
|
||||
public void init(IWorkbench workbench, IStructuredSelection selection)
|
||||
{
|
||||
this.selection = selection;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue