Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2015-02-13 05:41:24 -0500
committerAnsgar Radermacher2015-02-13 05:44:00 -0500
commit88586d4986afc80be8ec4cec06e51dd3f69263b9 (patch)
tree50513c311f6397148490e8e7433001aab7672684
parent070effdb29bb293adb9971aabaf3fdb9d51691ac (diff)
downloadorg.eclipse.papyrus-88586d4986afc80be8ec4cec06e51dd3f69263b9.tar.gz
org.eclipse.papyrus-88586d4986afc80be8ec4cec06e51dd3f69263b9.tar.xz
org.eclipse.papyrus-88586d4986afc80be8ec4cec06e51dd3f69263b9.zip
399864 - [CDT/StateMachine] Papyrus shall enable to see code on transitions
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/edit/part/CustomTransitionGuardEditPart.java110
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/parsers/TransitionPropertiesParser.java51
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/CSSOptionsConstants.java32
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/CustomTransitionPreferencePage.java4
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/PreferenceConstants.java8
5 files changed, 87 insertions, 118 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/edit/part/CustomTransitionGuardEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/edit/part/CustomTransitionGuardEditPart.java
index b6fcadfb4f2..1efdd04c625 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/edit/part/CustomTransitionGuardEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/edit/part/CustomTransitionGuardEditPart.java
@@ -14,7 +14,9 @@ package org.eclipse.papyrus.uml.diagram.statemachine.custom.edit.part;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure;
import org.eclipse.papyrus.uml.diagram.statemachine.edit.parts.TransitionGuardEditPart;
@@ -50,97 +52,19 @@ public class CustomTransitionGuardEditPart extends TransitionGuardEditPart {
}
}
- /**
- * The following code has been commented, since the custom class was not in use (CustomUMLEditPartFactory
- * returned generated TransitionGuardEditPart instead of this one) before adding setLabelTextHelper above.
- *
- *
- * public String getInformationFromTransition(Transition transition) {
- * String textToEdit = "";
- *
- * // Triggers
- * if(!transition.getTriggers().isEmpty()) {
- * boolean isFirstTrigger = true;
- * for(Trigger t : transition.getTriggers()) {
- * if(!isFirstTrigger)
- * textToEdit = textToEdit + ", ";
- * else
- * isFirstTrigger = false;
- * Event e = t.getEvent();
- * if(e instanceof CallEvent) {
- * if(((CallEvent)e).getOperation() != null)
- * textToEdit = textToEdit + ((CallEvent)e).getOperation().getName();
- * else
- * textToEdit = textToEdit + ((CallEvent)e).getName();
- *
- * } else if(e instanceof SignalEvent) {
- * if(((SignalEvent)e).getSignal() != null)
- * textToEdit = textToEdit + ((SignalEvent)e).getSignal().getName();
- * else
- * textToEdit = textToEdit + ((SignalEvent)e).getName();
- * } else if(e instanceof ChangeEvent) {
- *
- * textToEdit = textToEdit + "when " + "\"" + retrieveBody((OpaqueExpression)((ChangeEvent)e).getChangeExpression(), "Natural language") + "\"";
- * } else if(e instanceof TimeEvent) {
- * String absRelPrefix = "" + (((TimeEvent)e).isRelative() ? "after " : "at ");
- * textToEdit = textToEdit + absRelPrefix + "\"" + retrieveBody((OpaqueExpression)((TimeEvent)e).getWhen().getExpr(), "Natural language") + "\"";
- * } else { // any receive event
- * textToEdit = textToEdit + "all";
- * }
- * }
- * }
- *
- * // Guard
- * if(transition.getGuard() != null && transition.getGuard().getSpecification() != null) {
- * textToEdit = textToEdit + " [" + "\"" + retrieveBody((OpaqueExpression)transition.getGuard().getSpecification(), "Natural language") + "\"" +
- * "]";
- * }
- *
- * if(transition.getEffect() != null) {
- * textToEdit = textToEdit + " / ";
- * String behaviorKind = "";
- * behaviorKind = behaviorKind + ((behaviorKind.equals("") && (transition.getEffect() instanceof Activity)) ? "Activity " : "");
- * behaviorKind = behaviorKind + ((behaviorKind.equals("") && (transition.getEffect() instanceof StateMachine)) ? "StateMachine " : "");
- * behaviorKind = behaviorKind + ((behaviorKind.equals("") && (transition.getEffect() instanceof OpaqueBehavior)) ? "OpaqueBehavior " : "");
- * textToEdit = textToEdit + behaviorKind + " " + transition.getEffect().getName();
- * }
- *
- * return textToEdit;
- * }
- *
- * @Override
- * protected void handleNotificationEvent(Notification notification) {
- * // TODO Auto-generated method stub
- * super.handleNotificationEvent(notification);
- *
- *
- * refreshVisuals();
- * }
- * @Override
- * protected void refreshVisuals() {
- * // TODO Auto-generated method stub
- * super.refreshVisuals();
- *
- * WrappingLabel transitionGuardLabel = (WrappingLabel)getFigure();
- * Transition transition = (Transition)((View)getModel()).getElement();
- * transitionGuardLabel.setText(getInformationFromTransition(transition));
- * }
- *
- * private String retrieveBody(OpaqueExpression exp, String languageName) {
- * String body = "";
- * if(exp == null)
- * return body;
- * int index = 0;
- * for(String _languageName : exp.getLanguages()) {
- * if(_languageName.equals(languageName)) {
- * if(index < exp.getBodies().size())
- * return exp.getBodies().get(index);
- * else
- * return "";
- * }
- * index++;
- * }
- * return body;
- * }
- */
+
+ @Override
+ protected String getLabelText() {
+ String text = null;
+ EObject parserElement = getParserElement();
+ if (parserElement != null && getParser() != null) {
+ text = getParser().getPrintString(
+ new EObjectAdapter((View) getModel()),
+ getParserOptions().intValue());
+ }
+ if (text == null || text.length() == 0) {
+ text = super.getLabelText();
+ }
+ return text;
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/parsers/TransitionPropertiesParser.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/parsers/TransitionPropertiesParser.java
index 1c77b28baca..1bb077c2889 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/parsers/TransitionPropertiesParser.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/parsers/TransitionPropertiesParser.java
@@ -33,11 +33,14 @@ import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
+import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.uml.diagram.statemachine.custom.preferences.CSSOptionsConstants;
import org.eclipse.papyrus.uml.diagram.statemachine.custom.preferences.PreferenceConstants;
import org.eclipse.papyrus.uml.diagram.statemachine.part.UMLDiagramEditorPlugin;
import org.eclipse.papyrus.uml.tools.utils.OpaqueBehaviorUtil;
@@ -155,19 +158,24 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
*/
protected String getValueString(IAdaptable element, int flags) {
Object obj = element.getAdapter(EObject.class);
+ View view = null;
+ if (obj instanceof View) {
+ view = (View) obj;
+ obj = view.getElement();
+ }
if (obj instanceof Transition) {
Transition trans = (Transition) obj;
StringBuilder result = new StringBuilder();
- String textForTrigger = getTextForTrigger(trans);
+ String textForTrigger = getTextForTrigger(view, trans);
if (textForTrigger != null && !EMPTY_STRING.equals(textForTrigger)) {
result.append(textForTrigger);
}
result.append(getTextForGuard(trans));
- String textForEffect = getTextForEffect(trans);
+ String textForEffect = getTextForEffect(view, trans);
if (textForEffect != null && !EMPTY_STRING.equals(textForEffect)) {
if (textForEffect != null && !EMPTY_STRING.equals(textForEffect)) {
result.append("/"); //$NON-NLS-1$
- if (lineBreakBeforeEffect()) {
+ if (lineBreakBeforeEffect(view)) {
result.append("\n"); //$NON-NLS-1$
}
result.append(textForEffect);
@@ -201,7 +209,7 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
* @param trans
* @return
*/
- protected String getTextForEffect(Transition trans) {
+ protected String getTextForEffect(View view, Transition trans) {
StringBuilder result = new StringBuilder();
Behavior effect = trans.getEffect();
if (effect != null) {
@@ -210,7 +218,7 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
OpaqueBehavior ob = (OpaqueBehavior) effect;
if (ob.getBodies().size() > 0) {
// return body of behavior (only handle case of a single body)
- result.append(retrieveBody(ob));
+ result.append(retrieveBody(view, ob));
return result.toString();
}
}
@@ -227,7 +235,7 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
* @param trans
* @return
*/
- protected String getTextForTrigger(Transition trans) {
+ protected String getTextForTrigger(View view, Transition trans) {
StringBuilder result = new StringBuilder();
boolean isFirstTrigger = true;
for (Trigger t : trans.getTriggers()) {
@@ -242,7 +250,7 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
Operation op = ((CallEvent) e).getOperation();
if (op != null) {
result.append(op.getName());
- if ((op.getOwnedParameters().size() > 0) && displayParamDots()) {
+ if ((op.getOwnedParameters().size() > 0) && displayParamDots(view)) {
result.append(PARAM_DOTS);
}
} else {
@@ -252,7 +260,7 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
Signal signal = ((SignalEvent) e).getSignal();
if (signal != null) {
result.append(signal.getName());
- if ((signal.getAttributes().size() > 0) && displayParamDots()) {
+ if ((signal.getAttributes().size() > 0) && displayParamDots(view)) {
result.append(PARAM_DOTS);
}
} else {
@@ -262,7 +270,7 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
ValueSpecification vs = ((ChangeEvent) e).getChangeExpression();
String value;
if (vs instanceof OpaqueExpression) {
- value = retrieveBody((OpaqueExpression) vs);
+ value = retrieveBody(view, (OpaqueExpression) vs);
}
else {
value = vs.stringValue();
@@ -278,7 +286,7 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
if (te != null) {
ValueSpecification vs = te.getExpr();
if (vs instanceof OpaqueExpression) {
- value = retrieveBody((OpaqueExpression) vs);
+ value = retrieveBody(view, (OpaqueExpression) vs);
}
else {
value = vs.stringValue();
@@ -357,12 +365,12 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
* an opaque expression
* @return the associated body
*/
- public static String retrieveBody(OpaqueExpression exp) {
+ public static String retrieveBody(View view, OpaqueExpression exp) {
String body = OpaqueExpressionUtil.getBodyForLanguage(exp, "Natural Language"); //$NON-NLS-1$
if (body.equals(EMPTY_STRING)) {
body = OpaqueExpressionUtil.getBodyForLanguage(exp, null);
}
- return cutBodyString(body);
+ return cutBodyString(view, body);
}
/**
@@ -373,12 +381,12 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
* an opaque expression
* @return the associated body
*/
- public static String retrieveBody(OpaqueBehavior ob) {
+ public static String retrieveBody(View view, OpaqueBehavior ob) {
String body = OpaqueBehaviorUtil.getBody(ob, "Natural Language"); //$NON-NLS-1$
if (body.equals(EMPTY_STRING) && ob.getBodies().size() > 0) {
body = ob.getBodies().get(0);
}
- return cutBodyString(body);
+ return cutBodyString(view, body);
}
/**
@@ -388,9 +396,10 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
* the body string
* @return
*/
- public static String cutBodyString(String body) {
+ public static String cutBodyString(View view, String body) {
IPreferenceStore preferenceStore = UMLDiagramEditorPlugin.getInstance().getPreferenceStore();
- int cutLength = preferenceStore.getInt(PreferenceConstants.BODY_CUT_LENGTH);
+ int prefCutLength = preferenceStore.getInt(PreferenceConstants.BODY_CUT_LENGTH);
+ int cutLength = NotationUtils.getIntValue(view, CSSOptionsConstants.BODY_CUT_LENGTH, prefCutLength);
if (cutLength == 0) {
return DOTS;
}
@@ -425,17 +434,19 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser {
*
* @return true, if the presence of parameters should be indicated by (...)
*/
- public static boolean displayParamDots() {
+ public static boolean displayParamDots(View view) {
IPreferenceStore preferenceStore = UMLDiagramEditorPlugin.getInstance().getPreferenceStore();
- return preferenceStore.getBoolean(PreferenceConstants.INDICATE_PARAMETERS);
+ boolean prefValue = preferenceStore.getBoolean(PreferenceConstants.INDICATE_PARAMETERS);
+ return NotationUtils.getBooleanValue(view, CSSOptionsConstants.INDICATE_PARAMETERS, prefValue);
}
/**
*
* @return true, if the presence of parameters should be indicated by (...)
*/
- public static boolean lineBreakBeforeEffect() {
+ public static boolean lineBreakBeforeEffect(View view) {
IPreferenceStore preferenceStore = UMLDiagramEditorPlugin.getInstance().getPreferenceStore();
- return preferenceStore.getBoolean(PreferenceConstants.LINEBREAK_BEFORE_EFFECT);
+ boolean prefValue = preferenceStore.getBoolean(PreferenceConstants.LINEBREAK_BEFORE_EFFECT);
+ return NotationUtils.getBooleanValue(view, CSSOptionsConstants.LINEBREAK_BEFORE_EFFECT, prefValue);
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/CSSOptionsConstants.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/CSSOptionsConstants.java
new file mode 100644
index 00000000000..7054907037b
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/CSSOptionsConstants.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ */
+package org.eclipse.papyrus.uml.diagram.statemachine.custom.preferences;
+
+/**
+ * Values to use in CSS styles for transition options (how to show code attached to a transition)
+ */
+public class CSSOptionsConstants {
+ /**
+ * integer: Maximum length of displayed bodies.
+ */
+ public final static String BODY_CUT_LENGTH = "bodyCutLength"; //$NON-NLS-1$
+
+ /**
+ * Boolean: if true, indicate presence of parameters (attributes) by adding (...) to call or signal event.
+ */
+ public final static String INDICATE_PARAMETERS = "indicateParameters"; //$NON-NLS-1$
+
+ /**
+ * Boolean: if true, add a line-break to the transition label before the effect
+ */
+ public final static String LINEBREAK_BEFORE_EFFECT = "lineBreakBeforeEffect"; //$NON-NLS-1$
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/CustomTransitionPreferencePage.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/CustomTransitionPreferencePage.java
index f9021da0a1d..a08f363d917 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/CustomTransitionPreferencePage.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/CustomTransitionPreferencePage.java
@@ -15,7 +15,9 @@ public class CustomTransitionPreferencePage extends FieldEditorPreferencePage
public CustomTransitionPreferencePage() {
super(GRID);
setPreferenceStore(UMLDiagramEditorPlugin.getInstance().getPreferenceStore());
- setDescription("This preference page allows to customize label appearance on transitions");
+ setDescription(
+ "This preference page allows to customize label appearance on transitions. " + //$NON-NLS-1$
+ "Please note that per diagram or element settings can be done via CSS."); //$NON-NLS-1$
}
boolean updatePending;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/PreferenceConstants.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/PreferenceConstants.java
index d204b0192f0..68b8c5a01c6 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/PreferenceConstants.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/preferences/PreferenceConstants.java
@@ -12,21 +12,21 @@
package org.eclipse.papyrus.uml.diagram.statemachine.custom.preferences;
/**
- *
+ * Constants for Transition preferences (use same constants as for CSS options)
*/
public class PreferenceConstants {
/**
* integer: Maximum length of displayed bodies.
*/
- public final static String BODY_CUT_LENGTH = "bodyCutLength"; //$NON-NLS-1$
+ public final static String BODY_CUT_LENGTH = CSSOptionsConstants.BODY_CUT_LENGTH;
/**
* Boolean: if true, indicate presence of parameters (attributes) by adding (...) to call or signal event.
*/
- public final static String INDICATE_PARAMETERS = "indicateParameters"; //$NON-NLS-1$
+ public final static String INDICATE_PARAMETERS = CSSOptionsConstants.INDICATE_PARAMETERS;
/**
* Boolean: if true, add a line-break to the transition label before the effect
*/
- public final static String LINEBREAK_BEFORE_EFFECT = "lineBreakBeforeEffect"; //$NON-NLS-1$
+ public final static String LINEBREAK_BEFORE_EFFECT = CSSOptionsConstants.LINEBREAK_BEFORE_EFFECT;
}

Back to the top