View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.argeo.eclipse.ui.util;
17  
18  import org.eclipse.jface.viewers.TableViewer;
19  import org.eclipse.jface.viewers.TableViewerColumn;
20  import org.eclipse.jface.viewers.TreeViewer;
21  import org.eclipse.jface.viewers.TreeViewerColumn;
22  import org.eclipse.swt.widgets.Table;
23  import org.eclipse.swt.widgets.TableColumn;
24  import org.eclipse.swt.widgets.TreeColumn;
25  
26  /**
27   * Centralise useful methods to manage JFace Table, Tree and TreeColumn viewers.
28   */
29  public class ViewerUtils {
30  
31  	/**
32  	 * Creates a basic column for the given table. For the time being, we do not
33  	 * support movable columns.
34  	 */
35  	public static TableColumn createColumn(Table parent, String name, int style, int width) {
36  		TableColumn result = new TableColumn(parent, style);
37  		result.setText(name);
38  		result.setWidth(width);
39  		result.setResizable(true);
40  		return result;
41  	}
42  
43  	/**
44  	 * Creates a TableViewerColumn for the given viewer. For the time being, we do
45  	 * not support movable columns.
46  	 */
47  	public static TableViewerColumn createTableViewerColumn(TableViewer parent, String name, int style, int width) {
48  		TableViewerColumn tvc = new TableViewerColumn(parent, style);
49  		TableColumn column = tvc.getColumn();
50  		column.setText(name);
51  		column.setWidth(width);
52  		column.setResizable(true);
53  		return tvc;
54  	}
55  
56  	// public static TableViewerColumn createTableViewerColumn(TableViewer parent,
57  	// Localized name, int style, int width) {
58  	// return createTableViewerColumn(parent, name.lead(), style, width);
59  	// }
60  
61  	/**
62  	 * Creates a TreeViewerColumn for the given viewer. For the time being, we do
63  	 * not support movable columns.
64  	 */
65  	public static TreeViewerColumn createTreeViewerColumn(TreeViewer parent, String name, int style, int width) {
66  		TreeViewerColumn tvc = new TreeViewerColumn(parent, style);
67  		TreeColumn column = tvc.getColumn();
68  		column.setText(name);
69  		column.setWidth(width);
70  		column.setResizable(true);
71  		return tvc;
72  	}
73  }