From e382ff8fc461fd0c94abaacfc6b8822b7478972d Mon Sep 17 00:00:00 2001 From: Patric Plitzner Date: Thu, 4 Jun 2015 10:54:32 +0000 Subject: [PATCH] - added context menu entry for editing classifications - used generic extension point for cdmViewer in navigation project (#4865) --- .gitattributes | 2 + .../taxeditor/editor/EditorCdmViewer.java | 3 +- eu.etaxonomy.taxeditor.navigation/plugin.xml | 20 ++++++++ .../navigation/NavigationCdmViewer.java | 50 +++++++++++++++++++ eu.etaxonomy.taxeditor.store/plugin.xml | 5 ++ ...u.etaxonomy.taxeditor.store.cdmViewer.exsd | 2 +- .../taxeditor/handler/OpenHandler.java | 25 ++++++++++ .../taxeditor/view/CdmViewerChooser.java | 10 ++-- .../etaxonomy/taxeditor/view/ICdmViewer.java | 5 +- 9 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java create mode 100644 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java diff --git a/.gitattributes b/.gitattributes index c04da5788..8767af15c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -949,6 +949,7 @@ eu.etaxonomy.taxeditor.navigation/icons/tree_icon.jpg -text eu.etaxonomy.taxeditor.navigation/p2.inf -text eu.etaxonomy.taxeditor.navigation/plugin.xml -text eu.etaxonomy.taxeditor.navigation/pom.xml -text +eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java -text eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java -text eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigatorStateManager.java -text eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/RecentNamesContributionItem.java -text @@ -1261,6 +1262,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/Op eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizard.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizardPage.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenDistributionEditorWizardHandler.java -text +eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenPasswordWizzardHandler.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ShowLoginWindowHandler.java -text eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/identificationkey/AbstractIdentificaitonKeyWizard.java -text diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java index 877ed28f4..4d92e047d 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorCdmViewer.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; +import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.ui.PartInitException; import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; @@ -34,7 +35,7 @@ public class EditorCdmViewer implements ICdmViewer { * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object) */ @Override - public void show(Object input, Class viewerClass) { + public void show(Object input, Class viewerClass, ExecutionEvent event) { try { if(viewerClass.equals(MultiPageTaxonEditor.class)){ if(input instanceof TaxonBase){ diff --git a/eu.etaxonomy.taxeditor.navigation/plugin.xml b/eu.etaxonomy.taxeditor.navigation/plugin.xml index 5caf3402c..c935307f6 100644 --- a/eu.etaxonomy.taxeditor.navigation/plugin.xml +++ b/eu.etaxonomy.taxeditor.navigation/plugin.xml @@ -163,6 +163,20 @@ + + + + + + + + + + + + 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 new file mode 100644 index 000000000..9784c9a76 --- /dev/null +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationCdmViewer.java @@ -0,0 +1,50 @@ +package eu.etaxonomy.taxeditor.navigation; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.handlers.HandlerUtil; + +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); + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.view.ICdmViewer#show(java.lang.Object) + */ + @Override + public void show(Object input, Class viewerClass, ExecutionEvent event) { + 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(HandlerUtil.getActiveShell(event), classificationWizard); + dialog.open(); + } + } + } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.view.ICdmViewer#getViewerClasses(java.lang.Object) + */ + @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/plugin.xml b/eu.etaxonomy.taxeditor.store/plugin.xml index 37c33cdfe..41a4ad279 100644 --- a/eu.etaxonomy.taxeditor.store/plugin.xml +++ b/eu.etaxonomy.taxeditor.store/plugin.xml @@ -697,6 +697,11 @@ id="eu.etaxonomy.taxeditor.editor.definedTerms.delete" name="%command.name.14"> + + diff --git a/eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd b/eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd index d885f0288..42791ec3b 100644 --- a/eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd +++ b/eu.etaxonomy.taxeditor.store/schema/eu.etaxonomy.taxeditor.store.cdmViewer.exsd @@ -16,7 +16,7 @@ - Extensions must provide and ICdmViewer which maps input elements to viewers which are able to display information for them. + Extensions must provide an ICdmViewer which maps input elements to viewers which are able to display information for them. diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java new file mode 100644 index 000000000..eecb24ba9 --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenHandler.java @@ -0,0 +1,25 @@ +package eu.etaxonomy.taxeditor.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.handlers.HandlerUtil; + +import eu.etaxonomy.taxeditor.view.CdmViewerChooser; + +public class OpenHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection currentSelection = HandlerUtil.getCurrentSelection(event); + if(currentSelection instanceof IStructuredSelection){ + Object firstElement = ((IStructuredSelection) currentSelection).getFirstElement(); + CdmViewerChooser viewerChooser = new CdmViewerChooser(HandlerUtil.getActiveShell(event)); + viewerChooser.chooseViewer(firstElement, event); + } + return null; + } + +} diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java index a862b6946..3b3909385 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionRegistry; @@ -50,6 +51,7 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi private Object input; private Map, String>, ICdmViewer> nameViewerMap; + private ExecutionEvent executionEvent; public CdmViewerChooser(Shell parentShell) { this(parentShell, SWT.RESIZE | SWT.ON_TOP, true, false, false, false, false, "Open in ...", @@ -66,9 +68,11 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi /** * Opens a popup dialog with all possible viewers for the given input. * @param input the input for which the viewers are listed + * @param event the {@link ExecutionEvent} if invoked via command/handler */ - public void chooseViewer(Object input){ + public void chooseViewer(Object input, ExecutionEvent event){ this.input = input; + this.executionEvent = event; this.nameViewerMap = new HashMap, String>, ICdmViewer>(); IExtensionRegistry reg = Platform.getExtensionRegistry(); @@ -95,7 +99,7 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi if(nameViewerMap.size()==1){ Entry, String> next = nameViewerMap.keySet().iterator().next(); ICdmViewer cdmViewer = nameViewerMap.get(next); - cdmViewer.show(input, next.getKey()); + cdmViewer.show(input, next.getKey(), event); } else{ if(nameViewerMap.isEmpty()){ @@ -129,7 +133,7 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi if(nameViewerMap.containsKey(firstElement)){ Entry, String> entry = (Entry, String>)firstElement; ICdmViewer cdmViewer = nameViewerMap.get(entry); - cdmViewer.show(input, entry.getKey()); + cdmViewer.show(input, entry.getKey(), this.executionEvent); this.close(); } } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java index 0dd9e9b44..877daa81a 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/ICdmViewer.java @@ -11,6 +11,8 @@ package eu.etaxonomy.taxeditor.view; import java.util.Map; +import org.eclipse.core.commands.ExecutionEvent; + /** * Implementors of this interface provide a mapping of input elements to views @@ -38,7 +40,8 @@ public interface ICdmViewer { * Opens the viewer defined by the given viewerClass for the given input. * @param input the input for which a viewer should be opened * @param viewerClass the qualified class name of the viewer + * @param event the {@link ExecutionEvent} if invoked via command/handler */ - public void show(Object input, Class viewerClass); + public void show(Object input, Class viewerClass, ExecutionEvent event); } -- 2.34.1