Active diagram listener

Hello,
Is there any listener that would react to the change of the active diagram by the user? I suppose that if that method should exist it would be in IProjectDiagramListener.
IDiagramListener2 as a selectedValueChanged method, but I think it is only to changes inside an specific diagram, no?

Any idea?

Cheers & thanks
Luis M

Ok, I found a hacky walk around for getting a notification when the active diagram changes.

My plugin base implements VPPlugin so it has the method “public void projectAfterOpened(IProject aProject)” which is invoked as soon as the project has finished loading. There I start a class implementing java.lang.Runnable which will be repeatedly called, every 500ms, by a ScheduledFuture service.

Heres the code which you can put inside the projectAfterOpened method:


ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
ScheduledFuture future = executor.scheduleWithFixedDelay(new ActiveDiagramPollingService(), 0, 500, TimeUnit.MILLISECONDS);

And here’s the ActiveDiagramPollingService class:


class ActiveDiagramPollingService implements Runnable {
    private String lastDiagramName = "";
    public IProject lproject;
    ViewManager lViewManager = ApplicationManager.instance().getViewManager();
    
    @Override
    public void run() {
                String diagramName = ApplicationManager.instance().getDiagramManager().getActiveDiagram().getName();
                if(!diagramName.equals(lastDiagramName)){
                    lastDiagramName = diagramName;
                     
               // DO SOMETHING WITH THE ACTIVE DIAGRAM HERE
                    lViewManager.showMessage("----------------------------------------");
                    lViewManager.showMessage("Current Diagram is: "+ lastDiagramName);
                    lViewManager.showMessage("----------------------------------------");

                }
    }
}

Any suggestion to solve the problem in a more elegant way?

Cheers
Milan

Hi Imcarril

I’m wondering exactly the same…

In my opinion the com.vp.plugin.diagram.IDiagramListener.diagramUIModelLoaded method should be invoked: http://www.visual-paradigm.com/support/documents/pluginjavadoc/com/vp/plugin/diagram/IDiagramListener.html

I didn’t see your post when creating this one http://forums.visual-paradigm.com/posts/list/295419.html

You mean the selectionChanged method inside the IDiagramListener2:

 void selectionChanged(IDiagramUIModel diagramUIModel){
           // Invoked when selection of the diagram is changed.
}

But tt triggers only when you select an element inside an active (business process) diagram, at least in Agilian 3.3sp2.

Any help is highly appreciated!

Cheers
Milan