Revision 95aceac2
Added by Patrick Plitzner about 7 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java | ||
---|---|---|
48 | 48 |
*/ |
49 | 49 |
public class CdmViewerChooser extends PopupDialog implements ISelectionChangedListener, ILabelProvider{ |
50 | 50 |
|
51 |
private Map<String, String> nameViewerMap;
|
|
51 |
private Map<Command, String> nameViewerMap;
|
|
52 | 52 |
private Object input; |
53 | 53 |
|
54 | 54 |
public CdmViewerChooser(Shell parentShell) { |
... | ... | |
73 | 73 |
|
74 | 74 |
//if only one editor is available then open it |
75 | 75 |
if(nameViewerMap.size()==1){ |
76 |
String commandId = nameViewerMap.keySet().iterator().next();
|
|
77 |
executeCommand(commandId, input);
|
|
76 |
Command command = nameViewerMap.keySet().iterator().next();
|
|
77 |
executeCommand(command.getId(), input);
|
|
78 | 78 |
} |
79 | 79 |
else{ |
80 | 80 |
if(nameViewerMap.isEmpty()){ |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java | ||
---|---|---|
20 | 20 |
import org.eclipse.ui.IWorkbenchWindow; |
21 | 21 |
import org.eclipse.ui.PlatformUI; |
22 | 22 |
import org.eclipse.ui.actions.CompoundContributionItem; |
23 |
import org.eclipse.ui.commands.ICommandService; |
|
24 | 23 |
import org.eclipse.ui.handlers.IHandlerService; |
25 | 24 |
|
26 | 25 |
import eu.etaxonomy.cdm.model.common.ICdmBase; |
... | ... | |
43 | 42 |
final ISelection selection = window.getActivePage().getSelection(); |
44 | 43 |
if(selection instanceof IStructuredSelection){ |
45 | 44 |
Object firstElement = ((IStructuredSelection) selection).getFirstElement(); |
46 |
Map<String, String> availableViewers = CdmViewerUtil.getAvailableViewers(firstElement); |
|
47 |
Map<Command, String> enabledCommands = getEnabledCommands(availableViewers); |
|
45 |
Map<Command, String> enabledCommands = CdmViewerUtil.getAvailableViewers(firstElement); |
|
48 | 46 |
|
49 | 47 |
//check if only one or multiple viewers/commands are available |
50 | 48 |
if(enabledCommands.size()==1){ |
... | ... | |
78 | 76 |
return contributionItems; |
79 | 77 |
} |
80 | 78 |
|
81 |
private Map<Command, String> getEnabledCommands(Map<String, String> availableViewers) { |
|
82 |
Map<Command, String> enabledCommands = new HashMap<Command, String>(); |
|
83 |
for(Entry<String, String> entry:availableViewers.entrySet()){ |
|
84 |
final String commandId = entry.getKey(); |
|
85 |
ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); |
|
86 |
Command command = commandService.getCommand(commandId); |
|
87 |
if(command.isEnabled()){ |
|
88 |
enabledCommands.put(command, entry.getValue()); |
|
89 |
} |
|
90 |
} |
|
91 |
return enabledCommands; |
|
92 |
} |
|
93 |
|
|
94 | 79 |
private final class CommandInvoker extends SelectionAdapter { |
95 | 80 |
private final Command command; |
96 | 81 |
private final Object selectedObject; |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java | ||
---|---|---|
38 | 38 |
* @return a key-value map of available commands and their string |
39 | 39 |
* representation |
40 | 40 |
*/ |
41 |
public static Map<String, String> getAvailableViewers(Object input){
|
|
42 |
Map<String, String> commandViewerNameMap = new HashMap<String, String>();
|
|
41 |
public static Map<Command, String> getAvailableViewers(Object input){
|
|
42 |
Map<Command, String> commandViewerNameMap = new HashMap<Command, String>();
|
|
43 | 43 |
|
44 | 44 |
if(input!=null){ |
45 | 45 |
IExtensionRegistry reg = Platform.getExtensionRegistry(); |
... | ... | |
56 | 56 |
Command command = commandService.getCommand(commandId); |
57 | 57 |
//TODO: maybe pass the command directly instead of just the command id |
58 | 58 |
if(command.isEnabled()){ |
59 |
commandViewerNameMap.put(commandId, viewerName);
|
|
59 |
commandViewerNameMap.put(command, viewerName); |
|
60 | 60 |
} |
61 | 61 |
} |
62 | 62 |
} catch (ClassNotFoundException e) { |
Also available in: Unified diff
Refactor generic "open in..." framework