From 124382f76c5260f98a34fea494528e4f0eb33aea Mon Sep 17 00:00:00 2001 From: Patrick Plitzner Date: Thu, 10 Dec 2015 08:39:17 +0100 Subject: [PATCH] Applied generic framework for opening objects to classifications in taxon navigator --- eu.etaxonomy.taxeditor.navigation/plugin.xml | 24 ++----- .../navigation/NavigationCdmViewer.java | 43 ------------ .../META-INF/MANIFEST.MF | 1 + eu.etaxonomy.taxeditor.store/plugin.xml | 27 ++++++++ ....java => UuidsParameterTypeConverter.java} | 15 +++-- ...efaultOpenClassificationWizardHandler.java | 66 +++++++++++++++++++ 6 files changed, 109 insertions(+), 67 deletions(-) delete mode 100644 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java rename eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/{UuidParameterConverter.java => UuidsParameterTypeConverter.java} (67%) create mode 100644 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenClassificationWizardHandler.java diff --git a/eu.etaxonomy.taxeditor.navigation/plugin.xml b/eu.etaxonomy.taxeditor.navigation/plugin.xml index 9767c38e9..d67d60300 100644 --- a/eu.etaxonomy.taxeditor.navigation/plugin.xml +++ b/eu.etaxonomy.taxeditor.navigation/plugin.xml @@ -190,20 +190,10 @@ - - - - - - - - + + - - - - diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java deleted file mode 100644 index 8ba357df8..000000000 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java +++ /dev/null @@ -1,43 +0,0 @@ -package eu.etaxonomy.taxeditor.navigation; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.log4j.Logger; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.ui.PlatformUI; - -import eu.etaxonomy.cdm.model.taxon.Classification; -import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard; -import eu.etaxonomy.taxeditor.view.ICdmViewer; - -public class NavigationCdmViewer implements ICdmViewer { - - - @SuppressWarnings("unused") - private final Logger logger = Logger.getLogger(NavigationCdmViewer.class); - - @Override - public void show(Object input, Class viewerClass) { - if(viewerClass.equals(NewClassificationWizard.class)){ - if(input instanceof Classification){ - Classification classification = (Classification)input; - NewClassificationWizard classificationWizard = new NewClassificationWizard(); - classificationWizard.init(null, null); - classificationWizard.setEntity(classification); - WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard); - dialog.open(); - } - } - } - - @Override - public Map, String> getViewerClasses(Object input) { - Map, String> viewerNameMap = new HashMap, String>(); - if(input instanceof Classification){ - viewerNameMap.put(NewClassificationWizard.class, "Classification Wizard"); - } - return viewerNameMap; - } - -} diff --git a/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF index 2b4298631..aea7552f4 100644 --- a/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF +++ b/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF @@ -15,6 +15,7 @@ Export-Package: eu.etaxonomy.cdm, eu.etaxonomy.taxeditor.editor.definedterm.input, eu.etaxonomy.taxeditor.featuretree, eu.etaxonomy.taxeditor.handler, + eu.etaxonomy.taxeditor.handler.defaultHandler, eu.etaxonomy.taxeditor.io, eu.etaxonomy.taxeditor.io.wizard, eu.etaxonomy.taxeditor.labels, diff --git a/eu.etaxonomy.taxeditor.store/plugin.xml b/eu.etaxonomy.taxeditor.store/plugin.xml index 8e7a4532b..40bf6eb07 100644 --- a/eu.etaxonomy.taxeditor.store/plugin.xml +++ b/eu.etaxonomy.taxeditor.store/plugin.xml @@ -756,6 +756,25 @@ id="eu.etaxonomy.taxeditor.store.open" name="%command.name.15"> + + + + + + + + @@ -1365,4 +1384,12 @@ + + + + diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java similarity index 67% rename from eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java rename to eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java index 5bd3db11e..e23482714 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java @@ -5,10 +5,17 @@ import java.util.UUID; import org.eclipse.core.commands.AbstractParameterValueConverter; import org.eclipse.core.commands.ParameterValueConversionException; -public class UuidParameterConverter extends AbstractParameterValueConverter { +/** + * Converts {@link UUID}s to a string representation + * and vica versa. + * + * @author pplitzner + * @date Sep 15, 2015 + * + */ +public class UuidsParameterTypeConverter extends AbstractParameterValueConverter { - public UuidParameterConverter() { - // TODO Auto-generated constructor stub + public UuidsParameterTypeConverter() { } @Override @@ -21,4 +28,4 @@ public class UuidParameterConverter extends AbstractParameterValueConverter { return parameterValue.toString(); } -} +} \ No newline at end of file diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenClassificationWizardHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenClassificationWizardHandler.java new file mode 100644 index 000000000..512b84628 --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenClassificationWizardHandler.java @@ -0,0 +1,66 @@ +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.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 { + + @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; + } + + private void openClassificationWizard(ExecutionEvent event, Classification classification) { + NewClassificationWizard classificationWizard = new NewClassificationWizard(); + classificationWizard.init(null, null); + classificationWizard.setEntity(classification); + WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard); + dialog.open(); + } + +} \ No newline at end of file -- 2.34.1