name="%command.name.41">
</command>
<command
- defaultHandler="eu.etaxonomy.taxeditor.editor.handler.defaultHandler.DefaultOpenTaxonEditorHandler"
+ defaultHandler="eu.etaxonomy.taxeditor.editor.handler.defaultHandler.DefaultOpenTaxonEditorForTaxonHandler"
id="eu.etaxonomy.taxeditor.editor.openTaxonEditorForTaxon"
name="%command.name.42">
<commandParameter
</commandParameter>
</command>
<command
- defaultHandler="eu.etaxonomy.taxeditor.editor.handler.defaultHandler.DefaultOpenTaxonEditorHandler"
+ defaultHandler="eu.etaxonomy.taxeditor.editor.handler.defaultHandler.DefaultOpenTaxonEditorForTaxonNodeHandler"
id="eu.etaxonomy.taxeditor.editor.openTaxonEditorForTaxonNode"
name="Open Taxon Editor for taxonnode">
<commandParameter
--- /dev/null
+package eu.etaxonomy.taxeditor.editor.handler.defaultHandler;
+import java.util.UUID;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.ui.PartInitException;
+
+import eu.etaxonomy.cdm.api.service.ITaxonService;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenHandlerBase;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+
+public class DefaultOpenTaxonEditorForTaxonHandler extends DefaultOpenHandlerBase<TaxonBase> {
+
+ @Override
+ protected TaxonBase getEntity(UUID uuid) {
+ return CdmStore.getService(ITaxonService.class).load(uuid);
+ }
+
+ @Override
+ protected void open(ExecutionEvent event, TaxonBase entity) {
+ TaxonEditorInput input = TaxonEditorInput.NewInstanceFromTaxonBase(entity.getUuid());
+ try {
+ EditorUtil.open(input);
+ } catch (PartInitException e) {
+ MessagingUtils.error(DefaultOpenTaxonEditorForTaxonHandler.class, "Could not open taxon editor for taxon "+input.getTaxon(), e);
+ }
+ }
+
+}
--- /dev/null
+package eu.etaxonomy.taxeditor.editor.handler.defaultHandler;
+import java.util.UUID;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.ui.PartInitException;
+
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenHandlerBase;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+
+public class DefaultOpenTaxonEditorForTaxonNodeHandler extends DefaultOpenHandlerBase<TaxonNode> {
+
+ @Override
+ protected TaxonNode getEntity(UUID uuid) {
+ return CdmStore.getService(ITaxonNodeService.class).load(uuid);
+ }
+
+ @Override
+ protected void open(ExecutionEvent event, TaxonNode entity) {
+ TaxonEditorInput input = TaxonEditorInput.NewInstanceFromTaxonBase(entity.getTaxon().getUuid());
+ try {
+ EditorUtil.open(input);
+ } catch (PartInitException e) {
+ MessagingUtils.error(DefaultOpenTaxonEditorForTaxonNodeHandler.class, "Could not open taxon editor for taxon "+input.getTaxon(), e);
+ }
+ }
+
+}
+++ /dev/null
-package eu.etaxonomy.taxeditor.editor.handler.defaultHandler;
-import java.util.UUID;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.ParameterType;
-import org.eclipse.core.commands.common.NotDefinedException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
-import eu.etaxonomy.cdm.api.service.ITaxonService;
-import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
-import eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenClassificationWizardHandler;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-
-
-public class DefaultOpenTaxonEditorHandler extends AbstractHandler {
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- String commandId = event.getCommand().getId();
- String uuidParameterId = commandId+".uuid";
- //check if uuid parameter is set
- if(event.getParameter(uuidParameterId)!=null){
- Object object = event.getObjectParameterForExecution(uuidParameterId);
- ParameterType parameterType;
- try {
- parameterType = event.getCommand().getParameterType(uuidParameterId);
- if(parameterType.isCompatible(object)){
- TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load((UUID) object);
- if(taxonNode!=null){
- openTaxonEditor(event, taxonNode.getTaxon().getUuid());
- }
- else {
- TaxonBase taxon = CdmStore.getService(ITaxonService.class).load((UUID) object);
- openTaxonEditor(event, taxon.getUuid());
- }
- }
- } catch (NotDefinedException e) {
- MessagingUtils.error(DefaultOpenClassificationWizardHandler.class, "Error while opening classification!", e);
- }
- }
- //if not try current selection
- else{
- ISelection selection = HandlerUtil.getCurrentSelection(event);
-
- if(selection instanceof IStructuredSelection){
- final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
-
- Taxon taxon = null;
- Object firstElement = structuredSelection.getFirstElement();
- if(firstElement instanceof TaxonBase){
- openTaxonEditor(event, (HibernateProxyHelper.deproxy(firstElement, TaxonBase.class).getUuid()));
- }
- else if(firstElement instanceof TaxonNode){
- taxon = (HibernateProxyHelper.deproxy(firstElement, TaxonNode.class)).getTaxon();
- openTaxonEditor(event, taxon.getUuid());
- }
- }
- }
- return null;
- }
-
- private void openTaxonEditor(ExecutionEvent event, UUID taxonUuid) {
- TaxonEditorInput input = TaxonEditorInput.NewInstanceFromTaxonBase(taxonUuid);
- try {
- EditorUtil.open(input);
- } catch (PartInitException e) {
- MessagingUtils.error(DefaultOpenTaxonEditorHandler.class, "Could not open taxon editor for taxon "+input.getTaxon(), e);
- }
- }
-
-
-}
import java.util.UUID;
-import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.ParameterType;
-import org.eclipse.core.commands.common.NotDefinedException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.handlers.HandlerUtil;
import eu.etaxonomy.cdm.api.service.IClassificationService;
import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
import eu.etaxonomy.taxeditor.store.CdmStore;
-public class DefaultOpenClassificationWizardHandler extends AbstractHandler {
+public class DefaultOpenClassificationWizardHandler extends DefaultOpenHandlerBase<Classification> {
@Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- String commandId = event.getCommand().getId();
- String uuidParameterId = commandId+".uuid";
- //check if uuid parameter is set
- if(event.getParameter(uuidParameterId)!=null){
- Object object = event.getObjectParameterForExecution(uuidParameterId);
- ParameterType parameterType;
- try {
- parameterType = event.getCommand().getParameterType(uuidParameterId);
- if(parameterType.isCompatible(object)){
- Classification classification = CdmStore.getService(IClassificationService.class).load((UUID) object);
- openClassificationWizard(event, classification);
- }
- } catch (NotDefinedException e) {
- MessagingUtils.error(DefaultOpenClassificationWizardHandler.class, "Error while opening classification!", e);
- }
- }
- //if not try current selection
- else{
- ISelection selection = HandlerUtil.getCurrentSelection(event);
-
- if(selection instanceof IStructuredSelection){
- final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
-
- if(structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof Classification){
- Classification classification = (Classification) structuredSelection.getFirstElement();
- openClassificationWizard(event, classification);
- }
- }
- }
- return null;
+ protected Classification getEntity(UUID uuid) {
+ return CdmStore.getService(IClassificationService.class).load(uuid);
}
- private void openClassificationWizard(ExecutionEvent event, Classification classification) {
+ @Override
+ protected void open(ExecutionEvent event, Classification entity) {
NewClassificationWizard classificationWizard = new NewClassificationWizard();
classificationWizard.init(null, null);
- classificationWizard.setEntity(classification);
+ classificationWizard.setEntity(entity);
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard);
dialog.open();
}
+
}
\ No newline at end of file
--- /dev/null
+package eu.etaxonomy.taxeditor.handler.defaultHandler;
+
+import java.util.UUID;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.ParameterType;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+
+public abstract class DefaultOpenHandlerBase <T> extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ String commandId = event.getCommand().getId();
+ String uuidParameterId = commandId+".uuid";
+ //check if uuid parameter is set
+ if(event.getParameter(uuidParameterId)!=null){
+ Object object = event.getObjectParameterForExecution(uuidParameterId);
+ ParameterType parameterType;
+ try {
+ parameterType = event.getCommand().getParameterType(uuidParameterId);
+ if(parameterType.isCompatible(object)){
+ T entity = getEntity((UUID) object);
+ open(event, entity);
+ }
+ } catch (NotDefinedException e) {
+ MessagingUtils.error(DefaultOpenHandlerBase.class, "Error while opening classification!", e);
+ }
+ }
+ //if not try current selection
+ else{
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if(selection instanceof IStructuredSelection){
+ open(event, (T) ((IStructuredSelection) selection).getFirstElement());
+ }
+ }
+ return null;
+ }
+
+
+ protected abstract T getEntity(UUID uuid);
+
+ protected abstract void open(ExecutionEvent event, T entity);
+
+}
\ No newline at end of file