KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > layout > TableColumnLayout


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  *******************************************************************************/

13
14 package org.eclipse.jface.layout;
15
16 import org.eclipse.jface.viewers.ColumnLayoutData;
17 import org.eclipse.jface.viewers.ColumnPixelData;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Layout;
20 import org.eclipse.swt.widgets.Scrollable;
21 import org.eclipse.swt.widgets.Table;
22 import org.eclipse.swt.widgets.TableColumn;
23 import org.eclipse.swt.widgets.Widget;
24
25 /**
26  * The TableColumnLayout is the {@link Layout} used to maintain
27  * {@link TableColumn} sizes in a {@link Table}.
28  *
29  * <p>
30  * <b>You can only add the {@link Layout} to a container whose <i>only</i>
31  * child is the {@link Table} control you want the {@link Layout} applied to.
32  * Don't assign the layout directly the {@link Table}</b>
33  * </p>
34  *
35  * @since 3.3
36  */

37 public class TableColumnLayout extends AbstractColumnLayout {
38
39     /*
40      * (non-Javadoc)
41      *
42      * @see org.eclipse.jface.layout.AbstractColumnLayout#getColumnCount(org.eclipse.swt.widgets.Scrollable)
43      */

44     int getColumnCount(Scrollable tableTree) {
45         return ((Table) tableTree).getColumnCount();
46     }
47
48     /*
49      * (non-Javadoc)
50      *
51      * @see org.eclipse.jface.layout.AbstractColumnLayout#setColumnWidths(org.eclipse.swt.widgets.Scrollable,
52      * int[])
53      */

54     void setColumnWidths(Scrollable tableTree, int[] widths) {
55         TableColumn[] columns = ((Table) tableTree).getColumns();
56         for (int i = 0; i < widths.length; i++) {
57             columns[i].setWidth(widths[i]);
58         }
59     }
60
61     /*
62      * (non-Javadoc)
63      *
64      * @see org.eclipse.jface.layout.AbstractColumnLayout#getLayoutData(int)
65      */

66     ColumnLayoutData getLayoutData(Scrollable tableTree, int columnIndex) {
67         TableColumn column = ((Table) tableTree).getColumn(columnIndex);
68         return (ColumnLayoutData) column.getData(LAYOUT_DATA);
69     }
70
71     Composite getComposite(Widget column) {
72         return ((TableColumn) column).getParent().getParent();
73     }
74
75     /* (non-Javadoc)
76      * @see org.eclipse.jface.layout.AbstractColumnLayout#updateColumnData(org.eclipse.swt.widgets.Widget)
77      */

78     void updateColumnData(Widget column) {
79         TableColumn tColumn = (TableColumn) column;
80         Table t = tColumn.getParent();
81         
82         if( ! IS_GTK || t.getColumn(t.getColumnCount()-1) != tColumn ){
83             tColumn.setData(LAYOUT_DATA,new ColumnPixelData(tColumn.getWidth()));
84             layout(t.getParent(), true);
85         }
86     }
87 }
88
Popular Tags