01: /*******************************************************************************
02: * Copyright (c) 2006 Tom Schindl and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Tom Schindl - initial API and implementation
10: ******************************************************************************/package org.eclipse.jface.viewers;
11:
12: import org.eclipse.swt.widgets.Tree;
13: import org.eclipse.swt.widgets.TreeColumn;
14:
15: /**
16: * ViewerColumn implementation for TreeViewer to enable column-specific label
17: * providers and editing support.
18: *
19: * @since 3.3
20: *
21: */
22: public final class TreeViewerColumn extends ViewerColumn {
23: private TreeColumn column;
24:
25: /**
26: * Creates a new viewer column for the given {@link TreeViewer} on a new
27: * {@link TreeColumn} with the given style bits. The column is inserted at
28: * the given index into the list of columns.
29: *
30: * @param viewer
31: * the tree viewer to which this column belongs
32: * @param style
33: * the style bits used to create the column, for applicable style bits
34: * see {@link TreeColumn}
35: * @see TreeColumn#TreeColumn(Tree, int)
36: */
37: public TreeViewerColumn(TreeViewer viewer, int style) {
38: this (viewer, style, -1);
39: }
40:
41: /**
42: * Creates a new viewer column for the given {@link TreeViewer} on a new
43: * {@link TreeColumn} with the given style bits. The column is added at the
44: * end of the list of columns.
45: *
46: * @param viewer
47: * the tree viewer to which this column belongs
48: * @param style
49: * the style bits used to create the column, for applicable style bits
50: * see {@link TreeColumn}
51: * @param index
52: * the index at which to place the newly created column
53: * @see TreeColumn#TreeColumn(Tree, int, int)
54: */
55: public TreeViewerColumn(TreeViewer viewer, int style, int index) {
56: this (viewer, createColumn(viewer.getTree(), style, index));
57: }
58:
59: /**
60: * Creates a new viewer column for the given {@link TreeViewer} on the given
61: * {@link TreeColumn}.
62: *
63: * @param viewer
64: * the tree viewer to which this column belongs
65: * @param column
66: * the underlying tree column
67: */
68: public TreeViewerColumn(TreeViewer viewer, TreeColumn column) {
69: super (viewer, column);
70: this .column = column;
71: }
72:
73: private static TreeColumn createColumn(Tree table, int style,
74: int index) {
75: if (index >= 0) {
76: return new TreeColumn(table, style, index);
77: }
78:
79: return new TreeColumn(table, style);
80: }
81:
82: /**
83: * @return the underlying SWT column
84: */
85: public TreeColumn getColumn() {
86: return column;
87: }
88: }
|