Bug 375497 - Enabled referencing domain objects for shapes and
connections in new plugin wizard and added support for patterns
diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/META-INF/MANIFEST.MF b/plugins/org.eclipse.graphiti.tools.newprojectwizard/META-INF/MANIFEST.MF
index 4633fe3..f979c68 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/META-INF/MANIFEST.MF
@@ -9,7 +9,10 @@
 Require-Bundle: org.eclipse.ui;bundle-version="[3.7.0,4.0.0)",
  org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)",
  org.eclipse.pde.ui;bundle-version="[3.6.0,4.0.0)",
- org.eclipse.core.resources;bundle-version="[3.7.0,4.0.0)"
+ org.eclipse.core.resources;bundle-version="[3.7.0,4.0.0)",
+ org.eclipse.jdt.ui;bundle-version="[3.7.0,4.0.0)",
+ org.eclipse.jdt.core;bundle-version="[3.7.0,4.0.0)",
+ org.eclipse.emf.ecore;bundle-version="[2.7.0,3.0.0)"
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-ActivationPolicy: lazy
 
diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GraphitiEditorTemplateSection.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GraphitiEditorTemplateSection.java
index 8246a9e..2beefcb 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GraphitiEditorTemplateSection.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GraphitiEditorTemplateSection.java
@@ -34,6 +34,10 @@
 import org.eclipse.pde.ui.templates.PluginReference;

 import org.eclipse.pde.ui.templates.StringOption;

 import org.eclipse.pde.ui.templates.TemplateOption;

+import org.eclipse.swt.events.SelectionAdapter;

+import org.eclipse.swt.events.SelectionEvent;

+import org.eclipse.swt.events.SelectionListener;

