Improve ACR viewer.
[lgpl/argeo-commons.git] / eclipse / org.argeo.cms.swt / src / org / argeo / cms / swt / widgets / SwtTabularPart.java
index 02f2f815354e332d0c8617f9fd4f7173b37295e6..9872551be31546742f86287f520442915c53f43f 100644 (file)
@@ -3,12 +3,14 @@ package org.argeo.cms.swt.widgets;
 import java.util.function.Consumer;
 
 import org.argeo.cms.swt.CmsSwtUtils;
+import org.argeo.cms.ux.widgets.Column;
 import org.argeo.cms.ux.widgets.TabularPart;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.TableItem;
 
 /** {@link TabularPart} implementation based on a {@link Table}. */
@@ -24,6 +26,7 @@ public class SwtTabularPart implements TabularPart {
                area = new Composite(parent, style);
                area.setLayout(CmsSwtUtils.noSpaceGridLayout());
                table = new Table(area, SWT.VIRTUAL | SWT.BORDER);
+               table.setLinesVisible(true);
        }
 
        @Override
@@ -67,13 +70,23 @@ public class SwtTabularPart implements TabularPart {
        }
 
        protected void refreshItem(TableItem item) {
-
+               int row = getTable().indexOf(item);
+               for (int i = 0; i < item.getParent().getColumnCount(); i++) {
+                       Column<Object> column = (Column<Object>) item.getParent().getColumn(i).getData();
+                       Object data = getData(row);
+                       String text = data != null ? column.getText(data) : "";
+                       item.setText(i, text);
+               }
        }
 
        protected int getItemCount() {
                return 0;
        }
 
+       protected Object getData(int row) {
+               return null;
+       }
+
        protected Table getTable() {
                return table;
        }
@@ -86,4 +99,16 @@ public class SwtTabularPart implements TabularPart {
                this.onAction = onAction;
        }
 
+       @Override
+       public void addColumn(Column<?> column) {
+               TableColumn swtColumn = new TableColumn(table, SWT.NONE);
+               swtColumn.setWidth(column.getWidth());
+               swtColumn.setData(column);
+
+       }
+
+       public Composite getArea() {
+               return area;
+       }
+
 }