]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Copy-paste in SCL issues view 62/1262/3
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 24 Nov 2017 11:53:15 +0000 (13:53 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 27 Nov 2017 14:59:48 +0000 (16:59 +0200)
refs #7643

Change-Id: I3a417ccaba81e3df9a0dfa796756ebb9362603eb

bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java

index 10e2288e1b3d81b0a8cd639444b28e6b270bfa2b..9f4994eb1ddd42b141d680a370e0b60be1018cbe 100644 (file)
@@ -1,5 +1,10 @@
 package org.simantics.scl.ui.issues;
 
+import java.util.Iterator;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.resource.ImageRegistry;
@@ -11,6 +16,9 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.TableViewerColumn;
 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.events.ControlAdapter;
 import org.eclipse.swt.events.ControlEvent;
 import org.eclipse.swt.graphics.Image;
@@ -23,6 +31,7 @@ import org.eclipse.swt.widgets.Table;
 import org.eclipse.ui.IMemento;
 import org.eclipse.ui.IViewSite;
 import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.part.ViewPart;
 import org.simantics.scl.compiler.errors.ErrorSeverity;
 import org.simantics.scl.osgi.SCLOsgi;
@@ -43,6 +52,8 @@ public class SCLIssuesView extends ViewPart {
     
     SCLIssuesContentProvider issuesContentProvider = new SCLIssuesContentProvider();
     
+    Clipboard clipboard;
+    
     public SCLIssuesView() {
         super();
         imageRegistry = Activator.getInstance().getImageRegistry();
@@ -65,10 +76,12 @@ public class SCLIssuesView extends ViewPart {
     
     @Override
     public void createPartControl(Composite parent) {
+        this.clipboard = new Clipboard(parent.getDisplay());
+        
         this.parent = parent;
         parent.setLayout(new FillLayout());
         tableViewer = new TableViewer(parent,
-                SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
+                SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
         ColumnViewerToolTipSupport.enableFor(tableViewer);
         tableViewer.setContentProvider(issuesContentProvider);
 
@@ -148,6 +161,25 @@ public class SCLIssuesView extends ViewPart {
                 entry.openLocation();
             }
         });
+        
+        IHandlerService serv = (IHandlerService) getSite().getService(IHandlerService.class);
+        serv.activateHandler(org.eclipse.ui.IWorkbenchCommandConstants.EDIT_COPY, new CopyHandler());
+    }
+    
+    class CopyHandler extends AbstractHandler {
+        @Override
+        public Object execute(ExecutionEvent event) throws ExecutionException {
+            IStructuredSelection selection = tableViewer.getStructuredSelection();
+            if(!selection.isEmpty()) {
+                StringBuilder b = new StringBuilder();
+                for(Iterator it=selection.iterator();it.hasNext();) {
+                    SCLIssuesTableEntry entry = (SCLIssuesTableEntry)it.next();
+                    b.append(entry.moduleName).append('\t').append(entry.error.description).append('\n');
+                }
+                clipboard.setContents(new Object[] { b.toString() }, new Transfer[] { TextTransfer.getInstance() });
+            }
+            return null;
+        }
     }
 
     private void resizeColumns() {
@@ -179,6 +211,10 @@ public class SCLIssuesView extends ViewPart {
     public void dispose() {
         super.dispose();
         issuesContentProvider.dispose();
+        if(clipboard != null) {
+            clipboard.dispose();
+            clipboard = null;
+        }
     }
 
 }