- added context menu entry for editing classifications
authorPatric Plitzner <p.plitzner@bgbm.org>
Thu, 4 Jun 2015 10:54:32 +0000 (10:54 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Thu, 4 Jun 2015 10:54:32 +0000 (10:54 +0000)
 - used generic extension point for cdmViewer in navigation project (#4865)

.gitattributes
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java
eu.etaxonomy.taxeditor.navigation/plugin.xml
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java

index c04da5788a5976610f666f917a7bdd30b31dafb8..8767af15ce25a09220a0e3123acea6956b50a901 100644 (file)
@@ -949,6 +949,7 @@ eu.etaxonomy.taxeditor.navigation/icons/tree_icon.jpg -text
 eu.etaxonomy.taxeditor.navigation/p2.inf -text
 eu.etaxonomy.taxeditor.navigation/plugin.xml -text
 eu.etaxonomy.taxeditor.navigation/pom.xml -text
+eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigatorStateManager.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/RecentNamesContributionItem.java -text
@@ -1261,6 +1262,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/Op
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizard.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizardPage.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenDistributionEditorWizardHandler.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenPasswordWizzardHandler.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ShowLoginWindowHandler.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/identificationkey/AbstractIdentificaitonKeyWizard.java -text
index 877ed28f44530befcf5ce97db7b069ce3947e9c4..4d92e047d995a46409f4df9ea2c85a64db9dbd29 100644 (file)
@@ -13,6 +13,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
+import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.ui.PartInitException;
 
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
@@ -34,7 +35,7 @@ public class EditorCdmViewer implements ICdmViewer {
      * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
      */
     @Override
-    public void show(Object input, Class<?> viewerClass) {
+    public void show(Object input, Class<?> viewerClass, ExecutionEvent event) {
         try {
             if(viewerClass.equals(MultiPageTaxonEditor.class)){
                 if(input instanceof TaxonBase){
index 5caf3402c685bcb28702864b1a12a66c5b6d29ae..c935307f6a1cef4dabbbdfa329ab016bbc051585 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>
          <command
                commandId="eu.etaxonomy.taxeditor.navigator.command.update.changeAcceptedToSynonym"
                label="%command.label.6"
          </with>
       </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
new file mode 100644 (file)
index 0000000..9784c9a
--- /dev/null
@@ -0,0 +1,50 @@
+package eu.etaxonomy.taxeditor.navigation;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+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);
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object)
+     */
+    @Override
+    public void show(Object input, Class<?> viewerClass, ExecutionEvent event) {
+        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(HandlerUtil.getActiveShell(event), classificationWizard);
+                dialog.open();
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object)
+     */
+    @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 37c33cdfeb15a1690faac784e1c68b90427e895a..41a4ad279bcfe7f014dca98ed5648424dd114637 100644 (file)
             id="eu.etaxonomy.taxeditor.editor.definedTerms.delete"
             name="%command.name.14">
       </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.handler.OpenHandler"
+            id="eu.etaxonomy.taxeditor.store.open"
+            name="Open">
+      </command>
    </extension>
    <extension
          point="org.eclipse.ui.importWizards">
index d885f02880ef9bb394893692ed8dbcbadc55425a..42791ec3b89d6c6967cb86041814a7d482ff7619 100644 (file)
@@ -16,7 +16,7 @@
             <meta.element />
          </appInfo>
          <documentation>
-            Extensions must provide and ICdmViewer which maps input elements to viewers which are able to display information for them.
+            Extensions must provide an ICdmViewer which maps input elements to viewers which are able to display information for them.
          </documentation>
       </annotation>
       <complexType>
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java
new file mode 100644 (file)
index 0000000..eecb24b
--- /dev/null
@@ -0,0 +1,25 @@
+package eu.etaxonomy.taxeditor.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
+
+public class OpenHandler extends AbstractHandler {
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+        if(currentSelection instanceof IStructuredSelection){
+            Object firstElement = ((IStructuredSelection) currentSelection).getFirstElement();
+            CdmViewerChooser viewerChooser = new CdmViewerChooser(HandlerUtil.getActiveShell(event));
+            viewerChooser.chooseViewer(firstElement, event);
+        }
+        return null;
+    }
+
+}
index a862b694640103098dda6844f3a2bcb5bb5875d0..3b3909385445adf05e0d0ad3d47bb5aabc711996 100644 (file)
@@ -13,6 +13,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtensionRegistry;
@@ -50,6 +51,7 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
 
     private Object input;
     private Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap;
+    private ExecutionEvent executionEvent;
 
     public CdmViewerChooser(Shell parentShell) {
         this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...",
@@ -66,9 +68,11 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
     /**
      * Opens a popup dialog with all possible viewers for the given input.
      * @param input the input for which the viewers are listed
+     * @param event the {@link ExecutionEvent} if invoked via command/handler
      */
-    public void chooseViewer(Object input){
+    public void chooseViewer(Object input, ExecutionEvent event){
         this.input = input;
+        this.executionEvent = event;
         this.nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>();
 
         IExtensionRegistry reg = Platform.getExtensionRegistry();
@@ -95,7 +99,7 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
         if(nameViewerMap.size()==1){
             Entry<Class<?>, String> next = nameViewerMap.keySet().iterator().next();
             ICdmViewer cdmViewer = nameViewerMap.get(next);
-            cdmViewer.show(input, next.getKey());
+            cdmViewer.show(input, next.getKey(), event);
         }
         else{
             if(nameViewerMap.isEmpty()){
@@ -129,7 +133,7 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
             if(nameViewerMap.containsKey(firstElement)){
                 Entry<Class<?>, String> entry = (Entry<Class<?>, String>)firstElement;
                 ICdmViewer cdmViewer = nameViewerMap.get(entry);
-                cdmViewer.show(input, entry.getKey());
+                cdmViewer.show(input, entry.getKey(), this.executionEvent);
                 this.close();
             }
         }
index 0dd9e9b445e7d74df05c893c5c0ffc4d0220505b..877daa81adc69c3c9822ce4873b1f340515ffd3d 100644 (file)
@@ -11,6 +11,8 @@ package eu.etaxonomy.taxeditor.view;
 
 import java.util.Map;
 
+import org.eclipse.core.commands.ExecutionEvent;
+
 
 /**
  * Implementors of this interface provide a mapping of input elements to views
@@ -38,7 +40,8 @@ public interface ICdmViewer {
      * Opens the viewer defined by the given viewerClass for the given input.
      * @param input the input for which a viewer should be opened
      * @param viewerClass the qualified class name of the viewer
+     * @param event the {@link ExecutionEvent} if invoked via command/handler
      */
-    public void show(Object input, Class<?> viewerClass);
+    public void show(Object input, Class<?> viewerClass, ExecutionEvent event);
 
 }