| package org.eclipse.nebula.widgets.nattable.renderer.swt |
| |
| import org.eclipse.nebula.widgets.nattable.core.layer.impl.DimensionallyDependentLayer |
| import org.eclipse.nebula.widgets.nattable.core.layer.impl.DummyLayer |
| import org.eclipse.nebula.widgets.nattable.core.layer.impl.LayerDataAccessorImpl |
| import org.eclipse.nebula.widgets.nattable.core.layer.impl.composite.CompositeLayer |
| import org.eclipse.nebula.widgets.nattable.core.layer.impl.header.ColumnHeaderLayer |
| import org.eclipse.nebula.widgets.nattable.core.layer.impl.header.RowHeaderLayer |
| import org.eclipse.swt.SWT |
| import org.eclipse.swt.layout.FillLayout |
| import org.eclipse.swt.widgets.Display |
| import org.eclipse.swt.widgets.Shell |
| |
| class SWTExample { |
| |
| def static void main(String[] args) { |
| run(400, 300) |
| } |
| |
| static def void run(int shellWidth, int shellHeight) { |
| val display = Display::getDefault |
| val shell = new Shell(display, SWT::SHELL_TRIM) |
| shell.setLayout(new FillLayout) |
| shell.setSize(shellWidth, shellHeight) |
| shell.setText("NatTable -> SWT") |
| |
| // Create example control |
| val natTable = shell.SWTNatTable |
| |
| // Start |
| shell.open |
| |
| while (!shell.disposed) { |
| if (!display.readAndDispatch) { |
| display.sleep |
| } |
| } |
| |
| // Stop |
| natTable.dispose |
| |
| shell.dispose |
| display.dispose |
| } |
| |
| static def getSWTNatTable(Shell shell) { |
| val natTable = new SWTNatTable(shell) |
| |
| val bodyLayer = new DummyLayer(4, 4, 200, 100) |
| // val bodyLayer = new ViewportLayer(new DummyLayer(4, 4, 200, 100), new SWTControlPixelArea(natTable)) |
| // natTable.horizontalBar.addListener(SWT::Selection, [ Event event | |
| // println(event) |
| // ]) |
| // natTable.verticalBar.addListener(SWT::Selection, [ Event event | |
| // println(event) |
| // ]) |
| |
| val String[] columnHeaders = #[ "A", "B", "C", "D" ] |
| val columnHeaderLayer = new ColumnHeaderLayer(bodyLayer.horizontalAxis, new LayerDataAccessorImpl [ layer, columnId, rowId | columnHeaders.get(columnId as Integer) ]) |
| val rowHeaderLayer = new RowHeaderLayer(bodyLayer.verticalAxis, new LayerDataAccessorImpl [ layer, columnId, rowId | rowId ]) |
| val cornerLayer = new DimensionallyDependentLayer(rowHeaderLayer.horizontalAxis, columnHeaderLayer.verticalAxis, new LayerDataAccessorImpl [ layer, columnId, rowId | "" ]) |
| |
| natTable.layer = new CompositeLayer => [ |
| addRow(cornerLayer, columnHeaderLayer) |
| addRow(rowHeaderLayer, bodyLayer) |
| ] |
| |
| natTable |
| } |
| |
| } |