001: package net.refractions.udig.catalog.internal.ui;
002:
003: import java.lang.reflect.InvocationTargetException;
004:
005: import net.refractions.udig.catalog.ui.CatalogUIPlugin;
006: import net.refractions.udig.catalog.ui.internal.Messages;
007: import net.refractions.udig.catalog.ui.workflow.Workflow;
008: import net.refractions.udig.catalog.ui.workflow.WorkflowWizard;
009:
010: import org.eclipse.core.runtime.IProgressMonitor;
011: import org.eclipse.jface.dialogs.IPageChangedListener;
012: import org.eclipse.jface.dialogs.PageChangedEvent;
013: import org.eclipse.jface.operation.IRunnableWithProgress;
014: import org.eclipse.jface.viewers.IStructuredSelection;
015: import org.eclipse.jface.wizard.IWizardPage;
016: import org.eclipse.jface.wizard.WizardDialog;
017: import org.eclipse.ui.IImportWizard;
018: import org.eclipse.ui.IWorkbench;
019:
020: public class CatalogImportDelegateWizard extends WorkflowWizard
021: implements IImportWizard {
022:
023: // used to figure out when user presses back
024: PageListener pageListener;
025:
026: public CatalogImportDelegateWizard() {
027: super (new MyCatalogImport().createWorkflow(),
028: new MyCatalogImport().createPageMapping());
029:
030: setWindowTitle(Messages.CatalogImportDelegateWizard_windowTitle);
031: }
032:
033: public void init(IWorkbench workbench,
034: IStructuredSelection selection) {
035: getWorkflow().start(null);
036: }
037:
038: @Override
039: public IWizardPage getNextPage(IWizardPage page) {
040: //create the page listener
041: if (pageListener == null) {
042: pageListener = new PageListener();
043: WizardDialog dialog = (WizardDialog) getContainer();
044: dialog.addPageChangedListener(pageListener);
045: }
046:
047: //move the workflow to the next state
048: try {
049: getContainer().run(true, true, new IRunnableWithProgress() {
050:
051: public void run(IProgressMonitor monitor)
052: throws InvocationTargetException,
053: InterruptedException {
054:
055: getWorkflow().next(monitor);
056: }
057:
058: });
059: } catch (InvocationTargetException e) {
060: CatalogUIPlugin.log(e.getLocalizedMessage(), e);
061: } catch (InterruptedException e) {
062: return null;
063: }
064:
065: return super .getNextPage(page);
066: }
067:
068: @Override
069: protected boolean performFinish(IProgressMonitor monitor) {
070:
071: if (!getWorkflow().isFinished())
072: getWorkflow().next(monitor);
073:
074: CatalogImport.CatalogImportWizard catalogImportWizard = new CatalogImport.CatalogImportWizard(
075: getWorkflow(), getStateMap());
076: catalogImportWizard.setContainer(getContainer());
077: boolean performFinish = catalogImportWizard.performFinish();
078:
079: // TODO Something will need to be done here...
080: // if( !performFinish )
081: // getWorkflow().previous(monitor);
082: return performFinish;
083: }
084:
085: @Override
086: public boolean needsProgressMonitor() {
087: return true;
088: }
089:
090: static class MyCatalogImport extends CatalogImport {
091: @Override
092: void init() {
093: //do nothing
094: }
095: }
096:
097: class PageListener implements IPageChangedListener {
098: public void pageChanged(PageChangedEvent event) {
099: if (event.getSelectedPage() == null)
100: return;
101:
102: //going backward?
103: Workflow.State state = getWorkflow().getCurrentState();
104: if (state != null && state.getPreviousState() != null) {
105: if (event.getSelectedPage().equals(
106: getPage(state.getPreviousState()))) {
107: //yes, move workflow backward
108: try {
109: getContainer().run(true, true,
110: new IRunnableWithProgress() {
111:
112: public void run(
113: IProgressMonitor monitor)
114: throws InvocationTargetException,
115: InterruptedException {
116:
117: getWorkflow().previous(monitor);
118: }
119:
120: });
121: } catch (InvocationTargetException e) {
122: CatalogUIPlugin.log(e.getLocalizedMessage(), e);
123: } catch (InterruptedException e) {
124: }
125:
126: //update buttons
127: getContainer().updateButtons();
128: }
129: }
130: }
131: }
132: }
|