file [Solved] Adding a customized element to a diagram

4 years 10 months ago - 4 years 10 months ago #3276 by ua138
How can I add a customized element to a diagram?

I have followed the JUnit tutorial to develop the following customized diagram



For example if I want to add a UseCase to the diagram I have created, first I write the prototype:
<Stereotype name="UseCaseStereotype" metaclass="UseCase" is-hidden="false" label="Use Case Stereotype" uid="4cd73ab5-4ea8-4fad-b526-f13ba1412601">
                <Icon path="res/icons/Stereotype1_16.png"/>
                <Image path="res/icons/Stereotype1_48.png"/>
                <TagTypes/>
            </Stereotype>

And then I create the command
<Command id="CreateUseCase" label="%CreateUseCase.label" tooltip="%CreateUseCase.tooltip" image="%CreateUseCase.image" group="%CreateUseCase.group" modify-model="true" group-image="%CreateUseCase.groupimage">
                <Scope metaclass="UseCase"/>
                <Handler class="org.casesuite.rcase.command.create.CreateUseCase">
                    <HParameter name="metaclass" value="UseCase"/>
                    <HParameter name="stereotype" value="UseCaseStereotype"/>
                </Handler>
            </Command>

In the CreateUseCase.java I have the following code:
public class CreateUseCase extends DefaultModuleCommandHandler{
[...]
	public void actionPerformed( List<MObject> selectedElements, IModule module){
		IModelingSession session = Modelio.getInstance().getModelingSession();
		IUmlModel model = session.getModel();
		IDiagramService diagramService = Modelio.getInstance().getDiagramService();
		
		
		ITransaction t = session.createTransaction("Create Use Case");
		//UseCase uc = model.createUseCase();
		
		Modelio.getInstance().getModelingSession().getModel().createUseCase("UseCase", Utils.getNameSpaceOwner(selectedElements.get(0)));
		
		t.commit();

But I do not manage to drag and drop the element to the diagram. What I am doing wrong?
What is the code needed for such a thing?
Thank you very much in advance.
Attachments:

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

4 years 10 months ago #3277 by ebr
Hi ua,

There is a difference between what we call a Command and a Tool.

A command is available on the contextual menu as depicted below.



And a tool is available on palette diagram as shown in the next capture.



If I am right, it seems that you defined both on your module. Your Use Case Tool does not work but you send us your Use Case Command so maybe could you send us the whole project.


Many thanks in advance,

EBR
Attachments:

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

4 years 10 months ago #3278 by ua138
Thank you very much for your response. The whole project is a mess, because as I am learning it has lots of classes. But I will give you the main ones. If you really need the project I can "clean" it and send it to you. Please let me know anything you further need.

File Attachment:

File Name: ProjectFiles.zip
File Size:4 KB
Attachments:

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

4 years 10 months ago #3279 by ua138
Thank you very much. The whole project is a mess. As I am still learning I have a lot of classes that do not correspond and it could be difficult to interpret. Nevertheless, if you require the whole project I can clean it and send it to you. I leave attached the module file and the UseCase class. Please do not hesitate to ask for any further thing you may need.

File Attachment:

File Name: ProjectFil...3-25.zip
File Size:4 KB
Attachments:

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

4 years 10 months ago #3281 by ua138
I have cleaned all the project.

I attach it to you here:


File Attachment:

File Name: rcase.zip
File Size:656 KB


Thank you!
Attachments:

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

4 years 10 months ago #3292 by ebr
Hi UA,

The issue comes from how you attach the created UseCase to a NameSpace.

So I changed UseCaseTool code to correctly attached the created Usecase.

I also update the UseCaseToo in the module.xml and the UseCaseTool.acceptElement() in order to be sure that the owner will be a NameSpace both test are not necessary just one is enought.

File Attachment:

File Name: rcase.zip
File Size:26 KB


Hoping it is clear.

EBR
Attachments:

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

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