file [Solved] Copy of Element through command

3 years 2 months ago - 3 years 2 months ago #4300 by kurales
Hi,

I would like to create a command to copy an element (component) in diagram, but can't understand, how can I get the root Element for the method modelFactory.createComponent("Component", (NameSpace) parent, s);
where "parent" should be this root element. I know, that when I implement IBoxTool-Interface there is an diagramHandle, for which I can get .getDiagram().getOrigin() for my purpose, but when I create a command where I extend DefaultModuleCommandHandler, I can't understand what to do.

Can somebody help me?

Please Log in or Create an account to join the conversation.

3 years 2 months ago #4301 by kurales
I have found, how can I get the root Element:

MObject root = Modelio.getInstance().getModelingSession().getModel().getModelRoots().get(0);
Package rootPackage = ((Project) root).getModel();
and then
modelFactory.createComponent("Component", rootPackage, s);

But the created Element appears in the project-tree and not on the diagram. Is there something like
diagramHandle.unmask(newElement, rect.x, rect.y);
in this case?

Please Log in or Create an account to join the conversation.

3 years 2 months ago #4302 by kurales
I did it too:
IDiagramService diagramServices = Modelio.getInstance().getDiagramService();for (StaticDiagram diagram : session.findByClass(StaticDiagram.class)) {
 	            // if diagram context is root
 	          if (rootPackage.equals(diagram.getOrigin())) {

 	                // Get a IDiagramHandle for content manipulation.
 	                IDiagramHandle dh = diagramServices.getDiagramHandle(diagram);

 	                    dh.unmask(createdElement, 0, 0);
 	                    // Save all diagram modifications
 	                    dh.save();
 	
 	                    // Close the handle now it is no longer used
 	                    dh.close();
 	                }
 	          }

There is now only one question: how can I get bounds of the element?

Please Log in or Create an account to join the conversation.

3 years 2 months ago #4303 by kurales
For my previous question:
IDiagramNode dg = (IDiagramNode) dh.getDiagramGraphics(el).get(0); 
dh.unmask(createdElement, dg.getBounds().x+100, dg.getBounds().y);

And the last question: how can I get the list of stereotypes (or only one) of my host-element? I see only functions, which require the name of Stereotype, but this name I would like to get.

Please Log in or Create an account to join the conversation.

3 years 2 months ago #4304 by chm
Hi kurales,

to get names of all stereotypes applied on your model element, try this:
List<String> stereotypeNames = new ArrayList<>();
for (Stereotype s : el.getExtension()) {
  stereotypeNames.add(s.getName());
}

Hope this helps,


chm

Please Log in or Create an account to join the conversation.

3 years 2 months ago #4305 by kurales
Hi chm,

Thank you very much, it works!

Please Log in or Create an account to join the conversation.

Moderators: tmachmaab
Time to create page: 0.044 seconds
^ Back to Top