ref #7095 add excel export
authorPatrick Plitzner <p.plitzner@bgbm.org>
Sat, 2 Dec 2017 16:29:05 +0000 (17:29 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Sat, 2 Dec 2017 16:29:05 +0000 (17:29 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java

index c5f9ce345fe2c846c8854a10f295bb2014085697..baac7ac964235125f562235f84763f93d1cbe7c7 100644 (file)
@@ -31,6 +31,8 @@ import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfigurat
 import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
 import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
 import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
+import org.eclipse.nebula.widgets.nattable.export.command.ExportCommand;
+import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
@@ -48,7 +50,11 @@ import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
 import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
 import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
 import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
@@ -142,7 +148,6 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
         //add default configuration because autoconfigure is set to false in constructor
         natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
 
-
         // add custom configuration for data conversion
         viewportLayer.addConfiguration(new AbstractRegistryConfiguration() {
 
@@ -166,6 +171,10 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
             }
         });
 
+        // add the ExportCommandHandler to the ViewportLayer in order to make
+        // exporting work
+        viewportLayer.registerCommandHandler(new ExportCommandHandler(viewportLayer));
+
         //propagate single cell selection
         natTable.addLayerListener(new ILayerListener() {
 
@@ -186,6 +195,19 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
 
         GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
 
+        //excel export
+        Button addColumnButton = new Button(parent, SWT.PUSH);
+        addColumnButton.setText("Export");
+        addColumnButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                natTable.doCommand(
+                        new ExportCommand(
+                                natTable.getConfigRegistry(),
+                                natTable.getShell()));
+            }
+        });
+
         parent.layout();
     }