Merge branch 'develop' into featureTreeEditor
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / CdmViewerUtil.java
index 8113b9703dca8d066640d50ec9957dc895d3b5a8..2162f0c49d82d0c1f392c8e76f82636ce29aa349 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
 * Copyright (C) 2015 EDIT
 * European Distributed Institute of Taxonomy
@@ -16,10 +15,13 @@ import org.eclipse.core.commands.Command;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtensionRegistry;
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.commands.ICommandService;
 
+import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point.
@@ -42,6 +44,18 @@ public class CdmViewerUtil {
         Map<Command, String> commandViewerNameMap = new HashMap<Command, String>();
 
         if(input!=null){
+            //for generic UuidAndTitleCache objects try to load the object
+            if (input instanceof UuidAndTitleCache){
+                UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache)input;
+                input = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
+            }
+            //for tree nodes get the value resp. the object of the node
+            else if (input instanceof TreeNode){
+                TreeNode treeNode = (TreeNode)input;
+                input = treeNode.getValue();
+            }
+
+
             IExtensionRegistry reg = Platform.getExtensionRegistry();
             IConfigurationElement[] extensions = reg
                     .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$
@@ -52,9 +66,8 @@ public class CdmViewerUtil {
                         String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$
                         Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$
                         if(selectionClass.isAssignableFrom(input.getClass())){
-                            ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
+                            ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
                             Command command = commandService.getCommand(commandId);
-                            //TODO: maybe pass the command directly instead of just the command id
                             if(command.isEnabled()){
                                 commandViewerNameMap.put(command, viewerName);
                             }