Fix type check in CdmViewerChooser
authorp.plitzner <p.plitzner@bgbm.org>
Wed, 17 Feb 2016 17:06:53 +0000 (18:06 +0100)
committerp.plitzner <p.plitzner@bgbm.org>
Wed, 17 Feb 2016 17:06:53 +0000 (18:06 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java

index 09f3784042fbbc3cd5f4476c1f55c12aefc5968f..330301f8f7bc2ed7a62873640c8f3467139663cb 100644 (file)
@@ -74,7 +74,7 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
         //if only one editor is available then open it
         if(nameViewerMap.size()==1){
             Command command = nameViewerMap.keySet().iterator().next();
-            executeCommand(command.getId(), input);
+            executeCommand(command, input);
         }
         else{
             if(nameViewerMap.isEmpty()){
@@ -84,15 +84,12 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
         }
     }
 
-    private void executeCommand(String commandId, Object input) {
-        ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
-        //get the command from plugin.xml
-        Command command = commandService.getCommand(commandId);
-
+    private void executeCommand(Command command, Object input) {
         //set uuid parameter
         if(input instanceof ICdmBase){
             Map<String, UUID> params = new HashMap<String, UUID>();
-            params.put(commandId+".uuid", ((ICdmBase) input).getUuid());
+            String commandId = command.getId();
+                       params.put(commandId+".uuid", ((ICdmBase) input).getUuid());
 
             //build the parameterized command
             ParameterizedCommand pc = ParameterizedCommand.generateCommand(command, params);
@@ -125,8 +122,8 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
         ISelection selection = event.getSelection();
         if(selection instanceof IStructuredSelection){
             Object firstElement = ((IStructuredSelection) selection).getFirstElement();
-            if(firstElement instanceof String && nameViewerMap.containsKey(firstElement)){
-                executeCommand((String) firstElement, this.input);
+            if(firstElement instanceof Command && nameViewerMap.containsKey(firstElement)){
+                executeCommand((Command) firstElement, this.input);
                 this.close();
             }
         }