+import org.eclipse.swt.widgets.Button;

 

 public class GraphitiEditorTemplateSection extends OptionTemplateSection {

 

@@ -48,35 +52,98 @@
 	private static final String KEY_DTP_DESCRIPTION = "diagramTypeProviderDescription"; //$NON-NLS-1$

 

 	private static final String KEY_FEATURE_PROVIDER_CLASS_NAME = "featureProviderClassName"; //$NON-NLS-1$

+	private static final String KEY_USE_PATTERNS = "usePatterns"; //$NON-NLS-1$

+

+	private static final String KEY_USE_SHAPE_DOMAIN_OBJECT = "useShapeDomainObject"; //$NON-NLS-1$

+	private static final String KEY_SHAPE_DOMAIN_OBJECT_CLASS_NAME = "shapeDomainObjectClassName"; //$NON-NLS-1$

+	private static final String KEY_SHAPE_DOMAIN_OBJECT_CLASS_NAME_SHORT = "shapeDomainObjectClassNameShort"; //$NON-NLS-1$

+

+	private static final String KEY_USE_CONNECTION_DOMAIN_OBJECT = "useConnectionDomainObject"; //$NON-NLS-1$

+	private static final String KEY_CONNECTION_DOMAIN_OBJECT_CLASS_NAME = "connectionDomainObjectClassName"; //$NON-NLS-1$

+	private static final String KEY_CONNECTION_DOMAIN_OBJECT_CLASS_NAME_SHORT = "connectionDomainObjectClassNameShort"; //$NON-NLS-1$

+

+	private SelectTypeOption shapeDomainObjectOption;

+	private SelectTypeOption connectionDomainObjectOption;

 

 	public GraphitiEditorTemplateSection() {

 		super();

-		setPageCount(1);

+		setPageCount(2);

 		createOptions();

 	}

 

 	private void createOptions() {

 

-		GroupOption diagramTypeGroupOption = addGroupOption(0, Messages.GraphitiEditorTemplateSection_groupNameDiagramType);

+		GroupOption diagramTypeGroupOption = addGroupOption(0,

+				Messages.GraphitiEditorTemplateSection_groupNameDiagramType);

 		addGroupedOption(KEY_DT_ID, Messages.GraphitiEditorTemplateSection_fieldNameId, null, 0, diagramTypeGroupOption);

-		addGroupedOption(KEY_DT_NAME, Messages.GraphitiEditorTemplateSection_fieldNameName, null, 0, diagramTypeGroupOption);

-		addGroupedOption(KEY_DT_TYPE, Messages.GraphitiEditorTemplateSection_fieldNameType, null, 0, diagramTypeGroupOption);

-		TemplateOption diagramTypeDescriptionOption = addGroupedOption(KEY_DT_DESCRIPTION, Messages.GraphitiEditorTemplateSection_fieldNameDescription, "", 0, //$NON-NLS-2$ //$NON-NLS-1$

+		addGroupedOption(KEY_DT_NAME, Messages.GraphitiEditorTemplateSection_fieldNameName, null, 0,

+				diagramTypeGroupOption);

+		addGroupedOption(KEY_DT_TYPE, Messages.GraphitiEditorTemplateSection_fieldNameType, null, 0,

+				diagramTypeGroupOption);

+		TemplateOption diagramTypeDescriptionOption = addGroupedOption(KEY_DT_DESCRIPTION,

+				Messages.GraphitiEditorTemplateSection_fieldNameDescription, "", 0, //$NON-NLS-1$

 				diagramTypeGroupOption);

 		diagramTypeDescriptionOption.setRequired(false);

 

-		GroupOption diagramTypeProviderGroupOption = addGroupOption(0, Messages.GraphitiEditorTemplateSection_groupNameDiagramTypeProvider);

-		addGroupedOption(KEY_PACKAGE_NAME, Messages.GraphitiEditorTemplateSection_fieldNamePackageName, null, 0, diagramTypeProviderGroupOption);

-		addGroupedOption(KEY_DTP_ID, Messages.GraphitiEditorTemplateSection_fieldNameId, null, 0, diagramTypeProviderGroupOption);

-		addGroupedOption(KEY_DTP_NAME, Messages.GraphitiEditorTemplateSection_fieldNameName, null, 0, diagramTypeProviderGroupOption);

-		addGroupedOption(KEY_DTP_CLASS_NAME, Messages.GraphitiEditorTemplateSection_fieldNameClassName, null, 0, diagramTypeProviderGroupOption);

-		TemplateOption diagramTypeProviderDescriptionOption = addGroupedOption(KEY_DTP_DESCRIPTION, Messages.GraphitiEditorTemplateSection_fieldNameDescription, "", //$NON-NLS-2$ //$NON-NLS-1$

+		GroupOption diagramTypeProviderGroupOption = addGroupOption(0,

+				Messages.GraphitiEditorTemplateSection_groupNameDiagramTypeProvider);

+		addGroupedOption(KEY_PACKAGE_NAME, Messages.GraphitiEditorTemplateSection_fieldNamePackageName, null, 0,

+				diagramTypeProviderGroupOption);

+		addGroupedOption(KEY_DTP_ID, Messages.GraphitiEditorTemplateSection_fieldNameId, null, 0,

+				diagramTypeProviderGroupOption);

+		addGroupedOption(KEY_DTP_NAME, Messages.GraphitiEditorTemplateSection_fieldNameName, null, 0,

+				diagramTypeProviderGroupOption);

+		addGroupedOption(KEY_DTP_CLASS_NAME, Messages.GraphitiEditorTemplateSection_fieldNameClassName, null, 0,

+				diagramTypeProviderGroupOption);

+		TemplateOption diagramTypeProviderDescriptionOption = addGroupedOption(KEY_DTP_DESCRIPTION,

+				Messages.GraphitiEditorTemplateSection_fieldNameDescription, "", //$NON-NLS-1$

 				0, diagramTypeProviderGroupOption);

 		diagramTypeProviderDescriptionOption.setRequired(false);

 

-		GroupOption featureProviderGroupOption = addGroupOption(0, Messages.GraphitiEditorTemplateSection_groupNameFeatureProvider);

+		GroupOption featureProviderGroupOption = addGroupOption(0,

+				Messages.GraphitiEditorTemplateSection_groupNameFeatureProvider);

 		addGroupedOption(KEY_FEATURE_PROVIDER_CLASS_NAME, Messages.GraphitiEditorTemplateSection_fieldNameClassName,

 				null, 0, featureProviderGroupOption);

+		addGroupedOption(KEY_USE_PATTERNS, Messages.GraphitiEditorTemplateSection_fieldNameUsePatterns, false, 0, featureProviderGroupOption,

+				new SelectionAdapter() {

+					@Override

+					public void widgetSelected(SelectionEvent e) {

+						Button source = (Button) e.getSource();

+						boolean selection = source.getSelection();

+						shapeDomainObjectOption.setRequired(selection);

+						shapeDomainObjectOption.setEnabled(selection);

+					}

+				});

+

+		GroupOption shapeDomainObjectGroupOption = addGroupOption(1, Messages.GraphitiEditorTemplateSection_groupNameShapeDomainObject);

+		addGroupedOption(KEY_USE_SHAPE_DOMAIN_OBJECT, Messages.GraphitiEditorTemplateSection_fieldNameUseShapeDomainObject, false, 1, shapeDomainObjectGroupOption,

+				new SelectionAdapter() {

+					@Override

+					public void widgetSelected(SelectionEvent e) {

+						Button source = (Button) e.getSource();

+						boolean selection = source.getSelection();

+						shapeDomainObjectOption.setRequired(selection);

+						shapeDomainObjectOption.setEnabled(selection);

+					}

+				});

+		shapeDomainObjectOption = addSelectTypeOption(KEY_SHAPE_DOMAIN_OBJECT_CLASS_NAME, Messages.GraphitiEditorTemplateSection_fieldNameShapeDomainObject, null, 1,

+				shapeDomainObjectGroupOption);

+		shapeDomainObjectOption.setRequired(false);

+

+		GroupOption connectionDomainObjectGroupOption = addGroupOption(1, Messages.GraphitiEditorTemplateSection_groupNameConnectionDomainObject);

+		addGroupedOption(KEY_USE_CONNECTION_DOMAIN_OBJECT, Messages.GraphitiEditorTemplateSection_fieldNameUseConenctionDomainObject, false, 1,

+				connectionDomainObjectGroupOption, new SelectionAdapter() {

+					@Override

+					public void widgetSelected(SelectionEvent e) {

+						Button source = (Button) e.getSource();

+						boolean selection = source.getSelection();

+						connectionDomainObjectOption.setRequired(selection);

+						connectionDomainObjectOption.setEnabled(selection);

+					}

+				});

+		connectionDomainObjectOption = addSelectTypeOption(KEY_CONNECTION_DOMAIN_OBJECT_CLASS_NAME, Messages.GraphitiEditorTemplateSection_fieldNameConnectionDomainObject, null, 1,

+				connectionDomainObjectGroupOption);

+		connectionDomainObjectOption.setRequired(false);

 	}

 

 	private GroupOption addGroupOption(int pageIndex, String label) {

@@ -92,6 +159,20 @@
 		return option;

 	}

 

+	private GroupableBooleanOption addGroupedOption(String name, String label, boolean value, int pageIndex,

+			GroupOption groupOption, SelectionListener listener) {

+		GroupableBooleanOption option = new GroupableBooleanOption(this, name, label, groupOption, listener);

+		registerOption(option, value, pageIndex);

+		return option;

+	}

+

+	private SelectTypeOption addSelectTypeOption(String name, String label, String value, int pageIndex,

+			GroupOption groupOption) {

+		SelectTypeOption option = new SelectTypeOption(this, name, label, groupOption);

+		registerOption(option, value, pageIndex);

+		return option;

+	}

+

 	@Override

 	public boolean isDependentOnParentWizard() {

 		// Return true to indicate that the data collection in previous steps of

@@ -138,6 +219,14 @@
 

 		// Feature provider

 		initializeOption(KEY_FEATURE_PROVIDER_CLASS_NAME, classNamePrefix + "FeatureProvider"); //$NON-NLS-1$

+

+		// Shape domain object

+		initializeOption(KEY_USE_SHAPE_DOMAIN_OBJECT, false);

+		initializeOption(KEY_SHAPE_DOMAIN_OBJECT_CLASS_NAME, ""); //$NON-NLS-1$

+

+		// Connection domain object

+		initializeOption(KEY_USE_CONNECTION_DOMAIN_OBJECT, false);

+		initializeOption(KEY_CONNECTION_DOMAIN_OBJECT_CLASS_NAME, ""); //$NON-NLS-1$

 	}

 

 	private String getFormattedPackageName(String name) {

@@ -161,6 +250,12 @@
 		page.setTitle(Messages.GraphitiEditorTemplateSection_pageName);

 		page.setDescription(Messages.GraphitiEditorTemplateSection_pageDescription);

 		wizard.addPage(page);

+

+		page = createPage(1);

+		page.setTitle(Messages.GraphitiEditorTemplateSection_pageTitleDomainObjects);

+		page.setDescription(Messages.GraphitiEditorTemplateSection_pageDescriptionDomainObjects);

+		wizard.addPage(page);

+

 		markPagesAdded();

 	}

 

@@ -175,6 +270,23 @@
 

 		result.add(new PluginReference("org.eclipse.graphiti", null, 0)); //$NON-NLS-1$

 		result.add(new PluginReference("org.eclipse.graphiti.ui", null, 0)); //$NON-NLS-1$

+		if (Boolean.TRUE.equals(getValue(KEY_USE_PATTERNS))) {

+			result.add(new PluginReference("org.eclipse.graphiti.pattern", null, 0)); //$NON-NLS-1$

+		}

+

+		// Add additional references defined on page 2 of the wizard (domain

+		// dependency)

+		if (Boolean.TRUE.equals(getValue(KEY_USE_SHAPE_DOMAIN_OBJECT))) {

+			String bundleName = shapeDomainObjectOption.getBundleName();

+			result.add(new PluginReference(bundleName, null, 0));

+		}

+		if (Boolean.TRUE.equals(getValue(KEY_USE_CONNECTION_DOMAIN_OBJECT))) {

+			String bundleName = connectionDomainObjectOption.getBundleName();

+			PluginReference reference = new PluginReference(bundleName, null, 0);

+			if (!result.contains(reference)) {

+				result.add(reference);

+			}

+		}

 

 		return (IPluginReference[]) result.toArray(new IPluginReference[result.size()]);

 	}

@@ -186,7 +298,11 @@
 

 	@Override

 	public String getSectionId() {

-		return "newgraphitieditor"; //$NON-NLS-1$

+		if ((Boolean) getValue(KEY_USE_PATTERNS)) {

+			return "patterns"; //$NON-NLS-1$

+		} else {

+			return "features"; //$NON-NLS-1$

+		}

 	}

 

 	public String getUsedExtensionPoint() {

@@ -251,4 +367,33 @@
 			plugin.add(extension);

 		}

 	}

+

+	@Override

+	public String getReplacementString(String fileName, String key) {

+		if (KEY_SHAPE_DOMAIN_OBJECT_CLASS_NAME_SHORT.equals(key)) {

+			String value = super.getReplacementString(fileName, KEY_SHAPE_DOMAIN_OBJECT_CLASS_NAME);

+			if (value != null && value.length() > 0) {

+				// Domain object name was given -> get last segment

+				int lastIndexOfDot = value.lastIndexOf("."); //$NON-NLS-1$

+				value = value.substring(lastIndexOfDot + 1);

+			} else {

+				// No domain object given -> use generic name

+				value = "DomainObject"; //$NON-NLS-1$

+			}

+			return value;

+		} else if (KEY_CONNECTION_DOMAIN_OBJECT_CLASS_NAME_SHORT.equals(key)) {

+			String value = super.getReplacementString(fileName, KEY_CONNECTION_DOMAIN_OBJECT_CLASS_NAME);

+			if (value != null && value.length() > 0) {

+				// Domain object name was given -> get last segment

+				int lastIndexOfDot = value.lastIndexOf("."); //$NON-NLS-1$

+				value = value.substring(lastIndexOfDot + 1);

+			} else {

+				// No domain object given -> use generic name

+				value = "DomainObjectConnection"; //$NON-NLS-1$

+			}

+			return value;

+		} else {

+			return super.getReplacementString(fileName, key);

+		}

+	}

 }

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GroupableBooleanOption.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GroupableBooleanOption.java
new file mode 100644
index 0000000..3bc238d
--- /dev/null
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GroupableBooleanOption.java
@@ -0,0 +1,55 @@
+/**

+ * <copyright>

+ * 

+ * Copyright (c) 2012, 2012 SAP AG.

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ * 

+ * Contributors:

+ *    SAP AG - initial API, implementation and documentation

+ * 

+ * </copyright>

+ */

