]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop/src/org/simantics/interop/utils/TableUtils.java
Allow type comparator to compare types, not just instances.
[simantics/interop.git] / org.simantics.interop / src / org / simantics / interop / utils / TableUtils.java
index f373bc2f3cafb34715f9dc08a8d123e75f5ef49a..aaf87cdf50c18a23b52450b983aabb975277c0d5 100644 (file)
@@ -2,16 +2,18 @@ package org.simantics.interop.utils;
 \r
 import org.eclipse.jface.viewers.TableViewer;\r
 import org.eclipse.jface.viewers.TableViewerColumn;\r
+import org.eclipse.jface.viewers.TreeViewer;\r
+import org.eclipse.jface.viewers.TreeViewerColumn;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.events.SelectionAdapter;\r
 import org.eclipse.swt.events.SelectionEvent;\r
 import org.eclipse.swt.widgets.TableColumn;\r
+import org.eclipse.swt.widgets.TreeColumn;\r
 \r
 public class TableUtils {\r
        public static TableViewerColumn addColumn(final TableViewer viewer, String text, boolean resize, boolean sort, int width) {\r
                final TableViewerColumn twc = new TableViewerColumn(viewer, SWT.NONE);\r
                final TableColumn tc = twc.getColumn();\r
-               //final TableColumn tc = new TableColumn(viewer.getTable(), SWT.NONE);\r
                tc.setText(text);\r
                tc.setResizable(resize);\r
                tc.setWidth(width);\r
@@ -19,8 +21,13 @@ public class TableUtils {
                        tc.addSelectionListener(new SelectionAdapter() {\r
                                @Override\r
                                public void widgetSelected(SelectionEvent e) {\r
-                                       StringColumnComparator comparator = (StringColumnComparator)viewer.getComparator();\r
-                                       //TableColumn tc = twc.getColumn();\r
+                                       StringColumnComparator comparator = null;\r
+                                       if (viewer.getComparator() instanceof StringColumnComparator) {\r
+                                               comparator = (StringColumnComparator)viewer.getComparator();\r
+                                       } else {\r
+                                               comparator = new StringColumnComparator();\r
+                                               viewer.setComparator(comparator);\r
+                                       }\r
                                        TableColumn tcs[] = viewer.getTable().getColumns();\r
                                        int index = -1;\r
                                        for (int i = 0; i <tcs.length; i++) {\r
@@ -48,4 +55,13 @@ public class TableUtils {
                }\r
                return twc;\r
        }\r
+       \r
+       public static TreeViewerColumn addColumn(final TreeViewer viewer, String text, boolean resize, int width) {\r
+               final TreeViewerColumn tvc = new TreeViewerColumn(viewer, SWT.NONE);\r
+               TreeColumn tc = tvc.getColumn();\r
+               tc.setResizable(resize);\r
+               tc.setText(text);\r
+               tc.setWidth(width);\r
+               return tvc;\r
+       }\r
 }\r