Create a new element programmatically when an attribute changes [message #143455] |
Thu, 19 July 2007 11:52 |
Eclipse User |
|
|
|
Originally posted by: bmoros.um.es
Hello everybody,
I want to create a semantic element (and show it in the diagram) when one of
the attributes of a class is set. The piece of the metamodel involved in the
process is attached to this message.
What I need to do is to create the value of the AttributeInstance
(NumberValue or StringValue) as soon as the instanceOf reference is set,
according to the Type of the selected Attribute. Thus, if the type of the
Attribute is NumberType, a NumberValue has to be created and set as the
value of the AttributeInstance.
I have overridden the handleNotificationEvent method in
AttributeInstanceEditPart class to handle the events related to the
instanceOf relationship.
protected void handleNotificationEvent(Notification notification) {
if (notification.getFeatureID(AttributeInstance.class) ==
AttributesMMPackage.ATTRIBUTE_INSTANCE__INSTANCE_OF &&
notification.getEventType() == Notification.SET ){
AttributeInstance att = (AttributeInstance) ((View) getModel())
.getElement();
if (att.getInstanceOf() != null) {
Value value = att.getInstanceOf().getValue();
att.setValue(value);
refreshChildren();
}
..
}
When this method is executed, the semantic element should be created. I
hoped that the execution of refreshChildren would detect that the list of
the children had changed and that it would create the value EditPart. To
achieve this, I needed to override the getModelChildren method, but the
problem is that I had to return a list of Views in GMF instead of the list
of semantic elements, but I only know how to implement the method
getSemanticModelChildren(). This method works correctly to visualize the
models defined using the tree editor but the diagram is not updated when the
instanceof reference changes (only if you close the diagram and reopen it
again). To create the view associated to a semantic element I have tried to
use the CreateViewAndElementRequest, after creating the semantic element in
the handleNotificationEvent method without success.
if (value instanceof StringValue)
elementType = AttributesMMElementTypes.StringValue_2003;
else elementType = AttributesMMElementTypes.NumberValue_2002;
CreateViewAndElementRequest createRequest = new CreateViewAndElementRequest(
elementType,value,this.getDiagramPreferencesHint());
Command command = this.getCommand(createRequest);
DiagramCommandStack commandStack =
this.getDiagramEditDomain().getDiagramCommandStack();
commandStack.execute(command);
I am new to GMF and perhaps my approach is completely wrong, but I really
have no idea how to link the notation element and the semantic element to
specify the list of children.
Any help will be very very welcome!!!
Thanks in advance,
Bego
|
|
|
Powered by
FUDForum. Page generated in 0.03590 seconds