From 5792209deb9a992f07a16fd5cc5e747cb68dd03c Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 28 Sep 2011 06:19:01 +0000 Subject: [PATCH] git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@22451 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/elements2/InputFactory.java | 11 +++- .../simantics/sysdyn/ui/values/ValueView.java | 62 +++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java index 353d640b..f3151bd9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java @@ -202,16 +202,21 @@ public class InputFactory extends SysdynElementFactory { String text = SysdynElementUtils.getInputReference(e); double scale = 0.235; AffineTransform at = ElementUtils.getTransform(e); - node.init(text, font, color, originX, font.getSize2D() * scale, scale); + node.init(text, font, color, originX, originY, scale); node.setBackgroundColor(fillColor); node.setBorderColor(borderColor); node.setHorizontalAlignment((byte) horizontalAlignment.ordinal()); node.setBorderWidth((float) 0); node.setEditable(false); node.setShowSelection(false); - - if(at != null) + + if(at != null) { node.setTransform(at); + // Use affinetransform to move the name of the valve below the valve symbol + AffineTransform at2 = (AffineTransform) at.clone(); + at2.translate(0, font.getSize2D() * scale); + node.setTransform(at2); + } } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java index 0ecb3a30..4eaefba7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java @@ -18,6 +18,11 @@ import java.util.List; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; 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.KeyEvent; +import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; @@ -71,6 +76,63 @@ public class ValueView extends ViewPart { } }; getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener); + + + /* + * A primitive copy paste to support exporting data from table to excel + * + * columnName\tcolumnName\tcolumnName\n + * value\tvalue\tvalue\n + * ... + * value\tvalue\tvalue\n + * + */ + + KeyListener kl = new KeyListener() { + + @Override + public void keyReleased(KeyEvent e) { + + } + + @Override + public void keyPressed(KeyEvent e) { + if (e.stateMask == SWT.CTRL && e.keyCode == 99) + { + System.out.println("CTRL C is pressed"); + + Clipboard cb = new Clipboard(e.display); + + TextTransfer textTransfer = TextTransfer.getInstance(); + + StringBuilder sb = new StringBuilder(); + int columnCount = table.getColumnCount(); + for(int i = 0; i < columnCount; i++) { + TableColumn tc = table.getColumn(i); + sb.append(tc.getText()); + if(i < columnCount - 1) + sb.append("\t"); + else + sb.append("\n"); + } + + + for(TableItem ti : table.getSelection()) + for(int i = 0; i < columnCount; i++) { + sb.append(ti.getText(i)); + if(i < columnCount - 1) + sb.append("\t"); + else + sb.append("\n"); + } + + cb.setContents(new Object[]{sb.toString()}, new Transfer[]{textTransfer}); + } + } + }; + + table.addKeyListener(kl); + } -- 2.47.1