From c0a0bd5e9df13653d7873c39ec4d3f58c70dccd2 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 16 Dec 2019 13:19:43 +0200 Subject: [PATCH] Better column customization gitlab #19 Change-Id: I88b1a992e612379032e3f5593237cbb375cb99dd --- .../update/editor/ModelUpdateEditor.java | 41 +++++++++++++------ .../simantics/interop/test/GraphChanges.java | 10 ++++- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java index f79b1c1..2c7f1ce 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java @@ -195,18 +195,15 @@ public abstract class ModelUpdateEditor extends Composite implements WarningList changeViewer.setUseHashlookup(true); - TableViewerColumn selection = TableUtils.addColumn(changeViewer, getColumntTitle(0), false, false, 20); - TableViewerColumn diagram = TableUtils.addColumn(changeViewer, getColumntTitle(1), true, true, 100); - TableViewerColumn symbol = TableUtils.addColumn(changeViewer, getColumntTitle(2), true, true, 100); - TableViewerColumn property = TableUtils.addColumn(changeViewer, getColumntTitle(3), true, true, 100); - TableViewerColumn oldValue = TableUtils.addColumn(changeViewer, getColumntTitle(4), true, true, 100); - TableViewerColumn newValue = TableUtils.addColumn(changeViewer, getColumntTitle(5), true, true, 100); - - diagram.setLabelProvider(getLabelProvider(1)); - symbol.setLabelProvider(getLabelProvider(2)); - property.setLabelProvider(getLabelProvider(3)); - oldValue.setLabelProvider(getLabelProvider(4)); - newValue.setLabelProvider(getLabelProvider(5)); + TableViewerColumn cols[] = new TableViewerColumn[getChangeListColumnCount()]; + TableViewerColumn selection = TableUtils.addColumn(changeViewer, getColumntTitle(0), false, false, getChangeListColumnWidth(0)); + cols[0] = selection; + for (int i = 1 ; i < getChangeListColumnCount(); i++) { + TableViewerColumn column = TableUtils.addColumn(changeViewer, getColumntTitle(i), true, getChangeListColumnSortable(i), getChangeListColumnWidth(i)); + cols[i] = column; + column.setLabelProvider(getLabelProvider(i)); + configureChangeListColumn(i, column); + } selection.setLabelProvider(new SelectionLabelProvider()); selection.getColumn().addSelectionListener(new SelectionAdapter() { @@ -264,6 +261,26 @@ public abstract class ModelUpdateEditor extends Composite implements WarningList }); } + protected int getChangeListColumnCount() { + return 6; + } + + protected int getChangeListColumnWidth(int col) { + if (col == 0) + return 20; + return 100; + } + + protected boolean getChangeListColumnSortable(int col) { + if (col == 0) + return false; + return true; + } + + protected void configureChangeListColumn(int col, TableViewerColumn column) { + + } + protected Session getSession() { return Simantics.getSession(); } diff --git a/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java b/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java index fb72ba5..8ec4102 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java @@ -175,20 +175,26 @@ public class GraphChanges { Statement stm = mod.getLeftStm(); sb.append(NameUtils.getSafeName(graph, mod.getLeftSub()) + " "+ NameUtils.getSafeName(graph, stm.getPredicate()) + " " + - NameUtils.getSafeName(graph, stm.getObject()) + " (" + + truncate(NameUtils.getSafeName(graph, stm.getObject())) + " (" + stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n"); } { Statement stm = mod.getRightStm(); sb.append(NameUtils.getSafeName(graph, mod.getRightSub()) + " "+ NameUtils.getSafeName(graph, stm.getPredicate()) + " " + - NameUtils.getSafeName(graph, stm.getObject()) + " (" + + truncate(NameUtils.getSafeName(graph, stm.getObject())) + " (" + stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n"); } } return sb.toString(); } + public String truncate(String s) { + if (s.length() < 100) + return s; + return s.substring(0, 100)+"..."; + } + public String comparableToString(ReadGraph graph) throws DatabaseException { StringBuilder sb = new StringBuilder(); sb.append("Comparable:\n"); -- 2.47.1