Browse Source

Changed element Type access to Registry

Andreas Mülder 14 years ago
parent
commit
97180df679

+ 10 - 10
plugins/org.yakindu.sct.statechart.diagram/plugin.xml

@@ -224,7 +224,7 @@
             </entry>
              <entry
                   description="Creates a state"
-                  id="State"
+                  id="org.yakindu.sct.statechart.diagram.State"
                   kind="tool"
                   label="State"
                   large_icon="icons/obj16/state_16x16.png"
@@ -238,7 +238,7 @@
             </entry>
              <entry
                    description="Creates a region"
-                   id="Region"
+                   id="org.yakindu.sct.statechart.diagram.Region"
                    kind="tool"
                    label="Region"
                    large_icon="icons/obj16/region_16x16.png"
@@ -247,7 +247,7 @@
              </entry>
              <entry
                    description="Creates a transition"
-                   id="Transition"
+                   id="org.yakindu.sct.statechart.diagram.Transition"
                    kind="tool"
                    label="Transition"
                    large_icon="icons/obj16/transition_16x16.png"
@@ -256,7 +256,7 @@
              </entry>
              <entry
                    description="Creates a choice"
-                   id="Choice"
+                   id="org.yakindu.sct.statechart.diagram.Choice"
                    kind="tool"
                    label="Choice"
                    large_icon="icons/obj16/choice_16x16.png"
@@ -265,7 +265,7 @@
              </entry>
              <entry
                    description="Creates a junction"
-                   id="Junction"
+                   id="org.yakindu.sct.statechart.diagram.Junction"
                    kind="tool"
                    label="Junction"
                    large_icon="icons/obj16/junction_16x16.png"
@@ -274,7 +274,7 @@
              </entry>
              <entry
                    description="Creates an initial state"
-                   id="Entry"
+                   id="org.yakindu.sct.statechart.diagram.Entry"
                    kind="tool"
                    label="Initial State"
                    large_icon="icons/obj16/initial_state_16x16.png"
@@ -283,7 +283,7 @@
              </entry>
               <entry
                    description="Creates a shallow history"
-                   id="ShallowHistory"
+                   id="org.yakindu.sct.statechart.diagram.ShallowHistory"
                    kind="tool"
                    label="Shallow History"
                    large_icon="icons/obj16/shallow_history_16x16.png"
@@ -292,7 +292,7 @@
              </entry>
              <entry
                    description="Creates a deep history"
-                   id="DeepHistory"
+                   id="org.yakindu.sct.statechart.diagram.DeepHistory"
                    kind="tool"
                    label="Deep History"
                    large_icon="icons/obj16/deep_history_16x16.png"
@@ -301,7 +301,7 @@
              </entry>
              <entry
                    description="Creates a final state"
-                   id="FinalState"
+                   id="org.yakindu.sct.statechart.diagram.FinalState"
                    kind="tool"
                    label="Final State"
                    large_icon="icons/obj16/final_state_16x16.png"
@@ -310,7 +310,7 @@
              </entry>
                <entry
                    description="Creates an exit point"
-                   id="Exit"
+                   id="org.yakindu.sct.statechart.diagram.Exit"
                    kind="tool"
                    label="Exit Point"
                    large_icon="icons/obj16/exit_point_16x16.png"

+ 5 - 4
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/editor/StatechartDiagramPaletteFactory.java

