Browse Source

Definitionsection with annotation border and rename refactoring support (#1901)

* Refactored StatechartDiagramEditor.
* Taken care of resizing bug - layouting of components is now in the order: layout , redraw, update for all affected components. Fixes the gray palette border bug when resizing the editor.
This ensure that all painting operations which were triggered by layout calculcations are definitely processed, so the correct layout is shown.
* Made changes to the EMF value binding of the statechart model, which caused large performance issues when the statechart specification was modified or the content assist was triggered.
** Removed UpdateValueStrategy
** Inlined observable values

* Refactored StatechartDiagramEditor.
* Replaced the simple texteditor for the definition section with an embedded Xtext editor which has an annotation border for error/warning marker.
* Enabled RenameRefactoring in new definition section editor
Fixed NPE in STextNameAreUniqueValidationHelper which was caused after specification was saved (due to fakeresource usage in StatechartDiagramEditor).

* Added checks for equal parent container in STextNamesAreUniqueValidator.
Need to check if given EObjects are in equal parent container to ensure that validation is not done across different ressources.

* Extracted XtextStyledTextSelectionProvider from StyledTextXtextAdapter to its own class.
InlineDefinitionSectionStyle is now set to false by default for new diagrams.
Introduce StatechartDefinitionSection - extracted and reworked from StatechartDiagramEditor.
fixed wrong package in plugin.xml

* added copyright header

* Inlined several listeners and moved their registration to the components itself.

* Refactorings and fixed key binding for macOS (CMD+'a')
Robert Rudi 7 years ago
parent
commit
fadc0806a7

+ 8 - 44
plugins/org.yakindu.base.xtext.utils.jface/src/org/yakindu/base/xtext/utils/jface/viewers/StyledTextXtextAdapter.java

@@ -13,7 +13,6 @@ package org.yakindu.base.xtext.utils.jface.viewers;
 import java.util.List;
 
 import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.emf.ecore.EObject;
 import org.eclipse.jface.bindings.keys.KeyStroke;
 import org.eclipse.jface.fieldassist.ControlDecoration;
 import org.eclipse.jface.resource.ImageDescriptor;
@@ -22,10 +21,7 @@ import org.eclipse.jface.text.contentassist.IContentAssistant;
 import org.eclipse.jface.text.source.AnnotationModel;
 import org.eclipse.jface.text.source.ICharacterPairMatcher;
 import org.eclipse.jface.text.source.ISharedTextColors;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.events.DisposeEvent;
@@ -44,9 +40,6 @@ import org.eclipse.ui.texteditor.AnnotationPreference;
 import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
-import org.eclipse.xtext.nodemodel.ICompositeNode;
-import org.eclipse.xtext.nodemodel.ILeafNode;
-import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
 import org.eclipse.xtext.parser.IParseResult;
 import org.eclipse.xtext.resource.XtextResource;
 import org.eclipse.xtext.ui.editor.XtextEditor;
@@ -79,7 +72,7 @@ import com.google.inject.Provider;
  */
 @SuppressWarnings("restriction")
 public class StyledTextXtextAdapter {
-	
+
 	@Inject
 	private IPreferenceStoreAccess preferenceStoreAccess;
 	@Inject
@@ -189,7 +182,8 @@ public class StyledTextXtextAdapter {
 			if (this.site == null) {
 				site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
 			}
-			XtextStyledTextSelectionProvider xtextStyledTextSelectionProvider = new XtextStyledTextSelectionProvider();
+			XtextStyledTextSelectionProvider xtextStyledTextSelectionProvider = new XtextStyledTextSelectionProvider(
+					this.styledText, getFakeResourceContext().getFakeResource());
 			ChangeSelectionProviderOnFocusGain listener = new ChangeSelectionProviderOnFocusGain(site,
 					xtextStyledTextSelectionProvider);
 			getStyledText().addFocusListener(listener);
@@ -197,7 +191,6 @@ public class StyledTextXtextAdapter {
 		} catch (NullPointerException ex) {
 			// Do nothing, not opened within editor context
 		}
-
 	}
 
 	private ControlDecoration createContentAssistDecoration(StyledText styledText) {
@@ -224,9 +217,8 @@ public class StyledTextXtextAdapter {
 	}
 
 	protected ValidationJob createValidationJob() {
-		return new ValidationJob(getValidator(), getXtextDocument(),
-				new AnnotationIssueProcessor(getXtextDocument(), getXtextSourceviewer().getAnnotationModel(), getResolutionProvider()),
-				CheckMode.FAST_ONLY);
+		return new ValidationJob(getValidator(), getXtextDocument(), new AnnotationIssueProcessor(getXtextDocument(),
+				getXtextSourceviewer().getAnnotationModel(), getResolutionProvider()), CheckMode.FAST_ONLY);
 	}
 
 	protected XtextFakeResourceContext createFakeResourceContext(Injector injector) {
@@ -234,7 +226,8 @@ public class StyledTextXtextAdapter {
 	}
 
 	protected XtextSourceViewer createXtextSourceViewer() {
-		final XtextSourceViewer result = new XtextSourceViewerEx(getStyledText(), getPreferenceStoreAccess().getPreferenceStore());
+		final XtextSourceViewer result = new XtextSourceViewerEx(getStyledText(),
+				getPreferenceStoreAccess().getPreferenceStore());
 		result.configure(getXtextSourceViewerConfiguration());
 		result.setDocument(getXtextDocument(), new AnnotationModel());
 		return result;
@@ -388,36 +381,7 @@ public class StyledTextXtextAdapter {
 		return this.xtextStyledTextHighlightingHelper;
 	}
 
-	protected class XtextStyledTextSelectionProvider implements ISelectionProvider {
-		
-		public void setSelection(ISelection selection) {
-		}
-
-		public void removeSelectionChangedListener(ISelectionChangedListener listener) {
-		}
-
-		public void addSelectionChangedListener(ISelectionChangedListener listener) {
-		}
-
-		public ISelection getSelection() {
-			if (getStyledText().isDisposed())
-				return StructuredSelection.EMPTY;
-			int offset = getStyledText().getCaretOffset() - 1;
-			XtextResource fakeResource = StyledTextXtextAdapter.this.getFakeResourceContext().getFakeResource();
-			IParseResult parseResult = fakeResource.getParseResult();
-			if (parseResult == null)
-				return StructuredSelection.EMPTY;
-			ICompositeNode rootNode = parseResult.getRootNode();
-			ILeafNode selectedNode = NodeModelUtils.findLeafNodeAtOffset(rootNode, offset);
-			final EObject selectedObject = NodeModelUtils.findActualSemanticObjectFor(selectedNode);
-			if (selectedObject == null) {
-				return StructuredSelection.EMPTY;
-			}
-			return new StructuredSelection(selectedObject);
-		}
-	}
-
-	protected class ChangeSelectionProviderOnFocusGain implements FocusListener, DisposeListener {
+	public static class ChangeSelectionProviderOnFocusGain implements FocusListener, DisposeListener {
 
 		protected ISelectionProvider selectionProviderOnFocusGain;
 		protected ISelectionProvider selectionProviderOnFocusLost;

+ 61 - 0
plugins/org.yakindu.base.xtext.utils.jface/src/org/yakindu/base/xtext/utils/jface/viewers/XtextStyledTextSelectionProvider.java

@@ -0,0 +1,61 @@
+/** 
+ * Copyright (c) 2018 committers of YAKINDU and others. 
+ * 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:
+ * committers of YAKINDU - initial API and implementation
+ *
+*/
+package org.yakindu.base.xtext.utils.jface.viewers;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.xtext.nodemodel.ICompositeNode;
+import org.eclipse.xtext.nodemodel.ILeafNode;
+import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
+import org.eclipse.xtext.parser.IParseResult;
+import org.eclipse.xtext.resource.XtextResource;
+
+
+public class XtextStyledTextSelectionProvider implements ISelectionProvider {
+
+	private StyledText styledText;
+	private XtextResource xtextResource;
+
+	public XtextStyledTextSelectionProvider(StyledText styledText, XtextResource xtextResource) {
+		this.styledText = styledText;
+		this.xtextResource = xtextResource;
+	}
+
+	public void setSelection(ISelection selection) {
+	}
+
+	public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+	}
+
+	public void addSelectionChangedListener(ISelectionChangedListener listener) {
+	}
+
+	public ISelection getSelection() {
+		if (styledText.isDisposed())
+			return StructuredSelection.EMPTY;
+		int offset = styledText.getCaretOffset() - 1;
+		XtextResource fakeResource = xtextResource;
+		IParseResult parseResult = fakeResource.getParseResult();
+		if (parseResult == null)
+			return StructuredSelection.EMPTY;
+		ICompositeNode rootNode = parseResult.getRootNode();
+		ILeafNode selectedNode = NodeModelUtils.findLeafNodeAtOffset(rootNode, offset);
+		final EObject selectedObject = NodeModelUtils.findActualSemanticObjectFor(selectedNode);
+		if (selectedObject == null) {
+			return StructuredSelection.EMPTY;
+		}
+		return new StructuredSelection(selectedObject);
+	}
+}

+ 36 - 34
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextNamesAreUniqueValidationHelper.java

@@ -31,12 +31,14 @@ import org.eclipse.xtext.validation.ValidationMessageAcceptor;
  * @author rbeckmann
  *
  */
-public class STextNamesAreUniqueValidationHelper extends NamesAreUniqueValidationHelper implements INamesAreUniqueValidationHelper {
+public class STextNamesAreUniqueValidationHelper extends NamesAreUniqueValidationHelper
+		implements
+			INamesAreUniqueValidationHelper {
 	protected OperationCanceledManager operationCanceledManager = new OperationCanceledManager();
 
 	protected Map<QualifiedName, IEObjectDescription> nameMap;
 	protected Map<QualifiedName, IEObjectDescription> caseInsensitiveMap;
-	
+
 	@Override
 	public void checkUniqueNames(Iterable<IEObjectDescription> descriptions, ValidationMessageAcceptor acceptor) {
 		checkUniqueNames(descriptions, null, acceptor);
@@ -67,76 +69,76 @@ public class STextNamesAreUniqueValidationHelper extends NamesAreUniqueValidatio
 	protected void checkDescriptionForDuplicatedName(IEObjectDescription description,
 			ValidationMessageAcceptor acceptor) {
 		QualifiedName qName = description.getName();
-		IEObjectDescription put = nameMap.put(qName, description);
-		IEObjectDescription lowerCasePut = caseInsensitiveMap.put(qName.toLowerCase(), description);
-		if(put != null) {
-			EClass common = checkForCommonSuperClass(put, description);
-			if(common != null) {
+		IEObjectDescription existing = nameMap.put(qName, description);
+		IEObjectDescription existingLowerCase = caseInsensitiveMap.put(qName.toLowerCase(), description);
+		if (existing != null) {
+			EClass common = checkForCommonSuperClass(existing, description);
+			if (inSameResource(existing, description) && common != null) {
 				createDuplicateNameError(description, common, acceptor);
-				createDuplicateNameError(put, common, acceptor);
+				createDuplicateNameError(existing, common, acceptor);
 			}
-		} else if(lowerCasePut != null) {
-			if(lowerCasePut.getEClass().equals(description.getEClass())) {
+		} else if (existingLowerCase != null) {
+			if (inSameResource(existingLowerCase, description)
+					&& existingLowerCase.getEClass().equals(description.getEClass())) {
 				createDuplicateNameWarning(description, description.getEClass(), acceptor);
-				createDuplicateNameWarning(lowerCasePut, description.getEClass(), acceptor);
+				createDuplicateNameWarning(existingLowerCase, description.getEClass(), acceptor);
 			}
 		}
 	}
 
+	protected boolean inSameResource(IEObjectDescription one, IEObjectDescription two) {
+		return one.getEObjectOrProxy().eResource().equals(two.getEObjectOrProxy().eResource());
+	}
+
 	protected void createDuplicateNameWarning(IEObjectDescription description, EClass eClass,
 			ValidationMessageAcceptor acceptor) {
 		EObject object = description.getEObjectOrProxy();
 		EStructuralFeature feature = getNameFeature(object);
-		acceptor.acceptWarning(
-				getDuplicateNameWarningMessage(description, eClass, feature), 
-				object, 
-				feature,
-				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
-				getErrorCode());
+		acceptor.acceptWarning(getDuplicateNameWarningMessage(description, eClass, feature), object, feature,
+				ValidationMessageAcceptor.INSIGNIFICANT_INDEX, getErrorCode());
 	}
 
 	protected String getDuplicateNameWarningMessage(IEObjectDescription description, EClass eClass,
 			EStructuralFeature feature) {
-		return getDuplicateNameErrorMessage(description, eClass, feature) + ". Names differ only in case, which can lead to compilation problems.";
+		return getDuplicateNameErrorMessage(description, eClass, feature)
+				+ ". Names differ only in case, which can lead to compilation problems.";
 	}
 
 	protected EClass checkForCommonSuperClass(IEObjectDescription one, IEObjectDescription two) {
-		
-		
 		List<EClass> flatOne = buildSuperClassList(one.getEClass());
 		List<EClass> flatTwo = buildSuperClassList(two.getEClass());
-		
-		for(EClass eC : flatOne) {
-			if(flatTwo.contains(eC))
+
+		for (EClass eC : flatOne) {
+			if (flatTwo.contains(eC))
 				return eC;
 		}
-		
+
 		return null;
 	}
-	
+
 	protected List<EClass> buildSuperClassList(EClass eClass) {
 		List<List<EClass>> superClasses = new ArrayList<>();
-		
+
 		buildSuperClassList(superClasses, eClass, 0);
-		
+
 		List<EClass> result = new ArrayList<>();
-		for(List<EClass> list : superClasses) {
+		for (List<EClass> list : superClasses) {
 			result.addAll(list);
 		}
-		
+
 		return result;
 	}
-	
+
 	protected void buildSuperClassList(List<List<EClass>> superClasses, EClass eClass, int depth) {
-		if(superClasses.size() <= depth) {
+		if (superClasses.size() <= depth) {
 			superClasses.add(depth, new ArrayList<>());
 		}
-		
+
 		List<EClass> superTypes = eClass.getESuperTypes();
 
 		superClasses.get(depth).add(eClass);
-		
-		for(EClass superType : superTypes) {
+
+		for (EClass superType : superTypes) {
 			buildSuperClassList(superClasses, superType, depth + 1);
 		}
 	}

+ 1 - 1
plugins/org.yakindu.sct.ui.editor/plugin.xml

@@ -920,7 +920,7 @@
  <extension
        point="org.eclipse.ui.elementFactories">
     <factory
-          class="org.yakindu.sct.ui.editor.DiagramEditorInputFactory"
+          class="org.yakindu.sct.ui.editor.partitioning.DiagramEditorInputFactory"
           id="org.yakindu.sct.ui.editor.DiagramEditorInputFactory">
     </factory>
  </extension>

+ 43 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/definitionsection/ReleaseSelectionOnFocusGain.java

@@ -0,0 +1,43 @@
+/**
+ * Copyright (c) 2018 committers of YAKINDU and others.
+ * 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.ui.editor.definitionsection;
+
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.yakindu.base.xtext.utils.jface.viewers.StyledTextXtextAdapter;
+
+/**
+ * Extends {@link StyledTextXtextAdapter.ChangeSelectionProviderOnFocusGain} to
+ * be able to release selection of previous selection provider. This in needed
+ * to be able to perform keyboard shortcuts on the text in the statechart
+ * definition section without interacting with the elements of the diagram.
+ * 
+ * @author robert rudi - Initial contribution and API
+ */
+public class ReleaseSelectionOnFocusGain extends StyledTextXtextAdapter.ChangeSelectionProviderOnFocusGain {
+
+	public ReleaseSelectionOnFocusGain(IWorkbenchPartSite site, ISelectionProvider selectionProviderOnFocusGain) {
+		super(site, selectionProviderOnFocusGain);
+	}
+
+	public void focusGained(FocusEvent e) {
+		releaseSelection();
+		super.focusGained(e);
+	}
+
+	protected void releaseSelection() {
+		if (site != null && this.selectionProviderOnFocusGain != null
+				&& !site.getSelectionProvider().equals(selectionProviderOnFocusGain))
+			site.getSelectionProvider().setSelection(StructuredSelection.EMPTY);
+	}
+}

+ 765 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/definitionsection/StatechartDefinitionSection.java

@@ -0,0 +1,765 @@
+/**
+ * Copyright (c) 2018 committers of YAKINDU and others.
+ * 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.ui.editor.definitionsection;
+
+import java.util.List;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.databinding.IEMFValueProperty;
+import org.eclipse.emf.databinding.edit.EMFEditProperties;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
+import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.databinding.swt.ISWTObservableValue;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ST;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Transform;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableEditor;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.XMLMemento;
+import org.eclipse.xtext.EcoreUtil2;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor;
+import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory;
+import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorModelAccess;
+import org.eclipse.xtext.ui.editor.embedded.IEditedResourceProvider;
+import org.yakindu.base.base.BasePackage;
+import org.yakindu.base.base.NamedElement;
+import org.yakindu.base.xtext.utils.jface.viewers.FilteringMenuManager;
+import org.yakindu.base.xtext.utils.jface.viewers.XtextStyledTextSelectionProvider;
+import org.yakindu.base.xtext.utils.jface.viewers.context.XtextFakeResourceContext;
+import org.yakindu.sct.domain.extension.DomainRegistry;
+import org.yakindu.sct.domain.extension.IDomain;
+import org.yakindu.sct.model.sgraph.SGraphPackage;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.sgraph.util.ContextElementAdapter;
+import org.yakindu.sct.model.sgraph.util.ContextElementAdapter.IContextElementProvider;
+import org.yakindu.sct.ui.editor.StatechartImages;
+import org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil;
+import org.yakindu.sct.ui.editor.propertysheets.ValidatingEMFDatabindingContext;
+
+import com.google.inject.Injector;
+
+/**
+ * 
+ * @author robert rudi - Initial contribution and API
+ *
+ */
+@SuppressWarnings("restriction")
+public class StatechartDefinitionSection extends Composite
+		implements
+			IPersistableEditor,
+			IPersistableElement,
+			IContextElementProvider {
+
+	protected static final String INLINE_TOOLTIP = "Inline definition section";
+	protected static final String SHOW_SECTION_TOOLTIP = "Show definition section";
+	protected static final String HIDE_SECTION_TOOLTIP = "Hide definition section";
+
+	protected static final int SASH_WIDTH = 5;
+	protected static final int BORDERWIDTH = 2;
+	protected static final int MAXIMIZED_CONTROL_INDEX = 1;
+	protected static final String REGEX_NO_WORD_NO_WHITESPACE = "[^\\w[\\s+]]";
+	protected static final String MEM_EXPANDED = "DefinitionSectionIsExpanded";
+	protected static final String MEM_FIRST_WEIGHT = "FirstSashWeight";
+	protected static final String MEM_SECOND_WEIGHT = "SecondSashWeight";
+	protected static final int[] MIN_SIZE = {11, 21};
+	protected static final int[] DEFAULT_WEIGHTS = new int[]{2, 10};
+	protected int[] previousWidths = DEFAULT_WEIGHTS;
+	private boolean isSectionExpanded = true;
+
+	private MouseListener mouseListener;
+	private ResizeListener resizeListener;
+	private ModifyListener nameModificationListener;
+	private ReleaseSelectionOnFocusGain selectionProviderListener;
+
+	private Label switchControl;
+	private Composite labelComposite;
+	private CollapsedBorder collapsedBorder;
+	private InlineIcon inlineIcon;
+
+	private EmbeddedEditor embeddedEditor;
+	private XtextResource xtextResource;
+	private SashForm sash;
+	private DiagramDocumentEditor editorPart;
+
+	private static IMemento memento;
+
+	public StatechartDefinitionSection(Composite parent, int style, DiagramDocumentEditor editorPart) {
+		super(parent, style);
+		this.sash = (SashForm) parent;
+		this.editorPart = editorPart;
+		this.switchControl = createSwitchControl();
+		this.labelComposite = createDefinitionSectionComponents();
+		this.embeddedEditor = createSpecificationEditor();
+		registerResizeListener();
+		GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(this);
+	}
+
+	protected Label createSwitchControl() {
+		Label switchControl = new Label(this, SWT.PUSH);
+		switchControl.setToolTipText(isSectionExpanded ? HIDE_SECTION_TOOLTIP : SHOW_SECTION_TOOLTIP);
+		switchControl.setImage(isSectionExpanded ? StatechartImages.COLLAPSE.image() : StatechartImages.EXPAND.image());
+		switchControl.setCursor(new Cursor(getDisplay(), SWT.CURSOR_HAND));
+		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(-1, -1).hint(MIN_SIZE[0], MIN_SIZE[1])
+				.applyTo(switchControl);
+		mouseListener = new MouseAdapter() {
+			@Override
+			public void mouseUp(MouseEvent e) {
+				toggleExpandState();
+			}
+		};
+		switchControl.addMouseListener(mouseListener);
+		return switchControl;
+	}
+
+	protected Composite createDefinitionSectionComponents() {
+		Composite labelComposite = new Composite(this, SWT.NONE);
+		GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(labelComposite);
+		GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(labelComposite);
+		createNameLabel(labelComposite);
+		createInlineIcon(labelComposite);
+		createSeparator(this);
+		createCollapsedBorder(this);
+		return labelComposite;
+	}
+
+	protected void createNameLabel(Composite labelComposite) {
+		Text nameLabel = new Text(labelComposite, SWT.SINGLE | SWT.NORMAL);
+		GridDataFactory.fillDefaults().indent(5, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(nameLabel);
+		nameLabel.setText(getStatechartName());
+		nameLabel.setEditable(isStatechart());
+		nameLabel.setBackground(ColorConstants.white);
+		nameModificationListener = new ModifyListener() {
+			@Override
+			public void modifyText(ModifyEvent e) {
+				if (getContextObject() instanceof Statechart) {
+					getSash().setRedraw(false);
+					TransactionalEditingDomain domain = getTransactionalEditingDomain();
+					SetCommand command = new SetCommand(domain, getContextObject(),
+							BasePackage.Literals.NAMED_ELEMENT__NAME, nameLabel.getText());
+					domain.getCommandStack().execute(command);
+					refresh(nameLabel.getParent());
+					getSash().setRedraw(true);
+				}
+			}
+		};
+		nameLabel.addModifyListener(nameModificationListener);
+	}
+
+	protected String getStatechartName() {
+		Statechart statechart = EcoreUtil2.getContainerOfType(getContextObject(), Statechart.class);
+		Assert.isNotNull(statechart);
+		return statechart.getName();
+	}
+
+	protected void createInlineIcon(Composite labelComposite) {
+		inlineIcon = new InlineIcon(labelComposite, SWT.FILL);
+	}
+
+	protected boolean isStatechart() {
+		return getContextObject() instanceof Statechart;
+	}
+
+	protected void createSeparator(Composite definitionSection) {
+		Label separator = new Label(definitionSection, SWT.SEPARATOR | SWT.HORIZONTAL);
+		GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(separator);
+	}
+
+	protected void createCollapsedBorder(Composite definitionSection) {
+		collapsedBorder = new CollapsedBorder(definitionSection, SWT.NONE);
+		refresh(definitionSection);
+	}
+
+	protected void refresh(Composite comp) {
+		comp.layout(false, true);
+		comp.redraw();
+		comp.update();
+	}
+
+	protected EmbeddedEditor createSpecificationEditor() {
+		EmbeddedEditor embeddedEditor = createEmbeddedEditor();
+		EmbeddedEditorModelAccess modelAccess = embeddedEditor.createPartialEditor();
+		modelAccess.updateModel(((Statechart) getContextObject()).getSpecification());
+		GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(embeddedEditor.getViewer().getControl());
+		initializeEmbeddedEditorWidget(embeddedEditor);
+		return embeddedEditor;
+	}
+
+	protected EmbeddedEditor createEmbeddedEditor() {
+		Injector embeddedEditorInjector = getEmbeddedStatechartSpecificationInjector();
+		EmbeddedEditorFactory instance = embeddedEditorInjector.getInstance(EmbeddedEditorFactory.class);
+		IEditedResourceProvider provider = getXtextResourceProvider(embeddedEditorInjector);
+		return instance.newEditor(provider).showErrorAndWarningAnnotations().withParent(this);
+	}
+
+	protected Injector getEmbeddedStatechartSpecificationInjector() {
+		IDomain domain = DomainRegistry.getDomain(getContextObject());
+		return domain.getInjector(IDomain.FEATURE_EDITOR, Statechart.class.getName());
+	}
+
+	protected IEditedResourceProvider getXtextResourceProvider(Injector injector) {
+		return new IEditedResourceProvider() {
+
+			@Override
+			public XtextResource createResource() {
+				XtextFakeResourceContext resource = new XtextFakeResourceContext(injector);
+				xtextResource = resource.getFakeResource();
+				xtextResource.eAdapters().add(new ContextElementAdapter(StatechartDefinitionSection.this));
+				return xtextResource;
+			}
+		};
+	}
+
+	protected void initializeEmbeddedEditorWidget(EmbeddedEditor embeddedEditor) {
+		StyledText embeddedEditorWidget = embeddedEditor.getViewer().getTextWidget();
+		embeddedEditorWidget.setAlwaysShowScrollBars(false);
+		embeddedEditorWidget.setSelection(0);
+		embeddedEditorWidget.setKeyBinding(SWT.MOD1 | SWT.KEY_MASK & 'a', ST.SELECT_ALL);
+		initXtextSelectionProvider(embeddedEditorWidget);
+		initBinding(embeddedEditorWidget);
+		initContextMenu(embeddedEditorWidget);
+	}
+
+	protected void initXtextSelectionProvider(StyledText embeddedEditorWidget) {
+		try {
+			XtextStyledTextSelectionProvider styledTextSelectionProvider = new XtextStyledTextSelectionProvider(
+					embeddedEditorWidget, xtextResource);
+			ReleaseSelectionOnFocusGain selectionChangeListener = new ReleaseSelectionOnFocusGain(
+					this.editorPart.getSite(), styledTextSelectionProvider);
+			embeddedEditorWidget.addFocusListener(selectionChangeListener);
+			embeddedEditorWidget.addDisposeListener(selectionChangeListener);
+		} catch (NullPointerException e) {
+			// do nothing, not opened within editor context
+		}
+	}
+
+	@SuppressWarnings({"unchecked", "rawtypes"})
+	protected void initBinding(StyledText embeddedEditorWidget) {
+		IEMFValueProperty modelProperty = EMFEditProperties.value(getTransactionalEditingDomain(),
+				SGraphPackage.Literals.SPECIFICATION_ELEMENT__SPECIFICATION);
+		ISWTObservableValue uiProperty = WidgetProperties.text(new int[]{SWT.FocusOut, SWT.Modify})
+				.observe(embeddedEditorWidget);
+		IObservableValue modelPropertyObservable = modelProperty.observe(getContextObject());
+		ValidatingEMFDatabindingContext context = new ValidatingEMFDatabindingContext(
+				(IContextElementProvider) editorPart, editorPart.getSite().getShell());
+		context.bindValue(uiProperty, modelPropertyObservable, null, null);
+	}
+
+	protected void initContextMenu(Control control) {
+		MenuManager menuManager = new FilteringMenuManager();
+		Menu contextMenu = menuManager.createContextMenu(control);
+		control.setMenu(contextMenu);
+		IWorkbenchPartSite site = editorPart.getSite();
+		if (site != null)
+			site.registerContextMenu("org.yakindu.base.xtext.utils.jface.viewers.StyledTextXtextAdapterContextMenu",
+					menuManager, site.getSelectionProvider());
+	}
+
+	protected void registerResizeListener() {
+		resizeListener = new ResizeListener();
+		getSash().addControlListener(resizeListener);
+		embeddedEditor.getViewer().getTextWidget().addControlListener(resizeListener);
+	}
+
+	protected TransactionalEditingDomain getTransactionalEditingDomain() {
+		return (TransactionalEditingDomain) editorPart.getAdapter(TransactionalEditingDomain.class);
+	}
+
+	@Override
+	public EObject getContextObject() {
+		return (EObject) editorPart.getAdapter(EObject.class);
+	}
+
+	protected Diagram getDiagram() {
+		return (Diagram) editorPart.getAdapter(Diagram.class);
+	}
+
+	protected void updateInlineStyle() {
+		TransactionalEditingDomain domain = getTransactionalEditingDomain();
+		Diagram diagram = getDiagram();
+		BooleanValueStyle inlineStyle = DiagramPartitioningUtil.getInlineDefinitionSectionStyle(diagram);
+		if (inlineStyle == null) {
+			inlineStyle = DiagramPartitioningUtil.createInlineDefinitionSectionStyle();
+			addInlineStyle(inlineStyle, domain);
+		}
+		setInlineStyleValue(inlineStyle, domain);
+	}
+
+	protected void setInlineStyleValue(BooleanValueStyle inlineStyle, TransactionalEditingDomain domain) {
+		SetCommand command = new SetCommand(domain, inlineStyle,
+				NotationPackage.Literals.BOOLEAN_VALUE_STYLE__BOOLEAN_VALUE, !inlineStyle.isBooleanValue());
+		domain.getCommandStack().execute(command);
+	}
+
+	protected void addInlineStyle(BooleanValueStyle inlineStyle, TransactionalEditingDomain domain) {
+		AddCommand command = new AddCommand(domain, (View) getDiagram(), NotationPackage.Literals.VIEW__STYLES,
+				inlineStyle);
+		domain.getCommandStack().execute(command);
+	}
+
+	public void toggleDefinitionSection() {
+		getSash().setMaximizedControl(!isInlined() ? null : getSash().getChildren()[MAXIMIZED_CONTROL_INDEX]);
+	}
+
+	protected boolean isInlined() {
+		BooleanValueStyle style = DiagramPartitioningUtil.getInlineDefinitionSectionStyle(getDiagram());
+		return style != null ? style.isBooleanValue() : true;
+	}
+
+	protected void collapseDefinitionSection() {
+		int parentWidth = getSash().getBounds().width;
+		int switchControlWidth = getSwitchControlWidth();
+		int[] sashWidths = getCollapsedSashWidths(parentWidth, switchControlWidth);
+		layoutDefinitionSection(0, sashWidths, false, 1);
+	}
+
+	protected void expandDefinitionSection() {
+		layoutDefinitionSection(SASH_WIDTH, previousWidths, true, 2);
+	}
+
+	protected int getSwitchControlWidth() {
+		return switchControl.getBounds().width + BORDERWIDTH;
+	}
+
+	protected int[] getCollapsedSashWidths(int parentWidth, int switchControlWidth) {
+		int diff = parentWidth - switchControlWidth;
+		if (diff < 0) {
+			return DEFAULT_WEIGHTS;
+		}
+		return new int[]{switchControlWidth, (diff % 2 != 0) ? diff - (1 + BORDERWIDTH) : diff};
+	}
+
+	protected void layoutDefinitionSection(int sashWidth, int[] weights, boolean visible, int hSpan) {
+		getSash().setRedraw(false);
+		getSash().setSashWidth(sashWidth);
+		getSash().setWeights(weights);
+		embeddedEditor.getViewer().getControl().setVisible(visible);
+		labelComposite.setVisible(visible);
+		if (visible)
+			refreshSwitchControl(HIDE_SECTION_TOOLTIP, StatechartImages.COLLAPSE.image());
+		else
+			refreshSwitchControl(SHOW_SECTION_TOOLTIP, StatechartImages.EXPAND.image());
+		layoutCollapsedBorder(hSpan);
+		layoutEmbeddedEditor(hSpan);
+		refresh(getSash());
+		getSash().setRedraw(true);
+	}
+
+	protected void toggleExpandState() {
+		getSash().setRedraw(false);
+		isSectionExpanded = !isSectionExpanded;
+		if (isSectionExpanded) {
+			expandDefinitionSection();
+		} else {
+			collapseDefinitionSection();
+		}
+		getSash().setRedraw(true);
+	}
+
+	protected void layoutEmbeddedEditor(int hSpan) {
+		((GridData) embeddedEditor.getViewer().getControl().getLayoutData()).horizontalSpan = hSpan;
+	}
+
+	protected void layoutCollapsedBorder(int hSpan) {
+		((GridData) collapsedBorder.getLayoutData()).horizontalSpan = hSpan;
+	}
+
+	protected void refreshSwitchControl(String tooltipText, Image image) {
+		switchControl.setToolTipText(tooltipText);
+		switchControl.setImage(image);
+	}
+
+	@Override
+	public void dispose() {
+		saveState(memento);
+		disposeEmbeddedEditor();
+		super.dispose();
+	}
+
+	protected void disposeEmbeddedEditor() {
+		if (mouseListener != null && switchControl != null && !switchControl.isDisposed()) {
+			switchControl.removeMouseListener(mouseListener);
+			mouseListener = null;
+			switchControl.dispose();
+			switchControl = null;
+		}
+		if (inlineIcon != null && !inlineIcon.isDisposed())
+			inlineIcon.dispose();
+
+		if (collapsedBorder != null && !collapsedBorder.isDisposed())
+			collapsedBorder.dispose();
+
+		if (embeddedEditor != null) {
+			StyledText embeddedEditorWidget = embeddedEditor.getViewer().getTextWidget();
+			if (embeddedEditorWidget != null && !embeddedEditorWidget.isDisposed()) {
+				if (resizeListener != null) {
+					embeddedEditorWidget.removeControlListener(resizeListener);
+					getSash().removeControlListener(resizeListener);
+					resizeListener = null;
+				}
+				if (selectionProviderListener != null) {
+					embeddedEditorWidget.removeFocusListener(selectionProviderListener);
+					embeddedEditorWidget.removeDisposeListener(selectionProviderListener);
+					selectionProviderListener = null;
+				}
+				embeddedEditorWidget.dispose();
+				embeddedEditorWidget = null;
+				embeddedEditor = null;
+			}
+		}
+		nameModificationListener = null;
+	}
+
+	public SashForm getSash() {
+		return this.sash;
+	}
+
+	protected void refreshEditorContents() {
+		((List<?>) ((DiagramEditPart) editorPart.getAdapter(DiagramEditPart.class)).getChildren()).forEach(part -> {
+			if (part instanceof EditPart)
+				((EditPart) part).refresh();
+		});
+	}
+
+	@Override
+	public String getFactoryId() {
+		return editorPart.getEditorInput().getPersistable().getFactoryId();
+	}
+
+	public void restoreSashWidths() {
+		if (memento == null) {
+			saveState(memento);
+		}
+		restoreState(memento);
+	}
+
+	@Override
+	public void saveState(IMemento memento) {
+		if (memento == null) {
+			memento = XMLMemento.createWriteRoot(getFactoryId());
+		}
+		setMementoProperties(memento);
+		saveCurrentMemento(memento);
+	}
+
+	@Override
+	public void restoreState(IMemento memento) {
+		if (getSash() != null && memento != null) {
+			Boolean hasMemento = getExpandProperty(memento);
+			if (hasMemento != null) {
+				previousWidths = getWeightProperties(memento);
+				isSectionExpanded = hasMemento.booleanValue();
+				refreshEditorContents();
+				saveCurrentMemento(memento);
+			} else {
+				saveState(memento);
+			}
+			getSash().setWeights(previousWidths);
+		}
+	}
+
+	protected void saveCurrentMemento(IMemento memento) {
+		StatechartDefinitionSection.memento = memento;
+	}
+
+	protected void setMementoProperties(IMemento memento) {
+		String sectionProperty = getSectionProperty(getContextObject());
+		memento.putInteger(sectionProperty + MEM_FIRST_WEIGHT, previousWidths[0]);
+		memento.putInteger(sectionProperty + MEM_SECOND_WEIGHT, previousWidths[1]);
+		memento.putBoolean(sectionProperty + MEM_EXPANDED, isSectionExpanded);
+	}
+
+	protected String getSectionProperty(EObject element) {
+		return stripElementName(((NamedElement) element).getName());
+	}
+
+	protected String stripElementName(String name) {
+		if (name != null)
+			return name.replaceAll(REGEX_NO_WORD_NO_WHITESPACE, "");
+		return "";
+	}
+
+	protected Boolean getExpandProperty(IMemento memento) {
+		String expandProperty = getSectionProperty(getContextObject()) + MEM_EXPANDED;
+		return memento.getBoolean(expandProperty);
+	}
+
+	protected int[] getWeightProperties(IMemento memento) {
+		String sectionProperty = getSectionProperty(getContextObject());
+		Integer first = memento.getInteger(sectionProperty + MEM_FIRST_WEIGHT);
+		Integer second = memento.getInteger(sectionProperty + MEM_SECOND_WEIGHT);
+		if (first != null && second != null)
+			return new int[]{first, second};
+		return DEFAULT_WEIGHTS;
+	}
+
+	/**
+	 * @author robert rudi - Initial contribution and API
+	 * 
+	 */
+	protected class ResizeListener extends ControlAdapter {
+
+		private static final int DELAY = 150;
+		private Job resizeFinishedJob = new Job("Resizing...") {
+
+			@Override
+			protected IStatus run(IProgressMonitor monitor) {
+				Display.getDefault().asyncExec(new Runnable() {
+
+					@Override
+					public void run() {
+						if (isDisposed() || getSash().isDisposed())
+							return;
+						if (isSectionExpanded) {
+							// save current weights so the widths can later be restored
+							previousWidths = getSash().getWeights();
+							saveState(memento);
+						} else {
+							// keep sash collapsed
+							if (getBounds().width != getSwitchControlWidth()) {
+								collapseDefinitionSection();
+							}
+						}
+					}
+				});
+				return Status.OK_STATUS;
+			}
+		};
+
+		@Override
+		public void controlResized(ControlEvent e) {
+			handleControlChanged();
+		}
+
+		@Override
+		public void controlMoved(ControlEvent e) {
+			handleControlChanged();
+		}
+
+		protected void handleControlChanged() {
+			resizeFinishedJob.cancel();
+			resizeFinishedJob.schedule(DELAY);
+		}
+	}
+
+	/**
+	 * @author robert rudi - Initial contribution and API
+	 * 
+	 */
+	protected class InlineIcon extends Composite implements MouseListener, MouseTrackListener, PaintListener {
+
+		private Cursor handCursor = new Cursor(getDisplay(), SWT.CURSOR_HAND);
+		private boolean iconHasFocus = false;
+		private Label icon;
+
+		public InlineIcon(Composite parent, int style) {
+			super(parent, style);
+			GridLayoutFactory.fillDefaults().applyTo(this);
+			icon = new Label(this, style);
+			icon.setCursor(handCursor);
+			icon.setImage(StatechartImages.PIN.image());
+			icon.setToolTipText(INLINE_TOOLTIP);
+			icon.setEnabled(isStatechart());
+			icon.addMouseListener(this);
+			icon.addMouseTrackListener(this);
+			icon.addPaintListener(this);
+		}
+
+		@Override
+		public void mouseUp(MouseEvent e) {
+			updateInlineStyle();
+			toggleDefinitionSection();
+			refreshEditorContents();
+			saveState(memento);
+		}
+
+		@Override
+		public void mouseDoubleClick(MouseEvent e) {
+		}
+
+		@Override
+		public void mouseDown(MouseEvent e) {
+		}
+
+		@Override
+		public void mouseHover(MouseEvent e) {
+		}
+
+		@Override
+		public void mouseEnter(MouseEvent e) {
+			iconHasFocus = true;
+			icon.redraw();
+		}
+
+		@Override
+		public void mouseExit(MouseEvent e) {
+			iconHasFocus = false;
+			icon.redraw();
+		}
+
+		@Override
+		public void paintControl(PaintEvent e) {
+			if (iconHasFocus) {
+				drawIconBorder(this.icon, e.gc);
+			}
+		}
+
+		protected void drawIconBorder(Label icon, GC gc) {
+			Rectangle rect = new Rectangle(0, 0, icon.getBounds().width - 1, icon.getBounds().height - 1);
+			Transform t = new Transform(getDisplay());
+			gc.setTransform(t);
+			t.dispose();
+			gc.setForeground(ColorConstants.lightGray);
+			gc.drawRectangle(0, 0, rect.width, rect.height);
+		}
+
+		@Override
+		public void dispose() {
+			icon.removeMouseListener(this);
+			icon.removeMouseTrackListener(this);
+			icon.removePaintListener(this);
+			handCursor.dispose();
+			icon.dispose();
+			super.dispose();
+		}
+
+	}
+
+	/**
+	 * @author robert rudi - Initial contribution and API
+	 * 
+	 */
+	protected class CollapsedBorder extends Canvas implements MouseListener, MouseTrackListener, PaintListener {
+
+		private String text;
+		float rotationAngle = -90f;
+		private Font font = new Font(getDisplay(), "Segoe UI", 8, SWT.NORMAL);
+		private Cursor arrowCursor = new Cursor(getDisplay(), SWT.CURSOR_ARROW);
+		private Cursor handCursor = new Cursor(getDisplay(), SWT.CURSOR_HAND);
+
+		public CollapsedBorder(Composite parent, int style) {
+			super(parent, style);
+			setText("Definition section", font);
+			GridDataFactory.fillDefaults().grab(false, false).span(2, 1).hint(0, parent.getBounds().height)
+					.applyTo(this);
+			addPaintListener(this);
+			addMouseListener(this);
+			addMouseTrackListener(this);
+		}
+
+		public void setText(String string, Font font) {
+			this.text = string;
+			setFont(font);
+			refresh(this);
+		}
+		@Override
+		public void paintControl(PaintEvent e) {
+			int w = e.width;
+			int h = e.height;
+			Transform tr = new Transform(e.display);
+			tr.translate(w / 2, h / 2);
+			tr.rotate(rotationAngle);
+			e.gc.setTransform(tr);
+			tr.dispose();
+			int drawHeight = -w + 2;
+			e.gc.drawString(isSectionExpanded ? "" : text, 0, drawHeight % 2 != 0 ? drawHeight + 1 : drawHeight - 1);
+		}
+
+		@Override
+		public void mouseUp(MouseEvent e) {
+			if (!isSectionExpanded)
+				toggleExpandState();
+			setCursor(arrowCursor);
+		}
+
+		@Override
+		public void mouseDown(MouseEvent e) {
+			if (mouseListener != null && !isSectionExpanded)
+				toggleExpandState();
+		}
+
+		@Override
+		public void mouseEnter(MouseEvent e) {
+			setCursor((!isSectionExpanded) ? handCursor : arrowCursor);
+			setToolTipText((!isSectionExpanded) ? SHOW_SECTION_TOOLTIP : null);
+		}
+
+		@Override
+		public void mouseExit(MouseEvent e) {
+		}
+
+		@Override
+		public void mouseHover(MouseEvent e) {
+		}
+
+		@Override
+		public void mouseDoubleClick(MouseEvent e) {
+		}
+
+		@Override
+		public void dispose() {
+			removePaintListener(this);
+			removeMouseListener(this);
+			removeMouseTrackListener(this);
+			handCursor.dispose();
+			arrowCursor.dispose();
+			font.dispose();
+			super.dispose();
+		}
+	}
+}

+ 24 - 697
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/StatechartDiagramEditor.java

@@ -13,7 +13,6 @@ package org.yakindu.sct.ui.editor.editor;
 import java.util.ArrayList;
 import java.util.Optional;
 
-import org.eclipse.core.databinding.observable.value.IObservableValue;
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
@@ -21,14 +20,7 @@ import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.databinding.IEMFValueProperty;
-import org.eclipse.emf.databinding.edit.EMFEditProperties;
 import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.edit.command.SetCommand;
 import org.eclipse.emf.transaction.TransactionalEditingDomain;
 import org.eclipse.emf.transaction.util.TransactionUtil;
 import org.eclipse.gef.KeyHandler;
@@ -39,84 +31,39 @@ import org.eclipse.gef.ui.actions.ZoomInAction;
 import org.eclipse.gef.ui.actions.ZoomOutAction;
 import org.eclipse.gmf.runtime.common.ui.services.marker.MarkerNavigationService;
 import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
 import org.eclipse.gmf.runtime.diagram.ui.internal.parts.DiagramGraphicalViewerKeyHandler;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
 import org.eclipse.gmf.runtime.gef.ui.internal.editparts.AnimatableZoomManager;
-import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.gmf.runtime.notation.Diagram;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.databinding.swt.ISWTObservableValue;
-import org.eclipse.jface.databinding.swt.WidgetProperties;
 import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.ControlAdapter;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.FocusAdapter;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseTrackAdapter;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Transform;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Canvas;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.IEditorSite;
 import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.IWorkbenchPartSite;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.XMLMemento;
 import org.eclipse.ui.help.IWorkbenchHelpSystem;
 import org.eclipse.ui.ide.IGotoMarker;
 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
 import org.eclipse.xtext.EcoreUtil2;
 import org.eclipse.xtext.ui.XtextProjectHelper;
-import org.yakindu.base.base.BasePackage;
 import org.yakindu.base.base.DomainElement;
-import org.yakindu.base.base.NamedElement;
 import org.yakindu.base.xtext.utils.gmf.resource.DirtyStateListener;
-import org.yakindu.base.xtext.utils.jface.viewers.FilteringMenuManager;
-import org.yakindu.base.xtext.utils.jface.viewers.StyledTextXtextAdapter;
-import org.yakindu.base.xtext.utils.jface.viewers.util.ActiveEditorTracker;
 import org.yakindu.sct.domain.extension.DomainRegistry;
 import org.yakindu.sct.domain.extension.DomainStatus;
 import org.yakindu.sct.domain.extension.DomainStatus.Severity;
 import org.yakindu.sct.domain.extension.IDomain;
-import org.yakindu.sct.model.sgraph.SGraphPackage;
 import org.yakindu.sct.model.sgraph.Statechart;
-import org.yakindu.sct.model.sgraph.util.ContextElementAdapter;
 import org.yakindu.sct.model.sgraph.util.ContextElementAdapter.IContextElementProvider;
 import org.yakindu.sct.ui.editor.DiagramActivator;
-import org.yakindu.sct.ui.editor.StatechartImages;
+import org.yakindu.sct.ui.editor.definitionsection.StatechartDefinitionSection;
 import org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningEditor;
 import org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil;
-import org.yakindu.sct.ui.editor.propertysheets.ValidatingEMFDatabindingContext;
 import org.yakindu.sct.ui.editor.proposals.ContentProposalViewerKeyHandler;
 import org.yakindu.sct.ui.editor.providers.ISCTOutlineFactory;
 import org.yakindu.sct.ui.editor.utils.HelpContextIds;
@@ -137,41 +84,14 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 
 	public static final String ID = "org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor";
 
-	protected static final String CANNOT_INLINE_SECTION = "Cannot be inlined for subdiagrams";
-	protected static final String DEFINITION_SECTION = "definition section";
-	protected static final String INLINE_SECTION = "Inline " + DEFINITION_SECTION;
-	protected static final String SHOW_SECTION = "Show " + DEFINITION_SECTION;
-	protected static final String HIDE_SECTION = "Hide " + DEFINITION_SECTION;
-
-	private static final int EDITOR_HORIZONTAL_MARGIN = 10;
-	private static final int EDITOR_VERTICAL_MARGIN = 10;
 	protected static final int INITIAL_PALETTE_SIZE = 175;
-	protected static final int[] MIN_SIZE = {11, 21};
-	protected static final int BORDERWIDTH = 2;
-	protected static boolean iconHasFocus = false;
-	protected int[] previousWidths = DEFAULT_WEIGHTS;
-	private boolean isSectionExpanded = true;
 
 	private KeyHandler keyHandler;
 	private DirtyStateListener domainAdapter;
 	private LiveValidationListener validationListener;
 	private IValidationIssueStore issueStore;
-	private SelectionListener selectionListener;
-	private ResizeListener resizeListener;
-	private IconPaintListener iconPaintListener;
-	private IconMouseListener iconMouseListener;
-	private IconMouseTrackListener iconMouseTrackListener;
-	private NameModificationListener nameModificationListener;
-	private CollapsedBorderMouseTrackListener collapsedBorderMouseTrackListener;
-	private CollapsedBorderMouseListener collapsedBorderMouseListener;
-	private EmbeddedEditorFocusListener embeddedEditorFocusListener;
-	private EmbeddedEditorKeyListener embeddedEditorKeyListener;
-
-	private Label switchControl;
-	private Composite labelComposite;
-	private CollapsedBorder collapsedBorder;
 
-	private StyledText embeddedEditor;
+	private StatechartDefinitionSection definitionSection;
 
 	public StatechartDiagramEditor() {
 		super(true);
@@ -274,11 +194,6 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 		return injector;
 	}
 
-	protected Injector getEmbeddedStatechartSpecificationInjector() {
-		IDomain domain = DomainRegistry.getDomain(getContextObject());
-		return domain.getInjector(IDomain.FEATURE_EDITOR, Statechart.class.getName());
-	}
-
 	protected void checkXtextNature() {
 		IFileEditorInput editorInput = (IFileEditorInput) getEditorInput();
 		IProject project = editorInput.getFile().getProject();
@@ -444,15 +359,10 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 		return ID;
 	}
 
-	@Override
-	public String getFactoryId() {
-		return getEditorInput().getPersistable().getFactoryId();
-	}
-
 	@Override
 	public void dispose() {
-		saveState(getMemento());
-
+		if (definitionSection != null && !definitionSection.isDisposed())
+			definitionSection.dispose();
 		if (validationListener != null) {
 			validationListener.dispose();
 		}
@@ -463,46 +373,9 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 		getEditingDomain().removeResourceSetListener(domainAdapter);
 		if (domainAdapter != null)
 			domainAdapter.dispose();
-
-		disposeEmbeddedEditor();
-
 		super.dispose();
 	}
 
-	protected void disposeEmbeddedEditor() {
-		if (selectionListener != null && switchControl != null && !switchControl.isDisposed()) {
-			switchControl.removeMouseListener(selectionListener);
-			selectionListener = null;
-			switchControl.dispose();
-			switchControl = null;
-		}
-
-		if (embeddedEditor != null && !embeddedEditor.isDisposed()) {
-			if (resizeListener != null) {
-				embeddedEditor.removeControlListener(resizeListener);
-				getSash().removeControlListener(resizeListener);
-				resizeListener = null;
-			}
-			if (embeddedEditorKeyListener != null) {
-				embeddedEditor.removeKeyListener(embeddedEditorKeyListener);
-				embeddedEditorKeyListener = null;
-			}
-			if (embeddedEditorFocusListener != null) {
-				embeddedEditor.removeFocusListener(embeddedEditorFocusListener);
-				embeddedEditorFocusListener = null;
-			}
-			embeddedEditor.dispose();
-			embeddedEditor = null;
-		}
-
-		iconMouseListener = null;
-		iconMouseTrackListener = null;
-		iconPaintListener = null;
-		nameModificationListener = null;
-		collapsedBorderMouseTrackListener = null;
-		collapsedBorderMouseListener = null;
-	}
-
 	@Override
 	protected int getInitialPaletteSize() {
 		return INITIAL_PALETTE_SIZE;
@@ -514,170 +387,41 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 			return createOutline(type);
 		} else if (IValidationIssueStore.class.equals(type)) {
 			return issueStore;
-		} else if (DiagramPartitioningEditor.class.equals(type)) {
-			return super.getAdapter(type);
+		} else if (EObject.class.equals(type)) {
+			return this.getContextObject();
+		} else if (TransactionalEditingDomain.class.equals(type)) {
+			return getTransactionalEditingDomain();
+		} else if (Diagram.class.equals(type)) {
+			return getDiagram();
+		} else if (DiagramEditPart.class.equals(type)) {
+			return getDiagramEditPart();
 		}
 		return super.getAdapter(type);
 	}
 
 	@Override
 	protected void createTextEditor(Composite parent) {
-		if (getContextObject() instanceof Statechart) {
-			Composite definitionSection = new Composite(parent, SWT.BORDER);
-			GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(definitionSection);
-
-			switchControl = createSwitchControl(definitionSection);
-			createDefinitionSectionLabels(definitionSection);
-			embeddedEditor = createEmbeddedEditor(definitionSection);
-
-			selectionListener = new SelectionListener(embeddedEditor);
-			switchControl.addMouseListener(selectionListener);
-
-			resizeListener = new ResizeListener(definitionSection);
-
-			parent.addControlListener(resizeListener);
-			embeddedEditor.addControlListener(resizeListener);
+		if (isStatechart()) {
+			definitionSection = new StatechartDefinitionSection(parent, SWT.BORDER, this);
 		}
 	}
 
-	/*
-	 * Need hook into part creation lifecycle because the Xtext controls depends on
-	 * the selection provider of IWorkbenchPartSite, so the Xtext enabling cannot be
-	 * done before or while the part is created.
-	 * 
-	 * @see org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningEditor#
-	 * createPartControl(org.eclipse.swt.widgets.Composite)
-	 */
 	@Override
 	public void createPartControl(Composite parent) {
 		super.createPartControl(parent);
-		if (getContextObject() instanceof Statechart) {
-			toggleDefinitionSection();
-			restoreSashWidths(getSash(), getMemento());
-			enableXtext(embeddedEditor);
-		}
-	}
+		toggleDefinitionSection();
 
-	@SuppressWarnings({"unchecked", "rawtypes"})
-	protected void enableXtext(StyledText xtextControl) {
-		final StyledTextXtextAdapter xtextAdapter = createXtextAdapter();
-		xtextAdapter.adapt((StyledText) xtextControl);
-		initContextMenu(xtextControl);
-		IEMFValueProperty modelProperty = EMFEditProperties.value(getEditingDomain(),
-				SGraphPackage.Literals.SPECIFICATION_ELEMENT__SPECIFICATION);
-		ISWTObservableValue uiProperty = WidgetProperties.text(new int[]{SWT.FocusOut, SWT.Modify})
-				.observe(xtextControl);
-		IObservableValue modelPropertyObservable = modelProperty.observe(
-				EcoreUtil.getObjectByType(getDiagram().eResource().getContents(), SGraphPackage.Literals.STATECHART));
-		ValidatingEMFDatabindingContext context = new ValidatingEMFDatabindingContext(this, getSite().getShell());
-		context.bindValue(uiProperty, modelPropertyObservable, null, null);
 	}
 
-	protected StyledTextXtextAdapter createXtextAdapter() {
-		final StyledTextXtextAdapter xtextAdapter = new StyledTextXtextAdapter(
-				getEmbeddedStatechartSpecificationInjector(), getSite());
-		xtextAdapter.getFakeResourceContext().getFakeResource().eAdapters().add(new ContextElementAdapter(this));
-		return xtextAdapter;
-	}
-
-	protected StyledText createEmbeddedEditor(Composite definitionSection) {
-		StyledText textControl = new StyledText(definitionSection, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
-		GridDataFactory.fillDefaults().grab(true, true).indent(EDITOR_HORIZONTAL_MARGIN, EDITOR_VERTICAL_MARGIN)
-				.span(2, 1).applyTo(textControl);
-
-		textControl.setAlwaysShowScrollBars(false);
-		textControl.setBackground(ColorConstants.white);
-		embeddedEditorKeyListener = new EmbeddedEditorKeyListener();
-		embeddedEditorFocusListener = new EmbeddedEditorFocusListener();
-		textControl.addKeyListener(embeddedEditorKeyListener);
-		textControl.addFocusListener(embeddedEditorFocusListener);
-		return textControl;
-	}
-
-	protected void createDefinitionSectionLabels(Composite definitionSection) {
-		labelComposite = new Composite(definitionSection, SWT.NONE);
-		GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(labelComposite);
-		GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(labelComposite);
-		createNameLabel(labelComposite);
-		createInlineIcon(labelComposite);
-		createSeparator(definitionSection);
-		createCollapsedBorder(definitionSection);
-	}
-
-	protected void createInlineIcon(Composite labelComposite) {
-		Label icon = new Label(labelComposite, SWT.FILL);
-		icon.setImage(StatechartImages.PIN.image());
-		icon.setToolTipText(INLINE_SECTION);
-		icon.setEnabled(getContextObject() instanceof Statechart);
-		labelComposite.setToolTipText(getInlineTooltipText());
-		GridDataFactory.fillDefaults().applyTo(icon);
-		iconMouseListener = new IconMouseListener();
-		iconMouseTrackListener = new IconMouseTrackListener(icon);
-		iconPaintListener = new IconPaintListener(icon);
-		icon.addMouseListener(iconMouseListener);
-		icon.addMouseTrackListener(iconMouseTrackListener);
-		icon.addPaintListener(iconPaintListener);
-	}
-
-	protected String getInlineTooltipText() {
-		return (getContextObject() instanceof Statechart) ? INLINE_SECTION : CANNOT_INLINE_SECTION;
-	}
-
-	protected SetCommand setBooleanValueStyle(BooleanValueStyle inlineStyle, TransactionalEditingDomain domain) {
-		SetCommand command = new SetCommand(domain, inlineStyle,
-				NotationPackage.Literals.BOOLEAN_VALUE_STYLE__BOOLEAN_VALUE, !inlineStyle.isBooleanValue());
-		return command;
-	}
-
-	protected AddCommand addBooleanValueStyle(View view, BooleanValueStyle inlineStyle,
-			TransactionalEditingDomain domain) {
-		AddCommand command = new AddCommand(domain, view, NotationPackage.Literals.VIEW__STYLES, inlineStyle);
-		return command;
-	}
-
-	protected void createNameLabel(Composite labelComposite) {
-		Text nameLabel = new Text(labelComposite, SWT.SINGLE | SWT.NORMAL);
-		GridDataFactory.fillDefaults().indent(5, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(nameLabel);
-
-		nameLabel.setText(getStatechartName());
-		nameLabel.setEditable(getContextObject() instanceof Statechart);
-		nameLabel.setBackground(ColorConstants.white);
-		nameModificationListener = new NameModificationListener(nameLabel);
-		nameLabel.addModifyListener(nameModificationListener);
-	}
-
-	protected String getStatechartName() {
-		Statechart statechart = EcoreUtil2.getContainerOfType(getContextObject(), Statechart.class);
-		return statechart.getName();
-	}
-
-	protected void createSeparator(Composite definitionSection) {
-		Label separator = new Label(definitionSection, SWT.SEPARATOR | SWT.HORIZONTAL);
-		GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(separator);
-	}
-
-	protected void createCollapsedBorder(Composite definitionSection) {
-		collapsedBorder = new CollapsedBorder(definitionSection, SWT.NONE);
-		collapsedBorder.setText("Definition section", new Font(getDisplay(), "Segoe UI", 8, SWT.NORMAL));
-		collapsedBorderMouseListener = new CollapsedBorderMouseListener(collapsedBorder);
-		collapsedBorderMouseTrackListener = new CollapsedBorderMouseTrackListener(collapsedBorder);
-		collapsedBorder.addMouseListener(collapsedBorderMouseListener);
-		collapsedBorder.addMouseTrackListener(collapsedBorderMouseTrackListener);
-
-		GridDataFactory.fillDefaults().grab(false, false).span(2, 1).hint(0, definitionSection.getBounds().height)
-				.applyTo(collapsedBorder);
-
-		refresh(definitionSection);
+	public void toggleDefinitionSection() {
+		if (definitionSection != null && !definitionSection.isDisposed() && isStatechart()) {
+			definitionSection.toggleDefinitionSection();
+			definitionSection.restoreSashWidths();
+		}
 	}
 
-	protected Label createSwitchControl(Composite definitionSection) {
-		Label switchControl = new Label(definitionSection, SWT.PUSH);
-		switchControl.setToolTipText(HIDE_SECTION);
-		switchControl.setImage(isSectionExpanded ? StatechartImages.COLLAPSE.image() : StatechartImages.EXPAND.image());
-		switchControl.setCursor(new Cursor(getDisplay(), SWT.CURSOR_HAND));
-		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(-1, 0).hint(MIN_SIZE[0], MIN_SIZE[1])
-				.applyTo(switchControl);
-		return switchControl;
+	protected boolean isStatechart() {
+		return getContextObject() instanceof Statechart;
 	}
 
 	@Override
@@ -688,424 +432,7 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 		return element;
 	}
 
-	protected void initContextMenu(Control control) {
-		MenuManager menuManager = new FilteringMenuManager();
-		Menu contextMenu = menuManager.createContextMenu(control);
-		control.setMenu(contextMenu);
-		IWorkbenchPartSite site = getSite();
-		if (site != null)
-			site.registerContextMenu("org.yakindu.base.xtext.utils.jface.viewers.StyledTextXtextAdapterContextMenu",
-					menuManager, site.getSelectionProvider());
-	}
-
-	protected void collapseDefinitionSection() {
-		int parentWidth = getSashWidth();
-		int switchControlWidth = getSwitchControlWidth();
-		int[] sashWidths = getCollapsedSashWidths(parentWidth, switchControlWidth);
-		if ((parentWidth - switchControlWidth) < 0 || (parentWidth < switchControlWidth)) {
-			sashWidths = DEFAULT_WEIGHTS;
-		}
-		layoutDefinitionSection(0, sashWidths, false, 1);
-	}
-
-	protected void expandDefinitionSection() {
-		layoutDefinitionSection(SASH_WIDTH, previousWidths, true, 2);
-	}
-
-	protected int getSashWidth() {
-		return getSash().getBounds().width;
-	}
-
-	protected int[] getCollapsedSashWidths(int parentWidth, int switchControlWidth) {
-		int diff = parentWidth - switchControlWidth;
-		return new int[]{switchControlWidth, (diff % 2 != 0) ? diff - (1 + BORDERWIDTH) : diff};
-	}
-
-	protected void layoutDefinitionSection(int sashWidth, int[] weights, boolean visible, int hSpan) {
-		getDisplay().asyncExec(() -> {
-			getSash().setRedraw(false);
-			getSash().setSashWidth(sashWidth);
-			getSash().setWeights(weights);
-			embeddedEditor.setVisible(visible);
-			labelComposite.setVisible(visible);
-			if (visible)
-				refreshSwitchControl(HIDE_SECTION, StatechartImages.COLLAPSE.image());
-			else
-				refreshSwitchControl(SHOW_SECTION, StatechartImages.EXPAND.image());
-			layoutCollapsedBorder(hSpan);
-			layoutEmbeddedEditor(hSpan);
-			refresh(getSash());
-			getSash().setRedraw(true);
-		});
-	}
-
-	protected void layoutEmbeddedEditor(int hSpan) {
-		((GridData) embeddedEditor.getLayoutData()).horizontalSpan = hSpan;
-	}
-
-	protected void layoutCollapsedBorder(int hSpan) {
-		((GridData) collapsedBorder.getLayoutData()).horizontalSpan = hSpan;
-	}
-
-	protected void refresh(Composite comp) {
-		comp.layout(false, true);
-		comp.redraw();
-		comp.update();
-	}
-
-	protected void refreshSwitchControl(String tooltipText, Image image) {
-		switchControl.setToolTipText(tooltipText);
-		switchControl.setImage(image);
-	}
-
-	@Override
-	protected boolean isDefinitionSectionInlined() {
-		BooleanValueStyle style = DiagramPartitioningUtil.getInlineDefinitionSectionStyle(getDiagram());
-		return style != null ? style.isBooleanValue() : true;
-	}
-
-	@Override
-	public void saveState(IMemento memento) {
-		if (memento == null) {
-			memento = XMLMemento.createWriteRoot(getFactoryId());
-		}
-		memento.putInteger(FIRST_SASH_WEIGHT, previousWidths[0]);
-		memento.putInteger(SECOND_SASH_WEIGHT, previousWidths[1]);
-		setExpandState(memento);
-
-		super.setMemento(memento);
-	}
-
-	@Override
-	protected void setExpandState(IMemento memento) {
-		if (getContextObject() != null) {
-			if (getContextObject() instanceof NamedElement) {
-				NamedElement element = (NamedElement) getContextObject();
-				if (element != null)
-					memento.putBoolean(stripElementName(element.getName()) + MEM_EXPANDED, isSectionExpanded);
-			}
-		}
-	}
-
-	@Override
-	public void restoreState(IMemento memento) {
-		if (getSash() != null && memento != null) {
-			if (memento.getInteger(FIRST_SASH_WEIGHT) != null && memento.getInteger(SECOND_SASH_WEIGHT) != null) {
-				int[] weights = new int[]{memento.getInteger(FIRST_SASH_WEIGHT),
-						memento.getInteger(SECOND_SASH_WEIGHT)};
-				getSash().setWeights(weights);
-				previousWidths = weights;
-				isSectionExpanded = getExpandState(memento);
-			}
-		}
-		super.setMemento(memento);
-	}
-
-	protected boolean getExpandState(IMemento memento) {
-		Object expandState = null;
-		if (getContextObject() instanceof NamedElement) {
-			NamedElement element = (NamedElement) getContextObject();
-			if (element != null)
-				expandState = memento.getBoolean(stripElementName(element.getName()) + MEM_EXPANDED);
-		}
-		return expandState != null ? ((Boolean) expandState).booleanValue() : true;
-	}
-
 	protected TransactionalEditingDomain getTransactionalEditingDomain() {
 		return TransactionUtil.getEditingDomain(getDiagram());
 	}
-
-	protected String getStatechartSpecification() {
-		return ((Statechart) getContextObject()).getSpecification();
-	}
-
-	protected Display getDisplay() {
-		return Display.getCurrent() != null ? Display.getCurrent() : Display.getDefault();
-	}
-
-	protected int getSwitchControlWidth() {
-		return switchControl.getBounds().width + BORDERWIDTH;
-	}
-
-	/**
-	 * 
-	 * @author robert rudi - Initial contribution and API
-	 *
-	 */
-	public class EmbeddedEditorKeyListener extends KeyAdapter {
-		@Override
-		public void keyReleased(KeyEvent e) {
-			if (e.stateMask == SWT.CTRL && e.keyCode == 'a') {
-				embeddedEditor.selectAll();
-			}
-		}
-	}
-
-	/**
-	 * @author robert rudi - Initial contribution and API
-	 * 
-	 */
-	protected class EmbeddedEditorFocusListener extends FocusAdapter {
-
-		@Override
-		public void focusGained(FocusEvent e) {
-			// needed to be able to show the right property sheet in PropertiesView
-			((DiagramDocumentEditor) ActiveEditorTracker.getLastActiveEditor()).getDiagramGraphicalViewer()
-					.select(getDiagramEditPart());
-		}
-
-		@Override
-		public void focusLost(FocusEvent e) {
-			embeddedEditor.setSelection(0);
-		}
-	}
-
-	/**
-	 * @author robert rudi - Initial contribution and API
-	 * 
-	 */
-	protected class NameModificationListener implements ModifyListener {
-
-		private final Text nameLabel;
-
-		protected NameModificationListener(Text nameLabel) {
-			this.nameLabel = nameLabel;
-		}
-
-		@Override
-		public void modifyText(ModifyEvent e) {
-			if (getContextObject() instanceof Statechart) {
-				getSash().setRedraw(false);
-				TransactionalEditingDomain domain = getTransactionalEditingDomain();
-				SetCommand command = new SetCommand(domain, getContextObject(),
-						BasePackage.Literals.NAMED_ELEMENT__NAME, nameLabel.getText());
-				domain.getCommandStack().execute(command);
-				refresh(nameLabel.getParent());
-				getSash().setRedraw(true);
-			}
-		}
-	}
-
-	/**
-	 * @author robert rudi - Initial contribution and API
-	 * 
-	 */
-	protected class CollapsedBorderMouseListener extends MouseAdapter {
-		private final CollapsedBorder collapsedBorder;
-		protected CollapsedBorderMouseListener(CollapsedBorder collapsedBorder) {
-			this.collapsedBorder = collapsedBorder;
-		}
-		@Override
-		public void mouseUp(MouseEvent e) {
-			if (!isSectionExpanded)
-				selectionListener.handleSelection();
-			collapsedBorder.setCursor(new Cursor(getDisplay(), SWT.CURSOR_ARROW));
-		}
-	}
-
-	/**
-	 * @author robert rudi - Initial contribution and API
-	 * 
-	 */
-	protected class CollapsedBorderMouseTrackListener extends MouseTrackAdapter {
-		private final CollapsedBorder collapsedBorder;
-		protected CollapsedBorderMouseTrackListener(CollapsedBorder collapsedBorder) {
-			this.collapsedBorder = collapsedBorder;
-		}
-		@Override
-		public void mouseEnter(MouseEvent e) {
-			collapsedBorder
-					.setCursor(new Cursor(getDisplay(), (!isSectionExpanded) ? SWT.CURSOR_HAND : SWT.CURSOR_ARROW));
-			collapsedBorder.setToolTipText((!isSectionExpanded) ? SHOW_SECTION : null);
-		}
-	}
-
-	/**
-	 * @author robert rudi - Initial contribution and API
-	 * 
-	 */
-	protected class IconMouseListener extends MouseAdapter {
-
-		@Override
-		public void mouseUp(MouseEvent e) {
-			TransactionalEditingDomain domain = getTransactionalEditingDomain();
-			BooleanValueStyle inlineStyle = DiagramPartitioningUtil.getInlineDefinitionSectionStyle(getDiagram());
-			if (inlineStyle == null) {
-				inlineStyle = DiagramPartitioningUtil.createInlineDefinitionSectionStyle();
-				AddCommand command = addBooleanValueStyle(getDiagram(), inlineStyle, domain);
-				domain.getCommandStack().execute(command);
-			}
-			// set the new value for the boolean value style
-			SetCommand command = setBooleanValueStyle(inlineStyle, domain);
-			domain.getCommandStack().execute(command);
-
-			toggleDefinitionSection();
-			refreshDiagramEditPartChildren();
-		}
-	}
-
-	/**
-	 * @author robert rudi - Initial contribution and API
-	 * 
-	 */
-	protected class IconMouseTrackListener extends MouseTrackAdapter {
-		private final Label icon;
-
-		protected IconMouseTrackListener(Label icon) {
-			this.icon = icon;
-		}
-
-		@Override
-		public void mouseEnter(MouseEvent e) {
-			icon.setCursor(new Cursor(getDisplay(), SWT.CURSOR_HAND));
-			iconHasFocus = true;
-			refresh(icon.getParent());
-		}
-
-		@Override
-		public void mouseExit(MouseEvent e) {
-			iconHasFocus = false;
-			refresh(icon.getParent());
-		}
-	}
-
-	/**
-	 * @author robert rudi - Initial contribution and API
-	 * 
-	 */
-	protected class IconPaintListener implements PaintListener {
-		private final Label icon;
-
-		protected IconPaintListener(Label icon) {
-			this.icon = icon;
-		}
-
-		@Override
-		public void paintControl(PaintEvent e) {
-			if (iconHasFocus) {
-				drawIconBorder(icon, e.gc);
-			}
-		}
-
-		protected void drawIconBorder(Label icon, GC gc) {
-			Rectangle rect = new Rectangle(0, 0, icon.getBounds().width - 1, icon.getBounds().height - 1);
-			Transform t = new Transform(getDisplay());
-			gc.setTransform(t);
-			gc.setForeground(ColorConstants.lightGray);
-			gc.drawRectangle(0, 0, rect.width, rect.height);
-			refresh(icon.getParent());
-		}
-	}
-
-	/**
-	 * @author robert rudi - Initial contribution and API
-	 * 
-	 */
-	protected class ResizeListener extends ControlAdapter {
-
-		private final Composite definitionSection;
-
-		protected ResizeListener(Composite definitionSection) {
-			this.definitionSection = definitionSection;
-		}
-
-		@Override
-		public void controlResized(ControlEvent e) {
-			handleControlChanged();
-		}
-
-		@Override
-		public void controlMoved(ControlEvent e) {
-			handleControlChanged();
-		}
-
-		protected void handleControlChanged() {
-			if (isSectionExpanded) {
-				previousWidths = getSash().getWeights();// save current weights so the widths can later be restored
-			} else {
-				if (definitionSection.getBounds().width != getSwitchControlWidth()) {
-					collapseDefinitionSection(); // keep sash collapsed
-				}
-			}
-		}
-	}
-
-	/**
-	 * @author robert rudi - Initial contribution and API
-	 * 
-	 */
-	protected class SelectionListener extends MouseAdapter {
-
-		protected final StyledText xtextEditor;
-
-		protected SelectionListener(StyledText xtextEditor) {
-			this.xtextEditor = xtextEditor;
-		}
-
-		protected void handleSelection() {
-			getSash().setRedraw(false);
-			isSectionExpanded = !isSectionExpanded;
-			if (isSectionExpanded) {
-				xtextEditor.setVisible(true);
-				expandDefinitionSection();
-			} else {
-				xtextEditor.setVisible(false);
-				collapseDefinitionSection();
-			}
-			getSash().setRedraw(true);
-		}
-
-		@Override
-		public void mouseUp(MouseEvent e) {
-			handleSelection();
-		}
-	}
-
-	/**
-	 * @author robert rudi - Initial contribution and API
-	 * 
-	 */
-	protected class CollapsedBorder extends Canvas {
-
-		private String text;
-		float rotationAngle = -90f;
-
-		public CollapsedBorder(Composite parent, int style) {
-			super(parent, style);
-
-			this.addPaintListener(new PaintListener() {
-				public void paintControl(PaintEvent e) {
-					paint(e);
-				}
-			});
-			this.addListener(SWT.MouseDown, new Listener() {
-
-				@Override
-				public void handleEvent(Event event) {
-					if (selectionListener != null && !isSectionExpanded)
-						selectionListener.handleSelection();
-				}
-			});
-		}
-
-		public void setText(String string, Font font) {
-			this.text = string;
-			setFont(font);
-			refresh(this);
-		}
-
-		public void paint(PaintEvent e) {
-			Transform tr = null;
-			tr = new Transform(e.display);
-			int w = e.width;
-			int h = e.height;
-			tr.translate(w / 2, h / 2);
-			tr.rotate(rotationAngle);
-			e.gc.setTransform(tr);
-			int drawHeight = -w + 2;
-			e.gc.drawString(isSectionExpanded ? "" : text, 0, drawHeight % 2 != 0 ? drawHeight + 1 : drawHeight - 1);
-			update();
-		}
-	}
-
 }

+ 2 - 68
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/partitioning/DiagramPartitioningEditor.java

@@ -54,15 +54,11 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.IPersistableEditor;
-import org.eclipse.ui.IPersistableElement;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.XMLMemento;
 import org.eclipse.ui.ide.FileStoreEditorInput;
 import org.eclipse.xtext.util.Arrays;
 import org.yakindu.base.base.BasePackage;
@@ -83,26 +79,16 @@ import org.yakindu.sct.ui.editor.StatechartImages;
 public abstract class DiagramPartitioningEditor extends DiagramDocumentEditor
 		implements
 			ISelectionChangedListener,
-			IEditingDomainProvider,
-			IPersistableEditor,
-			IPersistableElement {
+			IEditingDomainProvider
+			{
 
 	protected static final int SASH_WIDTH = 5;
-	private static final String REGEX_NO_WORD_NO_WHITESPACE = "[^\\w[\\s+]]";
-	protected static final String MEM_EXPANDED = "DefinitionSectionIsExpanded";
-	protected static final String FIRST_SASH_WEIGHT = "FirstSashControlWeight";
-	protected static final String SECOND_SASH_WEIGHT = "SecondSashControlWeight";
-	protected static final int[] DEFAULT_WEIGHTS = new int[]{2, 10};
-	protected static final int MAXIMIZED_CONTROL_INDEX = 1;
-
 	private DiagramPartitioningBreadcrumbViewer viewer;
 	private DiagramPartitioningDocumentProvider documentProvider;
 	private Adapter breadcrumbSynchronizer;
 
 	private SashForm sash;
 
-	private static IMemento memento;
-
 	protected abstract void createTextEditor(Composite parent);
 
 	protected abstract EObject getContextObject();
@@ -160,58 +146,6 @@ public abstract class DiagramPartitioningEditor extends DiagramDocumentEditor
 		return sash;
 	}
 
-	public void toggleDefinitionSection() {
-		sash.setMaximizedControl(!isDefinitionSectionInlined() ? null : sash.getChildren()[MAXIMIZED_CONTROL_INDEX]);
-	}	
-	
-	public void restoreSashWidths(SashForm sash, IMemento memento) {
-		if (memento == null) {
-			setDefaultSashWeights(sash);
-			memento = XMLMemento.createWriteRoot(getFactoryId());
-			memento.putInteger(FIRST_SASH_WEIGHT, DEFAULT_WEIGHTS[0]);
-			memento.putInteger(SECOND_SASH_WEIGHT, DEFAULT_WEIGHTS[1]);
-			setExpandState(memento);
-			setMemento(memento);
-		} else {
-			restoreState(memento);
-		}
-	}
-
-	protected abstract void setExpandState(IMemento memento);
-
-	protected String stripElementName(String name) {
-		if (name != null)
-			return name.replaceAll(REGEX_NO_WORD_NO_WHITESPACE, "");
-		return "";
-	}
-
-	public SashForm getSash() {
-		return sash;
-	}
-
-	protected void setDefaultSashWeights(SashForm sash) {
-		sash.setWeights(DEFAULT_WEIGHTS);
-	}
-
-	@Override
-	public abstract void restoreState(IMemento memento);
-
-	@Override
-	public abstract void saveState(IMemento memento);
-
-	public IMemento getMemento() {
-		return memento;
-	}
-
-	public void setMemento(IMemento memento) {
-		DiagramPartitioningEditor.memento = memento;
-	}
-
-	@Override
-	public abstract String getFactoryId();
-
-	protected abstract boolean isDefinitionSectionInlined();
-
 	@SuppressWarnings("restriction")
 	@Override
 	protected void sanityCheckState(IEditorInput input) {

+ 280 - 281
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/partitioning/DiagramPartitioningUtil.java

@@ -1,281 +1,280 @@
-/**
- * Copyright (c) 2012 committers of YAKINDU and others.
- * 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:
- * 	committers of YAKINDU - initial API and implementation
- * 
- */
-package org.yakindu.sct.ui.editor.partitioning;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
-import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.NotationFactory;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.Style;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorReference;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.FileEditorInput;
-import org.yakindu.sct.model.sgraph.CompositeElement;
-import org.yakindu.sct.model.sgraph.State;
-import org.yakindu.sct.model.sgraph.Statechart;
-import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
-import org.yakindu.sct.ui.editor.utils.GMFNotationUtil;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class DiagramPartitioningUtil {
-
-	/** GMFs notation {@link Style} id **/
-	public static final String INLINE_STYLE = "isInline";
-	public static final String INLINE_DEFINITION_SECTION_STYLE = "inlineDefinitionSection";
-
-	private static final String DOMAIN_ID = "org.yakindu.sct.domain";
-
-	private DiagramPartitioningUtil() {
-	}
-
-	/**
-	 * returns the style for diagram inlining
-	 * 
-	 */
-	public static BooleanValueStyle getInlineStyle(View view) {
-		BooleanValueStyle result = GMFNotationUtil.getBooleanValueStyle(view, INLINE_STYLE);
-		return result;
-	}
-	
-	/**
-	 * returns the style for diagram inlining
-	 * 
-	 */
-	public static BooleanValueStyle getInlineDefinitionSectionStyle(View view) {
-		BooleanValueStyle result = GMFNotationUtil.getBooleanValueStyle(view, INLINE_DEFINITION_SECTION_STYLE);
-		return result;
-	}
-
-
-	/**
-	 * creates a new style for diagam inlining
-	 */
-	public static BooleanValueStyle createInlineStyle() {
-		BooleanValueStyle result = NotationFactory.eINSTANCE.createBooleanValueStyle();
-		result.setName(INLINE_STYLE);
-		result.setBooleanValue(true);
-		return result;
-	}
-	
-	/**
-	 * creates a new style for diagam inlining
-	 */
-	public static BooleanValueStyle createInlineDefinitionSectionStyle() {
-		BooleanValueStyle result = NotationFactory.eINSTANCE.createBooleanValueStyle();
-		result.setName(INLINE_DEFINITION_SECTION_STYLE);
-		result.setBooleanValue(true);
-		return result;
-	}
-
-	/**
-	 * Returns the Shared Editing Domain that is used for all Editors acting on the
-	 * same {@link IResource}
-	 * 
-	 * @return the {@link TransactionalEditingDomain}
-	 */
-	public static synchronized TransactionalEditingDomain getSharedDomain() {
-		return TransactionalEditingDomain.Registry.INSTANCE
-				.getEditingDomain(DOMAIN_ID);
-	}
-
-	/**
-	 * Returns the {@link Diagram} that contains a given semantic element.
-	 */
-	public static Diagram getDiagramContaining(EObject element) {
-		Assert.isNotNull(element);
-		Resource eResource = element.eResource();
-		Collection<Diagram> objects = EcoreUtil.getObjectsByType(eResource.getContents(),
-				NotationPackage.Literals.DIAGRAM);
-		for (Diagram diagram : objects) {
-			TreeIterator<EObject> eAllContents = diagram.eAllContents();
-			while (eAllContents.hasNext()) {
-				EObject next = eAllContents.next();
-				if (next instanceof View) {
-					if (EcoreUtil.equals(((View) next).getElement(), element)) {
-						return ((View) next).getDiagram();
-					}
-				}
-			}
-		}
-		return null;
-	}
-
-	/**
-	 * Returns the Subdiagram for a given {@link State} or {@link Statechart}
-	 * 
-	 */
-	public static Diagram getSubDiagram(CompositeElement element) {
-		Assert.isNotNull(element);
-		Resource eResource = element.eResource();
-		Collection<Diagram> objects = EcoreUtil.getObjectsByType(eResource.getContents(),
-				NotationPackage.Literals.DIAGRAM);
-		for (Diagram diagram : objects) {
-			if (EcoreUtil.equals(diagram.getElement(), element))
-				return diagram;
-		}
-		return null;
-	}
-
-	/**
-	 * Opens the {@link StatechartDiagramEditor} for a fiven {@link IFile}
-	 * 
-	 */
-	public static IEditorPart openEditor(IFile file) {
-		try {
-			IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
-			final IWorkbenchPage wbPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-			return wbPage.openEditor(new FileEditorInput(file), desc.getId());
-		} catch (PartInitException e) {
-			e.printStackTrace();
-		}
-		return null;
-
-	}
-
-	/**
-	 * Opens a subdiagram for a given {@link Diagram}
-	 */
-	public static IEditorPart openEditor(Diagram diagramToOpen) {
-		IFile file = WorkspaceSynchronizer.getFile(diagramToOpen.eResource());
-		try {
-			IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
-			final IWorkbenchPage wbPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-			if (diagramToOpen.getElement() instanceof Statechart) {
-				return wbPage.openEditor(new FileEditorInput(file), desc.getId());
-			} else if (diagramToOpen.getElement() instanceof State) {
-				return wbPage.openEditor(new DiagramEditorInput(diagramToOpen), desc.getId());
-			}
-		} catch (PartInitException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-	
-	
-	public static View findNotationView(EObject semanticElement) {
-		Collection<Diagram> objects = EcoreUtil.getObjectsByType(semanticElement.eResource().getContents(),
-				NotationPackage.Literals.DIAGRAM);
-		for (Diagram diagram : objects) {
-			TreeIterator<EObject> eAllContents = diagram.eAllContents();
-			while (eAllContents.hasNext()) {
-				EObject next = eAllContents.next();
-				if (next instanceof View) {
-					if (((View) next).getElement() == semanticElement) {
-						return ((View) next);
-					}
-				}
-			}
-		}
-		return null;
-	}
-	
-	public static void selectElementsInDiagram(IDiagramWorkbenchPart diagramPart, List<EditPart> editParts) {
-		diagramPart.getDiagramGraphicalViewer().deselectAll();
-
-		EditPart firstPrimary = null;
-		for (Iterator<EditPart> it = editParts.iterator(); it.hasNext();) {
-			EditPart nextPart = it.next();
-			diagramPart.getDiagramGraphicalViewer().appendSelection(nextPart);
-			if (firstPrimary == null && nextPart instanceof IPrimaryEditPart) {
-				firstPrimary = nextPart;
-			}
-		}
-		if (!editParts.isEmpty()) {
-			diagramPart.getDiagramGraphicalViewer()
-					.reveal(firstPrimary != null ? firstPrimary : (EditPart) editParts.get(0));
-		}
-	}
-
-	/**
-	 * Forces the user to close all opened editors for subdiagrams that are inlined.
-	 * 
-	 * @return true if all editors were closed, false otherwise
-	 */
-	public static boolean closeSubdiagramEditors(State state) {
-		Diagram diagram = DiagramPartitioningUtil.getSubDiagram(state);
-		if (diagram == null)
-			return true;
-		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-		IEditorReference[] refs = activePage.getEditorReferences();
-		for (IEditorReference ref : refs) {
-			try {
-				if (ref.getEditorInput() instanceof IDiagramEditorInput) {
-					IDiagramEditorInput diagramInput = (IDiagramEditorInput) ref.getEditorInput();
-					if (diagramInput.getDiagram().equals(diagram)) {
-						boolean close = MessageDialog.openQuestion(activePage.getActivePart().getSite().getShell(),
-								"Close subdiagram editor?",
-								"The subdiagram is still open in another editor. Do you want to close it?");
-						if (close) {
-							activePage.closeEditor(ref.getEditor(false), false);
-						}
-						return close;
-					}
-				}
-			} catch (PartInitException e) {
-				e.printStackTrace();
-			}
-		}
-		return true;
-	}
-
-	public static List<Diagram> getDiagramContainerHierachy(Diagram diagram) {
-		Assert.isNotNull(diagram);
-		List<Diagram> result = new ArrayList<Diagram>();
-		result.add(diagram);
-		while (diagram.getElement() instanceof State) {
-			diagram = DiagramPartitioningUtil.getDiagramContaining((State) diagram.getElement());
-			result.add(diagram);
-		}
-		Collections.reverse(result);
-		return result;
-	}
-
-	public static List<Diagram> getSubDiagramHierachy(Diagram diagram) {
-		Assert.isNotNull(diagram);
-		List<Diagram> result = new ArrayList<Diagram>();
-		result.add(diagram);
-		while (diagram.getElement() instanceof State) {
-			diagram = DiagramPartitioningUtil.getSubDiagram((CompositeElement) diagram.getElement());
-			result.add(diagram);
-		}
-		Collections.reverse(result);
-		return result;
-	}
-}
+/**
+ * Copyright (c) 2012 committers of YAKINDU and others.
+ * 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.ui.editor.partitioning;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.Style;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+import org.yakindu.sct.model.sgraph.CompositeElement;
+import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
+import org.yakindu.sct.ui.editor.utils.GMFNotationUtil;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class DiagramPartitioningUtil {
+
+	/** GMFs notation {@link Style} id **/
+	public static final String INLINE_STYLE = "isInline";
+	public static final String INLINE_DEFINITION_SECTION_STYLE = "inlineDefinitionSection";
+
+	private static final String DOMAIN_ID = "org.yakindu.sct.domain";
+
+	private DiagramPartitioningUtil() {
+	}
+
+	/**
+	 * returns the style for diagram inlining
+	 * 
+	 */
+	public static BooleanValueStyle getInlineStyle(View view) {
+		BooleanValueStyle result = GMFNotationUtil.getBooleanValueStyle(view, INLINE_STYLE);
+		return result;
+	}
+	
+	/**
+	 * returns the style for diagram inlining
+	 * 
+	 */
+	public static BooleanValueStyle getInlineDefinitionSectionStyle(View view) {
+		BooleanValueStyle result = GMFNotationUtil.getBooleanValueStyle(view, INLINE_DEFINITION_SECTION_STYLE);
+		return result;
+	}
+
+
+	/**
+	 * creates a new style for diagam inlining
+	 */
+	public static BooleanValueStyle createInlineStyle() {
+		BooleanValueStyle result = NotationFactory.eINSTANCE.createBooleanValueStyle();
+		result.setName(INLINE_STYLE);
+		result.setBooleanValue(true);
+		return result;
+	}
+	
+	/**
+	 * creates a new style for diagam inlining
+	 */
+	public static BooleanValueStyle createInlineDefinitionSectionStyle() {
+		BooleanValueStyle result = NotationFactory.eINSTANCE.createBooleanValueStyle();
+		result.setName(INLINE_DEFINITION_SECTION_STYLE);
+		result.setBooleanValue(false);
+		return result;
+	}
+
+	/**
+	 * Returns the Shared Editing Domain that is used for all Editors acting on the
+	 * same {@link IResource}
+	 * 
+	 * @return the {@link TransactionalEditingDomain}
+	 */
+	public static synchronized TransactionalEditingDomain getSharedDomain() {
+		return TransactionalEditingDomain.Registry.INSTANCE
+				.getEditingDomain(DOMAIN_ID);
+	}
+
+	/**
+	 * Returns the {@link Diagram} that contains a given semantic element.
+	 */
+	public static Diagram getDiagramContaining(EObject element) {
+		Assert.isNotNull(element);
+		Resource eResource = element.eResource();
+		Collection<Diagram> objects = EcoreUtil.getObjectsByType(eResource.getContents(),
+				NotationPackage.Literals.DIAGRAM);
+		for (Diagram diagram : objects) {
+			TreeIterator<EObject> eAllContents = diagram.eAllContents();
+			while (eAllContents.hasNext()) {
+				EObject next = eAllContents.next();
+				if (next instanceof View) {
+					if (EcoreUtil.equals(((View) next).getElement(), element)) {
+						return ((View) next).getDiagram();
+					}
+				}
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * Returns the Subdiagram for a given {@link State} or {@link Statechart}
+	 * 
+	 */
+	public static Diagram getSubDiagram(CompositeElement element) {
+		Assert.isNotNull(element);
+		Resource eResource = element.eResource();
+		Collection<Diagram> objects = EcoreUtil.getObjectsByType(eResource.getContents(),
+				NotationPackage.Literals.DIAGRAM);
+		for (Diagram diagram : objects) {
+			if (EcoreUtil.equals(diagram.getElement(), element))
+				return diagram;
+		}
+		return null;
+	}
+
+	/**
+	 * Opens the {@link StatechartDiagramEditor} for a fiven {@link IFile}
+	 * 
+	 */
+	public static void openEditor(IFile file) {
+		try {
+			IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
+			final IWorkbenchPage wbPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+			wbPage.openEditor(new FileEditorInput(file), desc.getId());
+		} catch (PartInitException e) {
+			e.printStackTrace();
+		}
+
+	}
+
+	/**
+	 * Opens a subdiagram for a given {@link Diagram}
+	 */
+	public static IEditorPart openEditor(Diagram diagramToOpen) {
+		IFile file = WorkspaceSynchronizer.getFile(diagramToOpen.eResource());
+		try {
+			IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
+			final IWorkbenchPage wbPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+			if (diagramToOpen.getElement() instanceof Statechart) {
+				return wbPage.openEditor(new FileEditorInput(file), desc.getId());
+			} else if (diagramToOpen.getElement() instanceof State) {
+				return wbPage.openEditor(new DiagramEditorInput(diagramToOpen), desc.getId());
+			}
+		} catch (PartInitException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+	
+	
+	public static View findNotationView(EObject semanticElement) {
+		Collection<Diagram> objects = EcoreUtil.getObjectsByType(semanticElement.eResource().getContents(),
+				NotationPackage.Literals.DIAGRAM);
+		for (Diagram diagram : objects) {
+			TreeIterator<EObject> eAllContents = diagram.eAllContents();
+			while (eAllContents.hasNext()) {
+				EObject next = eAllContents.next();
+				if (next instanceof View) {
+					if (((View) next).getElement() == semanticElement) {
+						return ((View) next);
+					}
+				}
+			}
+		}
+		return null;
+	}
+	
+	public static void selectElementsInDiagram(IDiagramWorkbenchPart diagramPart, List<EditPart> editParts) {
+		diagramPart.getDiagramGraphicalViewer().deselectAll();
+
+		EditPart firstPrimary = null;
+		for (Iterator<EditPart> it = editParts.iterator(); it.hasNext();) {
+			EditPart nextPart = it.next();
+			diagramPart.getDiagramGraphicalViewer().appendSelection(nextPart);
+			if (firstPrimary == null && nextPart instanceof IPrimaryEditPart) {
+				firstPrimary = nextPart;
+			}
+		}
+		if (!editParts.isEmpty()) {
+			diagramPart.getDiagramGraphicalViewer()
+					.reveal(firstPrimary != null ? firstPrimary : (EditPart) editParts.get(0));
+		}
+	}
+
+	/**
+	 * Forces the user to close all opened editors for subdiagrams that are inlined.
+	 * 
+	 * @return true if all editors were closed, false otherwise
+	 */
+	public static boolean closeSubdiagramEditors(State state) {
+		Diagram diagram = DiagramPartitioningUtil.getSubDiagram(state);
+		if (diagram == null)
+			return true;
+		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+		IEditorReference[] refs = activePage.getEditorReferences();
+		for (IEditorReference ref : refs) {
+			try {
+				if (ref.getEditorInput() instanceof IDiagramEditorInput) {
+					IDiagramEditorInput diagramInput = (IDiagramEditorInput) ref.getEditorInput();
+					if (diagramInput.getDiagram().equals(diagram)) {
+						boolean close = MessageDialog.openQuestion(activePage.getActivePart().getSite().getShell(),
+								"Close subdiagram editor?",
+								"The subdiagram is still open in another editor. Do you want to close it?");
+						if (close) {
+							activePage.closeEditor(ref.getEditor(false), false);
+						}
+						return close;
+					}
+				}
+			} catch (PartInitException e) {
+				e.printStackTrace();
+			}
+		}
+		return true;
+	}
+
+	public static List<Diagram> getDiagramContainerHierachy(Diagram diagram) {
+		Assert.isNotNull(diagram);
+		List<Diagram> result = new ArrayList<Diagram>();
+		result.add(diagram);
+		while (diagram.getElement() instanceof State) {
+			diagram = DiagramPartitioningUtil.getDiagramContaining((State) diagram.getElement());
+			result.add(diagram);
+		}
+		Collections.reverse(result);
+		return result;
+	}
+
+	public static List<Diagram> getSubDiagramHierachy(Diagram diagram) {
+		Assert.isNotNull(diagram);
+		List<Diagram> result = new ArrayList<Diagram>();
+		result.add(diagram);
+		while (diagram.getElement() instanceof State) {
+			diagram = DiagramPartitioningUtil.getSubDiagram((CompositeElement) diagram.getElement());
+			result.add(diagram);
+		}
+		Collections.reverse(result);
+		return result;
+	}
+}