diff options
author | aradermache | 2012-01-30 13:58:08 +0000 |
---|---|---|
committer | aradermache | 2012-01-30 13:58:08 +0000 |
commit | bc6fb86bbce26fb1cda1df03896273a0dc28e149 (patch) | |
tree | 5997e212d778b1951944dfd14bdb0073acac2547 | |
parent | 513bb0b01bcb2aa24ee3a8a32e29e46d48ac59d1 (diff) | |
download | org.eclipse.papyrus-bc6fb86bbce26fb1cda1df03896273a0dc28e149.tar.gz org.eclipse.papyrus-bc6fb86bbce26fb1cda1df03896273a0dc28e149.tar.xz org.eclipse.papyrus-bc6fb86bbce26fb1cda1df03896273a0dc28e149.zip |
Fix for bug 369305
3 files changed, 160 insertions, 99 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomTransitionGuardEditPart.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomTransitionGuardEditPart.java index 2202366dab5..7c7d68dcce1 100644 --- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomTransitionGuardEditPart.java +++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/edit/part/CustomTransitionGuardEditPart.java @@ -1,20 +1,26 @@ +/***************************************************************************** + * Copyright (c) 2010-2012 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: + * + * Ansgar Radermacher (bug 369305) + * + *****************************************************************************/ + package org.eclipse.papyrus.diagram.statemachine.custom.edit.part; -import org.eclipse.emf.common.notify.Notification; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.diagram.common.figure.node.ILabelFigure; import org.eclipse.papyrus.diagram.statemachine.edit.parts.TransitionGuardEditPart; -import org.eclipse.uml2.uml.Activity; -import org.eclipse.uml2.uml.CallEvent; -import org.eclipse.uml2.uml.ChangeEvent; -import org.eclipse.uml2.uml.Event; -import org.eclipse.uml2.uml.OpaqueBehavior; -import org.eclipse.uml2.uml.OpaqueExpression; -import org.eclipse.uml2.uml.SignalEvent; -import org.eclipse.uml2.uml.StateMachine; -import org.eclipse.uml2.uml.TimeEvent; -import org.eclipse.uml2.uml.Transition; -import org.eclipse.uml2.uml.Trigger; public class CustomTransitionGuardEditPart extends TransitionGuardEditPart { @@ -24,92 +30,121 @@ public class CustomTransitionGuardEditPart extends TransitionGuardEditPart { // TODO Auto-generated constructor stub } - 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(); - } - + /** + * Label should be capable of wrapping, i.e. of displaying text in multiple lines + * which is in particular required when the code of an operation is shown instead of the operations name + * [see bug 369305] + * + * @see org.eclipse.papyrus.diagram.statemachine.edit.parts.TransitionGuardEditPart#setLabelTextHelper(org.eclipse.draw2d.IFigure, + * java.lang.String) + * + * @param figure + * @param text + */ @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++; + protected void setLabelTextHelper(IFigure figure, String text) { + if(figure instanceof WrappingLabel) { + ((WrappingLabel)figure).setText(text); + // [addition for bug 369305] + ((WrappingLabel)figure).setTextWrap(true); + } else if(figure instanceof ILabelFigure) { + ((ILabelFigure)figure).setText(text); + } else { + ((Label)figure).setText(text); } - return body; } + /** + * 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; + * } + */ } diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/factory/CustomUMLEditPartFactory.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/factory/CustomUMLEditPartFactory.java index bf60342c658..3ec28043fd1 100644 --- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/factory/CustomUMLEditPartFactory.java +++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/factory/CustomUMLEditPartFactory.java @@ -1,3 +1,19 @@ +/***************************************************************************** + * Copyright (c) 2010-2012 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: + * + * David Servat + * Ansgar Radermacher (bug 369305) + * + *****************************************************************************/ + package org.eclipse.papyrus.diagram.statemachine.custom.factory; import org.eclipse.gef.EditPart; @@ -13,6 +29,7 @@ import org.eclipse.papyrus.diagram.statemachine.custom.edit.part.CustomStateMach import org.eclipse.papyrus.diagram.statemachine.custom.edit.part.CustomStateMachineEditPart; import org.eclipse.papyrus.diagram.statemachine.custom.edit.part.CustomStateMachineNameEditPart; import org.eclipse.papyrus.diagram.statemachine.custom.edit.part.CustomStateNameEditPart; +import org.eclipse.papyrus.diagram.statemachine.custom.edit.part.CustomTransitionGuardEditPart; import org.eclipse.papyrus.diagram.statemachine.edit.parts.ConnectionPointReferenceNameEditPart; import org.eclipse.papyrus.diagram.statemachine.edit.parts.FinalStateEditPart; import org.eclipse.papyrus.diagram.statemachine.edit.parts.PackageEditPart; @@ -56,7 +73,7 @@ public class CustomUMLEditPartFactory extends UMLEditPartFactory { case StateCompartmentEditPart.VISUAL_ID: return new CustomStateCompartmentEditPart(view); case TransitionGuardEditPart.VISUAL_ID: - return new TransitionGuardEditPart(view); + return new CustomTransitionGuardEditPart(view); case ConnectionPointReferenceNameEditPart.VISUAL_ID: return new CustomConnectionPointReferenceNameEditPart(view); diff --git a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/parsers/TransitionPropertiesParser.java b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/parsers/TransitionPropertiesParser.java index 312f8aeeb17..3336f81a6be 100644 --- a/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/parsers/TransitionPropertiesParser.java +++ b/plugins/uml/org.eclipse.papyrus.diagram.statemachine/custom-src/org/eclipse/papyrus/diagram/statemachine/custom/parsers/TransitionPropertiesParser.java @@ -45,6 +45,7 @@ import org.eclipse.uml2.uml.Constraint; import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Event;
import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.OpaqueBehavior;
import org.eclipse.uml2.uml.OpaqueExpression;
import org.eclipse.uml2.uml.SignalEvent;
import org.eclipse.uml2.uml.TimeEvent;
@@ -152,7 +153,7 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser { result.append(getTextForGuard(trans));
String textForEffect = getTextForEffect(trans);
if(textForEffect != null && !EMPTY_STRING.equals(textForEffect)) {
- result.append("/ ").append(textForEffect); //$NON-NLS-1$
+ result.append("/\n").append(textForEffect); //$NON-NLS-1$
}
return result.toString();
}
@@ -187,8 +188,16 @@ public class TransitionPropertiesParser implements IParser, ISemanticParser { Behavior effect = trans.getEffect();
if(effect != null) {
EClass eClass = effect.eClass();
+ if(effect instanceof OpaqueBehavior) {
+ OpaqueBehavior ob = (OpaqueBehavior)effect;
+ if(ob.getBodies().size() > 0) {
+ // return body of behavior (only handle case of a single body)
+ result.append(ob.getBodies().get(0));
+ return result.toString();
+ }
+ }
if(eClass != null) {
- result.append(eClass.getName()).append(" :").append(effect.getName()); //$NON-NLS-1$
+ result.append(eClass.getName()).append(": ").append(effect.getName()); //$NON-NLS-1$
}
}
return result.toString();
|