KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > viewers > TreeViewerColumn


1 /*******************************************************************************
2  * Copyright (c) 2006 Tom Schindl and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Tom Schindl - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.jface.viewers;
13
14 import org.eclipse.swt.widgets.Tree;
15 import org.eclipse.swt.widgets.TreeColumn;
16
17 /**
18  * ViewerColumn implementation for TreeViewer to enable column-specific label
19  * providers and editing support.
20  *
21  * @since 3.3
22  *
23  */

24 public final class TreeViewerColumn extends ViewerColumn {
25     private TreeColumn column;
26
27     /**
28      * Creates a new viewer column for the given {@link TreeViewer} on a new
29      * {@link TreeColumn} with the given style bits. The column is inserted at
30      * the given index into the list of columns.
31      *
32      * @param viewer
33      * the tree viewer to which this column belongs
34      * @param style
35      * the style bits used to create the column, for applicable style bits
36      * see {@link TreeColumn}
37      * @see TreeColumn#TreeColumn(Tree, int)
38      */

39     public TreeViewerColumn(TreeViewer viewer, int style) {
40         this(viewer, style, -1);
41     }
42
43     /**
44      * Creates a new viewer column for the given {@link TreeViewer} on a new
45      * {@link TreeColumn} with the given style bits. The column is added at the
46      * end of the list of columns.
47      *
48      * @param viewer
49      * the tree viewer to which this column belongs
50      * @param style
51      * the style bits used to create the column, for applicable style bits
52      * see {@link TreeColumn}
53      * @param index
54      * the index at which to place the newly created column
55      * @see TreeColumn#TreeColumn(Tree, int, int)
56      */

57     public TreeViewerColumn(TreeViewer viewer, int style, int index) {
58         this(viewer, createColumn(viewer.getTree(), style, index));
59     }
60
61     /**
62      * Creates a new viewer column for the given {@link TreeViewer} on the given
63      * {@link TreeColumn}.
64      *
65      * @param viewer
66      * the tree viewer to which this column belongs
67      * @param column
68      * the underlying tree column
69      */

70     public TreeViewerColumn(TreeViewer viewer, TreeColumn column) {
71         super(viewer, column);
72         this.column = column;
73     }
74     
75     private static TreeColumn createColumn(Tree table, int style, int index) {
76         if (index >= 0) {
77             return new TreeColumn(table, style, index);
78         }
79
80         return new TreeColumn(table, style);
81     }
82
83     /**
84      * @return the underlying SWT column
85      */

86     public TreeColumn getColumn() {
87         return column;
88     }
89 }
90
Popular Tags