|
|
Re: How to create a classDiagram which which defines an Instance Specification? [message #1017383 is a reply to message #1017340] |
Mon, 11 March 2013 18:04 |
Mariem Makni Messages: 46 Registered: February 2013 |
Member |
|
|
Hi,
Thanks for your reply.
I'm doing a project using the Plug-in papyrus Marte in eclipse, I add a popup menu
named "named import platform" using commands and Handlers in the view
of the Model Explorer when creating a papyrus Model.
My goal is when I click on the command which defined by the popup menu, a ClassDiagram will be created and it contains the "Instance Specification" which I have implemented.
I used this method
protected Diagram createDiagram(Resource diagramResource, EObject owner, String name) {
Diagram diagram=null;
if(owner instanceof org.eclipse.uml2.uml.Package) {
Package pkg=(Package) ((Package) (owner)).getPackagedElement("UMLPackage.eINSTANCE.getPackage());
Class sharedResource = (Class((Package)owner).createOwnedClass("sharedResource", false);
Property attribute = sharedResource.createOwnedAttribute(
"newAttribute", null, UMLPackage.Literals.PROPERTY);
diagram = ViewService.createDiagram(owner, getDiagramNotationID(), getPreferenceHint());
diagram.setName(name);
//diagram.setElement();
diagramResource.getContents().add(diagram);
}
return diagram;
}
@Override
protected String getDiagramNotationID() {
return ModelEditPart.MODEL_ID;
}
@Override
protected PreferencesHint getPreferenceHint() {
return UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
}
@Override
protected String getDefaultDiagramName() {
return super.openDiagramNameDialog("specific model diagram");
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
return super.execute(event);
}
}
But this method will create a class Diagram which contains Class not Instance Specification.
Can you help me please.
|
|
|
|
|
Re: How to create a classDiagram which which defines an Instance Specification? [message #1017423 is a reply to message #1017410] |
Mon, 11 March 2013 19:56 |
Simon Schwichtenberg Messages: 127 Registered: September 2011 |
Senior Member |
|
|
try this in your handler (I have not tested it):
ServicesRegistry serviceRegistry = ServiceUtilsForActionHandlers
.getInstance().getServiceRegistry();
TransactionalEditingDomain ed = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
RecordingCommand c = new RecordingCommand(ed) {
@Override
protected void doExecute() {
Model model =// get a reference of the root element of the uml model
InstanceSpecification spec = UMLFactory.eINSTANCE.createInstanceSpecification();
org.eclipse.uml2.uml.Class type = UMLFactory.eINSTANCE.createClass();
spec.getClassifiers().add(type);
model.getPackagedElements().add(type);
model.getPackagedElements().add(spec);
}
};
ed.getCommandStack().execute(c);
In general, this only creates the model element. But if you're lucky the graphical representations in the diagram are also created for free.
[Updated on: Mon, 11 March 2013 19:57] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04164 seconds