NatExamplesIndex
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/.classpath b/org.eclipse.nebula.widgets.nattable.core.example/.classpath
new file mode 100644
index 0000000..9938e7c
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="xtend-gen"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/.project b/org.eclipse.nebula.widgets.nattable.core.example/.project
new file mode 100644
index 0000000..f7eb92c
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.nebula.widgets.nattable.core.example</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.nebula.widgets.nattable.core.example/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..f42de36
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/META-INF/MANIFEST.MF b/org.eclipse.nebula.widgets.nattable.core.example/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..28a2323
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Example
+Bundle-SymbolicName: org.eclipse.nebula.widgets.nattable.core.example
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Require-Bundle: org.eclipse.nebula.widgets.nattable.core;bundle-version="2.0.0",
+ org.eclipse.xtend.lib,
+ com.google.guava,
+ org.eclipse.xtext.xbase.lib
+Export-Package: org.eclipse.nebula.widgets.nattable.core.example,
+ org.eclipse.nebula.widgets.nattable.core.example.impl
+
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/build.properties b/org.eclipse.nebula.widgets.nattable.core.example/build.properties
new file mode 100644
index 0000000..d8e2f0e
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/build.properties
@@ -0,0 +1,5 @@
+source.. = src/,\
+ xtend-gen/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/GenerateNatExamplesIndex.xtend b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/GenerateNatExamplesIndex.xtend
new file mode 100644
index 0000000..5a8441a
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/GenerateNatExamplesIndex.xtend
@@ -0,0 +1,56 @@
+package org.eclipse.nebula.widgets.nattable.core.example
+
+import java.io.BufferedWriter
+import java.io.File
+import java.io.FileWriter
+import java.util.Properties
+
+import static extension org.eclipse.nebula.widgets.nattable.core.example.NatExamplesIndex.*
+
+/**
+ * Generates the natExamplesIndex.properties file. For details on the format of this file, see {@link NatExamplesIndex}.
+ */
+class GenerateNatExamplesIndex {
+
+ def static void main(String[] args) {
+ new GenerateNatExamplesIndex().run
+ }
+
+ //
+
+ /**
+ * Generate the NatExamplesIndex.properties file
+ */
+ def void run() {
+ val examplesIndex = new Properties
+
+ findExamples(new File("src" + BASE_PACKAGE_PATH), examplesIndex)
+ findExamples(new File("xtend-gen" + BASE_PACKAGE_PATH), examplesIndex)
+
+ val examplesIndexFile = new File("src" + BASE_PACKAGE_PATH, NAT_EXAMPLES_INDEX_FILE_NAME)
+ val writer = new BufferedWriter(new FileWriter(examplesIndexFile))
+ examplesIndex.store(writer, "NatExamplesIndex")
+ writer.flush
+ writer.close
+ }
+
+ /**
+ * Recursively find all examples in the given directory and below, accumulating information about them in the examples index.
+ */
+ def private void findExamples(File dir, Properties examplesIndex) {
+ for (String s : dir.list) {
+ val f = new File(dir, s)
+ if (f.directory)
+ findExamples(f, examplesIndex)
+ else {
+ var examplePath = (dir.canonicalPath + File::separator + s).replace(File::separator, "/") // Convert to /-delimited path
+ if (examplePath.endsWith(".java")) {
+ val exampleClass = examplePath.replaceAll("\\.java$", "").exampleClass
+ if (exampleClass != null)
+ examplesIndex.put(exampleClass.simpleName, exampleClass.canonicalName)
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/NatExample.xtend b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/NatExample.xtend
new file mode 100644
index 0000000..8f1fab5
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/NatExample.xtend
@@ -0,0 +1,9 @@
+package org.eclipse.nebula.widgets.nattable.core.example
+
+import org.eclipse.nebula.widgets.nattable.core.layer.Layer
+
+interface NatExample {
+
+ def Layer createLayer()
+
+}
\ No newline at end of file
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/NatExamplesIndex.xtend b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/NatExamplesIndex.xtend
new file mode 100644
index 0000000..1827174
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/NatExamplesIndex.xtend
@@ -0,0 +1,81 @@
+package org.eclipse.nebula.widgets.nattable.core.example
+
+import java.lang.reflect.Modifier
+import java.util.HashMap
+import java.util.Properties
+
+/**
+ * The examples index. The index is generated by {@link GenerateNatExamplesIndex} and stored as a properties file.
+ * The properties file has the following format:
+ * <ul>
+ * <li>exampleName=fully.qualified.example.class.name</li>
+ * </ul>
+ */
+class NatExamplesIndex {
+
+ public static val NAT_EXAMPLES_INDEX_FILE_NAME = "NatExamplesIndex.properties"
+ public static val BASE_PACKAGE = "org.eclipse.nebula.widgets.nattable.core.example.impl"
+ public static val BASE_PACKAGE_PATH = "/" + BASE_PACKAGE.replace('.', '/')
+
+ static NatExamplesIndex _singleton
+
+ def private static getSingleton() {
+ if (_singleton == null) {
+ _singleton = new NatExamplesIndex
+ }
+ _singleton
+ }
+
+ def static getExample(String exampleName) {
+ singleton.getExampleInstance(exampleName)
+ }
+
+ /**
+ * @return The example class in the given example path, or null if none exists.
+ */
+ def static Class<? extends NatExample> getExampleClass(String examplePath) {
+ // Find class
+ var className = examplePath.replace("/", ".")
+ var Class<?> clazz = null
+ while (clazz == null && className.indexOf(".") >= 0) {
+ try {
+ clazz = Class::forName(className)
+ } catch (ClassNotFoundException e) {
+ // Chop off prefix and try again
+ className = className.replaceFirst("^[^.]*\\.", "")
+ }
+ }
+
+ // Check if this is a concrete NatExample
+ if (clazz != null && !Modifier::isAbstract(clazz.modifiers) && typeof(NatExample).isAssignableFrom(clazz))
+ return clazz as Class<? extends NatExample>
+ }
+
+ //
+
+ val Properties natExamplesIndex
+ val cachedExamples = new HashMap<String, NatExample>
+
+ new() {
+ val inputStream = typeof(NatExamplesIndex).getResourceAsStream(BASE_PACKAGE_PATH + "/" + NAT_EXAMPLES_INDEX_FILE_NAME)
+ if (inputStream == null)
+ throw new IllegalStateException("Examples index not found! Please run GenerateNatExamplesIndex from the org.eclipse.nebula.widgets.nattable.core.example project.")
+
+ natExamplesIndex = new Properties
+ natExamplesIndex.load(inputStream)
+ }
+
+ def NatExample getExampleInstance(String exampleName) {
+ var example = cachedExamples.get(exampleName)
+ if (example == null) {
+ val examplePath = natExamplesIndex.getProperty(exampleName)
+ val exampleClass = examplePath.exampleClass
+ if (exampleClass != null) {
+ example = exampleClass.newInstance as NatExample
+ cachedExamples.put(exampleName, example)
+ }
+ }
+ example
+ }
+
+}
\ No newline at end of file
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/BigLayer.xtend b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/BigLayer.xtend
new file mode 100644
index 0000000..6a115fc
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/BigLayer.xtend
@@ -0,0 +1,31 @@
+package org.eclipse.nebula.widgets.nattable.core.example.impl
+
+import org.eclipse.nebula.widgets.nattable.core.example.NatExample
+import org.eclipse.nebula.widgets.nattable.core.layer.axis.impl.AxisImpl
+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
+
+class BigLayer implements NatExample {
+
+ override createLayer() {
+ val bodyLayer = new ViewportLayer(new DummyLayer(
+ new AxisImpl(10 * 1000 * 1000, 200), // Horizontal axis
+ new AxisImpl(10 * 1000 * 1000, 100) // Vertical axis
+ ))
+
+ 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 CompositeLayer => [
+ addRow(cornerLayer, columnHeaderLayer)
+ addRow(rowHeaderLayer, bodyLayer)
+ ]
+ }
+
+}
\ No newline at end of file
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/GridLayer.xtend b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/GridLayer.xtend
new file mode 100644
index 0000000..2c73eeb
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/GridLayer.xtend
@@ -0,0 +1,40 @@
+package org.eclipse.nebula.widgets.nattable.core.example.impl
+
+import org.eclipse.nebula.widgets.nattable.core.example.NatExample
+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
+
+class GridLayer implements NatExample {
+
+ override createLayer() {
+ 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 CompositeLayer => [
+ addRow(cornerLayer, columnHeaderLayer)
+ addRow(rowHeaderLayer, bodyLayer)
+ ]
+ }
+
+}
\ No newline at end of file
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/natExamplesIndex.properties b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/natExamplesIndex.properties
new file mode 100644
index 0000000..359256b
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/natExamplesIndex.properties
@@ -0,0 +1,4 @@
+#NatExamplesIndex
+#Thu May 30 16:59:54 EDT 2013
+BigLayer=org.eclipse.nebula.widgets.nattable.core.example.impl.BigLayer
+GridLayer=org.eclipse.nebula.widgets.nattable.core.example.impl.GridLayer
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt.example/META-INF/MANIFEST.MF b/org.eclipse.nebula.widgets.nattable.renderer.swt.example/META-INF/MANIFEST.MF
index bc864f9..1dd558c 100644
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt.example/META-INF/MANIFEST.MF
+++ b/org.eclipse.nebula.widgets.nattable.renderer.swt.example/META-INF/MANIFEST.MF
@@ -5,3 +5,4 @@
Bundle-Version: 2.0.0.qualifier
Fragment-Host: org.eclipse.nebula.widgets.nattable.renderer.swt;bundle-version="2.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Require-Bundle: org.eclipse.nebula.widgets.nattable.core.example;bundle-version="1.0.0"
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt.example/src/org/eclipse/nebula/widgets/nattable/renderer/swt/example/SWTExample.xtend b/org.eclipse.nebula.widgets.nattable.renderer.swt.example/src/org/eclipse/nebula/widgets/nattable/renderer/swt/example/SWTExample.xtend
deleted file mode 100644
index 0d4e719..0000000
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt.example/src/org/eclipse/nebula/widgets/nattable/renderer/swt/example/SWTExample.xtend
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.eclipse.nebula.widgets.nattable.renderer.swt.example
-
-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.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.SWTNatTable
-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)
- ])
- }
-
-}
\ No newline at end of file
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt.example/src/org/eclipse/nebula/widgets/nattable/renderer/swt/example/SWTNatExamplesRunner.xtend b/org.eclipse.nebula.widgets.nattable.renderer.swt.example/src/org/eclipse/nebula/widgets/nattable/renderer/swt/example/SWTNatExamplesRunner.xtend
new file mode 100644
index 0000000..d2e22dd
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.renderer.swt.example/src/org/eclipse/nebula/widgets/nattable/renderer/swt/example/SWTNatExamplesRunner.xtend
@@ -0,0 +1,71 @@
+package org.eclipse.nebula.widgets.nattable.renderer.swt.example
+
+import com.google.inject.Guice
+import com.google.inject.Injector
+import org.eclipse.nebula.widgets.nattable.core.example.NatExamplesIndex
+import org.eclipse.nebula.widgets.nattable.renderer.swt.SWTNatTable
+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 SWTNatExamplesRunner {
+
+ def static void main(String[] args) {
+ new SWTNatExamplesRunner(400, 300).run
+ }
+
+ //
+
+ val int shellWidth
+ val int shellHeight
+
+ new(int shellWidth, int shellHeight) {
+ this.shellWidth = shellWidth
+ this.shellHeight = shellHeight
+ }
+
+ def void run() {
+ 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 natExample = NatExamplesIndex::getExample("BigLayer")
+
+ val natTable = new SWTNatTable(shell) => [
+ injector = createInjector
+ layer = natExample.createLayer
+ ]
+
+ // Start
+ shell.open
+
+ while (!shell.disposed)
+ if (!display.readAndDispatch)
+ display.sleep
+
+ // Stop
+ natTable.dispose
+
+ shell.dispose
+ display.dispose
+ }
+
+ 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)
+ ])
+ }
+
+}
\ No newline at end of file