Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Problem with listener
Problem with listener [message #1727481] Wed, 23 March 2016 10:32 Go to next message
Alx Hvx is currently offline Alx HvxFriend
Messages: 40
Registered: March 2016
Member
Hi,

I have implemented a listener to my diagram to get the changes the users are doing on it.
When the user move an Element on a diagram I need the listener to do automatically some additional actions.

The problem is that when an Element is moved on the diagram I only get an Object of type "BoundsImpl" (from the package : org.eclipse.gmf.runtime.notation.impl) which is completely useless to me because I can't trace back to the actual EObject behind it. (For example if I move a Man on the diagram the listener will give me the BoundsImpl related to it and not the Person EObject).

Do you know if it is possible to find the Object related to the BoundImpl ?

Here is the code that I have :

 TransactionUtil.getEditingDomain(e).addResourceSetListener(new ResourceSetListenerImpl() {
			
			public void resourceSetChanged(ResourceSetChangeEvent event) {
				for (Iterator iter = event.getNotifications().iterator(); iter.hasNext();) {
					Notification notification = (Notification) iter.next();
					Object notifier = notification.getNotifier();
					notification.
					if (notifier instanceof EObject) {
						EObject eObject = (EObject) notifier;

						// only respond to changes to structural features of the object
						if (notification.getFeature() instanceof EStructuralFeature) {
							EStructuralFeature feature = (EStructuralFeature) notification.getFeature();
							
							// get the name of the changed feature and the qualified name of
							//    the object, substituting <type> for any element that has no name
							System.out.println("The " + feature.getName() + " of the object \""
									+eObject.getClass() + "\" has changed ");
						}
					}
				}


Here is some screens of what I have :

When I move this Element :
index.php/fa/25385/0/

I need the listener to notify me something like "Computer01" was moved.

But here is what I get on the console instead :

The x of the object "org.eclipse.gmf.runtime.notation.impl.BoundsImpl@1d53c272 (x: 225, y: 230) (width: 208, height: -1)" has changed 
The y of the object "org.eclipse.gmf.runtime.notation.impl.BoundsImpl@1d53c272 (x: 225, y: 230) (width: 208, height: -1)" has changed 


Do you have an idea ?

Regards,
Alex.
Re: Problem with listener [message #1727616 is a reply to message #1727481] Thu, 24 March 2016 13:21 Go to previous messageGo to next message
Alx Hvx is currently offline Alx HvxFriend
Messages: 40
Registered: March 2016
Member
Hi,

It's ok I found a solution.

I post here a minimal exemple in case one day someboby has the same problem as me :

Node node = SiriusGMFHelper.getGmfNode(diagramElement);
Location locationContainer = (Location) node.getLayoutConstraint();

Adapter adapter = new AdapterImpl() {
			public void notifyChanged(Notification notification) {
				System.out.println("Notifier class = " + notification.getNotifier().getClass());
				int x = location.getX();
				int y = location.getY();
				//do here whatever you want
			}};
		location.eAdapters().add(adapter);


to get the semantic EObject you just have to do :
diagramElement.getTarget();

[Updated on: Thu, 24 March 2016 13:28]

Report message to a moderator

Re: Problem with listener [message #1727647 is a reply to message #1727616] Thu, 24 March 2016 17:44 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 210
Registered: February 2014
Senior Member
Hi Alex,

I might need to do the same. Could you please tell me where to implement the code ? is it a Java Service ? Java Extensions or what ?

Thanks,
Parsa
Re: Problem with listener [message #1727682 is a reply to message #1727647] Fri, 25 March 2016 08:11 Go to previous messageGo to next message
Alx Hvx is currently offline Alx HvxFriend
Messages: 40
Registered: March 2016
Member
Hi Parsa,

I've put this code on a Java Service method that I call on the creation of a subNode. But it was only for test puposes, I don't think it is the clean way to do it so I will soon try to implement this on an "External Java Action Call" or "External Java Action" (I still don't know witch one is better).
I'll try to post the code here when it will be done.

Regards,
Alex
Re: Problem with listener [message #1727922 is a reply to message #1727481] Tue, 29 March 2016 12:59 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Alex,

Le 23/03/2016 11:32, Alx Hvx a écrit :
> Hi,
>
> I have implemented a listener to my diagram to get the changes the users are doing on it.
> When the user move an Element on a diagram I need the listener to do automatically some additional actions.
>
> The problem is that when an Element is moved on the diagram I only get an Object of type "BoundsImpl" (from the package : org.eclipse.gmf.runtime.notation.impl) which is completely useless to me because I can't trace back to the actual EObject behind it. (For example if I move a Man on the diagram the listener will give me the BoundsImpl related to it and not the Person EObject).
>
> Do you know if it is possible to find the Object related to the BoundImpl ?

Which Object do you want ? Your semantic object, the Sirius graphical
node ? The GMF node ?

If I call bounds your BoundsImpl element:
. bounds.eContainer() should give you
org.eclipse.gmf.runtime.notation.Node
. from this Node, node.getLayoutConstraint() allows you to retrieve
the bounds
. from this Node, node.getElement() gives you the Sirius
DDiagramElement (a DNode, a DNodeList or a DNodeContainer)
. from the DDiagramElement, you can call dde.getTarget() to retrieve
your domain element.



>
> Here is the code that I have :
>
> TransactionUtil.getEditingDomain(e).addResourceSetListener(new ResourceSetListenerImpl() {
>
> public void resourceSetChanged(ResourceSetChangeEvent event) {
> for (Iterator iter = event.getNotifications().iterator(); iter.hasNext();) {
> Notification notification = (Notification) iter.next();
> Object notifier = notification.getNotifier();
> notification.
> if (notifier instanceof EObject) {
> EObject eObject = (EObject) notifier;
>
> // only respond to changes to structural features of the object
> if (notification.getFeature() instanceof EStructuralFeature) {
> EStructuralFeature feature = (EStructuralFeature) notification.getFeature();
>
> // get the name of the changed feature and the qualified name of
> // the object, substituting <type> for any element that has no name
> System.out.println("The " + feature.getName() + " of the object \""
> +eObject.getClass() + "\" has changed ");
> }
> }
> }
>
> Here is some screens of what I have :

If I understand correctly this message ad the following ones, you
install a new resourceSet listener for each call of you tool.
You should install it only once. Do not hesitate to complete the
getFilter() method to finer control the calls of your listener.

You currently uses the resourceSetChanged method, so your are in post
commit, if you later want to impact the model, you will need to use
transactionAboutToCommit and also to isAggregatePrecommitListener,
isPrecommitOnly, isPostCommitOnly. You could also look at the
ModelChangeTrigger API, which allows to also control the priority of the
listener compared on the other Sirius model change listener (the call
order of resourceSet listener depends on their installation order).



>
> When I move this Element :
>
>
> I need the listener to notify me something like "Computer01" was moved.
>
> But here is what I get on the console instead :
>
> The x of the object "org.eclipse.gmf.runtime.notation.impl.BoundsImpl@1d53c272 (x: 225, y: 230) (width: 208, height: -1)" has changed
> The y of the object "org.eclipse.gmf.runtime.notation.impl.BoundsImpl@1d53c272 (x: 225, y: 230) (width: 208, height: -1)" has changed
>
> Do you have an idea ?
>
> Regards,
> Alex.
>


Regards,

--
Maxime - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Problem with listener [message #1727925 is a reply to message #1727682] Tue, 29 March 2016 13:10 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
Le 25/03/2016 09:11, Alx Hvx a écrit :
> Hi Parsa,
> I've put this code on a Java Service method that I call on the creation
> of a subNode. But it was only for test puposes, I don't think it is the
> clean way to do it so I will soon try to implement this on an "External
> Java Action Call" or "External Java Action" (I still don't know witch
> one is better).

ExternalJavaAction need to be declared in an extension points and must
inherit from org.eclipse.sirius.tools.api.ui.IExternalJavaAction. Then
you use them as an operation in a tool or as a "tool" which will result
as a contextual menu entry.
ExternalJavaActionCall in the VSM is a shortcut to simplify the call of
the same ExternalJavaAction in different locations of the VSM (no need
to redefine the parameter computation expressions)

See [1] for more information about ExternalJavaAction.


Java service [2] are Java classes you will reference from your VSM. Then
you can call their public methods from the different interpreter
supporting it (aql, service, acceleo3). See also [3], [4], [5].


> I'll try to post the code here when it will be done.
>
> Regards, Alex


Regards

--
Maxime - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
--
[1]
https://www.eclipse.org/sirius/doc/specifier/general/Model_Operations.html#extensions
[2]
https://www.eclipse.org/sirius/doc/specifier/general/Writing_Queries.html#service_methods
[3]
https://www.eclipse.org/sirius/doc/specifier/general/Writing_Queries.html#specialized
[4]
https://www.eclipse.org/sirius/doc/specifier/general/Writing_Queries.html#aql
[5]
https://www.eclipse.org/sirius/doc/specifier/general/Writing_Queries.html#acceleo


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Problem with listener [message #1727939 is a reply to message #1727925] Tue, 29 March 2016 14:58 Go to previous messageGo to next message
Alx Hvx is currently offline Alx HvxFriend
Messages: 40
Registered: March 2016
Member
Hi Maxime !
Thanks for your reply,

I am trying to add an ExternalJavaAction in the VSM.
I've added a new extension point in the MANIFEST.MF at tab "Extensions" and then I clicked on the actionClass* field to create a new class that implements IExternalJavaAction.
But the problem is that it is not working when I use the External Java Action in the odesign with the field Java Action Id* correctly set.

For exemple in the odesign when I want to call it at the creation of an element I have : Section --> Node Creation --> Begin --> Change Context --> Create Instance --> External Java Action
But each time I put the External Java Action I am not able to create the Element on the diagram (the mouse shows me a cross). Where is the problem ?

Also I need to call a Java Action at the opening (or creation) of a diagram, is it possible ?

Regards,
Alex
Re: Problem with listener [message #1728061 is a reply to message #1727939] Wed, 30 March 2016 16:32 Go to previous message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
Le 29/03/2016 16:58, Alx Hvx a écrit :
> Hi Maxime ! Thanks for your reply,
> I am trying to add an ExternalJavaAction in the VSM.
> I've added a new extension point in the MANIFEST.MF at tab "Extensions"
> and then I clicked on the actionClass* field to create a new class that
> implements IExternalJavaAction. But the problem is that it is not
> working when I use the External Java Action in the odesign with the
> field Java Action Id* correctly set.
>
> For exemple in the odesign when I want to call it at the creation of an
> element I have : Section --> Node Creation --> Begin --> Change
> Context --> Create Instance --> External Java Action

Did you deploy the modeler or launch a runtime ? (See
https://www.eclipse.org/sirius/doc/specifier/general/Model_Operations.html#external_java_action
)

> But each time I put the External Java Action I am not able to create the
> Element on the diagram (the mouse shows me a cross). Where is the problem ?

Do you have a precondition ?
Your tool is a Node Creation tool, it should reference a Node Mapping,
then Sirius will check the mapping structure to enable the tool or not
(the cross you see). Could you check that you tool is valid and that the
referenced mapping is a child od the diagram description (or reused from
it) ?

>
> Also I need to call a Java Action at the opening (or creation) of a
> diagram, is it possible ?

You could try this: on your Diagram description, right click > New
Operation > Begin
Then complete it as a tool, use a Change Context to call a Java service
or an ExternalJavaAction to call a external java action.

>
> Regards, Alex

Regards,


--
Maxime - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Strange rendering of scrollbars
Next Topic:Sirius runtime as standalone applicatio (rcp?)
Goto Forum:
  


Current Time: Thu Mar 28 18:56:50 GMT 2024

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

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

Back to the top