Selaa lähdekoodia

Visualisation order of regions in states do not match model order (YAKHMI-444)

markus.muehlbrandt@itemis.de 14 vuotta sitten
vanhempi
commit
aab1906f5b

+ 97 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/commands/CreateRegionCommand.java

@@ -0,0 +1,97 @@
+/**
+ * Copyright (c) 2011 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.commands;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.util.FeatureMapUtil;
+import org.eclipse.gmf.runtime.emf.core.resources.IResourceHelper;
+import org.eclipse.gmf.runtime.emf.core.util.Util;
+import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.yakindu.sct.ui.editor.DiagramActivator;
+
+import de.itemis.gmf.runtime.commons.editpolicies.CompartmentLayoutEditPolicy.RequestParameterKeys;
+
+/**
+ * 
+ * @author muehlbrandt
+ * 
+ */
+
+public class CreateRegionCommand extends CreateElementCommand {
+
+	public CreateRegionCommand(CreateElementRequest request) {
+		super(request);
+	}
+
+	@Override
+	protected EObject doDefaultElementCreation() {
+		if (getCreateRequest().getParameters().get(
+				RequestParameterKeys.RegionFeedbackIndex) != null) {
+			int regionFeedbackIndex = (Integer) getCreateRequest()
+					.getParameters().get(
+							RequestParameterKeys.RegionFeedbackIndex);
+			// -1 means add -> use original behavior
+			if (regionFeedbackIndex > -1) {
+				return doDefaultElementCreation(regionFeedbackIndex);
+			}
+		}
+		return super.doDefaultElementCreation();
+	}
+
+	@SuppressWarnings({ "rawtypes", "unchecked" })
+	protected EObject doDefaultElementCreation(int index) {
+		EObject result = null;
+		EReference reference = getContainmentFeature();
+		EClass eClass = getElementType().getEClass();
+
+		if (reference != null) {
+			EObject container = getElementToEdit();
+
+			if (container != null) {
+
+				IResourceHelper helper = Util.getHelper(container.eResource());
+
+				if (helper != null) {
+
+					result = helper.create(eClass);
+
+				} else {
+					result = eClass.getEPackage().getEFactoryInstance()
+							.create(eClass);
+				}
+
+				if (FeatureMapUtil.isMany(container, reference)) {
+					((List) container.eGet(reference)).add(index, result);
+				} else {
+					container.eSet(reference, result);
+				}
+
+				return result;
+			}
+		}
+
+		IStatus status = (result != null) ? Status.OK_STATUS : new Status(
+				Status.ERROR, DiagramActivator.PLUGIN_ID,
+				"CreateRegionCommand: No Region created: "
+						+ getElementType().getDisplayName());
+
+		setDefaultElementCreationStatus(status);
+
+		return result;
+	}
+}

+ 13 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/edithelper/StateEditHelper.java

@@ -10,9 +10,11 @@
  */
 package org.yakindu.sct.ui.editor.edithelper;
 
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
 import org.eclipse.gmf.runtime.common.core.command.ICommand;
 import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
 import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
 import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.swt.widgets.Shell;
@@ -21,9 +23,12 @@ import org.yakindu.sct.model.sgraph.Region;
 import org.yakindu.sct.model.sgraph.SGraphFactory;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
 import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.ui.editor.commands.CreateRegionCommand;
 import org.yakindu.sct.ui.editor.dialogs.SelectSubmachineDialog;
 import org.yakindu.sct.ui.editor.editor.StatechartElementTypes;
 
+import de.itemis.gmf.runtime.commons.editpolicies.CompartmentLayoutEditPolicy.RequestParameterKeys;
+
 /**
  * 
  * @author andreas muelder - Initial contribution and API
@@ -50,6 +55,14 @@ public class StateEditHelper extends VertexEditHelper {
 		return null;
 	}
 
+	@Override
+	protected ICommand getCreateCommand(CreateElementRequest req) {
+		if (req.getElementType() == StatechartElementTypes.REGION) {
+			return new CreateRegionCommand(req);
+		}
+		return super.getCreateCommand(req);
+	}
+
 	private ICommand createSubmachineStateCommand(ConfigureRequest req) {
 		SelectSubmachineDialog dialog = new SelectSubmachineDialog(new Shell(),
 				req.getElementToConfigure().eResource());