Home » Eclipse Projects » Sirius » Problem with listener
|
Re: Problem with listener [message #1727616 is a reply to message #1727481] |
Thu, 24 March 2016 13:21 |
Alx Hvx 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 #1727922 is a reply to message #1727481] |
Tue, 29 March 2016 12:59 |
|
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 #1728061 is a reply to message #1727939] |
Wed, 30 March 2016 16:32 |
|
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
|
|
|
Goto Forum:
Current Time: Fri Sep 20 11:47:20 GMT 2024
Powered by FUDForum. Page generated in 0.05382 seconds
|