Merge branch 'develop' into remoting-4.0
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 15 Sep 2015 10:11:19 +0000 (12:11 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 15 Sep 2015 10:11:19 +0000 (12:11 +0200)
Conflicts:
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewDerivedUnitBaseWizard.java

eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenDerivateViewHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewDerivedUnitBaseWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/SpecimenOrObservationPreferences.java

index d3812b9e34bf57ac742abd35716ba0dda4edfe10..b046571654ef77b5b12f17c32edd6c111d758b14 100644 (file)
             id="eu.etaxonomy.taxeditor.editor.view.descriptive.command.moveDescriptionElements"
             name="%command.name.12">
       </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.editor.handler.OpenDerivateViewHandler"
+            id="eu.etaxonomy.taxeditor.editor.openSpecimenEditor"
+            name="Open Specimen Editor">
+         <commandParameter
+               id="eu.etaxonomy.taxeditor.specimenUuidParameter"
+               name="Specimen UUID parameter"
+               optional="true"
+               typeId="eu.etaxonomy.taxeditor.specimenUuidParameterType">
+         </commandParameter>
+      </command>
         
    </extension>
+   <extension
+         point="org.eclipse.ui.commands">
+      <commandParameterType
+            converter="eu.etaxonomy.taxeditor.handler.UuidParameterConverter"
+            id="eu.etaxonomy.taxeditor.specimenUuidParameterType"
+            type="java.util.UUID">
+      </commandParameterType>
+   </extension>
    <extension
          point="org.eclipse.core.expressions.definitions">
       <definition
index 318191f82fa760fed8d2b965fd9bf183f57cb0a0..9094200090805c610265ff7987a10c49498462d7 100644 (file)
@@ -21,41 +21,51 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
 
 public class OpenDerivateViewHandler extends AbstractHandler {
 
-    /* (non-Javadoc)
-     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-     */
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
-        if(currentSelection instanceof IStructuredSelection){
-            Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
-            Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
-            while(selectionIterator.hasNext()){
-                Object object = selectionIterator.next();
-                if(object instanceof SpecimenOrObservationBase<?>){
-                    selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
-                }
-                else if(object instanceof IndividualsAssociation){
-                    SpecimenOrObservationBase specimen = ((IndividualsAssociation) object).getAssociatedSpecimenOrObservation();
-                    if(specimen!=null){
-                        selectedElementUUIDs.add(specimen.getUuid());
+        Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
+        Object parameter;
+        //check if parameter is set
+        try {
+            parameter = event.getObjectParameterForExecution("eu.etaxonomy.taxeditor.specimenUuidParameter");
+        } catch (ExecutionException e) {
+            parameter = null;
+        }
+        if(parameter instanceof UUID){
+            selectedElementUUIDs.add((UUID) parameter);
+        }
+        else{
+            //if not, try with current selection
+            ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+            if(currentSelection instanceof IStructuredSelection){
+                Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
+                while(selectionIterator.hasNext()){
+                    Object object = selectionIterator.next();
+                    if(object instanceof SpecimenOrObservationBase<?>){
+                        selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
+                    }
+                    else if(object instanceof IndividualsAssociation){
+                        SpecimenOrObservationBase specimen = ((IndividualsAssociation) object).getAssociatedSpecimenOrObservation();
+                        if(specimen!=null){
+                            selectedElementUUIDs.add(specimen.getUuid());
+                        }
                     }
                 }
             }
-            if(!selectedElementUUIDs.isEmpty()){
-                DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
-                try {
-                    EditorUtil.open(input);
-                } catch (PartInitException e) {
-                    MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivative Editor", e);
-                } catch (NullPointerException npe){
-                    MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe);
-                }
-            }
-            else{
-                MessagingUtils.informationDialog("Empty selection", "No Specimen selected.");
+        }
+        if(!selectedElementUUIDs.isEmpty()){
+            DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
+            try {
+                EditorUtil.open(input);
+            } catch (PartInitException e) {
+                MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivative Editor", e);
+            } catch (NullPointerException npe){
+                MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe);
             }
         }
+        else{
+            MessagingUtils.informationDialog("Empty selection", "No Specimen selected.");
+        }
         return null;
     }
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java
new file mode 100644 (file)
index 0000000..5bd3db1
--- /dev/null
@@ -0,0 +1,24 @@
+package eu.etaxonomy.taxeditor.handler;
+
+import java.util.UUID;
+
+import org.eclipse.core.commands.AbstractParameterValueConverter;
+import org.eclipse.core.commands.ParameterValueConversionException;
+
+public class UuidParameterConverter extends AbstractParameterValueConverter {
+
+    public UuidParameterConverter() {
+        // TODO Auto-generated constructor stub
+    }
+
+    @Override
+    public Object convertToObject(String parameterValue) throws ParameterValueConversionException {
+        return UUID.fromString(parameterValue);
+    }
+
+    @Override
+    public String convertToString(Object parameterValue) throws ParameterValueConversionException {
+        return parameterValue.toString();
+    }
+
+}
index 836c953c9ef7986fa2edfc4fbcb606eb2b72a380..59dee8496855c1bac5928fe4b999b16cd9d67b00 100644 (file)
@@ -1,15 +1,32 @@
 // $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;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionException;
+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;
+import org.eclipse.ui.handlers.IHandlerService;
+
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
@@ -19,7 +36,10 @@ import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 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;
@@ -27,6 +47,7 @@ import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitGeneralWizardPage
 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitGeneralWizardPage;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitWizardPage;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
+import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchCompositeController;
 
 /**
  * @author n.hoffmann
@@ -34,39 +55,39 @@ import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
  * @version 1.0
  */
 public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard<SpecimenOrObservationBase> 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
@@ -76,8 +97,8 @@ public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard<SpecimenOr
         } else {
             if (SpecimenOrObservationType.Media.equals(specOrObsType)
                     || ((specOrObsType.getKindOf() != null) && specOrObsType.getKindOf().equals(SpecimenOrObservationType.Media))) {
-                   MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(specOrObsType);
-                   //a MediaSpecimen with no media attached does not make sense. Hence, we add one
+                MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(specOrObsType);
+                //a MediaSpecimen with no media attached does not make sense. Hence, we add one
                 mediaSpecimen.setMediaSpecimen(Media.NewInstance());
                 return mediaSpecimen;
             } else if (specOrObsType.equals(SpecimenOrObservationType.FieldUnit)) {
@@ -88,16 +109,66 @@ public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard<SpecimenOr
         }
     }
 
+
        /** {@inheritDoc} */
        @Override
        protected void saveEntity() {
                CdmStore.getService(IOccurrenceService.class).merge(getEntity());
        }
 
-       @Override
-       protected String getEntityName() {
-               return "Specimen";
-       }
+
+    @Override
+    protected String getEntityName() {
+        return "Specimen";
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean performFinish() {
+        boolean performFinish = super.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 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<String, UUID> parameters = new HashMap<String, UUID>();
+            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 performFinish;
+    }
 
 
 }
index fc2422da97852185043d89dd3254ebce88d9377f..5e9432541ac74e65e983e505ac5cf0629cfc0e4e 100644 (file)
@@ -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";
 
index 9c9bd5aee17d34aaf503280f48c7394b1a51b4bd..d9a9ac3cc47bcd9ec02c87aa489635523a2dff21 100644 (file)
@@ -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()));
     }