/**
 * Copyright (c) 2013 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.refactoring.refactor.impl;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.yakindu.sct.model.sgraph.State;
import org.yakindu.sct.ui.editor.providers.SemanticHints;

/**
 * 
 * @author andreas muelder - Initial contribution and API
 * 
 */
public class InlineSubdiagramRefactoring extends SubdiagramRefactoring {

	@Override
	public boolean isExecutable() {
		return super.isExecutable() && !getInlineStyle().isBooleanValue();
	}

	@SuppressWarnings("unchecked")
	@Override
	protected void internalExecute() {
		getInlineStyle().setBooleanValue(true);

		View contextView = getContextObject();
		State contextElement = (State) contextView.getElement();
		Diagram inlineDiagram = findDiagramForState(contextElement);
		View figureCompartment = ViewUtil.getChildBySemanticHint(contextView,
				SemanticHints.STATE_FIGURE_COMPARTMENT);

		EList<View> children = inlineDiagram.getChildren();
		for (View view : children) {
			figureCompartment.insertChild(view);
		}
		getResource().getContents().remove(inlineDiagram);
	}

	protected Diagram findDiagramForState(State state) {
		EList<EObject> contents = getResource().getContents();
		for (EObject eObject : contents) {
			if (eObject instanceof Diagram) {
				if (EcoreUtil.equals(((Diagram) eObject).getElement(), state)) {
					return (Diagram) eObject;
				}
			}
		}
		return null;
	}
}

@@ -513,52 +513,28 @@
 pse.
-emf.ecore.EObject;%0D%0Aimport org.eclipse.emf.e
+gmf.runtime.diagram.
 core
@@ -539,21 +539,20 @@
 re.util.
-Ecore
+View
 Util;%0D%0Ai
@@ -585,34 +585,34 @@
 ime.
-diagram.core.util.ViewUtil
+notation.BooleanValueStyle
 ;%0D%0Ai
@@ -747,24 +747,91 @@
 aph.State;%0D%0A
+import org.yakindu.sct.ui.editor.breadcrumb.BreadcrumbViewerUtil;%0D%0A
 import org.y
@@ -1112,16 +1112,44 @@
 ble() &&
+ getInlineStyle() != null &&
  !getInl
@@ -1268,32 +1268,207 @@
 () %7B%0D%0A%09%09
-getInlineStyle()
+BooleanValueStyle inlineStyle = getInlineStyle();%0D%0A%09%09if (inlineStyle == null) %7B%0D%0A%09%09%09inlineStyle = createInlineStyle();%0D%0A%09%09%09getContextObject().getStyles().add(inlineStyle);%0D%0A%09%09%7D%0D%0A%09%09inlineStyle
 .setBool
@@ -1484,18 +1484,16 @@
 true);%0D%0A
-%0D%0A
 %09%09View c
@@ -1612,35 +1612,50 @@
 agram = 
-findDiagramForState
+BreadcrumbViewerUtil.getSubDiagram
 (context
@@ -1736,22 +1736,17 @@
 extView,
-%0D%0A%09%09%09%09
+ 
 Semantic
@@ -1978,336 +1978,7 @@
 %0D%0A%0D%0A
-%09protected Diagram findDiagramForState(State state) %7B%0D%0A%09%09EList%3CEObject%3E contents = getResource().getContents();%0D%0A%09%09for (EObject eObject : contents) %7B%0D%0A%09%09%09if (eObject instanceof Diagram) %7B%0D%0A%09%09%09%09if (EcoreUtil.equals(((Diagram) eObject).getElement(), state)) %7B%0D%0A%09%09%09%09%09return (Diagram) eObject;%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09return null;%0D%0A%09%7D%0D%0A
 %7D%0D%0A

Enable extract subdiagram refactoring on startup