]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - swt/org.argeo.cms.swt/src/org/argeo/cms/swt/widgets/SwtTableView.java
1 package org
.argeo
.cms
.swt
.widgets
;
3 import org
.argeo
.api
.cms
.ux
.CmsIcon
;
4 import org
.argeo
.cms
.swt
.CmsSwtTheme
;
5 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
6 import org
.argeo
.cms
.ux
.widgets
.Column
;
7 import org
.argeo
.cms
.ux
.widgets
.TabularPart
;
8 import org
.eclipse
.swt
.SWT
;
9 import org
.eclipse
.swt
.events
.SelectionEvent
;
10 import org
.eclipse
.swt
.graphics
.Image
;
11 import org
.eclipse
.swt
.widgets
.Composite
;
12 import org
.eclipse
.swt
.widgets
.Table
;
13 import org
.eclipse
.swt
.widgets
.TableColumn
;
14 import org
.eclipse
.swt
.widgets
.TableItem
;
16 /** View of a {@link TabularPart} based on a {@link Table}. */
17 public class SwtTableView
<INPUT
, T
> extends AbstractSwtView
<INPUT
, T
> {
18 private static final long serialVersionUID
= -1114155772446357750L;
19 private final Table table
;
20 private TabularPart
<INPUT
, T
> tabularPart
;
22 private CmsSwtTheme theme
;
24 public SwtTableView(Composite parent
, int style
, TabularPart
<INPUT
, T
> tabularPart
) {
25 super(parent
, tabularPart
);
26 theme
= CmsSwtUtils
.getCmsTheme(parent
);
28 table
= new Table(this, SWT
.VIRTUAL
| style
);
29 table
.setLinesVisible(true);
30 table
.setLayoutData(CmsSwtUtils
.fillAll());
32 this.tabularPart
= tabularPart
;
36 public void refresh() {
39 table
.addListener(SWT
.SetData
, event
-> {
40 TableItem item
= (TableItem
) event
.item
;
43 table
.setItemCount(tabularPart
.getItemCount());
44 for (int i
= 0; i
< tabularPart
.getColumnCount(); i
++) {
45 TableColumn swtColumn
= new TableColumn(table
, SWT
.NONE
);
46 swtColumn
.setWidth(tabularPart
.getColumn(i
).getWidth());
48 CmsSwtUtils
.fill(table
);
50 table
.addSelectionListener(selectionListener
);
54 protected Object
getDataFromEvent(SelectionEvent e
) {
55 Object data
= e
.item
.getData();
57 data
= tabularPart
.getData(getTable().indexOf((TableItem
) e
.item
));
61 protected void refreshItem(TableItem item
) {
62 int row
= getTable().indexOf(item
);
63 T data
= tabularPart
.getData(row
);
64 for (int i
= 0; i
< tabularPart
.getColumnCount(); i
++) {
65 Column
<T
> column
= tabularPart
.getColumn(i
);
67 String text
= data
!= null ? column
.getText(data
) : "";
69 item
.setText(i
, text
);
70 CmsIcon icon
= column
.getIcon(data
);
72 Image image
= theme
.getSmallIcon(icon
);
73 item
.setImage(i
, image
);
79 public void notifyItemCountChange() {
80 table
.setItemCount(tabularPart
.getItemCount());
83 protected Table
getTable() {