This is an automated email from the ASF dual-hosted git repository. pkluegl pushed a commit to branch bugfix/111-Support-copy-paste-clipboard-for-feature-values-in-annotation-browser-view-2 in repository https://gitbox.apache.org/repos/asf/uima-ruta.git
commit 3e0ff76c1bc32dffd4a0b594adc5ddf110606591 Author: Peter Klügl <[email protected]> AuthorDate: Fri Oct 28 12:08:05 2022 +0200 Issue #111: Support copy/paste clipboard for feature values in annotation browser view - fix clipboard --- .../view/tree/AnnotationTreeViewPage.java | 35 +++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeViewPage.java b/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeViewPage.java index f464d466..c259bd6c 100644 --- a/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeViewPage.java +++ b/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeViewPage.java @@ -269,23 +269,19 @@ public class AnnotationTreeViewPage extends Page implements MouseListener, IDoub @Override public void keyPressed(KeyEvent e) { + int keyCode = e.keyCode; // backspace or delete: delete annotations if (keyCode == SWT.BS || keyCode == SWT.DEL) { deleteSelectedAnnotations(); } // ctrl and c: copy type name to clipboard - if ((e.stateMask & SWT.CTRL) == SWT.CTRL && keyCode == 'c') { + if (e.stateMask == SWT.CTRL && (e.keyCode == 'c' || e.keyCode == 'C')) { TreeItem[] selection = treeView.getTree().getSelection(); - if (selection != null && selection.length == 1) { - Object obj = selection[0].getData(); - if (obj instanceof TypeTreeNode) { - TypeTreeNode typeTreeNode = (TypeTreeNode) obj; - Type type = typeTreeNode.getType(); - TextTransfer textTransfer = TextTransfer.getInstance(); - clipboard.setContents(new Object[] { type.getName() }, - new Transfer[] { textTransfer }); - } + if (selection != null) { + Object[] contents = getContents(selection); + TextTransfer textTransfer = TextTransfer.getInstance(); + clipboard.setContents(contents, new Transfer[] { textTransfer }); } } // ctrl and c: copy type name to clipboard: @@ -302,6 +298,25 @@ public class AnnotationTreeViewPage extends Page implements MouseListener, IDoub } } + private Object[] getContents(TreeItem[] selection) { + + List<String> list = new ArrayList<>(); + for (TreeItem item : selection) { + Object data = item.getData(); + if(data instanceof TypeTreeNode) { + list.add(((TypeTreeNode) data).getType().getName()); + } else if(data instanceof PrimitiveFeatureTreeNode) { + list.add(((PrimitiveFeatureTreeNode) data).getValue()); + } else if(data instanceof AnnotationTreeNode) { + list.add(((AnnotationTreeNode) data).getAnnotation().getCoveredText()); + } else if(data instanceof ITreeNode) { + list.add(((ITreeNode) data).getName()); + } + } + + return new Object[]{StringUtils.join(list, "\n")}; + } + }); styleListener = new TreeViewAnnotationStyleChangeListener();
