From c3f51ad2df19b5b938377173cf1d2d90c7fe8b63 Mon Sep 17 00:00:00 2001 From: Patrick Plitzner Date: Tue, 15 Sep 2015 10:52:47 +0200 Subject: [PATCH] Add preference for opening a newly created specimen in specimen editor --- .../newWizard/NewDerivedUnitBaseWizard.java | 176 ++++++++++-------- .../taxeditor/preference/IPreferenceKeys.java | 4 + .../SpecimenOrObservationPreferences.java | 13 +- 3 files changed, 106 insertions(+), 87 deletions(-) diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewDerivedUnitBaseWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewDerivedUnitBaseWizard.java index c4215fd34..41de8fd8e 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewDerivedUnitBaseWizard.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewDerivedUnitBaseWizard.java @@ -1,12 +1,12 @@ // $Id$ /** -* Copyright (C) 2007 EDIT -* 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. -*/ + * Copyright (C) 2007 EDIT + * 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. + */ package eu.etaxonomy.taxeditor.newWizard; @@ -20,6 +20,8 @@ import org.eclipse.core.commands.NotEnabledException; import org.eclipse.core.commands.NotHandledException; import org.eclipse.core.commands.ParameterizedCommand; import org.eclipse.core.commands.common.NotDefinedException; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService; @@ -37,6 +39,7 @@ import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; import eu.etaxonomy.taxeditor.model.AbstractUtility; import eu.etaxonomy.taxeditor.model.IDerivedUnitFacadePart; import eu.etaxonomy.taxeditor.model.MessagingUtils; +import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; import eu.etaxonomy.taxeditor.preference.PreferencesUtil; import eu.etaxonomy.taxeditor.store.CdmStore; import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseWizardPage; @@ -52,39 +55,39 @@ import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchCompositeControl * @version 1.0 */ public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard implements IDerivedUnitFacadePart{ - private SpecimenOrObservationType specOrObsType = null; + private SpecimenOrObservationType specOrObsType = null; - public NewDerivedUnitBaseWizard() { - super(); - } + public NewDerivedUnitBaseWizard() { + super(); + } - public NewDerivedUnitBaseWizard(SpecimenOrObservationType specOrObsType) { - super(); - this.specOrObsType = specOrObsType; - } - /** {@inheritDoc} */ - @Override - public void addPages() { - DerivedUnitFacade facade = null; - try { - if(getEntity() instanceof DerivedUnit) { - facade = DerivedUnitFacade.NewInstance((DerivedUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator()); - addPage(new DerivedUnitGeneralWizardPage(formFactory, getConversationHolder(), facade)); - addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade)); - addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade)); - addPage(new DerivedUnitBaseWizardPage(formFactory, getConversationHolder(), facade)); - } - else if(getEntity() instanceof FieldUnit){ - facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, (FieldUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator()); - addPage(new FieldUnitGeneralWizardPage(formFactory, getConversationHolder(), facade)); - addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade)); - addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade)); - } - } catch (DerivedUnitFacadeNotSupportedException e) { - // we should never get here - throw new IllegalStateException(); - } - } + public NewDerivedUnitBaseWizard(SpecimenOrObservationType specOrObsType) { + super(); + this.specOrObsType = specOrObsType; + } + /** {@inheritDoc} */ + @Override + public void addPages() { + DerivedUnitFacade facade = null; + try { + if(getEntity() instanceof DerivedUnit) { + facade = DerivedUnitFacade.NewInstance((DerivedUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator()); + addPage(new DerivedUnitGeneralWizardPage(formFactory, getConversationHolder(), facade)); + addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade)); + addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade)); + addPage(new DerivedUnitBaseWizardPage(formFactory, getConversationHolder(), facade)); + } + else if(getEntity() instanceof FieldUnit){ + facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, (FieldUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator()); + addPage(new FieldUnitGeneralWizardPage(formFactory, getConversationHolder(), facade)); + addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade)); + addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade)); + } + } catch (DerivedUnitFacadeNotSupportedException e) { + // we should never get here + throw new IllegalStateException(); + } + } /** {@inheritDoc} */ @Override @@ -94,8 +97,8 @@ public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard parameters = new HashMap(); - parameters.put("eu.etaxonomy.taxeditor.specimenUuidParameter", getEntity().getUuid()); - ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, parameters); + @Override + protected String getEntityName() { + return "Specimen"; + } - //execute the command - try { - handlerService.executeCommand(parameterizedCommand, null); - } catch (ExecutionException e) { - MessagingUtils.error(DerivateSearchCompositeController.class, e); - } catch (NotDefinedException e) { - MessagingUtils.error(DerivateSearchCompositeController.class, e); - } catch (NotEnabledException e) { - MessagingUtils.error(DerivateSearchCompositeController.class, e); - } catch (NotHandledException e) { - MessagingUtils.error(DerivateSearchCompositeController.class, e); + /** + * {@inheritDoc} + */ + @Override + public boolean performFinish() { + int returnCode = IDialogConstants.NO_ID; + if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.PROMPT_FOR_OPEN_SPECIMEN_IN_EDITOR)){ + MessageDialogWithToggle messageDialog = MessageDialogWithToggle.openYesNoQuestion(getShell(), + "Choose opening option", "Do you want to open the specimen in the specimen editor?", + "Remember my decision?", false, PreferencesUtil.getPreferenceStore(), + IPreferenceKeys.ALWAYS_OPEN_SPECIMEN_IN_EDITOR); + returnCode = messageDialog.getReturnCode(); + PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.PROMPT_FOR_OPEN_SPECIMEN_IN_EDITOR, messageDialog.getToggleState()); + if (returnCode != IDialogConstants.YES_ID) { + return super.performFinish(); + } } - - return performFinish; - } + if (returnCode==IDialogConstants.YES_ID || + PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.ALWAYS_OPEN_SPECIMEN_IN_EDITOR) + .equals(MessageDialogWithToggle.ALWAYS)) { + IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class); + + // get the command from plugin.xml + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + ICommandService cmdService = (ICommandService) window.getService(ICommandService.class); + Command command = cmdService.getCommand("eu.etaxonomy.taxeditor.editor.openSpecimenEditor"); + Map parameters = new HashMap(); + parameters.put("eu.etaxonomy.taxeditor.specimenUuidParameter", getEntity().getUuid()); + ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, parameters); + + // execute the command + try { + handlerService.executeCommand(parameterizedCommand, null); + } catch (ExecutionException e) { + MessagingUtils.error(DerivateSearchCompositeController.class, e); + } catch (NotDefinedException e) { + MessagingUtils.error(DerivateSearchCompositeController.class, e); + } catch (NotEnabledException e) { + MessagingUtils.error(DerivateSearchCompositeController.class, e); + } catch (NotHandledException e) { + MessagingUtils.error(DerivateSearchCompositeController.class, e); + } + } + return super.performFinish(); + } } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java index fc2422da9..5e9432541 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java @@ -143,6 +143,10 @@ public interface IPreferenceKeys { public static final String SHOW_ADVANCED_MEDIA_SECTION = "eu.etaxonomy.taxeditor.media.showAdvancedMedia"; + public static final String ALWAYS_OPEN_SPECIMEN_IN_EDITOR = "eu.etaxonomy.taxeditor.specimen.alwaysOpenSpecimenInEditor"; + + public static final String PROMPT_FOR_OPEN_SPECIMEN_IN_EDITOR = "eu.etaxonomy.taxeditor.specimen.promptForOpenSpecimenInEditor"; + // TODO RL public static final String IS_RL = "eu.etaxonomy.taxeditor.isRL"; diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/SpecimenOrObservationPreferences.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/SpecimenOrObservationPreferences.java index 9c9bd5aee..d9a9ac3cc 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/SpecimenOrObservationPreferences.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/SpecimenOrObservationPreferences.java @@ -9,7 +9,9 @@ */ package eu.etaxonomy.taxeditor.preference; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.ComboFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -21,17 +23,11 @@ import org.eclipse.ui.IWorkbenchPreferencePage; */ public class SpecimenOrObservationPreferences extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) - */ @Override public void init(IWorkbench workbench) { setPreferenceStore(PreferencesUtil.getPreferenceStore()); } - /* (non-Javadoc) - * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors() - */ @Override protected void createFieldEditors() { addField(new BooleanFieldEditor(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS, @@ -43,7 +39,10 @@ public class SpecimenOrObservationPreferences extends FieldEditorPreferencePage addField(new BooleanFieldEditor(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS, "Show taxon associations of a specimen in the details view", getFieldEditorParent())); - + addField(new ComboFieldEditor(IPreferenceKeys.ALWAYS_OPEN_SPECIMEN_IN_EDITOR, + "Open newly created specimens in specimen editor", new String[][] { + { "always", MessageDialogWithToggle.ALWAYS }, { "never", MessageDialogWithToggle.NEVER } }, + getFieldEditorParent())); } -- 2.34.1