commit d9b8df42564c086eacc4b7c483613842ec77774d
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Wed May 30 15:10:55 2018 +0200

    ref #7439 Add "Copy" to context menu
    
     - show context menu for empty editor when clicking on header

diff --git a/eu.etaxonomy.taxeditor.bulkeditor/fragment.e4xmi b/eu.etaxonomy.taxeditor.bulkeditor/fragment.e4xmi
index 5f2d876ce..5fd177a34 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/fragment.e4xmi
+++ b/eu.etaxonomy.taxeditor.bulkeditor/fragment.e4xmi
@@ -16,6 +16,7 @@
     <elements xsi:type="commands:Command" xmi:id="_tLGKgJcOEeeM745tzuPNCQ" elementId="taxeditor-bulkeditor.dynamicdeleteobjectcommand" commandName="%command.name.3"/>
     <elements xsi:type="commands:Command" xmi:id="_Svo9oKK6EeeZb4PEjoRsuw" elementId="taxeditor-bulkeditor.command.setMarkerFlag" commandName="%command.name.6"/>
     <elements xsi:type="commands:Command" xmi:id="_hh5p4K9kEeejfdQ69MxTUA" elementId="eu.etaxonomy.taxeditor.bulkeditor.openBulkEditorForIdentifiableEntity" commandName="%command.commandname.1"/>
+    <elements xsi:type="commands:Command" xmi:id="_FSL3YGQEEeiuIMJ7WBlkCA" elementId="eu.etaxonomy.taxeditor.bulkeditor.command.copy" commandName="Copy"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_l_8NMCQUEeelPNxAg-e3TA" featurename="children" parentElementId="eu.etaxonomy.taxeditor.workbench.menu.admin">
     <elements xsi:type="menu:MenuSeparator" xmi:id="_zph3kDF2Eee-JvlKXQGppA" elementId="eu.etaxonomy.taxeditor.bulkeditor.menuseparator.0"/>
@@ -72,6 +73,7 @@
       <handlers xmi:id="_a-U4EJcOEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMergeTargetHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMergeTargetHandlerE4" command="_GAm9cJcNEeeM745tzuPNCQ"/>
       <handlers xmi:id="_qPOPQJcOEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler.NewObjectHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler.NewObjectHandlerE4" command="_jWkVYJcOEeeM745tzuPNCQ"/>
       <handlers xmi:id="_c9ppwKK6EeeZb4PEjoRsuw" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMarkerFlagHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMarkerFlagHandlerE4" command="_Svo9oKK6EeeZb4PEjoRsuw"/>
+      <handlers xmi:id="_I8Q8cGQEEeiuIMJ7WBlkCA" elementId="eu.etaxonomy.taxeditor.bulkeditor.handler.0" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.handler.CopyHandler" command="_FSL3YGQEEeiuIMJ7WBlkCA"/>
       <menus xsi:type="menu:PopupMenu" xmi:id="_B6IFsJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor">
         <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_H83EMJcMEeeM745tzuPNCQ" coreExpressionId="isCdmStoreConnected"/>
         <children xsi:type="menu:DynamicMenuContribution" xmi:id="_Y49vAJfHEeeUB5KN7hGpYQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicNewObjectMenuE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicNewObjectMenuE4"/>
@@ -88,6 +90,7 @@
         <children xsi:type="menu:MenuSeparator" xmi:id="_p-7bYJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.menuseparator.3"/>
         <children xsi:type="menu:DynamicMenuContribution" xmi:id="_MughoKK6EeeZb4PEjoRsuw" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicMarkerTypeEditingMenuE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicMarkerTypeEditingMenuE4"/>
         <children xsi:type="menu:MenuSeparator" xmi:id="_x3rgUJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.menuseparator.4"/>
+        <children xsi:type="menu:HandledMenuItem" xmi:id="_-LVJcGQDEeiuIMJ7WBlkCA" elementId="eu.etaxonomy.taxeditor.bulkeditor.handledmenuitem.copy" label="Copy" command="_FSL3YGQEEeiuIMJ7WBlkCA"/>
         <children xsi:type="menu:HandledMenuItem" xmi:id="_yt2TUJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.handledmenuitem.delete" label="%command.label.4" command="_S8xR4JcNEeeM745tzuPNCQ"/>
       </menus>
     </elements>
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
index 359a57763..26223ec90 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
@@ -59,9 +59,13 @@ 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.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Menu;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
@@ -273,12 +277,8 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
         menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
         // get the menu registered by EMenuService
         final Menu e4Menu = natTable.getMenu();
-
         // remove the menu reference from NatTable instance
         natTable.setMenu(null);
-
-        //add default configuration because autoconfigure is set to false in constructor
-        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
         natTable.addConfiguration(
                 new AbstractUiBindingConfiguration() {
 
@@ -297,9 +297,18 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
                                 GridRegion.BODY,
                                 MouseEventMatcher.RIGHT_BUTTON),
                         new PopupMenuAction(e4Menu));
+                // register the UI binding
+                uiBindingRegistry.registerMouseDownBinding(
+                        new MouseEventMatcher(
+                                SWT.NONE,
+                                GridRegion.COLUMN_HEADER,
+                                MouseEventMatcher.RIGHT_BUTTON),
+                        new PopupMenuAction(e4Menu));
             }
         });
 
+        //add default configuration because autoconfigure is set to false in constructor
+        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
         natTable.configure();
         GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
 
@@ -467,6 +476,25 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
         return input;
     }
 
+    public void copyDataToClipboard() {
+        String textData = "";
+        IStructuredSelection selection = getSelection();
+        Object[] objects = selection.toArray();
+        for (Object object : objects) {
+            if(object instanceof CdmBase){
+                textData += getEditorInput().getText((CdmBase)object);
+            }
+        }
+        final TextTransfer textTransfer = TextTransfer.getInstance();
+        final Clipboard clipboard = new Clipboard(Display.getDefault());
+        try {
+            clipboard.setContents(new Object[] { textData.toString() },
+                    new Transfer[] { textTransfer });
+        } finally {
+            clipboard.dispose();
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/CopyHandler.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/CopyHandler.java
new file mode 100644
index 000000000..5085b09a9
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/CopyHandler.java
@@ -0,0 +1,46 @@
+/**
+* Copyright (C) 2007 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.bulkeditor.e4.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.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.taxeditor.bulkeditor.e4.BulkEditorE4;
+
+/**
+ *
+ * @author pplitzner
+ * @date 12.09.2017
+ *
+ */
+public class CopyHandler  {
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
+        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
+        editor.copyDataToClipboard();
+    }
+
+    @CanExecute
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+            MHandledMenuItem menuItem) {
+        boolean canExecute = false;
+        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
+        IStructuredSelection selection = editor.getSelection();
+        canExecute = selection.size()==1;
+        menuItem.setVisible(canExecute);
+        return canExecute;
+    }
+}
