Révision 2013
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/SuperTableViewer.java (revision 2013) | ||
---|---|---|
1 |
package org.txm.rcp.swt.widget; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
|
|
5 |
import org.eclipse.jface.viewers.TableViewer; |
|
6 |
import org.eclipse.swt.SWT; |
|
7 |
import org.eclipse.swt.events.SelectionAdapter; |
|
8 |
import org.eclipse.swt.events.SelectionEvent; |
|
9 |
import org.eclipse.swt.layout.FormAttachment; |
|
10 |
import org.eclipse.swt.layout.FormData; |
|
11 |
import org.eclipse.swt.layout.FormLayout; |
|
12 |
import org.eclipse.swt.widgets.Composite; |
|
13 |
import org.eclipse.swt.widgets.Sash; |
|
14 |
|
|
15 |
public class SuperTableViewer extends Composite { |
|
16 |
|
|
17 |
protected ArrayList<SuperTableColumn> columns; |
|
18 |
|
|
19 |
public SuperTableViewer(Composite parent, int style) { |
|
20 |
super(parent, style); |
|
21 |
this.setLayout(new FormLayout()); |
|
22 |
} |
|
23 |
|
|
24 |
private void updatePositions() { |
|
25 |
for (int i = 0 ; i < columns.size() ; i++) { |
|
26 |
columns.get(i).updatePosition(i); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
public SuperTableColumn newColumn(String name) { |
|
31 |
return newColumn(name, -1); |
|
32 |
} |
|
33 |
|
|
34 |
public SuperTableColumn newColumn(String name, int position) { |
|
35 |
SuperTableColumn col = new SuperTableColumn(this, name); |
|
36 |
if (position > 0) { |
|
37 |
this.columns.add(position, col); |
|
38 |
} else { |
|
39 |
this.columns.add(col); |
|
40 |
} |
|
41 |
updatePositions(); |
|
42 |
return col; |
|
43 |
} |
|
44 |
|
|
45 |
public class SuperTableColumn extends TableViewer { |
|
46 |
SuperTableViewer table; |
|
47 |
Sash sash; |
|
48 |
FormData data = new FormData(); |
|
49 |
FormData data2 = new FormData(); |
|
50 |
String name; |
|
51 |
int position; |
|
52 |
|
|
53 |
protected SuperTableColumn(SuperTableViewer table, String name) { |
|
54 |
super(table, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); |
|
55 |
|
|
56 |
this.table = table; |
|
57 |
|
|
58 |
sash = new Sash(table, SWT.VERTICAL); |
|
59 |
sash.addSelectionListener(new SelectionAdapter() { |
|
60 |
public void widgetSelected(SelectionEvent event) { |
|
61 |
((FormData) sash.getLayoutData()).left = new FormAttachment(0, event.x); |
|
62 |
sash.getParent().layout(); |
|
63 |
} |
|
64 |
}); |
|
65 |
} |
|
66 |
|
|
67 |
public void updatePosition(int position) { |
|
68 |
data.top = new FormAttachment(0); |
|
69 |
data.bottom = new FormAttachment(100); |
|
70 |
if (position == 0) { |
|
71 |
data.left = new FormAttachment(0); |
|
72 |
} else { |
|
73 |
data.left = new FormAttachment(table.getColumn(position-1).getTable()); |
|
74 |
} |
|
75 |
data.right = new FormAttachment(sash,0); |
|
76 |
this.getTable().setLayoutData(data); |
|
77 |
|
|
78 |
data2.top = new FormAttachment(0, 0); |
|
79 |
data2.bottom = new FormAttachment(100, 0); |
|
80 |
data2.left = new FormAttachment(10); |
|
81 |
if (position < table.getNColumn() -1) { |
|
82 |
data2.right = new FormAttachment(table.getColumn(position+1).getTable()); |
|
83 |
} else { |
|
84 |
data2.right = new FormAttachment(100); |
|
85 |
} |
|
86 |
sash.setLayoutData(data2); |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
public SuperTableColumn getColumn(int i) { |
|
91 |
return columns.get(i); |
|
92 |
} |
|
93 |
|
|
94 |
public int getNColumn() { |
|
95 |
return columns.size(); |
|
96 |
} |
|
97 |
} |
|
0 | 98 |
Formats disponibles : Unified diff