Skip to content

Commit

Permalink
#251: messages labels
Browse files Browse the repository at this point in the history
- extend add/remove semantic listeners to get notifications on model
changes required for label updates
- small NPE coming from reorient message update

Change-Id: I31b346b998ca52014cd34966bda1a13a4a67b6a2
Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
  • Loading branch information
rschnekenbu committed Oct 17, 2018
1 parent a5bfcb7 commit e9c80c6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.edit.parts;

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.common.notify.Notification;
Expand Down Expand Up @@ -46,6 +48,9 @@
public class MessageLabelEditPart extends LabelEditPart implements ITextAwareEditPart, ISequenceEditPart {
private IParser parser;

/** the element to listen to as suggested by the parser */
private List<?> parserElements = null;

private WrappingLabel label;

static {
Expand All @@ -62,6 +67,32 @@ protected IFigure createFigure() {
return label;
}

@Override
protected void addSemanticListeners() {
if (getParser() instanceof ISemanticParser) {
EObject semanticElement = resolveSemanticElement();
parserElements = ((ISemanticParser)getParser()).getSemanticElementsBeingParsed(semanticElement);

for (int i = 0; i < parserElements.size(); i++) {
addListenerFilter("SemanticModel" + i, this, (EObject)parserElements.get(i)); //$NON-NLS-1$
}

} else {
super.addSemanticListeners();
}
}

@Override
protected void removeSemanticListeners() {
if (parserElements != null) {
for (int i = 0; i < parserElements.size(); i++) {
removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
}
} else {
super.removeSemanticListeners();
}
}

protected EObject getParserElement() {
return resolveSemanticElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import java.util.stream.Collectors;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.util.OperationUtil;
import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization;
Expand Down Expand Up @@ -63,6 +65,47 @@ public MessageParser() {
super(new EAttribute[] {UMLPackage.Literals.NAMED_ELEMENT__NAME });
}

protected EStructuralFeature getEStructuralFeature(Object notification) {
EStructuralFeature featureImpl = null;
if (notification instanceof Notification) {
Object feature = ((Notification)notification).getFeature();
if (feature instanceof EStructuralFeature) {
featureImpl = (EStructuralFeature)feature;
}
}
return featureImpl;
}

@Override
public boolean isAffectingEvent(Object event, int flags) {
EStructuralFeature feature = getEStructuralFeature(event);
return isValidFeature(feature);
}

@Override
public boolean areSemanticElementsAffected(EObject listener, Object notification) {
EStructuralFeature feature = getEStructuralFeature(notification);
return isValidFeature(feature);
}

/**
* Determines if the given feature has to be taken into account in this parser
*
* @param feature
* the feature to test
* @return true if is valid, false otherwise
*/
private boolean isValidFeature(EStructuralFeature feature) {
return UMLPackage.eINSTANCE.getNamedElement_Name().equals(feature)
|| UMLPackage.Literals.TYPED_ELEMENT__TYPE.equals(feature)
|| UMLPackage.eINSTANCE.getLiteralInteger_Value().equals(feature)
|| UMLPackage.eINSTANCE.getLiteralUnlimitedNatural_Value().equals(feature)
|| UMLPackage.eINSTANCE.getLiteralBoolean_Value().equals(feature)
|| UMLPackage.eINSTANCE.getLiteralString_Value().equals(feature)
|| UMLPackage.Literals.MESSAGE__SIGNATURE.equals(feature)
|| UMLPackage.Literals.BEHAVIORAL_FEATURE__OWNED_PARAMETER.equals(feature);
}

@Override
public String getPrintString(IAdaptable adapter, int flags) {
EObject obj = adapter.getAdapter(EObject.class);
Expand Down Expand Up @@ -285,11 +328,6 @@ protected void appendReplyOutputs(Message message, StringBuilder result) {
}
}

@Override
public boolean areSemanticElementsAffected(EObject listener, Object notification) {
return true;
}

@Override
public List<Element> getSemanticElementsBeingParsed(EObject element) {
List<Element> result = new ArrayList<Element>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ public CreationCommand<Message> createMessage(Supplier<? extends MessageEnd> sen
Supplier<? extends MessageEnd> recvEvent, MessageSort sort, NamedElement signature,
CreationParameters parameters) {

Interaction interaction = (Interaction)parameters.getContainer();
parameters.setEClass(UMLPackage.Literals.MESSAGE);
Supplier<Message> message = () -> {
MessageEnd send = sendEvent.get();
Expand All @@ -407,6 +406,7 @@ public CreationCommand<Message> createMessage(Supplier<? extends MessageEnd> sen
result.setReceiveEvent(recv);
result.setMessageSort(sort);
result.setSignature(signature);
Interaction interaction = (Interaction)parameters.getContainer();
autoname(result, getNameBase(sort), interaction.getMessages());
return result;
};
Expand Down

0 comments on commit e9c80c6

Please sign in to comment.