Skip to main content



      Home
Home » Modeling » UML2 » How to assign a value to a slot in an objectDiagram?
How to assign a value to a slot in an objectDiagram? [message #556671] Thu, 02 September 2010 05:47 Go to next message
Eclipse UserFriend
Hi everyone,
I'm trying to create an object diagram, so I menage to create the instances of the classes but I can't actually link them.
I create slots and set the instances in the slots (take a look at the code), but I don't know how to assign the value of the slot?

Any ideas?

Thanks,
chica


Class abstractState = (Class) m.getMember("AbstractState");
Property otProperty = abstractState.getOwnedAttribute("outgoingTransition", null);
Association asso = otProperty.getAssociation();

InstanceSpecification assoInstance = (InstanceSpecificationImpl) m.createPackagedElement("asso", UMLPackage.eINSTANCE.getInstanceSpecification());;
assoInstance.getClassifiers().add(asso);

Class transition = (Class) m.getMember("Transition");
InstanceSpecification trInstance = (InstanceSpecificationImpl) m.createPackagedElement("transition", UMLPackage.eINSTANCE.getInstanceSpecification());;
trInstance.getClassifiers().add(transition);
Property trProperty = abstractState.getOwnedAttribute("source", null);

// Slot srcSlot = assoInstance.createSlot();
// srcSlot.setDefiningFeature(trProperty);
// srcSlot.setOwningInstance(trInstance);

InstanceSpecification asInstance = (InstanceSpecificationImpl) m.createPackagedElement("abState", UMLPackage.eINSTANCE.getInstanceSpecification());;
asInstance.getClassifiers().add(abstractState);
System.out.println("spec: " + (asInstance.getSpecification()));

Slot tgtSlot = assoInstance.createSlot();
tgtSlot.setDefiningFeature(otProperty);
tgtSlot.setOwningInstance(asInstance);

// create the diagram
Diagram d = UMLModeler.getUMLDiagramHelper().createDiagram(m, UMLDiagramKind.OBJECT_LITERAL);
d.setName("My Object diagram_6");

Node vv1 = UMLModeler.getUMLDiagramHelper().createNode(d,asInstance);
Node vv2 = UMLModeler.getUMLDiagramHelper().createNode(d,trInstance);
Node vv3 = UMLModeler.getUMLDiagramHelper().createNode(d,assoInstance);

// layout the diagram
UMLModeler.getUMLDiagramHelper().layoutNodes(d.getChildren() , LayoutType.RADIAL);
UMLModeler.getUMLDiagramHelper().openDiagramEditor(d);
Re: How to assign a value to a slot in an objectDiagram? [message #628996 is a reply to message #556671] Sat, 25 September 2010 13:06 Go to previous message
Eclipse UserFriend
What is the value you want to assign?

If you already have the value you can just add it to the collection of values of the slot:

ValueSpecification newValue - ...;
tgtSlot.getValues().add(newValue);

if you don't, you can create it using #createValue().

HTH,

Rafael
http://alphasimple.com
Previous Topic:Problem adding comment
Next Topic:How to create sequence diagram using java
Goto Forum:
  


Current Time: Wed Jul 16 12:54:32 EDT 2025

Powered by FUDForum. Page generated in 0.14694 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top