From 95aceac2b7b43d28372ed4070e13bc07144c101a Mon Sep 17 00:00:00 2001
From: Patrick Plitzner
Date: Wed, 13 Jan 2016 19:13:27 +0100
Subject: [PATCH] Refactor generic "open in..." framework
---
.../taxeditor/view/CdmViewerChooser.java | 6 +++---
.../taxeditor/view/CdmViewerContextMenu.java | 17 +----------------
.../etaxonomy/taxeditor/view/CdmViewerUtil.java | 6 +++---
3 files changed, 7 insertions(+), 22 deletions(-)
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
index 939f753b6..09f378404 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
@@ -48,7 +48,7 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
*/
public class CdmViewerChooser extends PopupDialog implements ISelectionChangedListener, ILabelProvider{
- private Map nameViewerMap;
+ private Map nameViewerMap;
private Object input;
public CdmViewerChooser(Shell parentShell) {
@@ -73,8 +73,8 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
//if only one editor is available then open it
if(nameViewerMap.size()==1){
- String commandId = nameViewerMap.keySet().iterator().next();
- executeCommand(commandId, input);
+ Command command = nameViewerMap.keySet().iterator().next();
+ executeCommand(command.getId(), input);
}
else{
if(nameViewerMap.isEmpty()){
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java
index 2811fe14a..bfe10e7cd 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java
@@ -20,7 +20,6 @@ import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.CompoundContributionItem;
-import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
import eu.etaxonomy.cdm.model.common.ICdmBase;
@@ -43,8 +42,7 @@ public class CdmViewerContextMenu extends CompoundContributionItem {
final ISelection selection = window.getActivePage().getSelection();
if(selection instanceof IStructuredSelection){
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
- Map availableViewers = CdmViewerUtil.getAvailableViewers(firstElement);
- Map enabledCommands = getEnabledCommands(availableViewers);
+ Map enabledCommands = CdmViewerUtil.getAvailableViewers(firstElement);
//check if only one or multiple viewers/commands are available
if(enabledCommands.size()==1){
@@ -78,19 +76,6 @@ public class CdmViewerContextMenu extends CompoundContributionItem {
return contributionItems;
}
- private Map getEnabledCommands(Map availableViewers) {
- Map enabledCommands = new HashMap();
- for(Entry entry:availableViewers.entrySet()){
- final String commandId = entry.getKey();
- ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
- Command command = commandService.getCommand(commandId);
- if(command.isEnabled()){
- enabledCommands.put(command, entry.getValue());
- }
- }
- return enabledCommands;
- }
-
private final class CommandInvoker extends SelectionAdapter {
private final Command command;
private final Object selectedObject;
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java
index 4436ced69..8113b9703 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java
@@ -38,8 +38,8 @@ public class CdmViewerUtil {
* @return a key-value map of available commands and their string
* representation
*/
- public static Map getAvailableViewers(Object input){
- Map commandViewerNameMap = new HashMap();
+ public static Map getAvailableViewers(Object input){
+ Map commandViewerNameMap = new HashMap();
if(input!=null){
IExtensionRegistry reg = Platform.getExtensionRegistry();
@@ -56,7 +56,7 @@ public class CdmViewerUtil {
Command command = commandService.getCommand(commandId);
//TODO: maybe pass the command directly instead of just the command id
if(command.isEnabled()){
- commandViewerNameMap.put(commandId, viewerName);
+ commandViewerNameMap.put(command, viewerName);
}
}
} catch (ClassNotFoundException e) {
--
2.34.1