@@ -14,23 +14,24 @@ import org.eclipse.gef.Tool;
 import org.eclipse.gmf.runtime.diagram.ui.services.palette.PaletteFactory;
 import org.eclipse.gmf.runtime.diagram.ui.tools.ConnectionCreationTool;
 import org.eclipse.gmf.runtime.diagram.ui.tools.CreationTool;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
 import org.eclipse.gmf.runtime.emf.type.core.IElementType;
 
 /**
  * 
- * @author muelder
+ * @author andreas muelder
  * 
  */
 public class StatechartDiagramPaletteFactory extends PaletteFactory.Adapter {
 
 	@Override
 	public Tool createTool(String toolId) {
-		IElementType elementType = StatechartElementTypes
-				.fromSemanticId(toolId);
+		IElementType elementType = ElementTypeRegistry.getInstance().getType(
+				toolId);
 		if (elementType == null)
 			throw new IllegalStateException("No Tool for toolId " + toolId
 					+ " found!");
-		if (toolId.equals("Transition")) {
+		if (toolId.equals(StatechartElementTypes.TRANSITION.getId())) {
 			return new ConnectionCreationTool(elementType);
 		} else
 			return new CreationTool(elementType);

+ 0 - 25
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/editor/StatechartElementTypes.java

@@ -10,8 +10,6 @@
  */
 package org.yakindu.sct.statechart.diagram.editor;
 
-import java.lang.reflect.Field;
-
 import org.eclipse.gmf.runtime.emf.type.core.AbstractElementTypeEnumerator;
 import org.eclipse.gmf.runtime.emf.type.core.IElementType;
 
@@ -24,10 +22,6 @@ import org.eclipse.gmf.runtime.emf.type.core.IElementType;
  */
 public final class StatechartElementTypes extends AbstractElementTypeEnumerator {
 
-	private StatechartElementTypes() {
-		// only static methods
-	}
-
 	/** Element Types **/
 	public static final IElementType STATECHART = getElementType("org.yakindu.sct.statechart.diagram.Statechart");
 	public static final IElementType REGION = getElementType("org.yakindu.sct.statechart.diagram.Region");
@@ -41,23 +35,4 @@ public final class StatechartElementTypes extends AbstractElementTypeEnumerator
 	public static final IElementType FINALSTATE = getElementType("org.yakindu.sct.statechart.diagram.FinalState");
 	public static final IElementType EXIT = getElementType("org.yakindu.sct.statechart.diagram.Exit");
 
-
-	/**
-	 * Helper method that returns the {@link IElementType} for a given semantic
-	 * id per naming convention.
-	 * 
-	 * @param semanticId
-	 *            the semantic id
-	 * @return the matching {@link IElementType}
-	 */
-	public static IElementType fromSemanticId(String semanticId) {
-		try {
-			Field field = StatechartElementTypes.class.getField(semanticId
-					.toUpperCase());
-			return (IElementType) field.get(StatechartElementTypes.class);
-		} catch (Exception e) {
-			throw new RuntimeException(
-					"No IElementType found for semanticHint " + semanticId);
-		}
-	}
 }

+ 9 - 3
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/editparts/EntryEditPart.java

@@ -11,11 +11,11 @@
 package org.yakindu.sct.statechart.diagram.editparts;
 
 import org.eclipse.draw2d.Ellipse;
-import org.eclipse.draw2d.IFigure;
 import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
 import org.eclipse.gmf.runtime.diagram.ui.handles.ConnectionHandle.HandleDirection;
+import org.eclipse.gmf.runtime.notation.Node;
 import org.eclipse.gmf.runtime.notation.View;
 import org.yakindu.model.sct.statechart.Entry;
 import org.yakindu.model.sct.statechart.StatechartPackage;
@@ -76,10 +76,16 @@ public class EntryEditPart extends EllipseFixedSizeShapeNodeEditPart {
 		// We have to update the primary shape when the entry kind changes
 		if (StatechartPackage.eINSTANCE.getEntry_Kind().equals(
 				notification.getFeature())) {
-			getFigure().remove((IFigure) getFigure().getChildren().get(0));
-			getFigure().add(getPrimaryShape());
+			// TODO: We have to remove the old figure, this does not work
+			// currently because the connections get broken then.
+			getNodeFigure().add(getPrimaryShape());
 		}
 		super.handleNotificationEvent(notification);
 	}
 
+	@Override
+	public Node getNotationView() {
+		return (Node) super.getNotationView();
+	}
+
 }

+ 14 - 7
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/policies/CompartmentCreationEditPolicy.java

@@ -14,6 +14,7 @@ import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.gef.commands.Command;
 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
 import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
 import org.eclipse.gmf.runtime.emf.type.core.IElementType;
 import org.yakindu.sct.statechart.diagram.editor.StatechartElementTypes;
 
@@ -27,15 +28,21 @@ import com.google.common.collect.ImmutableList;
  */
 public class CompartmentCreationEditPolicy extends CreationEditPolicy {
 
-	private static final ImmutableList<IElementType> fixedSizeElements = ImmutableList.of(
-			StatechartElementTypes.CHOICE, StatechartElementTypes.JUNCTION, StatechartElementTypes.ENTRY,
-			StatechartElementTypes.FINALSTATE, StatechartElementTypes.DEEPHISTORY,
-			StatechartElementTypes.SHALLOWHISTORY, StatechartElementTypes.EXIT);
+	private static final ImmutableList<IElementType> fixedSizeElements = ImmutableList
+			.of(StatechartElementTypes.CHOICE, StatechartElementTypes.JUNCTION,
+					StatechartElementTypes.ENTRY,
+					StatechartElementTypes.FINALSTATE,
+					StatechartElementTypes.DEEPHISTORY,
+					StatechartElementTypes.SHALLOWHISTORY,
+					StatechartElementTypes.EXIT);
 
 	@Override
-	protected Command getCreateElementAndViewCommand(CreateViewAndElementRequest request) {
-		String semanticHint = request.getViewAndElementDescriptor().getSemanticHint();
-		IElementType elementType = StatechartElementTypes.fromSemanticId(semanticHint);
+	protected Command getCreateElementAndViewCommand(
+			CreateViewAndElementRequest request) {
+		String semanticHint = request.getViewAndElementDescriptor()
+				.getSemanticHint();
+		IElementType elementType = ElementTypeRegistry.getInstance().getType(
+				semanticHint);
 		if (fixedSizeElements.contains(elementType))
 			request.setSize(new Dimension(-1, -1));
 		return super.getCreateElementAndViewCommand(request);

+ 8 - 0
plugins/org.yakindu.sct.statechart.diagram/src/org/yakindu/sct/statechart/diagram/propertysheets/SheetLabelProvider.java

@@ -35,6 +35,10 @@ public class SheetLabelProvider extends BaseLabelProvider implements
 		if (element instanceof IGraphicalEditPart) {
 			EObject semanticElement = ((IGraphicalEditPart) element)
 					.resolveSemanticElement();
+			
+			if(semanticElement == null)
+				return null;
+			
 			IElementType elementType = ElementTypeRegistry.getInstance()
 					.getElementType(semanticElement);
 			StringBuilder builder = new StringBuilder();
@@ -54,6 +58,10 @@ public class SheetLabelProvider extends BaseLabelProvider implements
 		if (element instanceof IGraphicalEditPart) {
 			EObject semanticElement = ((IGraphicalEditPart) element)
 					.resolveSemanticElement();
+			
+			if(semanticElement == null)
+				return null;
+			
 			IElementType elementType = ElementTypeRegistry.getInstance()
 					.getElementType(semanticElement);
 			Image image = DiagramActivator.getDefault().getImageRegistry()