From 7c6e83fe0ab93017b619b75580da1c585193b2b2 Mon Sep 17 00:00:00 2001 From: Patric Plitzner Date: Mon, 27 Oct 2014 12:48:42 +0000 Subject: [PATCH] - fixed double exception dialog popup when not connected to data source - fixed NPE when starting ABCD import with dirty editors --- .../io/wizard/AbstractImportWizard.java | 60 ++++++++++--------- .../etaxonomy/taxeditor/store/CdmStore.java | 15 ++--- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/AbstractImportWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/AbstractImportWizard.java index 4b946fa36..4c946a9a5 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/AbstractImportWizard.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/AbstractImportWizard.java @@ -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 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 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 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(); + } + /** *

getConfigurator

* diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java index 00a999bd8..8b151109d 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java @@ -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.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; @@ -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.database.ICdmDataSource; 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; - } else if (instance == null || !instance.isConnected) { + } else{// if (instance == null || !instance.isConnected) { 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); - + 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); } - + } /** @@ -203,7 +198,7 @@ public class CdmStore { private CdmStore(ICdmApplicationConfiguration applicationController, ICdmSource cdmSource) { - this.applicationConfiguration = applicationController; + this.applicationConfiguration = applicationController; this.cdmSource = cdmSource; isConnected = true; } @@ -512,7 +507,7 @@ public class CdmStore { } return null; } - + /** *

* getDataSource -- 2.34.1