01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation 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 <tom.schindl@bestsolution.at> - initial API and implementation
10: * - fix for bug 178280
11: * IBM Corporation - API refactoring and general maintenance
12: *******************************************************************************/package org.eclipse.jface.layout;
13:
14: import org.eclipse.jface.viewers.ColumnLayoutData;
15: import org.eclipse.jface.viewers.ColumnPixelData;
16: import org.eclipse.swt.widgets.Composite;
17: import org.eclipse.swt.widgets.Layout;
18: import org.eclipse.swt.widgets.Scrollable;
19: import org.eclipse.swt.widgets.Table;
20: import org.eclipse.swt.widgets.TableColumn;
21: import org.eclipse.swt.widgets.Widget;
22:
23: /**
24: * The TableColumnLayout is the {@link Layout} used to maintain
25: * {@link TableColumn} sizes in a {@link Table}.
26: *
27: * <p>
28: * <b>You can only add the {@link Layout} to a container whose <i>only</i>
29: * child is the {@link Table} control you want the {@link Layout} applied to.
30: * Don't assign the layout directly the {@link Table}</b>
31: * </p>
32: *
33: * @since 3.3
34: */
35: public class TableColumnLayout extends AbstractColumnLayout {
36:
37: /*
38: * (non-Javadoc)
39: *
40: * @see org.eclipse.jface.layout.AbstractColumnLayout#getColumnCount(org.eclipse.swt.widgets.Scrollable)
41: */
42: int getColumnCount(Scrollable tableTree) {
43: return ((Table) tableTree).getColumnCount();
44: }
45:
46: /*
47: * (non-Javadoc)
48: *
49: * @see org.eclipse.jface.layout.AbstractColumnLayout#setColumnWidths(org.eclipse.swt.widgets.Scrollable,
50: * int[])
51: */
52: void setColumnWidths(Scrollable tableTree, int[] widths) {
53: TableColumn[] columns = ((Table) tableTree).getColumns();
54: for (int i = 0; i < widths.length; i++) {
55: columns[i].setWidth(widths[i]);
56: }
57: }
58:
59: /*
60: * (non-Javadoc)
61: *
62: * @see org.eclipse.jface.layout.AbstractColumnLayout#getLayoutData(int)
63: */
64: ColumnLayoutData getLayoutData(Scrollable tableTree, int columnIndex) {
65: TableColumn column = ((Table) tableTree).getColumn(columnIndex);
66: return (ColumnLayoutData) column.getData(LAYOUT_DATA);
67: }
68:
69: Composite getComposite(Widget column) {
70: return ((TableColumn) column).getParent().getParent();
71: }
72:
73: /* (non-Javadoc)
74: * @see org.eclipse.jface.layout.AbstractColumnLayout#updateColumnData(org.eclipse.swt.widgets.Widget)
75: */
76: void updateColumnData(Widget column) {
77: TableColumn tColumn = (TableColumn) column;
78: Table t = tColumn.getParent();
79:
80: if (!IS_GTK || t.getColumn(t.getColumnCount() - 1) != tColumn) {
81: tColumn.setData(LAYOUT_DATA, new ColumnPixelData(tColumn
82: .getWidth()));
83: layout(t.getParent(), true);
84: }
85: }
86: }
|