| package org.eclipse.nebula.widgets.nattable.renderer.swt |
| |
| import com.google.inject.Guice |
| import com.google.inject.Injector |
| import org.eclipse.nebula.widgets.nattable.core.layer.axis.impl.AxisImpl |
| import org.eclipse.nebula.widgets.nattable.core.layer.axis.impl.hideshow.HideShowAxis |
| import org.eclipse.nebula.widgets.nattable.core.layer.axis.impl.reorder.ReorderAxis |
| 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.nebula.widgets.nattable.core.layer.impl.viewport.ViewportLayer |
| import org.eclipse.nebula.widgets.nattable.renderer.swt.event.binding.KeyBinding |
| import org.eclipse.nebula.widgets.nattable.renderer.swt.event.binding.UiBindings |
| import org.eclipse.nebula.widgets.nattable.renderer.swt.event.binding.UiBindingsImpl |
| 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 { |
| |
| static def void main(String[] args) { |
| new SWTExample().run(400, 300) |
| } |
| |
| 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 = createNatTable(shell) |
| |
| // Start |
| shell.open |
| |
| while (!shell.disposed) { |
| if (!display.readAndDispatch) { |
| display.sleep |
| } |
| } |
| |
| // Stop |
| natTable.dispose |
| |
| shell.dispose |
| display.dispose |
| } |
| |
| def createNatTable(Shell shell) { |
| val bodyLayer = new ViewportLayer(new DummyLayer( |
| // Horizontal axis |
| // new ReorderAxis( |
| new AxisImpl(10, 200)// => [ setPixelSizeOfSegmentPosition(100, 0) ] |
| // ) => [ reorderSegmentPosition(0, 2) ] |
| , |
| |
| // Vertical axis |
| // new HideShowAxis( |
| new AxisImpl(10, 100)// => [ setPixelSizeOfSegmentPosition(200, 2) ] |
| // ) => [ hideSegmentId(0) ] |
| )) |
| |
| val columnHeaderLayer = new ColumnHeaderLayer(bodyLayer.horizontalAxis, new LayerDataAccessorImpl([ layer, columnId, rowId | columnId ])) |
| 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 | "" ])) |
| |
| new SWTNatTable(shell) => [ |
| injector = createInjector |
| layer = new CompositeLayer => [ |
| addRow(cornerLayer, columnHeaderLayer) |
| addRow(rowHeaderLayer, bodyLayer) |
| ] |
| ] |
| } |
| |
| def Injector createInjector() { |
| // UI bindings |
| val uiBindings = new UiBindingsImpl |
| uiBindings.keyBindings += new KeyBinding([ event | event.keyCode == Character::valueOf('a') ], [ event | println((event.widget as SWTNatTable).layer) ]) |
| |
| // Create injector |
| Guice::createInjector([ binder | |
| binder.bind(typeof(UiBindings)).toInstance(uiBindings) |
| ]) |
| } |
| |
| } |