Chess: Creation of board
diff --git a/examples/org.eclipse.graphiti.examples.chess/META-INF/MANIFEST.MF b/examples/org.eclipse.graphiti.examples.chess/META-INF/MANIFEST.MF
index 4509284..2301622 100644
--- a/examples/org.eclipse.graphiti.examples.chess/META-INF/MANIFEST.MF
+++ b/examples/org.eclipse.graphiti.examples.chess/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Chess Example for Graphiti
-Bundle-SymbolicName: org.eclipse.graphiti.examples.chess
+Bundle-SymbolicName: org.eclipse.graphiti.examples.chess;singleton:=true
 Bundle-Version: 0.9.0.qualifier
 Bundle-Activator: org.eclipse.graphiti.examples.chess.Activator
 Bundle-Vendor: Eclipse Modeling Project
diff --git a/examples/org.eclipse.graphiti.examples.chess/build.properties b/examples/org.eclipse.graphiti.examples.chess/build.properties
index 34d2e4d..e9863e2 100644
--- a/examples/org.eclipse.graphiti.examples.chess/build.properties
+++ b/examples/org.eclipse.graphiti.examples.chess/build.properties
@@ -1,4 +1,5 @@
 source.. = src/
 output.. = bin/
 bin.includes = META-INF/,\
