ref #7674 Add context menu to add taxon descriptions
authorPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 7 Sep 2018 13:50:49 +0000 (15:50 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 7 Sep 2018 13:50:49 +0000 (15:50 +0200)
eu.etaxonomy.taxeditor.editor/fragment.e4xmi
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixPart.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateDefaultTaxonDescriptionHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateLiteratureTaxonDescriptionHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateTaxonDescriptionHandler.java [new file with mode: 0644]

index c9c0530b5a56472165d25451d68185424d354787..350061b7adb65650a8cd0cb4cd7f64a355414af3 100644 (file)
     </elements>
     <elements xsi:type="basic:PartDescriptor" xmi:id="_rpaDsNK2EeeWSJT7vW9jsw" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart" label="%partdescriptor.label.4" tooltip="%partdescriptor.tooltip.2" allowMultiple="true" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart">
       <handlers xmi:id="_d_HUYOPBEeeIH8IplZ0cuA" elementId="eu.etaxonomy.taxeditor.editor.handler.2" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.charactermatrix.handler.ExportCharacterMatrixHandler" command="_YeWagOPBEeeIH8IplZ0cuA"/>
+      <handlers xmi:id="_mUM1cLKVEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.CreateDefaultTaxonDescriptionHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.CreateDefaultTaxonDescriptionHandler" command="_ZHC3oLKVEeikjKoOnLFm2w"/>
+      <handlers xmi:id="_t8dAQLKVEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.CreateLiteratureTaxonDescriptionHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.CreateLiteratureTaxonDescriptionHandler" command="_fkPkkLKVEeikjKoOnLFm2w"/>
       <menus xmi:id="_PLw00OPBEeeIH8IplZ0cuA" elementId="eu.etaxonomy.taxeditor.editor.menu.characterMatrix" label="%menu.label.7">
         <children xsi:type="menu:HandledMenuItem" xmi:id="_TGK04OPBEeeIH8IplZ0cuA" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.characterMatrix.export" label="%handledmenuitem.label.12" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/export.gif" command="_YeWagOPBEeeIH8IplZ0cuA"/>
       </menus>
+      <menus xsi:type="menu:PopupMenu" xmi:id="__10yYLKREeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix">
+        <children xsi:type="menu:HandledMenuItem" xmi:id="_AyHbgLKSEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.createdefaultdescription" label="Create default description" command="_ZHC3oLKVEeikjKoOnLFm2w"/>
+        <children xsi:type="menu:HandledMenuItem" xmi:id="_DYlHcLKSEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.createliteraturedescription" label="Create literature description" command="_fkPkkLKVEeikjKoOnLFm2w"/>
+      </menus>
     </elements>
     <elements xsi:type="basic:PartDescriptor" xmi:id="_XcQMEN8mEee9zP45RW4C3A" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetNavigator" label="%partdescriptor.label.5" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetNavigator">
       <handlers xmi:id="_JvYVgNXoEeeLtdyzt6BEAA" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.handler.OpenCharacterMatrixHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.handler.OpenCharacterMatrixHandler" command="_FnWwMNXoEeeLtdyzt6BEAA"/>
     <elements xsi:type="commands:Command" xmi:id="_c3wW8FeBEeiJAP3GTkE0aQ" elementId="eu.etaxonomy.taxeditor.editor.command.descriptivedataseteditor.removeTaxon" commandName="%command.commandname.21"/>
     <elements xsi:type="commands:Command" xmi:id="_HSKdYFgXEeiQk_eTMvMviQ" elementId="eu.etaxonomy.taxeditor.editor.name.createProParteSynonym" commandName="%command.name.60"/>
     <elements xsi:type="commands:Command" xmi:id="_BgX6gFj_EeiQk_eTMvMviQ" elementId="eu.etaxonomy.taxeditor.editor.command.changeToProParteSynonym" commandName="%command.name.61"/>
+    <elements xsi:type="commands:Command" xmi:id="_ZHC3oLKVEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.charactermatrix.command.createDefaultTaxonDescription" commandName="Create default taxon description"/>
+    <elements xsi:type="commands:Command" xmi:id="_fkPkkLKVEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.charactermatrix.command.createLiteratureTaxonDescription" commandName="Create literature taxon description"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_pZmusEalEeeXMc6kSYO7Xg" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView" positionInList="after:eu.etaxonomy.taxeditor.workbench.menuseparator.navigation">
     <elements xsi:type="menu:HandledMenuItem" xmi:id="_FPIHQKNwEeebGZ23ERGMGw" elementId="eu.etaxonomy.taxeditor.editor.showViewMenu.conceptGraph" label="%view.name.3" iconURI="" tooltip="%view.name.3" command="_WPjpoDSnEeek0dKsFNy--Q">
index 3ad6594761aa3df29b65e8d369928b64af499269..9e8101dba8f5dcad9310031830a3cba5b3e8fa5e 100644 (file)
@@ -29,12 +29,17 @@ import org.eclipse.core.runtime.jobs.IJobChangeEvent;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.core.runtime.jobs.JobChangeAdapter;
 import org.eclipse.e4.ui.di.UISynchronize;
+import org.eclipse.e4.ui.services.EMenuService;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
 import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
 import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
 import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
+import org.eclipse.nebula.widgets.nattable.coordinate.Range;
 import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
 import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
 import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
@@ -70,12 +75,17 @@ import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer;
 import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
 import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModel;
 import org.eclipse.nebula.widgets.nattable.tree.TreeLayer;
+import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
+import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
+import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
+import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
 import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
 
 import ca.odell.glazedlists.BasicEventList;
 import ca.odell.glazedlists.EventList;
@@ -124,6 +134,9 @@ public class CharacterMatrix extends Composite {
     @Inject
     private UISynchronize sync;
 
+    @Inject
+    private EMenuService menuService;
+
     private DescriptiveDataSet descriptiveDataSet;
 
     private NatTable natTable;
@@ -473,6 +486,31 @@ public class CharacterMatrix extends Composite {
         //register aggregation configuration
         summaryRowLayer.addConfiguration(new AggregationConfiguration(this));
 
+      //+++CONTEXT MENU+++
+        menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix"); //$NON-NLS-1$
+        // get the menu registered by EMenuService
+        final Menu e4Menu = natTable.getMenu();
+        // remove the menu reference from NatTable instance
+        natTable.setMenu(null);
+        natTable.addConfiguration(
+                new AbstractUiBindingConfiguration() {
+            @Override
+            public void configureUiBindings(
+                    UiBindingRegistry uiBindingRegistry) {
+                // add e4 menu to NatTable
+                new PopupMenuBuilder(natTable, e4Menu)
+                    .build();
+
+                // register the UI binding for header, corner and body region
+                uiBindingRegistry.registerMouseDownBinding(
+                        new MouseEventMatcher(
+                                SWT.NONE,
+                                null,
+                                MouseEventMatcher.RIGHT_BUTTON),
+                        new PopupMenuAction(e4Menu));
+            }
+        });
+
         natTable.configure();
     }
 
@@ -575,6 +613,17 @@ public class CharacterMatrix extends Composite {
         job.schedule();
     }
 
+    public IStructuredSelection getSelection(){
+        Set<Range> selectedRowPositions = bodyLayer.getSelectionLayer().getSelectedRowPositions();
+        List<Object> selectedObjects = new ArrayList<>();
+        for (Range range : selectedRowPositions) {
+            for(int i=range.start;i<range.end;i++){
+                selectedObjects.add(bodyDataProvider.getRowObject(i));
+            }
+        }
+        return new StructuredSelection(selectedObjects);
+    }
+
     private void loadingDone() {
         this.part.loadingDone();
     }
index 8a93bc60b74679def25ab7ed9a3a6d9f01559f2a..50f62ef96b3bc7f4f4b52cfb9370e8585e1f6a32 100644 (file)
@@ -32,6 +32,7 @@ import org.eclipse.e4.ui.di.Persist;
 import org.eclipse.e4.ui.model.application.ui.MDirtyable;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.nebula.widgets.nattable.NatTable;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.StackLayout;
@@ -146,6 +147,10 @@ ICdmEntitySessionEnabled{
         }
     }
 
+    public IStructuredSelection getSelection(){
+        return matrix.getSelection();
+    }
+
     public void setDirty() {
         this.dirty.setDirty(true);
     }
@@ -166,6 +171,10 @@ ICdmEntitySessionEnabled{
         return selService;
     }
 
+    public CharacterMatrix getMatrix() {
+        return matrix;
+    }
+
     @Persist
     @Override
     public void save(IProgressMonitor monitor) {
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateDefaultTaxonDescriptionHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateDefaultTaxonDescriptionHandler.java
new file mode 100644 (file)
index 0000000..1bd38fe
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+* Copyright (C) 2018 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler;
+
+import eu.etaxonomy.cdm.model.common.MarkerType;
+
+/**
+ * @author pplitzner
+ * @since Sep 7, 2018
+ *
+ */
+public class CreateDefaultTaxonDescriptionHandler extends CreateTaxonDescriptionHandler{
+
+    @Override
+    protected boolean getMarkerFlag() {
+        return true;
+    }
+
+    @Override
+    protected MarkerType getMarkerType() {
+        return MarkerType.USE();
+    }
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateLiteratureTaxonDescriptionHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateLiteratureTaxonDescriptionHandler.java
new file mode 100644 (file)
index 0000000..4daa92f
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+* Copyright (C) 2018 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler;
+
+import eu.etaxonomy.cdm.model.common.MarkerType;
+
+/**
+ * @author pplitzner
+ * @since Sep 7, 2018
+ *
+ */
+public class CreateLiteratureTaxonDescriptionHandler extends CreateTaxonDescriptionHandler{
+
+    @Override
+    protected boolean getMarkerFlag() {
+        return true;
+    }
+
+    @Override
+    protected MarkerType getMarkerType() {
+        return MarkerType.IN_BIBLIOGRAPHY();
+    }
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateTaxonDescriptionHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/CreateTaxonDescriptionHandler.java
new file mode 100644 (file)
index 0000000..ea0304f
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+* Copyright (C) 2018 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler;
+
+import javax.inject.Named;
+
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.di.UISynchronize;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
+import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
+import eu.etaxonomy.cdm.model.common.MarkerType;
+import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author pplitzner
+ * @since Sep 7, 2018
+ *
+ */
+public abstract class CreateTaxonDescriptionHandler {
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, UISynchronize sync) {
+        CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
+        DescriptiveDataSet descriptiveDataSet = matrixPart.getDescriptiveDataSet();
+        TaxonNode node = (TaxonNode) matrixPart.getSelection().getFirstElement();
+        TaxonRowWrapperDTO taxonRowWrapperDTO = CdmStore.getService(IDescriptiveDataSetService.class)
+                .createTaxonDescription(descriptiveDataSet.getUuid(), node.getUuid(), getMarkerType(), getMarkerFlag());
+        matrixPart.getMatrix().getDescriptions().add(taxonRowWrapperDTO);
+    }
+
+    protected abstract boolean getMarkerFlag();
+
+
+    protected abstract MarkerType getMarkerType();
+
+    @CanExecute
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+            MHandledMenuItem menuItem){
+        boolean canExecute = false;
+        IStructuredSelection selection = ((CharacterMatrixPart)activePart.getObject()).getSelection();
+        canExecute = selection.size()==1
+                && selection.getFirstElement() instanceof TaxonNode;
+        menuItem.setVisible(canExecute);
+        return canExecute;
+    }
+
+}