X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=eclipse%2Forg.argeo.cms.swt%2Fsrc%2Forg%2Fargeo%2Fcms%2Fswt%2Fwidgets%2FSwtTabularPart.java;h=2f10cac75ef0765b94fe19f22f87247c2250b554;hb=dbb84b4ec2d313ec0724d035c32f482ac57974c5;hp=02f2f815354e332d0c8617f9fd4f7173b37295e6;hpb=e168383bac50637131fef8c41e119db7eb2284a7;p=lgpl%2Fargeo-commons.git diff --git a/eclipse/org.argeo.cms.swt/src/org/argeo/cms/swt/widgets/SwtTabularPart.java b/eclipse/org.argeo.cms.swt/src/org/argeo/cms/swt/widgets/SwtTabularPart.java index 02f2f8153..2f10cac75 100644 --- a/eclipse/org.argeo.cms.swt/src/org/argeo/cms/swt/widgets/SwtTabularPart.java +++ b/eclipse/org.argeo.cms.swt/src/org/argeo/cms/swt/widgets/SwtTabularPart.java @@ -1,29 +1,35 @@ package org.argeo.cms.swt.widgets; -import java.util.function.Consumer; - +import org.argeo.api.cms.ux.CmsIcon; +import org.argeo.cms.swt.CmsSwtTheme; 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.graphics.Image; 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}. */ -public class SwtTabularPart implements TabularPart { - private Composite area; - +public class SwtTabularPart extends AbstractSwtPart { + private static final long serialVersionUID = -1114155772446357750L; private final Table table; + private TabularPart tabularPart; + + private CmsSwtTheme theme; - private Consumer onSelected; - private Consumer onAction; + public SwtTabularPart(Composite parent, int style, TabularPart tabularPart) { + super(parent, style, tabularPart); + theme = CmsSwtUtils.getCmsTheme(parent); - public SwtTabularPart(Composite parent, int style) { - area = new Composite(parent, style); - area.setLayout(CmsSwtUtils.noSpaceGridLayout()); - table = new Table(area, SWT.VIRTUAL | SWT.BORDER); + table = new Table(this, SWT.VIRTUAL | SWT.BORDER); + table.setLinesVisible(true); + table.setLayoutData(CmsSwtUtils.fillAll()); + + this.tabularPart = tabularPart; } @Override @@ -34,56 +40,43 @@ public class SwtTabularPart implements TabularPart { TableItem item = (TableItem) event.item; refreshItem(item); }); - table.setItemCount(getItemCount()); + table.setItemCount(tabularPart.getItemCount()); + for (int i = 0; i < tabularPart.getColumnCount(); i++) { + TableColumn swtColumn = new TableColumn(table, SWT.NONE); + swtColumn.setWidth(tabularPart.getColumn(i).getWidth()); + } CmsSwtUtils.fill(table); - table.addSelectionListener(new SelectionListener() { - private static final long serialVersionUID = -5225905921522775948L; - - @Override - public void widgetSelected(SelectionEvent e) { - if (onSelected != null) - onSelected.accept(e.item.getData()); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - if (onAction != null) - onAction.accept(e.item.getData()); - } - }); + table.addSelectionListener(selectionListener); } - @Override - public void setInput(Object data) { - area.setData(data); - refresh(); - } - - @Override - public Object getInput() { - return area.getData(); + protected Object getDataFromEvent(SelectionEvent e) { + Object data = e.item.getData(); + if (data == null) + data = tabularPart.getData(getTable().indexOf((TableItem) e.item)); + return data; } protected void refreshItem(TableItem item) { - - } - - protected int getItemCount() { - return 0; + int row = getTable().indexOf(item); + for (int i = 0; i < tabularPart.getColumnCount(); i++) { + Column column = tabularPart.getColumn(i); + T data = tabularPart.getData(row); + item.setData(data); + String text = data != null ? column.getText(data) : ""; + if (text != null) + item.setText(i, text); + CmsIcon icon = column.getIcon(data); + if (icon != null) { + Image image = theme.getSmallIcon(icon); + item.setImage(i, image); + } + } } protected Table getTable() { return table; } - public void onSelected(Consumer onSelected) { - this.onSelected = onSelected; - } - - public void onAction(Consumer onAction) { - this.onAction = onAction; - } - }