Issue #111: Support copy/paste clipboard for feature values in annotation browser view
- fix clipboard
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 f464d46..12efdd0 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 @@
@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 @@
}
}
+ 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();