]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Better column customization 14/3714/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 16 Dec 2019 11:19:43 +0000 (13:19 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 16 Dec 2019 11:19:43 +0000 (13:19 +0200)
gitlab #19

Change-Id: I88b1a992e612379032e3f5593237cbb375cb99dd

org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java
org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java

index f79b1c19dac103684dd78e01dc1a1163327159a4..2c7f1ce03b0c000499dbc285accf7083b0c83a83 100644 (file)
@@ -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();
        }
index fb72ba50f8e7e8b2b84266217f722405ab85b018..8ec4102a6bea3c6720899ea60fd6c77ef2b375aa 100644 (file)
@@ -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");