file Intercept Drop element from Model Explorer to Diagram

5 years 1 week ago #3081 by jcantoniochamp
Hello,

I would like to know how to intercept Drop element from Model Explorer to Diagram (in my case an attribute to a Static diagram) to create an element which is not of the same type as the dropped element.
The idea is to do something similar when dragging a class to an object diagram, which creates an object not a class.

Kind regards,

JClaude

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

5 years 1 week ago #3086 by jcantoniochamp
Hello ,

I found this looking in the source code of many XXXEditPart classes:
// Override the default drop policy with a specific one that handles instances differently.
installEditPolicy(ModelElementDropRequest.TYPE, ....

but I still don't know the correct way to hook within the plugin.

Kind regards,

Jean-Claude

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

5 years 1 week ago #3088 by chm

jcantoniochamp wrote: The idea is to do something similar when dragging a class to an object diagram, which creates an object not a class.


Hi jcantoniochamp,

you should take a look at ObjectDiagramElementDropEditPolicy, we are calling this kind of behavior a "smart interaction". You could add your code to the existing drop policy, or redefine one completely...

Could you provide us a little more details about what you're trying to insert?

Hope this helps,


chm

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

5 years 1 week ago #3090 by jcantoniochamp
It seems that one has to start by the plugin.xml
In the case of the object diagram the ObjectProcessor is declared with
<extension id="diagram.object" point="org.eclipse.e4.workbench.model">
<fragment
uri="e4model/diagram_object_editor.e4xmi">
</fragment>
<processor beforefragment="true" class="org.modelio.diagram.editor.object.plugin.ObjectProcessor"/>
</extension>

ObjectProcessor registers the ObjectDiagramEditPartFactory factory which creates the ObjectDiagramEditPart which installs the policy.

So do I need to go through all this and create my own plugin.xml?

I just want register an extra DiagramElementDropEditPolicy

Today for my diagram I only have this line which creates the diagram:
diagram = session.getModel().createStaticDiagram(name, owner, UIModule.MODULE_NAME, UIStereotypes.UIDIAGRAM);

What is the simple way to add a drop policy for this diagram?

Kind regards,

JClaude

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

5 years 1 week ago #3091 by chm

jcantoniochamp wrote: It seems that one has to start by the plugin.xml
In the case of the object diagram the ObjectProcessor is declared with
<extension id="diagram.object" point="org.eclipse.e4.workbench.model">
<fragment
uri="e4model/diagram_object_editor.e4xmi">
</fragment>
<processor beforefragment="true" class="org.modelio.diagram.editor.object.plugin.ObjectProcessor"/>
</extension>

ObjectProcessor registers the ObjectDiagramEditPartFactory factory which creates the ObjectDiagramEditPart which installs the policy.

So do I need to go through all this and create my own plugin.xml?

I just want register an extra DiagramElementDropEditPolicy


You're right about that, edit part factories are declared that way when the application starts, but you do not need to add more or them as far as I can tell. Everything is already in place.

jcantoniochamp wrote: Today for my diagram I only have this line which creates the diagram:
diagram = session.getModel().createStaticDiagram(name, owner, UIModule.MODULE_NAME, UIStereotypes.UIDIAGRAM);

What is the simple way to add a drop policy for this diagram?


If you want to change the drop behavior on a static diagram, you should go directly to the createEditPolicies method in StaticDiagramEditPart.

You'll have to install your own drop policy instead of the standard DiagramElementDropEditPolicy (installed in AbstractDiagramEditPart), just like it is done with an Object diagram.


chm

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

5 years 1 week ago #3092 by jcantoniochamp
Hello,

Thanks.
Do you suggested that I have my own StaticDiagramEditPart class in my module?
How would it get picked up instead of the original StaticDiagramEditPart?

Kind regards,

JClaude

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

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