- fixed double exception dialog popup when not connected to data source
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / AbstractImportWizard.java
index 4b946fa36f118ca55a29402cc11a601c4fd4d0e8..4c946a9a53b2541f01ca7ef3267303f6bb945179 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -14,7 +14,6 @@ import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.IWizardContainer;
 import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.SWT;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IEditorReference;
@@ -33,16 +32,16 @@ import eu.etaxonomy.cdm.io.common.IIoConfigurator;
  * @version 1.0
  */
 public abstract class AbstractImportWizard<CONFIG extends IIoConfigurator> extends Wizard implements IImportWizard {
-       
-       protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE"; 
-       
+
+       protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE";
+
        private GenericConfiguratorWizardPage pageConfiguration;
        private NomenclaturalCodeWizardPage pageNomenclaturalCode;
 
        private IWorkbench workbench;
 
        private IStructuredSelection selection;
-       
+
 
        /* (non-Javadoc)
         * @see org.eclipse.jface.wizard.Wizard#addPages()
@@ -51,25 +50,30 @@ public abstract class AbstractImportWizard<CONFIG extends IIoConfigurator> exten
        @Override
        public void addPages() {
                super.addPages();
-               
+
                pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator());
                this.addPage(pageConfiguration);
-               
+
                pageNomenclaturalCode = new NomenclaturalCodeWizardPage((IImportConfigurator)getConfigurator());
                this.addPage(pageNomenclaturalCode);
-               
-               
+
+
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.jface.wizard.Wizard#setContainer(org.eclipse.jface.wizard.IWizardContainer)
         */
        @Override
        public void setContainer(IWizardContainer wizardContainer) {
-               super.setContainer(wizardContainer);
-               checkForUnsavedEditors();
+               if(existUnsavedEditors()){
+                   MessageDialog.open(MessageDialog.WARNING, getShell(), "Unsaved editors", "Please save all open editors before executing " +
+                           "an import operation. The import operation will be cancelled", SWT.NONE);
+               }
+               else{
+                   super.setContainer(wizardContainer);
+               }
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
         */
@@ -78,28 +82,28 @@ public abstract class AbstractImportWizard<CONFIG extends IIoConfigurator> exten
                this.setWorkbench(workbench);
                this.setSelection(selection);
        }
-       
-       protected void checkForUnsavedEditors(){
+
+       protected boolean existUnsavedEditors(){
                IWorkbenchPage activePage = getWorkbench().getActiveWorkbenchWindow().getActivePage();
-               
                if(activePage != null){
                        for (IEditorReference reference : activePage.getEditorReferences()) {
                                IEditorPart editor = reference.getEditor(false);
                                if(editor.isDirty()){
-                                       
-                                       MessageDialog.open(MessageDialog.WARNING, getShell(), "Unsaved editors", "Please save all open editors before executing " +
-                                                       "an import operation. The import operation will be cancelled", SWT.NONE);
-                                       
-                                       performCancel();
-                                       if(getContainer() instanceof WizardDialog){
-                                               ((WizardDialog)getContainer()).close();
-                                       }
-                                       
+                                       return true;
                                }
                        }
                }
+               return false;
        }
-       
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.wizard.Wizard#canFinish()
+        */
+       @Override
+       public boolean canFinish() {
+           return !existUnsavedEditors();
+       }
+
        /**
         * <p>getConfigurator</p>
         *