- fixed double exception dialog popup when not connected to data source
authorPatric Plitzner <p.plitzner@bgbm.org>
Mon, 27 Oct 2014 12:48:42 +0000 (12:48 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Mon, 27 Oct 2014 12:48:42 +0000 (12:48 +0000)
 - fixed NPE when starting ABCD import with dirty editors

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/AbstractImportWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java

index 4b946fa36f118ca55a29402cc11a601c4fd4d0e8..4c946a9a53b2541f01ca7ef3267303f6bb945179 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
 * 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.
 */
 * 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.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;
 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 {
  * @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;
        private GenericConfiguratorWizardPage pageConfiguration;
        private NomenclaturalCodeWizardPage pageNomenclaturalCode;
 
        private IWorkbench workbench;
 
        private IStructuredSelection selection;
-       
+
 
        /* (non-Javadoc)
         * @see org.eclipse.jface.wizard.Wizard#addPages()
 
        /* (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();
        @Override
        public void addPages() {
                super.addPages();
-               
+
                pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator());
                this.addPage(pageConfiguration);
                pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator());
                this.addPage(pageConfiguration);
-               
+
                pageNomenclaturalCode = new NomenclaturalCodeWizardPage((IImportConfigurator)getConfigurator());
                this.addPage(pageNomenclaturalCode);
                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) {
        /* (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)
         */
        /* (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);
        }
                this.setWorkbench(workbench);
                this.setSelection(selection);
        }
-       
-       protected void checkForUnsavedEditors(){
+
+       protected boolean existUnsavedEditors(){
                IWorkbenchPage activePage = getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IWorkbenchPage activePage = getWorkbench().getActiveWorkbenchWindow().getActivePage();
-               
                if(activePage != null){
                        for (IEditorReference reference : activePage.getEditorReferences()) {
                                IEditorPart editor = reference.getEditor(false);
                                if(editor.isDirty()){
                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>
         *
        /**
         * <p>getConfigurator</p>
         *
index 00a999bd835a197d2a17f7243d8f25cea94fedcd..8b151109d24e2cf12f5d26087a06c041ea6319ae 100644 (file)
@@ -17,8 +17,6 @@ import java.util.EnumSet;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.swt.widgets.Display;
-import org.hibernate.collection.internal.AbstractPersistentCollection;
-import org.hibernate.proxy.AbstractLazyInitializer;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 import org.springframework.security.access.PermissionEvaluator;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 import org.springframework.security.access.PermissionEvaluator;
@@ -32,7 +30,6 @@ import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.config.ICdmSource;
 import eu.etaxonomy.cdm.database.DbSchemaValidation;
 import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.config.ICdmSource;
 import eu.etaxonomy.cdm.database.DbSchemaValidation;
-import eu.etaxonomy.cdm.database.ICdmDataSource;
 import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
@@ -100,7 +97,7 @@ public class CdmStore {
        protected static CdmStore getDefault() {
                if (instance != null && instance.isConnected) {
                        return instance;
        protected static CdmStore getDefault() {
                if (instance != null && instance.isConnected) {
                        return instance;
-               } else if (instance == null || !instance.isConnected) {
+               } else{// if (instance == null || !instance.isConnected) {
 
                        MessagingUtils
                                        .warningDialog(
 
                        MessagingUtils
                                        .warningDialog(
@@ -110,10 +107,8 @@ public class CdmStore {
                                                        + "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
 
                        AbstractUtility.showView(CdmDataSourceViewPart.ID);
                                                        + "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
 
                        AbstractUtility.showView(CdmDataSourceViewPart.ID);
-
+                       return null;
                }
                }
-
-               throw new RuntimeException();
        }
 
        /**
        }
 
        /**
@@ -129,7 +124,7 @@ public class CdmStore {
                        MessagingUtils.messageDialog("Connection to CDM Source Failed", CdmStore.class, "Could not connect to target CDM Source", e);
                }
 
                        MessagingUtils.messageDialog("Connection to CDM Source Failed", CdmStore.class, "Could not connect to target CDM Source", e);
                }
 
-               
+
        }
 
        /**
        }
 
        /**
@@ -203,7 +198,7 @@ public class CdmStore {
 
        private CdmStore(ICdmApplicationConfiguration applicationController,
                        ICdmSource cdmSource) {
 
        private CdmStore(ICdmApplicationConfiguration applicationController,
                        ICdmSource cdmSource) {
-               this.applicationConfiguration = applicationController;          
+               this.applicationConfiguration = applicationController;
                this.cdmSource = cdmSource;
                isConnected = true;
        }
                this.cdmSource = cdmSource;
                isConnected = true;
        }
@@ -512,7 +507,7 @@ public class CdmStore {
                }
                return null;
        }
                }
                return null;
        }
-       
+
        /**
         * <p>
         * getDataSource
        /**
         * <p>
         * getDataSource