Add some utils method to simplify JFace Table and TreeColumn viewer management
authorBruno Sinou <bsinou@argeo.org>
Tue, 21 Aug 2012 12:09:31 +0000 (12:09 +0000)
committerBruno Sinou <bsinou@argeo.org>
Tue, 21 Aug 2012 12:09:31 +0000 (12:09 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@5524 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/ViewerUtils.java [new file with mode: 0644]

diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/ViewerUtils.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/ViewerUtils.java
new file mode 100644 (file)
index 0000000..50ed4ee
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.argeo.eclipse.ui.utils;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TreeColumn;
+
+/**
+ * Centralizes useful methods to manage Jface Table, Tree and TreeColumn
+ * viewers.
+ */
+public class ViewerUtils {
+
+       /**
+        * Creates a basic column for the given table. For the time being, we do not
+        * support moveable columns.
+        */
+       public static TableColumn createColumn(Table parent, String name,
+                       int style, int width) {
+               TableColumn result = new TableColumn(parent, style);
+               result.setText(name);
+               result.setWidth(width);
+               result.setResizable(true);
+               return result;
+       }
+
+       /**
+        * Creates a TableViewerColumn for the given viewer. For the time being, we
+        * do not support moveable columns.
+        */
+       public static TableViewerColumn createTableViewerColumn(TableViewer parent,
+                       String name, int style, int width) {
+               TableViewerColumn tvc = new TableViewerColumn(parent, style);
+               final TableColumn column = tvc.getColumn();
+               column.setText(name);
+               column.setWidth(width);
+               column.setResizable(true);
+               return tvc;
+       }
+
+       /**
+        * Creates a TreeViewerColumn for the given viewer. For the time being, we
+        * do not support moveable columns.
+        */
+       public static TreeViewerColumn createTreeViewerColumn(TreeViewer parent,
+                       String name, int style, int width) {
+               TreeViewerColumn tvc = new TreeViewerColumn(parent, style);
+               final TreeColumn column = tvc.getColumn();
+               column.setText(name);
+               column.setWidth(width);
+               column.setResizable(true);
+               return tvc;
+       }
+}