32
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2007 IBM Corporation 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 <tom.schindl@bestsolution.at> - initial API and implementation
|
|
10 * - fix for bug 178280, 183999, 184609
|
|
11 * IBM Corporation - API refactoring and general maintenance
|
|
12 * Port to the D programming language:
|
|
13 * Frank Benoit <benoit@tionex.de>
|
|
14 *******************************************************************************/
|
|
15
|
|
16 module dwtx.jface.layout.TreeColumnLayout;
|
|
17
|
|
18 import dwtx.jface.layout.AbstractColumnLayout;
|
|
19
|
|
20 import dwt.events.TreeEvent;
|
|
21 import dwt.events.TreeListener;
|
|
22 import dwt.widgets.Composite;
|
|
23 import dwt.widgets.Layout;
|
|
24 import dwt.widgets.Scrollable;
|
|
25 import dwt.widgets.Tree;
|
|
26 import dwt.widgets.TreeColumn;
|
|
27 import dwt.widgets.Widget;
|
|
28 import dwtx.jface.viewers.ColumnLayoutData;
|
|
29 import dwtx.jface.viewers.ColumnPixelData;
|
|
30
|
|
31 import dwt.dwthelper.utils;
|
|
32 import dwt.dwthelper.Runnable;
|
|
33
|
|
34 /**
|
|
35 * The TreeColumnLayout is the {@link Layout} used to maintain {@link TreeColumn} sizes in a
|
|
36 * {@link Tree}.
|
|
37 *
|
|
38 * <p>
|
|
39 * <b>You can only add the {@link Layout} to a container whose <i>only</i>
|
|
40 * child is the {@link Tree} control you want the {@link Layout} applied to.
|
|
41 * Don't assign the layout directly the {@link Tree}</b>
|
|
42 * </p>
|
|
43 *
|
|
44 * @since 3.3
|
|
45 */
|
|
46 public class TreeColumnLayout : AbstractColumnLayout {
|
|
47 private bool addListener = true;
|
|
48
|
|
49 private static class TreeLayoutListener : TreeListener {
|
|
50
|
|
51 public void treeCollapsed(TreeEvent e) {
|
|
52 update(cast(Tree) e.widget);
|
|
53 }
|
|
54
|
|
55 public void treeExpanded(TreeEvent e) {
|
|
56 update(cast(Tree) e.widget);
|
|
57 }
|
|
58
|
|
59 private void update(Tree tree) {
|
|
60 tree.getDisplay().asyncExec(new class Runnable {
|
|
61 Tree tree_;
|
|
62 this(){
|
|
63 tree_=tree;
|
|
64 }
|
|
65 public void run() {
|
|
66 tree_.update();
|
|
67 tree_.getParent().layout();
|
|
68 }
|
|
69
|
|
70 });
|
|
71 }
|
|
72
|
|
73 }
|
|
74
|
|
75 private static const TreeLayoutListener listener;
|
|
76
|
|
77 static this(){
|
|
78 listener = new TreeLayoutListener();
|
|
79 }
|
|
80
|
|
81 protected void layout(Composite composite, bool flushCache) {
|
|
82 super.layout(composite, flushCache);
|
|
83 if( addListener ) {
|
|
84 addListener=false;
|
|
85 (cast(Tree)getControl(composite)).addTreeListener(listener);
|
|
86 }
|
|
87 }
|
|
88
|
|
89 /* (non-Javadoc)
|
|
90 * @see dwtx.jface.layout.AbstractColumnLayout#getColumnCount(dwt.widgets.Scrollable)
|
|
91 */
|
|
92 int getColumnCount(Scrollable tree) {
|
|
93 return (cast(Tree) tree).getColumnCount();
|
|
94 }
|
|
95
|
|
96 /* (non-Javadoc)
|
|
97 * @see dwtx.jface.layout.AbstractColumnLayout#setColumnWidths(dwt.widgets.Scrollable, int[])
|
|
98 */
|
|
99 void setColumnWidths(Scrollable tree, int[] widths) {
|
|
100 TreeColumn[] columns = (cast(Tree) tree).getColumns();
|
|
101 for (int i = 0; i < widths.length; i++) {
|
|
102 columns[i].setWidth(widths[i]);
|
|
103 }
|
|
104 }
|
|
105
|
|
106 /* (non-Javadoc)
|
|
107 * @see dwtx.jface.layout.AbstractColumnLayout#getLayoutData(dwt.widgets.Scrollable, int)
|
|
108 */
|
|
109 ColumnLayoutData getLayoutData(Scrollable tableTree, int columnIndex) {
|
|
110 TreeColumn column = (cast(Tree) tableTree).getColumn(columnIndex);
|
|
111 return cast(ColumnLayoutData) column.getData(LAYOUT_DATA);
|
|
112 }
|
|
113
|
|
114 void updateColumnData(Widget column) {
|
|
115 TreeColumn tColumn = cast(TreeColumn) column;
|
|
116 Tree t = tColumn.getParent();
|
|
117
|
|
118 if( ! IS_GTK || t.getColumn(t.getColumnCount()-1) !is tColumn ){
|
|
119 tColumn.setData(LAYOUT_DATA,new ColumnPixelData(tColumn.getWidth()));
|
|
120 layout(t.getParent(), true);
|
|
121 }
|
|
122 }
|
|
123 }
|