-               .
+               .,\
+               plugin.xml
diff --git a/examples/org.eclipse.graphiti.examples.chess/plugin.xml b/examples/org.eclipse.graphiti.examples.chess/plugin.xml
new file mode 100644
index 0000000..8e39f4a
--- /dev/null
+++ b/examples/org.eclipse.graphiti.examples.chess/plugin.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+   <extension
+         point="org.eclipse.graphiti.ui.diagramTypes">
+      <diagramType
+            description="Diagram Type for Graphiti Chess Example"
+            id="org.eclipse.graphiti.examples.chess.ChessDiagramType"
+            name="Diagram Type for Graphiti Chess Example"
+            type="chess">
+      </diagramType>
+   </extension>
+   <extension
+         point="org.eclipse.graphiti.ui.diagramTypeProviders">
+      <diagramTypeProvider
+            class="org.eclipse.graphiti.examples.chess.diagram.ChessDiagramTypeProvider"
+            description="This is the editor for the Graphiti chess example"
+            id="org.eclipse.graphiti.examples.chess.ChessDiagramTypeProvider"
+            name="Graphiti Chess Example Editor">
+         <diagramType
+               id="org.eclipse.graphiti.examples.chess.ChessDiagramType">
+         </diagramType>
+      </diagramTypeProvider>
+   </extension>
+
+</plugin>
diff --git a/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/diagram/ChessDiagramTypeProvider.java b/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/diagram/ChessDiagramTypeProvider.java
new file mode 100644
index 0000000..aa2d26d
--- /dev/null
+++ b/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/diagram/ChessDiagramTypeProvider.java
@@ -0,0 +1,12 @@
+package org.eclipse.graphiti.examples.chess.diagram;
+
+import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+
+public class ChessDiagramTypeProvider extends AbstractDiagramTypeProvider implements IDiagramTypeProvider {
+
+	public ChessDiagramTypeProvider() {
+		super();
+		setFeatureProvider(new ChessFeatureProvider(this));
+	}
+}
diff --git a/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/diagram/ChessFeatureProvider.java b/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/diagram/ChessFeatureProvider.java
new file mode 100644
index 0000000..30dbb35
--- /dev/null
+++ b/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/diagram/ChessFeatureProvider.java
@@ -0,0 +1,27 @@
+package org.eclipse.graphiti.examples.chess.diagram;
+
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.examples.chess.features.AddChessBoardFeature;
+import org.eclipse.graphiti.examples.chess.features.CreateChessBoardFeature;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.ICreateFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
+
+public class ChessFeatureProvider extends DefaultFeatureProvider implements IFeatureProvider {
+
+	public ChessFeatureProvider(IDiagramTypeProvider dtp) {
+		super(dtp);
+	}
+	
+	@Override
+	public ICreateFeature[] getCreateFeatures() {
+		return new ICreateFeature[] {new CreateChessBoardFeature(this)};
+	}
+	
+	@Override
+	public IAddFeature getAddFeature(IAddContext context) {
+		return new AddChessBoardFeature(this);
+	}
+}
diff --git a/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/features/AddChessBoardFeature.java b/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/features/AddChessBoardFeature.java
new file mode 100644
index 0000000..163e1b3
--- /dev/null
+++ b/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/features/AddChessBoardFeature.java
@@ -0,0 +1,69 @@
+package org.eclipse.graphiti.examples.chess.features;
+
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature;
+import org.eclipse.graphiti.mm.algorithms.Rectangle;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.ICreateService;
+import org.eclipse.graphiti.services.IGaLayoutService;
+import org.eclipse.graphiti.util.IColorConstant;
+
+public class AddChessBoardFeature extends AbstractAddShapeFeature implements IAddFeature {
+
+	private static final int CHESS_BOARD_ROWS = 8;
+	private static final int CHESS_BOARD_COLUMNS = 8;
+
+	public AddChessBoardFeature(IFeatureProvider fp) {
+		super(fp);
+	}
+
+	@Override
+	public boolean canAdd(IAddContext context) {
+		if (context.getTargetContainer() instanceof Diagram) {
+			// Add new board only in case of an empty diagram
+			return context.getTargetContainer().getChildren().size() == 0;
+		}
+		return false;
+	}
+
+	@Override
+	public PictogramElement add(IAddContext context) {
+		ICreateService createService = Graphiti.getCreateService();
+		IGaLayoutService layoutService = Graphiti.getGaLayoutService();
+
+		ContainerShape outerContainerShape = createService.createContainerShape(getDiagram(), true);
+		Rectangle outerRectangle = createService.createRectangle(outerContainerShape);
+		layoutService.setLocationAndSize(outerRectangle, 50, 50, 400, 400);
+
+		for (int i = 0; i <= CHESS_BOARD_ROWS; i++) {
+			for (int j = 0; j <= CHESS_BOARD_COLUMNS; j++) {
+				ContainerShape fieldShape = createService.createContainerShape(outerContainerShape, true);
+				Rectangle fieldRectangle = createService.createRectangle(fieldShape);
+				layoutService.setLocationAndSize(fieldRectangle, i * 50, j * 50, 50, 50);
+				IColorConstant color;
+				if (i % 2 == 0) {
+					if (j % 2 == 0) {
+						color = IColorConstant.WHITE;
+					} else {
+						color = IColorConstant.BLACK;
+					}
+				} else {
+					if (j % 2 == 0) {
+						color = IColorConstant.BLACK;
+					} else {
+						color = IColorConstant.WHITE;
+					}
+				}
+				fieldRectangle.setBackground(manageColor(color));
+			}
+		}
+
+		return outerContainerShape;
+	}
+
+}
diff --git a/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/features/CreateChessBoardFeature.java b/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/features/CreateChessBoardFeature.java
new file mode 100644
index 0000000..7d2ad6b
--- /dev/null
+++ b/examples/org.eclipse.graphiti.examples.chess/src/org/eclipse/graphiti/examples/chess/features/CreateChessBoardFeature.java
@@ -0,0 +1,29 @@
+package org.eclipse.graphiti.examples.chess.features;
+
+import org.eclipse.graphiti.features.ICreateFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+
+public class CreateChessBoardFeature extends AbstractCreateFeature implements ICreateFeature {
+
+	public CreateChessBoardFeature(IFeatureProvider fp) {
+		super(fp, "Create Board", "Create a new chess board");
+	}
+
+	@Override
+	public boolean canCreate(ICreateContext context) {
+		if (context.getTargetContainer() instanceof Diagram) {
+			// Add new board only in case of an empty diagram
+			return context.getTargetContainer().getChildren().size() == 0;
+		}
+		return false;
+	}
+
+	@Override
+	public Object[] create(ICreateContext context) {
+		addGraphicalRepresentation(context, null);
+		return null;
+	}
+}