*/
public class CdmViewerChooser extends PopupDialog implements ISelectionChangedListener, ILabelProvider{
- private Map<String, String> nameViewerMap;
+ private Map<Command, String> nameViewerMap;
private Object input;
public CdmViewerChooser(Shell parentShell) {
//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()){
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;
final ISelection selection = window.getActivePage().getSelection();
if(selection instanceof IStructuredSelection){
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
- Map<String, String> availableViewers = CdmViewerUtil.getAvailableViewers(firstElement);
- Map<Command, String> enabledCommands = getEnabledCommands(availableViewers);
+ Map<Command, String> enabledCommands = CdmViewerUtil.getAvailableViewers(firstElement);
//check if only one or multiple viewers/commands are available
if(enabledCommands.size()==1){
return contributionItems;
}
- private Map<Command, String> getEnabledCommands(Map<String, String> availableViewers) {
- Map<Command, String> enabledCommands = new HashMap<Command, String>();
- for(Entry<String, String> 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;
* @return a key-value map of available commands and their string
* representation
*/
- public static Map<String, String> getAvailableViewers(Object input){
- Map<String, String> commandViewerNameMap = new HashMap<String, String>();
+ public static Map<Command, String> getAvailableViewers(Object input){
+ Map<Command, String> commandViewerNameMap = new HashMap<Command, String>();
if(input!=null){
IExtensionRegistry reg = Platform.getExtensionRegistry();
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) {