import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.api.service.ITaxonService;
import eu.etaxonomy.cdm.model.common.ICdmBase;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
/**
* This class opens a popup dialog and provides the possibility to choose from a
//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()){
}
}
- 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) {
+ //for generic UuidAndTitleCache objects try to load the object
+ if (input instanceof UuidAndTitleCache){
+ UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache)input;
+ Class type = uuidAndTitleCache.getType();
+ if(type == Taxon.class || type == Synonym.class){
+ input = CdmStore.getService(ITaxonService.class).load(uuidAndTitleCache.getUuid());
+ }
+ else if(SpecimenOrObservationBase.class.isAssignableFrom(type)){
+ input = CdmStore.getService(IOccurrenceService.class).load(uuidAndTitleCache.getUuid());
+ }
+ }
//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());
+
+ if(command.isEnabled()) {
- //build the parameterized command
- ParameterizedCommand pc = ParameterizedCommand.generateCommand(command, params);
+ //build the parameterized command
+ ParameterizedCommand pc = ParameterizedCommand.generateCommand(command, params);
- if(command.isEnabled()) {
IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
try {
- handlerService.executeCommand(pc, null);
+ if(pc!=null){
+ handlerService.executeCommand(pc, null);
+ }
+ else{
+ handlerService.executeCommand(commandId, null);
+ }
} catch (NotDefinedException nde) {
throw new RuntimeException("Could not find open command: " + commandId);
} catch (Exception exception) {
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();
}
}