Applied generic framework for opening objects to classifications in
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 10 Dec 2015 07:39:17 +0000 (08:39 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 10 Dec 2015 07:39:17 +0000 (08:39 +0100)
taxon navigator

eu.etaxonomy.taxeditor.navigation/plugin.xml
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java [deleted file]
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java [moved from eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java with 67% similarity]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenClassificationWizardHandler.java [new file with mode: 0644]

index 9767c38e9a1f11287aaebd930a234739b1ee91d6..d67d603004d4c094e513666174f5ab568ab08d0f 100644 (file)
                </or>
             </visibleWhen>
          </command>
-         <command
-               commandId="eu.etaxonomy.taxeditor.store.open"
-               label="Edit"
-               style="push">
-            <visibleWhen
-                  checkEnabled="true">
-               <with
-                     variable="selection">
-                  <reference
-                        definitionId="isClassification">
-                  </reference>
-               </with>
-            </visibleWhen>
-         </command>
+         <dynamic
+               class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
+               id="eu.etaxonomy.taxeditor.navigation.cdmViewerContextMenu">
+         </dynamic>
          <command
                commandId="eu.etaxonomy.taxeditor.navigator.command.update.changeAcceptedToSynonym"
                label="%command.label.6"
          </test>
       </definition>
    </extension>
-   <extension
-         point="eu.etaxonomy.taxeditor.store.cdmViewer">
-      <cdmViewer
-            class="eu.etaxonomy.taxeditor.navigation.NavigationCdmViewer">
-      </cdmViewer>
-   </extension>
 </plugin>
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java
deleted file mode 100644 (file)
index 8ba357d..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-package eu.etaxonomy.taxeditor.navigation;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.ui.PlatformUI;
-
-import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
-import eu.etaxonomy.taxeditor.view.ICdmViewer;
-
-public class NavigationCdmViewer implements ICdmViewer {
-
-
-    @SuppressWarnings("unused")
-    private final Logger logger = Logger.getLogger(NavigationCdmViewer.class);
-
-    @Override
-    public void show(Object input, Class<?> viewerClass) {
-        if(viewerClass.equals(NewClassificationWizard.class)){
-            if(input instanceof Classification){
-                Classification classification = (Classification)input;
-                NewClassificationWizard classificationWizard = new NewClassificationWizard();
-                classificationWizard.init(null, null);
-                classificationWizard.setEntity(classification);
-                WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard);
-                dialog.open();
-            }
-        }
-    }
-
-    @Override
-    public Map<Class<?>, String> getViewerClasses(Object input) {
-        Map<Class<?>, String> viewerNameMap = new HashMap<Class<?>, String>();
-        if(input instanceof Classification){
-            viewerNameMap.put(NewClassificationWizard.class, "Classification Wizard");
-        }
-        return viewerNameMap;
-    }
-
-}
index 2b4298631c09465690dfebebbd151787d525eee3..aea7552f4f49e4ee1e6d8ffff5bea7bfa706065b 100644 (file)
@@ -15,6 +15,7 @@ Export-Package: eu.etaxonomy.cdm,
  eu.etaxonomy.taxeditor.editor.definedterm.input,
  eu.etaxonomy.taxeditor.featuretree,
  eu.etaxonomy.taxeditor.handler,
+ eu.etaxonomy.taxeditor.handler.defaultHandler,
  eu.etaxonomy.taxeditor.io,
  eu.etaxonomy.taxeditor.io.wizard,
  eu.etaxonomy.taxeditor.labels,
index 8e7a4532b909d73a51bc3ac89db09839fa27f5b1..40bf6eb077055f071d3c7e7537b779fde0ff92d7 100644 (file)
             id="eu.etaxonomy.taxeditor.store.open"
             name="%command.name.15">
       </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenClassificationWizardHandler"