+package org.eclipse.graphiti.tools.newprojectwizard.internal;

+

+import org.eclipse.pde.ui.templates.BaseOptionTemplateSection;

+import org.eclipse.pde.ui.templates.BooleanOption;

+import org.eclipse.swt.events.SelectionListener;

+import org.eclipse.swt.widgets.Button;

+import org.eclipse.swt.widgets.Composite;

+import org.eclipse.swt.widgets.Control;

+

+/**

+ * A boolean option that can be added to a group

+ */

+public class GroupableBooleanOption extends BooleanOption {

+

+	private GroupOption groupOption;

+	private SelectionListener listener;

+

+	public GroupableBooleanOption(BaseOptionTemplateSection section, String name, String label,

+			GroupOption groupOption, SelectionListener listener) {

+		super(section, name, label);

+		this.groupOption = groupOption;

+		this.listener = listener;

+	}

+

+	@Override

+	public void createControl(Composite parent, int span) {

+		super.createControl(groupOption.getGroup(), span);

+		if (listener != null) {

+			addSelectionListener(listener);

+		}

+	}

+

+	private void addSelectionListener(SelectionListener listener) {

+		Control[] children = groupOption.getGroup().getChildren();

+		for (Control control : children) {

+			if (control instanceof Button) {

+				((Button) control).addSelectionListener(listener);

+			}

+		}

+	}

+}

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/Messages.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/Messages.java
index 5dbc027..5ccf297 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/Messages.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/Messages.java
@@ -5,17 +5,29 @@
 public class Messages extends NLS {

 	private static final String BUNDLE_NAME = "org.eclipse.graphiti.tools.newprojectwizard.internal.messages"; //$NON-NLS-1$

 	public static String GraphitiEditorTemplateSection_fieldNameClassName;

+	public static String GraphitiEditorTemplateSection_fieldNameConnectionDomainObject;

 	public static String GraphitiEditorTemplateSection_fieldNameDescription;

 	public static String GraphitiEditorTemplateSection_fieldNameId;

 	public static String GraphitiEditorTemplateSection_fieldNameName;

 	public static String GraphitiEditorTemplateSection_fieldNamePackageName;

+	public static String GraphitiEditorTemplateSection_fieldNameShapeDomainObject;

 	public static String GraphitiEditorTemplateSection_fieldNameType;

+	public static String GraphitiEditorTemplateSection_fieldNameUseConenctionDomainObject;

+	public static String GraphitiEditorTemplateSection_fieldNameUsePatterns;

+	public static String GraphitiEditorTemplateSection_fieldNameUseShapeDomainObject;

+	public static String GraphitiEditorTemplateSection_groupNameConnectionDomainObject;

 	public static String GraphitiEditorTemplateSection_groupNameDiagramType;

 	public static String GraphitiEditorTemplateSection_groupNameDiagramTypeProvider;

 	public static String GraphitiEditorTemplateSection_groupNameFeatureProvider;

+	public static String GraphitiEditorTemplateSection_groupNameShapeDomainObject;

 	public static String GraphitiEditorTemplateSection_pageDescription;

+	public static String GraphitiEditorTemplateSection_pageDescriptionDomainObjects;

 	public static String GraphitiEditorTemplateSection_pageName;

+	public static String GraphitiEditorTemplateSection_pageTitleDomainObjects;

 	public static String NewGraphitiEditorWizard_windowTitle;

+	public static String SelectTypeOption_BrowseButton;

+	public static String SelectTypeOption_DescriptionSelectDomainObject;

+	public static String SelectTypeOption_TitleSelectDomainObject;

 	static {

 		// initialize resource bundle

 		NLS.initializeMessages(BUNDLE_NAME, Messages.class);

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/SelectTypeOption.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/SelectTypeOption.java
new file mode 100644
index 0000000..738fd3c
--- /dev/null
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/SelectTypeOption.java
@@ -0,0 +1,249 @@
+/**

+ * <copyright>

+ * 

+ * Copyright (c) 2012, 2012 SAP AG.

+ * All rights reserved. This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v1.0

+ * which accompanies this distribution, and is available at

+ * http://www.eclipse.org/legal/epl-v10.html

+ * 

+ * Contributors:

+ *    SAP AG - initial API, implementation and documentation

+ * 

+ * </copyright>

+ */

+package org.eclipse.graphiti.tools.newprojectwizard.internal;

+

+import org.eclipse.jdt.core.IType;

+import org.eclipse.jdt.core.JavaModelException;

+import org.eclipse.jdt.core.search.SearchEngine;

+import org.eclipse.jdt.ui.IJavaElementSearchConstants;

+import org.eclipse.jdt.ui.JavaUI;

+import org.eclipse.jface.dialogs.Dialog;

+import org.eclipse.jface.dialogs.MessageDialog;

+import org.eclipse.pde.ui.templates.BaseOptionTemplateSection;

+import org.eclipse.pde.ui.templates.StringOption;

+import org.eclipse.swt.SWT;

+import org.eclipse.swt.events.ModifyEvent;

+import org.eclipse.swt.events.ModifyListener;

+import org.eclipse.swt.events.SelectionEvent;

+import org.eclipse.swt.events.SelectionListener;

+import org.eclipse.swt.layout.GridData;

+import org.eclipse.swt.layout.GridLayout;

+import org.eclipse.swt.widgets.Button;

+import org.eclipse.swt.widgets.Composite;

+import org.eclipse.swt.widgets.Display;

+import org.eclipse.swt.widgets.Label;

+import org.eclipse.swt.widgets.Shell;

+import org.eclipse.swt.widgets.Text;

+import org.eclipse.ui.PlatformUI;

+import org.eclipse.ui.dialogs.SelectionDialog;

+import org.osgi.framework.Bundle;

+import org.osgi.framework.BundleReference;

+

+/**

+ * An option that realizes a group.

+ */

+public class SelectTypeOption extends StringOption {

+

+	private GroupOption groupOption;

+

+	private Text text;

+	private Label labelControl;

+	private boolean ignoreListener;

+	private Button buttonControl;

+	private int fStyle;

+

+	private String bundleName = null;

+

+	private final static int F_DEFAULT_STYLE = SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY;

+

+	/**

+	 * The constructor.

+	 * 

+	 * @param section

+	 *            the parent section

+	 * @param name

+	 *            the unique option name

+	 * @param label

+	 *            the translatable label of the option

+	 * @param groupOption

+	 */

+	public SelectTypeOption(BaseOptionTemplateSection section, String name, String label, GroupOption groupOption) {

+		super(section, name, label);

+		fStyle = F_DEFAULT_STYLE;

+		setRequired(true);

+		this.groupOption = groupOption;

+	}

+

+	/**

+	 * A utility version of the <samp>getValue() </samp> method that converts

+	 * the current value into the String object.

+	 * 

+	 * @return the string version of the current value.

+	 */

+	public String getText() {

+		if (getValue() != null)

+			return getValue().toString();

+		return null;

+	}

+

+	/**

+	 * A utility version of the <samp>setValue </samp> method that accepts

+	 * String objects.

+	 * 

+	 * @param newText

+	 *            the new text value of the option

+	 * @see #setValue(Object)

+	 */

+	public void setText(String newText) {

+		setValue(newText);

+	}

+

+	/**

+	 * Implements the superclass method by passing the string value of the new

+	 * value to the widget

+	 * 

+	 * @param value

+	 *            the new option value

+	 */

+	public void setValue(Object value) {

+		super.setValue(value);

+		if (text != null) {

+			ignoreListener = true;

+			String textValue = getText();

+			text.setText(textValue != null ? textValue : ""); //$NON-NLS-1$

+			ignoreListener = false;

+		}

+	}

+

+	/**

+	 * Creates the string option control.

+	 * 

+	 * @param parent

+	 *            parent composite of the string option widget

+	 * @param span

+	 *            the number of columns that the widget should span

+	 */

+	public void createControl(Composite parent, int span) {

+		Composite composite = new Composite(groupOption.getGroup(), SWT.NONE);

+		GridData gd = new GridData(GridData.FILL_HORIZONTAL);

+		gd.horizontalSpan = span;

+		composite.setLayoutData(gd);

+		composite.setLayout(new GridLayout(3, false));

+

+		labelControl = createLabel(composite, 1);

+		labelControl.setEnabled(isEnabled());

+

+		text = new Text(composite, fStyle);

+		if (getValue() != null)

+			text.setText(getValue().toString());

+		gd = new GridData(GridData.FILL_HORIZONTAL);

+		gd.horizontalSpan = 1;

+		text.setLayoutData(gd);

+		text.setEnabled(isEnabled());

+		text.addModifyListener(new ModifyListener() {

+			public void modifyText(ModifyEvent e) {

+				if (ignoreListener)

+					return;

+				SelectTypeOption.super.setValue(text.getText());

+				getSection().validateOptions(SelectTypeOption.this);

+			}

+		});

+

+		buttonControl = new Button(composite, SWT.PUSH);

+		buttonControl.setText(Messages.SelectTypeOption_BrowseButton);

+		buttonControl.addSelectionListener(new SelectionListener() {

+			public void widgetSelected(SelectionEvent e) {

+				Shell parent = Display.getCurrent().getActiveShell();

+				SelectionDialog dialog = null;

+				try {

+					dialog = JavaUI.createTypeDialog(parent, PlatformUI.getWorkbench().getProgressService(),

+							SearchEngine.createWorkspaceScope(),

+							IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES, false);

+				} catch (JavaModelException jme) {

+					MessageDialog.openError(parent, "Could not open type selection dialog", jme.getMessage()); //$NON-NLS-1$

+					return;

+				}

+

+				// SelectionDialog dialog = new OpenTypeSelectionDialog(parent,

+				// true, PlatformUI.getWorkbench()

+				// .getProgressService(), null, IJavaSearchConstants.TYPE);

+				dialog.setTitle(Messages.SelectTypeOption_TitleSelectDomainObject);

+				dialog.setMessage(Messages.SelectTypeOption_DescriptionSelectDomainObject);

+

+				if (dialog.open() == Dialog.OK) {

+					Object[] result = dialog.getResult();

+					if (result != null && result.length > 0 && result[0] instanceof IType) {

+						IType type = (IType) result[0];

+						text.setText(type.getFullyQualifiedName());

+						

+						Bundle containingBundle = null;

+

+						// Search for the first bundle that can resolve the

+						// desired class

+						Bundle[] bundles = Activator.getDefault().getBundle().getBundleContext().getBundles();

+						for (Bundle bundle : bundles) {

+							try {

+								Class<?> loadClass = bundle.loadClass(type.getFullyQualifiedName());

+

+								// Use the class loader of the class to identify

+								// the containing bundle

+								ClassLoader classLoader = loadClass.getClassLoader();

+								if (classLoader instanceof BundleReference) {

+									containingBundle = ((BundleReference) classLoader).getBundle();

+									setBundleName(containingBundle.getSymbolicName());

+									return;

+								}

+							} catch (ClassNotFoundException cnfe) {

+								// Simply ignore

+							}

+						}

+						if (containingBundle == null) {

+							MessageDialog.openError(parent, "No Bundle found", //$NON-NLS-1$

+									"The class '" + type.getFullyQualifiedName() //$NON-NLS-1$

+											+ "' could not be resolved within an installed plugin."); //$NON-NLS-1$

+						}

+					}

+				}

+			}

+

+			public void widgetDefaultSelected(SelectionEvent e) {

+				widgetSelected(e);

+			}

+		});

+		buttonControl.setEnabled(isEnabled());

+	}

+

+	/**

+	 * A string option is empty if its text field contains no text.

+	 * 

+	 * @return true if there is no text in the text field.

+	 */

+	public boolean isEmpty() {

+		return getValue() == null || getValue().toString().length() == 0;

+	}

+

+	/**

+	 * Implements the superclass method by passing the enabled state to the

+	 * option's widget.

+	 * 

+	 * @param enabled

+	 */

+	public void setEnabled(boolean enabled) {

+		super.setEnabled(enabled);

+		if (labelControl != null) {

+			labelControl.setEnabled(enabled);

+			text.setEnabled(enabled);

+			buttonControl.setEnabled(enabled);

+		}

+	}

+

+	public String getBundleName() {

+		return bundleName;

+	}

+

+	public void setBundleName(String bundleName) {

+		this.bundleName = bundleName;

+	}

+}

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/messages.properties b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/messages.properties
index 1cd7feb..95d5f2e 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/messages.properties
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/messages.properties
@@ -1,12 +1,24 @@
 GraphitiEditorTemplateSection_fieldNameClassName=Class Name 

+GraphitiEditorTemplateSection_fieldNameConnectionDomainObject=Name

 GraphitiEditorTemplateSection_fieldNameDescription=Description

 GraphitiEditorTemplateSection_fieldNameId=ID

 GraphitiEditorTemplateSection_fieldNameName=Name

 GraphitiEditorTemplateSection_fieldNamePackageName=Package Name

+GraphitiEditorTemplateSection_fieldNameShapeDomainObject=Name

 GraphitiEditorTemplateSection_fieldNameType=Type

+GraphitiEditorTemplateSection_fieldNameUseConenctionDomainObject=Use Domain Object

+GraphitiEditorTemplateSection_fieldNameUsePatterns=Use Patterns

+GraphitiEditorTemplateSection_fieldNameUseShapeDomainObject=Use Domain Object

+GraphitiEditorTemplateSection_groupNameConnectionDomainObject=Domain Object for Connection

 GraphitiEditorTemplateSection_groupNameDiagramType=Diagram Type

 GraphitiEditorTemplateSection_groupNameDiagramTypeProvider=Diagram Type Provider

 GraphitiEditorTemplateSection_groupNameFeatureProvider=Feature Provider

+GraphitiEditorTemplateSection_groupNameShapeDomainObject=Domain Object for Shape

 GraphitiEditorTemplateSection_pageDescription=Define how the new Graphiti editor will be registered to the plug-in.

+GraphitiEditorTemplateSection_pageDescriptionDomainObjects=Define the domain object used in the editor.

 GraphitiEditorTemplateSection_pageName=Graphiti Providers

+GraphitiEditorTemplateSection_pageTitleDomainObjects=Domain Object

 NewGraphitiEditorWizard_windowTitle=New Plug-In Project with a Sample Graphiti Editor

+SelectTypeOption_BrowseButton=Browse...

+SelectTypeOption_DescriptionSelectDomainObject=&Enter type name prefix or pattern (*, ?, or camel case):

+SelectTypeOption_TitleSelectDomainObject=Select Domain Object

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/diagram/$diagramTypeProviderClassName$.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/diagram/$diagramTypeProviderClassName$.java
similarity index 100%
rename from plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/diagram/$diagramTypeProviderClassName$.java
rename to plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/diagram/$diagramTypeProviderClassName$.java
diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/diagram/$featureProviderClassName$.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/diagram/$featureProviderClassName$.java
similarity index 62%
rename from plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/diagram/$featureProviderClassName$.java
rename to plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/diagram/$featureProviderClassName$.java
index af28ae0..4c234f5 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/diagram/$featureProviderClassName$.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/diagram/$featureProviderClassName$.java
@@ -11,12 +11,18 @@
 import org.eclipse.graphiti.mm.pictograms.ContainerShape;

 import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;

 

-import $packageName$.features.AddDomainObjectConnectionFeature;

-import $packageName$.features.AddDomainObjectFeature;

-import $packageName$.features.CreateDomainObjectConnectionFeature;

-import $packageName$.features.CreateDomainObjectFeature;

-import $packageName$.features.LayoutDomainObjectFeature;

+import $packageName$.features.Add$connectionDomainObjectClassNameShort$ConnectionFeature;

+import $packageName$.features.Add$shapeDomainObjectClassNameShort$Feature;

+import $packageName$.features.Create$connectionDomainObjectClassNameShort$ConnectionFeature;

+import $packageName$.features.Create$shapeDomainObjectClassNameShort$Feature;

+import $packageName$.features.Layout$shapeDomainObjectClassNameShort$Feature;

 

+%if useShapeDomainObject

+import $shapeDomainObjectClassName$;

+%endif

+%if useConnectionDomainObject

+import $connectionDomainObjectClassName$;

+%endif

 

 public class $featureProviderClassName$ extends DefaultFeatureProvider {

 

@@ -26,22 +32,23 @@
 

 	@Override

 	public ICreateFeature[] getCreateFeatures() {

-		return new ICreateFeature[] {new CreateDomainObjectFeature(this)};

+		return new ICreateFeature[] {new Create$shapeDomainObjectClassNameShort$Feature(this)};

 	}

 	

 	@Override

 	public ICreateConnectionFeature[] getCreateConnectionFeatures() {

-		return new ICreateConnectionFeature[] {new CreateDomainObjectConnectionFeature(this)};

+		return new ICreateConnectionFeature[] {new Create$connectionDomainObjectClassNameShort$ConnectionFeature(this)};

 	}

 	

 	@Override

 	public IAddFeature getAddFeature(IAddContext context) {

 		// TODO: check for right domain object instances below

 		if (context instanceof IAddConnectionContext /* && context.getNewObject() instanceof <DomainObject> */) {

-			return new AddDomainObjectConnectionFeature(this);

+			return new Add$connectionDomainObjectClassNameShort$ConnectionFeature(this);

 		} else if (context instanceof IAddContext /* && context.getNewObject() instanceof <DomainObject> */) {

-			return new AddDomainObjectFeature(this);

+			return new Add$shapeDomainObjectClassNameShort$Feature(this);

 		}

+

 		return super.getAddFeature(context);

 	}

 	

@@ -49,9 +56,9 @@
 	public ILayoutFeature getLayoutFeature(ILayoutContext context) {

 		// TODO: check for right domain object instances below

 		if (context.getPictogramElement() instanceof ContainerShape /* && getBusinessObjectForPictogramElement(context.getPictogramElement()) instanceof <DomainObject> */) {

-			return  new LayoutDomainObjectFeature(this);

+			return  new Layout$shapeDomainObjectClassNameShort$Feature(this);

 		}

-

+	

 		return super.getLayoutFeature(context);

 	}

 }

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/AddDomainObjectConnectionFeature.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Add$connectionDomainObjectClassNameShort$ConnectionFeature.java
similarity index 79%
copy from plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/AddDomainObjectConnectionFeature.java
copy to plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Add$connectionDomainObjectClassNameShort$ConnectionFeature.java
index 908dc2a..11f19ba 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/AddDomainObjectConnectionFeature.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Add$connectionDomainObjectClassNameShort$ConnectionFeature.java
@@ -13,20 +13,21 @@
 import org.eclipse.graphiti.services.IPeCreateService;

 import org.eclipse.graphiti.util.IColorConstant;

 

-public class AddDomainObjectConnectionFeature extends AbstractAddFeature implements

+%if useConnectionDomainObject

+import $connectionDomainObjectClassName$;

+%endif

+

+public class Add$connectionDomainObjectClassNameShort$ConnectionFeature extends AbstractAddFeature implements

 		IAddFeature {

 

-	public AddDomainObjectConnectionFeature(IFeatureProvider fp) {

+	public Add$connectionDomainObjectClassNameShort$ConnectionFeature(IFeatureProvider fp) {

 		super(fp);

 	}

 

 	@Override

 	public boolean canAdd(IAddContext context) {

 		// TODO: check for right domain object instance below

-		if (context instanceof IAddConnectionContext /* && context.getNewObject() instanceof <DomainObject> */) {

-			return true;

-		}

-		return false;

+		return context instanceof IAddConnectionContext /* && context.getNewObject() instanceof $connectionDomainObjectClassNameShort$ */;

 	}

 

 	@Override

@@ -45,7 +46,7 @@
 		// TODO: enable the link to the domain object

 		// Object addedDomainObjectConnection = context.getNewObject();

 		// link(connection, addedDomainObjectConnection);

-		

+

 		return connection;

 	}

 

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/AddDomainObjectFeature.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Add$shapeDomainObjectClassNameShort$Feature.java
similarity index 81%
rename from plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/AddDomainObjectFeature.java
rename to plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Add$shapeDomainObjectClassNameShort$Feature.java
index 6de649b..0821e95 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/AddDomainObjectFeature.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Add$shapeDomainObjectClassNameShort$Feature.java
@@ -15,17 +15,21 @@
 import org.eclipse.graphiti.services.IGaService;

 import org.eclipse.graphiti.services.IPeCreateService;

 

-public class AddDomainObjectFeature extends AbstractAddFeature implements

+%if useShapeDomainObject

+import $shapeDomainObjectClassName$;

+%endif

+

+public class Add$shapeDomainObjectClassNameShort$Feature extends AbstractAddFeature implements

 		IAddFeature {

 

-	public AddDomainObjectFeature(IFeatureProvider fp) {

+	public Add$shapeDomainObjectClassNameShort$Feature(IFeatureProvider fp) {

 		super(fp);

 	}

 

 	@Override

 	public boolean canAdd(IAddContext context) {

 		// TODO: check for right domain object instance below

-		return /* context.getNewObject() instanceof <DomainObject> && */ context.getTargetContainer() instanceof Diagram;

+		return /* context.getNewObject() instanceof $shapeDomainObjectClassNameShort$ && */ context.getTargetContainer() instanceof Diagram;

 	}

 

 	@Override

@@ -41,7 +45,7 @@
 		roundedRectangle.setFilled(false);

 		

 		Shape shape = peCreateService.createShape(containerShape, false);

-		Text text = gaService.createText(shape, "Domain Object");

+		Text text = gaService.createText(shape, "$shapeDomainObjectClassNameShort$");

 		text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);

 		text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);

 		gaService.setLocationAndSize(text, 0, 0, context.getWidth(), context.getHeight());

@@ -54,5 +58,4 @@
 

 		return containerShape;

 	}

-

 }

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/CreateDomainObjectConnectionFeature.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Create$connectionDomainObjectClassNameShort$ConnectionFeature.java
similarity index 83%
rename from plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/CreateDomainObjectConnectionFeature.java
rename to plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Create$connectionDomainObjectClassNameShort$ConnectionFeature.java
index dda0baa..70fe433 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/CreateDomainObjectConnectionFeature.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Create$connectionDomainObjectClassNameShort$ConnectionFeature.java
@@ -8,11 +8,11 @@
 import org.eclipse.graphiti.mm.pictograms.Connection;

 import org.eclipse.graphiti.mm.pictograms.PictogramElement;

 

-public class CreateDomainObjectConnectionFeature extends AbstractCreateConnectionFeature

+public class Create$connectionDomainObjectClassNameShort$ConnectionFeature extends AbstractCreateConnectionFeature

 		implements ICreateConnectionFeature {

 

-	public CreateDomainObjectConnectionFeature(IFeatureProvider fp) {

-		super(fp, "Connection", "Creates a new connection between two domain objects");

+	public Create$connectionDomainObjectClassNameShort$ConnectionFeature(IFeatureProvider fp) {

+		super(fp, "$connectionDomainObjectClassNameShort$", "Creates a new $connectionDomainObjectClassNameShort$ between two $shapeDomainObjectClassNameShort$s");

 	}

 

 	@Override

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Create$shapeDomainObjectClassNameShort$Feature.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Create$shapeDomainObjectClassNameShort$Feature.java
new file mode 100644
index 0000000..3b4e819
--- /dev/null
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Create$shapeDomainObjectClassNameShort$Feature.java
@@ -0,0 +1,32 @@
+package $packageName$.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 Create$shapeDomainObjectClassNameShort$Feature extends AbstractCreateFeature implements

+		ICreateFeature {

+

+	public Create$shapeDomainObjectClassNameShort$Feature(IFeatureProvider fp) {

+		super(fp, "$shapeDomainObjectClassNameShort$", "Creates a new $shapeDomainObjectClassNameShort$");

+	}

+

+	@Override

+	public boolean canCreate(ICreateContext context) {

+		return context.getTargetContainer() instanceof Diagram;

+	}

+

+	@Override

+	public Object[] create(ICreateContext context) {

+		// TODO: create the domain object here

+		Object new$shapeDomainObjectClassNameShort$ = null;

+		

+		// TODO: in case of an EMF object add the new object to a suitable resource

+		// getDiagram().eResource().getContents().add(new$shapeDomainObjectClassNameShort$);

+

+		addGraphicalRepresentation(context, new$shapeDomainObjectClassNameShort$);

+		return new Object[] { new$shapeDomainObjectClassNameShort$ };

+	}

+}

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/LayoutDomainObjectFeature.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Layout$shapeDomainObjectClassNameShort$Feature.java
similarity index 88%
rename from plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/LayoutDomainObjectFeature.java
rename to plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Layout$shapeDomainObjectClassNameShort$Feature.java
index 34dc746..4ef0b07 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/LayoutDomainObjectFeature.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/features/java/features/Layout$shapeDomainObjectClassNameShort$Feature.java
@@ -13,10 +13,14 @@
 import org.eclipse.graphiti.mm.pictograms.Shape;

 import org.eclipse.graphiti.services.Graphiti;

 

-public class LayoutDomainObjectFeature extends AbstractLayoutFeature implements

+%if useShapeDomainObject

+import $shapeDomainObjectClassName$;

+%endif

+

+public class Layout$shapeDomainObjectClassNameShort$Feature extends AbstractLayoutFeature implements

 		ILayoutFeature {

 

-	public LayoutDomainObjectFeature(IFeatureProvider fp) {

+	public Layout$shapeDomainObjectClassNameShort$Feature(IFeatureProvider fp) {

 		super(fp);

 	}

 

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/CreateDomainObjectFeature.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/CreateDomainObjectFeature.java
deleted file mode 100644
index 9c83365..0000000
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/CreateDomainObjectFeature.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package $packageName$.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 CreateDomainObjectFeature extends AbstractCreateFeature implements

-		ICreateFeature {

-

-	public CreateDomainObjectFeature(IFeatureProvider fp) {

-		super(fp, "Domain Object", "Creates a new domain object");

-	}

-

-	@Override

-	public boolean canCreate(ICreateContext context) {

-		return context.getTargetContainer() instanceof Diagram;

-	}

-

-	@Override

-	public Object[] create(ICreateContext context) {

-		// TODO: create the domain object here

-		Object newDomainObject = null;

-		

-		// TODO: in case of an EMF object add the new object to a suitable resource

-		// getDiagram().eResource().getContents().add(newDomainObject);

-		

-		addGraphicalRepresentation(context, newDomainObject);

-		return new Object[] { newDomainObject };

-	}

-}

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/diagram/$diagramTypeProviderClassName$.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/diagram/$diagramTypeProviderClassName$.java
similarity index 100%
copy from plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/diagram/$diagramTypeProviderClassName$.java
copy to plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/diagram/$diagramTypeProviderClassName$.java
diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/diagram/$featureProviderClassName$.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/diagram/$featureProviderClassName$.java
new file mode 100644
index 0000000..8c6f6b2
--- /dev/null
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/diagram/$featureProviderClassName$.java
@@ -0,0 +1,35 @@
+package $packageName$.diagram;

+

+import org.eclipse.graphiti.dt.IDiagramTypeProvider;

+import org.eclipse.graphiti.features.IAddFeature;

+import org.eclipse.graphiti.features.ICreateConnectionFeature;

+import org.eclipse.graphiti.features.context.IAddConnectionContext;

+import org.eclipse.graphiti.features.context.IAddContext;

+import org.eclipse.graphiti.pattern.DefaultFeatureProviderWithPatterns;

+

+import $packageName$.features.Add$connectionDomainObjectClassNameShort$ConnectionFeature;

+import $packageName$.features.Create$connectionDomainObjectClassNameShort$ConnectionFeature;

+import $packageName$.patterns.$shapeDomainObjectClassNameShort$Pattern;

+

+

+public class $featureProviderClassName$ extends DefaultFeatureProviderWithPatterns {

+

+	public $featureProviderClassName$(IDiagramTypeProvider dtp) {

+		super(dtp);

+		addPattern(new $shapeDomainObjectClassNameShort$Pattern(null));

+	}

+

+	@Override

+	public ICreateConnectionFeature[] getCreateConnectionFeatures() {

+		return new ICreateConnectionFeature[] {new Create$connectionDomainObjectClassNameShort$ConnectionFeature(this)};

+	}

+	

+	@Override

+	public IAddFeature getAddFeature(IAddContext context) {

+		// TODO: check for right domain object instances below

+		if (context instanceof IAddConnectionContext /* && context.getNewObject() instanceof $connectionDomainObjectClassNameShort$ */) {

+			return new Add$connectionDomainObjectClassNameShort$ConnectionFeature(this);

+		}

+		return super.getAddFeature(context);

+	}

+}

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/AddDomainObjectConnectionFeature.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/features/Add$connectionDomainObjectClassNameShort$ConnectionFeature.java
similarity index 79%
rename from plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/AddDomainObjectConnectionFeature.java
rename to plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/features/Add$connectionDomainObjectClassNameShort$ConnectionFeature.java
index 908dc2a..f1af72b 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/AddDomainObjectConnectionFeature.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/features/Add$connectionDomainObjectClassNameShort$ConnectionFeature.java
@@ -13,20 +13,21 @@
 import org.eclipse.graphiti.services.IPeCreateService;

 import org.eclipse.graphiti.util.IColorConstant;

 

-public class AddDomainObjectConnectionFeature extends AbstractAddFeature implements

+%if useConnectionDomainObject

+import $connectionDomainObjectClassName$;

+%endif

+

+public class Add$connectionDomainObjectClassNameShort$ConnectionFeature extends AbstractAddFeature implements

 		IAddFeature {

 

-	public AddDomainObjectConnectionFeature(IFeatureProvider fp) {

+	public Add$connectionDomainObjectClassNameShort$ConnectionFeature(IFeatureProvider fp) {

 		super(fp);

 	}

 

 	@Override

 	public boolean canAdd(IAddContext context) {

 		// TODO: check for right domain object instance below

-		if (context instanceof IAddConnectionContext /* && context.getNewObject() instanceof <DomainObject> */) {

-			return true;

-		}

-		return false;

+		return context instanceof IAddConnectionContext /* && context.getNewObject() instanceof <ConnectionDomainObject> */;

 	}

 

 	@Override

@@ -45,7 +46,7 @@
 		// TODO: enable the link to the domain object

 		// Object addedDomainObjectConnection = context.getNewObject();

 		// link(connection, addedDomainObjectConnection);

-		

+

 		return connection;

 	}

 

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/CreateDomainObjectConnectionFeature.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/features/Create$connectionDomainObjectClassNameShort$ConnectionFeature.java
similarity index 83%
copy from plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/CreateDomainObjectConnectionFeature.java
copy to plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/features/Create$connectionDomainObjectClassNameShort$ConnectionFeature.java
index dda0baa..70fe433 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/CreateDomainObjectConnectionFeature.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/features/Create$connectionDomainObjectClassNameShort$ConnectionFeature.java
@@ -8,11 +8,11 @@
 import org.eclipse.graphiti.mm.pictograms.Connection;

 import org.eclipse.graphiti.mm.pictograms.PictogramElement;

 

-public class CreateDomainObjectConnectionFeature extends AbstractCreateConnectionFeature

+public class Create$connectionDomainObjectClassNameShort$ConnectionFeature extends AbstractCreateConnectionFeature

 		implements ICreateConnectionFeature {

 

-	public CreateDomainObjectConnectionFeature(IFeatureProvider fp) {

-		super(fp, "Connection", "Creates a new connection between two domain objects");

+	public Create$connectionDomainObjectClassNameShort$ConnectionFeature(IFeatureProvider fp) {

+		super(fp, "$connectionDomainObjectClassNameShort$", "Creates a new $connectionDomainObjectClassNameShort$ between two $shapeDomainObjectClassNameShort$s");

 	}

 

 	@Override

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/LayoutDomainObjectFeature.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/features/Layout$shapeDomainObjectClassNameShort$Feature.java
similarity index 88%
copy from plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/LayoutDomainObjectFeature.java
copy to plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/features/Layout$shapeDomainObjectClassNameShort$Feature.java
index 34dc746..4ef0b07 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/newgraphitieditor/java/features/LayoutDomainObjectFeature.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/features/Layout$shapeDomainObjectClassNameShort$Feature.java
@@ -13,10 +13,14 @@
 import org.eclipse.graphiti.mm.pictograms.Shape;

 import org.eclipse.graphiti.services.Graphiti;

 

-public class LayoutDomainObjectFeature extends AbstractLayoutFeature implements

+%if useShapeDomainObject

+import $shapeDomainObjectClassName$;

+%endif

+

+public class Layout$shapeDomainObjectClassNameShort$Feature extends AbstractLayoutFeature implements

 		ILayoutFeature {

 

-	public LayoutDomainObjectFeature(IFeatureProvider fp) {

+	public Layout$shapeDomainObjectClassNameShort$Feature(IFeatureProvider fp) {

 		super(fp);

 	}

 

diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/patterns/$shapeDomainObjectClassNameShort$Pattern.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/patterns/$shapeDomainObjectClassNameShort$Pattern.java
new file mode 100644
index 0000000..fcf28ee
--- /dev/null
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/templates_3.4/patterns/java/patterns/$shapeDomainObjectClassNameShort$Pattern.java
@@ -0,0 +1,129 @@
+package $packageName$.patterns;

+

+import org.eclipse.emf.common.util.EList;

+import org.eclipse.graphiti.features.context.IAddContext;

+import org.eclipse.graphiti.features.context.ICreateContext;

+import org.eclipse.graphiti.features.context.ILayoutContext;

+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;

+import org.eclipse.graphiti.mm.algorithms.RoundedRectangle;

+import org.eclipse.graphiti.mm.algorithms.Text;

+import org.eclipse.graphiti.mm.algorithms.styles.Orientation;

+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.mm.pictograms.Shape;

+import org.eclipse.graphiti.pattern.AbstractPattern;

+import org.eclipse.graphiti.pattern.IPattern;

+import org.eclipse.graphiti.pattern.config.IPatternConfiguration;

+import org.eclipse.graphiti.services.Graphiti;

+import org.eclipse.graphiti.services.IGaService;

+import org.eclipse.graphiti.services.IPeCreateService;

+

+public class $shapeDomainObjectClassNameShort$Pattern extends AbstractPattern implements IPattern {

+

+	public $shapeDomainObjectClassNameShort$Pattern(IPatternConfiguration patternConfiguration) {

+		super(patternConfiguration);

+	}

+

+	@Override

+	public String getCreateName() {

+		return "$shapeDomainObjectClassNameShort$";

+	}

+

+	@Override

+	public boolean isMainBusinessObjectApplicable(Object mainBusinessObject) {

+		// TODO: check for right domain object instances below

+		// return mainBusinessObject instanceof Match;

+		return true;

+	}

+

+	@Override

+	protected boolean isPatternControlled(PictogramElement pictogramElement) {

+		Object domainObject = getBusinessObjectForPictogramElement(pictogramElement);

+		return isMainBusinessObjectApplicable(domainObject);

+	}

+

+	@Override

+	protected boolean isPatternRoot(PictogramElement pictogramElement) {

+		Object domainObject = getBusinessObjectForPictogramElement(pictogramElement);

+		return isMainBusinessObjectApplicable(domainObject);

+	}

+

+	@Override

+	public boolean canCreate(ICreateContext context) {

+		return context.getTargetContainer() instanceof Diagram;

+	}

+	

+	@Override

+	public Object[] create(ICreateContext context) {

+		// TODO: create the domain object here

+		Object new$shapeDomainObjectClassNameShort$ = null;

+		

+		// TODO: in case of an EMF object add the new object to a suitable resource

+		// getDiagram().eResource().getContents().add(new$shapeDomainObjectClassNameShort$);

+

+		addGraphicalRepresentation(context, new$shapeDomainObjectClassNameShort$);

+		return new Object[] { new$shapeDomainObjectClassNameShort$ };

+	}

+	

+	@Override

+	public boolean canAdd(IAddContext context) {

+		// TODO: check for right domain object instance below

+		return /* context.getNewObject() instanceof $shapeDomainObjectClassNameShort$ && */ context.getTargetContainer() instanceof Diagram;

+	}

+	

+	@Override

+	public PictogramElement add(IAddContext context) {

+

+		Diagram targetDiagram = (Diagram) context.getTargetContainer();

+		IPeCreateService peCreateService = Graphiti.getPeCreateService();

+		IGaService gaService = Graphiti.getGaService();

+

+		ContainerShape containerShape = peCreateService.createContainerShape(targetDiagram, true);

+		RoundedRectangle roundedRectangle = gaService.createRoundedRectangle(containerShape, 5, 5);

+		gaService.setLocationAndSize(roundedRectangle, context.getX(), context.getY(), context.getWidth(), context.getHeight());

+		roundedRectangle.setFilled(false);

+		

+		Shape shape = peCreateService.createShape(containerShape, false);

+		Text text = gaService.createText(shape, "$shapeDomainObjectClassNameShort$");

+		text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);

+		text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);

+		gaService.setLocationAndSize(text, 0, 0, context.getWidth(), context.getHeight());

+

+		peCreateService.createChopboxAnchor(containerShape);

+

+		// TODO: enable the link to the domain object

+		// Object addedDomainObject = context.getNewObject();

+		// link(containerShape, addedDomainObject);

+

+		return containerShape;

+	}

+	

+	@Override

+	public boolean canLayout(ILayoutContext context) {

+		// TODO: check for right domain object instances below

+		return context.getPictogramElement() instanceof ContainerShape /* && getBusinessObjectForPictogramElement(context.getPictogramElement()) instanceof $shapeDomainObjectClassNameShort$ */;

+	}

+	

+	@Override

+	public boolean layout(ILayoutContext context) {

+		PictogramElement pictogramElement = context.getPictogramElement();

+		if (pictogramElement instanceof ContainerShape) {

+			ContainerShape containerShape = (ContainerShape) pictogramElement;

+			GraphicsAlgorithm outerGraphicsAlgorithm = containerShape.getGraphicsAlgorithm();

+			if (outerGraphicsAlgorithm instanceof RoundedRectangle) {

+				RoundedRectangle roundedRectangle = (RoundedRectangle) outerGraphicsAlgorithm;

+				EList<Shape> children = containerShape.getChildren();

+				if (children.size() > 0) {

+					Shape shape = children.get(0);

+					GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm();

+					if (graphicsAlgorithm instanceof Text) {

+						Graphiti.getGaLayoutService().setLocationAndSize(graphicsAlgorithm, 0, 0, roundedRectangle.getWidth(), roundedRectangle.getHeight());

+						return true;

+					}

+				}

+			}

+		}

+		return false;

+	}

+}