Listener on an object

Started by Freddo, May 25, 2017, 10:01:51 AM

Previous topic - Next topic

Freddo

Hello All,
I am currently developing plugins on ARCHI 4.0.0 with Eclipse, and I wonder how it is possible to catch the selection of an object to make a specific action.

For example, if I click on a object "node", I would like to open a form (to update some properties and witch contains rules and constraints for these properties. This form already exists and is used during object creation).

A second example, if I click on an object "Block" in a canvas, I would like to reach an URL (witch is a property of my object).

I found a (bad) solution : I include some tests in function hookStatusLineSelectionListener()  in abstract class AbstractDiagramEditor but  :'( of doing that....

Could anybody help ? Many thanks in advance !

Phil Beauvoir

Generally you would register an ISelectionListener and listen to changes like this:

   
    public void selectionChanged(IWorkbenchPart part, ISelection selection) {
        if(selection instanceof IStructuredSelection && !selection.isEmpty()) {
            Object object = ((IStructuredSelection)selection).getFirstElement();
            // Do something with object
        }
    }


Take a look at com.archimatetool.editor.views.navigator.NavigatorView

and:

getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Freddo

Hello,

Many thanks for your answer, I'll try this code.

Another point, when I create an object (Canvas Block), I add the listener and the action is properly done (I reach may URL by example). Now, I save the model, close my Archi, reopen it, and when I come back on my page the click on my block do not work. I guess my listener is established when the object is created, but not when the model is opened.
How could I make my listener permanent (without any line in the original code) ?

Many thanks in advance,

Phil Beauvoir

Depends where you put the listener, putting it on the object doesn't sound right to me. And a listener may not be the right solution. You need to be very clear about your aim.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Freddo

Thanks for your answer, what I would like to do is the ability to fire an action when I click on an object automatically .

I thought a listener was the right solution, but I don't know how to mount it when a model is opened... Is there any other solution ?

Many thanks in advance.

Phil Beauvoir

A listener may be the solution, but you usually add the listener to one main listening class such as an Eclipse View, as with com.archimatetool.editor.views.navigator.NavigatorView class. This would then forward the object selected to the form.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Freddo

Many thanks to you.

I'll try to do so.

:)