+            id="eu.etaxonomy.taxeditor.command.openClassificationWizard"
+            name="Open Classification Wizard">
+         <commandParameter
+               id="eu.etaxonomy.taxeditor.command.openClassificationWizard.uuid"
+               name="Classification Uuid"
+               optional="true"
+               typeId="eu.etaxonomy.taxeditor.uuidParameterType">
+         </commandParameter>
+      </command>
+   </extension>
+   <extension
+         point="org.eclipse.ui.commands">
+      <commandParameterType
+            converter="eu.etaxonomy.taxeditor.handler.UuidsParameterTypeConverter"
+            id="eu.etaxonomy.taxeditor.uuidParameterType"
+            type="java.util.UUID">
+      </commandParameterType>
    </extension>
    <extension
          point="org.eclipse.ui.importWizards">
       </variable>
    </sourceProvider>
 </extension>
+<extension
+      point="eu.etaxonomy.taxeditor.store.cdmViewer">
+   <viewCommandMapping
+         commandId="eu.etaxonomy.taxeditor.command.openClassificationWizard"
+         selection="eu.etaxonomy.cdm.model.taxon.Classification"
+         viewerName="Classification Wizard">
+   </viewCommandMapping>
+</extension>
 </plugin>
similarity index 67%
rename from eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java
rename to eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java
index 5bd3db11e0cbdc0d3ffac447a90b6eb9343aef56..e23482714f7a82b235ab79c573545ffed87b34ea 100644 (file)
@@ -5,10 +5,17 @@ import java.util.UUID;
 import org.eclipse.core.commands.AbstractParameterValueConverter;
 import org.eclipse.core.commands.ParameterValueConversionException;
 
-public class UuidParameterConverter extends AbstractParameterValueConverter {
+/**
+ * Converts {@link UUID}s to a string representation
+ * and vica versa.
+ *
+ * @author pplitzner
+ * @date Sep 15, 2015
+ *
+ */
+public class UuidsParameterTypeConverter extends AbstractParameterValueConverter {
 
-    public UuidParameterConverter() {
-        // TODO Auto-generated constructor stub
+    public UuidsParameterTypeConverter() {
     }
 
     @Override
@@ -21,4 +28,4 @@ public class UuidParameterConverter extends AbstractParameterValueConverter {
         return parameterValue.toString();
     }
 
-}
+}
\ No newline at end of file
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenClassificationWizardHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenClassificationWizardHandler.java
new file mode 100644 (file)
index 0000000..512b846
--- /dev/null
@@ -0,0 +1,66 @@
+package eu.etaxonomy.taxeditor.handler.defaultHandler;
+
+import java.util.UUID;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.ParameterType;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+public class DefaultOpenClassificationWizardHandler extends AbstractHandler {
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        String commandId = event.getCommand().getId();
+        String uuidParameterId = commandId+".uuid";
+        //check if uuid parameter is set
+        if(event.getParameter(uuidParameterId)!=null){
+            Object object = event.getObjectParameterForExecution(uuidParameterId);
+            ParameterType parameterType;
+            try {
+                parameterType = event.getCommand().getParameterType(uuidParameterId);
+                if(parameterType.isCompatible(object)){
+                    Classification classification = CdmStore.getService(IClassificationService.class).load((UUID) object);
+                    openClassificationWizard(event, classification);
+                }
+            } catch (NotDefinedException e) {
+                MessagingUtils.error(DefaultOpenClassificationWizardHandler.class, "Error while opening classification!", e);
+            }
+        }
+        //if not try current selection
+        else{
+            ISelection selection = HandlerUtil.getCurrentSelection(event);
+
+            if(selection instanceof IStructuredSelection){
+                final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+
+                if(structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof Classification){
+                    Classification classification = (Classification) structuredSelection.getFirstElement();
+                    openClassificationWizard(event, classification);
+                }
+            }
+        }
+        return null;
+    }
+
+    private void openClassificationWizard(ExecutionEvent event, Classification classification) {
+        NewClassificationWizard classificationWizard = new NewClassificationWizard();
+        classificationWizard.init(null, null);
+        classificationWizard.setEntity(classification);
+        WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard);
+        dialog.open();
+    }
+
+}
\ No newline at end of file