Browse Source

Changed Access to Named Styled for GMFs Notation View because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=398976

Andreas Mülder 12 years ago
parent
commit
e15b4b7a5c

+ 3 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/commands/ToggleShowDocumentationCommand.java

@@ -28,6 +28,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.ui.handlers.HandlerUtil;
 import org.yakindu.base.base.BasePackage;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
+import org.yakindu.sct.ui.editor.utils.GMFNotationUtil;
 
 /**
  * 
@@ -40,8 +41,8 @@ public class ToggleShowDocumentationCommand extends AbstractHandler {
 
 	public Object execute(ExecutionEvent event) throws ExecutionException {
 		View view = unwrap(HandlerUtil.getCurrentSelection(event));
-		StringValueStyle style = (StringValueStyle) view.getNamedStyle(
-				NotationPackage.Literals.STRING_VALUE_STYLE, FEATURE_TO_SHOW);
+		StringValueStyle style = GMFNotationUtil.getStringValueStyle(view,
+				FEATURE_TO_SHOW);
 		if (style == null) {
 			style = createInitialStyle(view);
 		}

+ 3 - 4
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/commands/ToggleSubRegionLayoutCommand.java

@@ -28,13 +28,13 @@ import org.eclipse.gmf.runtime.common.core.command.CommandResult;
 import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
 import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
 import org.eclipse.gmf.runtime.notation.NotationFactory;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
 import org.eclipse.gmf.runtime.notation.View;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.ui.handlers.HandlerUtil;
 import org.yakindu.sct.ui.editor.editparts.StateEditPart;
 import org.yakindu.sct.ui.editor.factories.StateViewFactory;
+import org.yakindu.sct.ui.editor.utils.GMFNotationUtil;
 
 /**
  * 
@@ -108,9 +108,8 @@ public class ToggleSubRegionLayoutCommand extends AbstractHandler {
 		@SuppressWarnings("unchecked")
 		protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
 				IAdaptable info) throws ExecutionException {
-			BooleanValueStyle style = (BooleanValueStyle) view.getNamedStyle(
-					NotationPackage.Literals.BOOLEAN_VALUE_STYLE,
-					StateViewFactory.ALIGNMENT_ORIENTATION);
+			BooleanValueStyle style = GMFNotationUtil.getBooleanValueStyle(
+					view, StateViewFactory.ALIGNMENT_ORIENTATION);
 			if (style == null) {
 				style = NotationFactory.eINSTANCE.createBooleanValueStyle();
 				style.setBooleanValue(true);

+ 4 - 5
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/StateFigureCompartmentEditPart.java

@@ -25,6 +25,7 @@ import org.yakindu.sct.model.sgraph.SGraphPackage;
 import org.yakindu.sct.ui.editor.factories.StateViewFactory;
 import org.yakindu.sct.ui.editor.policies.StateCompartmentCanonicalEditPolicy;
 import org.yakindu.sct.ui.editor.policies.StateCompartmentCreationEditPolicy;
+import org.yakindu.sct.ui.editor.utils.GMFNotationUtil;
 
 import de.itemis.gmf.runtime.commons.editpolicies.CompartmentLayoutEditPolicy;
 
@@ -98,11 +99,9 @@ public class StateFigureCompartmentEditPart extends
 	}
 
 	protected boolean getAlignment() {
-		BooleanValueStyle style = (BooleanValueStyle) getParent()
-				.getNotationView().getNamedStyle(
-						NotationPackage.Literals.BOOLEAN_VALUE_STYLE,
-						StateViewFactory.ALIGNMENT_ORIENTATION);
-
+		BooleanValueStyle style = GMFNotationUtil.getBooleanValueStyle(
+				getParent().getNotationView(),
+				StateViewFactory.ALIGNMENT_ORIENTATION);
 		return (style != null) ? style.isBooleanValue() : true;
 	}
 

+ 3 - 4
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/StateTextCompartmentExpressionEditPart.java

@@ -22,6 +22,7 @@ import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.ui.editor.commands.ToggleShowDocumentationCommand;
 import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions.SemanticTarget;
 import org.yakindu.sct.ui.editor.policies.ContextSensitiveHelpPolicy;
+import org.yakindu.sct.ui.editor.utils.GMFNotationUtil;
 import org.yakindu.sct.ui.editor.utils.HelpContextIds;
 
 import de.itemis.xtext.utils.gmf.directedit.IXtextAwareEditPart;
@@ -109,10 +110,8 @@ public class StateTextCompartmentExpressionEditPart extends
 	}
 
 	private StringValueStyle getFeatureToShowStyle() {
-		StringValueStyle style = (StringValueStyle) getParentStateView()
-				.getNamedStyle(NotationPackage.Literals.STRING_VALUE_STYLE,
-						ToggleShowDocumentationCommand.FEATURE_TO_SHOW);
-		return style;
+		return GMFNotationUtil.getStringValueStyle(getParentStateView(),
+				ToggleShowDocumentationCommand.FEATURE_TO_SHOW);
 	}
 
 	@Override

+ 4 - 5
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/StatechartTextExpressionEditPart.java

@@ -24,6 +24,7 @@ import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.ui.editor.commands.ToggleShowDocumentationCommand;
 import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions.SemanticTarget;
 import org.yakindu.sct.ui.editor.policies.ContextSensitiveHelpPolicy;
+import org.yakindu.sct.ui.editor.utils.GMFNotationUtil;
 import org.yakindu.sct.ui.editor.utils.HelpContextIds;
 
 /**
@@ -112,11 +113,9 @@ public class StatechartTextExpressionEditPart extends
 			super.updateLabelText();
 	}
 
-	private StringValueStyle getFeatureToShowStyle() {
-		StringValueStyle style = (StringValueStyle) getParentStateView()
-				.getNamedStyle(NotationPackage.Literals.STRING_VALUE_STYLE,
-						ToggleShowDocumentationCommand.FEATURE_TO_SHOW);
-		return style;
+	protected StringValueStyle getFeatureToShowStyle() {
+		return GMFNotationUtil.getStringValueStyle(getParentStateView(),
+				ToggleShowDocumentationCommand.FEATURE_TO_SHOW);
 	}
 
 	@Override

+ 3 - 4
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/TransitionExpressionEditPart.java

@@ -23,6 +23,7 @@ import org.yakindu.sct.ui.editor.commands.ToggleShowDocumentationCommand;
 import org.yakindu.sct.ui.editor.extensions.ExpressionLanguageProviderExtensions.SemanticTarget;
 import org.yakindu.sct.ui.editor.policies.ContextSensitiveHelpPolicy;
 import org.yakindu.sct.ui.editor.policies.TransitionExpressionComponentEditPolicy;
+import org.yakindu.sct.ui.editor.utils.GMFNotationUtil;
 import org.yakindu.sct.ui.editor.utils.HelpContextIds;
 
 import de.itemis.xtext.utils.gmf.directedit.IXtextAwareEditPart;
@@ -108,10 +109,8 @@ public class TransitionExpressionEditPart extends
 	}
 
 	private StringValueStyle getFeatureToShowStyle() {
-		StringValueStyle style = (StringValueStyle) getParentView()
-				.getNamedStyle(NotationPackage.Literals.STRING_VALUE_STYLE,
-						ToggleShowDocumentationCommand.FEATURE_TO_SHOW);
-		return style;
+		return GMFNotationUtil.getStringValueStyle(getParentView(),
+				ToggleShowDocumentationCommand.FEATURE_TO_SHOW);
 	}
 
 	@Override

+ 52 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/utils/GMFNotationUtil.java

@@ -0,0 +1,52 @@
+/**
+ * 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.ui.editor.utils;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
+import org.eclipse.gmf.runtime.notation.NamedStyle;
+import org.eclipse.gmf.runtime.notation.StringValueStyle;
+import org.eclipse.gmf.runtime.notation.Style;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.gmf.runtime.notation.impl.ViewImpl;
+
+/**
+ * Should be used instead of {@link ViewImpl}
+ * {@link #getNamedStyle(View, Class, String)} because of
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=398976
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class GMFNotationUtil {
+
+	@SuppressWarnings("unchecked")
+	public static <T extends NamedStyle> T getNamedStyle(View view,
+			Class<T> type, String name) {
+		EList<Style> styles = view.getStyles();
+		for (Style style : styles) {
+			if (type.isAssignableFrom(style.getClass())) {
+				if (name.equals(((NamedStyle) style).getName()))
+					return (T) style;
+			}
+		}
+		return null;
+	}
+
+	public static BooleanValueStyle getBooleanValueStyle(View view, String name) {
+		return getNamedStyle(view, BooleanValueStyle.class, name);
+	}
+
+	public static StringValueStyle getStringValueStyle(View view, String name) {
+		return getNamedStyle(view, StringValueStyle.class, name);
+	}
+
+}