comparison org.eclipse.jface/src/org/eclipse/jface/layout/TableColumnLayout.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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
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 org.eclipse.jface.layout.TableColumnLayout;
17
18 import java.lang.all;
19
20 import org.eclipse.jface.layout.AbstractColumnLayout;
21
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Layout;
24 import org.eclipse.swt.widgets.Scrollable;
25 import org.eclipse.swt.widgets.Table;
26 import org.eclipse.swt.widgets.TableColumn;
27 import org.eclipse.swt.widgets.Widget;
28 import org.eclipse.jface.viewers.ColumnLayoutData;
29 import org.eclipse.jface.viewers.ColumnPixelData;
30
31 /**
32 * The TableColumnLayout is the {@link Layout} used to maintain
33 * {@link TableColumn} sizes in a {@link Table}.
34 *
35 * <p>
36 * <b>You can only add the {@link Layout} to a container whose <i>only</i>
37 * child is the {@link Table} control you want the {@link Layout} applied to.
38 * Don't assign the layout directly the {@link Table}</b>
39 * </p>
40 *
41 * @since 3.3
42 */
43 public class TableColumnLayout : AbstractColumnLayout {
44
45 /*
46 * (non-Javadoc)
47 *
48 * @see org.eclipse.jface.layout.AbstractColumnLayout#getColumnCount(org.eclipse.swt.widgets.Scrollable)
49 */
50 override int getColumnCount(Scrollable tableTree) {
51 return (cast(Table) tableTree).getColumnCount();
52 }
53
54 /*
55 * (non-Javadoc)
56 *
57 * @see org.eclipse.jface.layout.AbstractColumnLayout#setColumnWidths(org.eclipse.swt.widgets.Scrollable,
58 * int[])
59 */
60 override void setColumnWidths(Scrollable tableTree, int[] widths) {
61 TableColumn[] columns = (cast(Table) tableTree).getColumns();
62 for (int i = 0; i < widths.length; i++) {
63 columns[i].setWidth(widths[i]);
64 }
65 }
66
67 /*
68 * (non-Javadoc)
69 *
70 * @see org.eclipse.jface.layout.AbstractColumnLayout#getLayoutData(int)
71 */
72 override ColumnLayoutData getLayoutData(Scrollable tableTree, int columnIndex) {
73 TableColumn column = (cast(Table) tableTree).getColumn(columnIndex);
74 return cast(ColumnLayoutData) column.getData(LAYOUT_DATA);
75 }
76
77 Composite getComposite(Widget column) {
78 return (cast(TableColumn) column).getParent().getParent();
79 }
80
81 /* (non-Javadoc)
82 * @see org.eclipse.jface.layout.AbstractColumnLayout#updateColumnData(org.eclipse.swt.widgets.Widget)
83 */
84 override void updateColumnData(Widget column) {
85 TableColumn tColumn = cast(TableColumn) column;
86 Table t = tColumn.getParent();
87
88 if( ! IS_GTK || t.getColumn(t.getColumnCount()-1) !is tColumn ){
89 tColumn.setData(LAYOUT_DATA,new ColumnPixelData(tColumn.getWidth()));
90 layout(t.getParent(), true);
91 }
92 }
93 }