Skip to main content



      Home
Home » Eclipse Projects » Sirius » Viewpoint referencing event(Is there a way to listen to viewpoint referencing and retrieves diagrams which reference this viewpoint ?)
Viewpoint referencing event [message #1815150] Thu, 26 September 2019 05:00 Go to next message
Eclipse UserFriend
Hello,

I'm working on a viewpoint project for Capella (Modeling Editor based on Sirius). I need to run some code when user references the viewpoint from Viewpoint manager or when it is automatically referenced while opening Eclipse. I know a ViewpointRegistryListener2 can be added to ViewpointRegistry but its handler "modelerDescriptionFilesLoaded" does not fit my needs.

Using the
 Activator.start() 
method does not seems right because it is called before any session is loaded. As a workaround I tried to use an Eclipse Job to asynchronously wait the editor to be opened, something like below :
			  UIJob job = new UIJob("") {
					@Override
					public IStatus runInUIThread(IProgressMonitor monitor) {
						IWorkbenchWindow workbench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
						while (workbench == null){
							workbench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
							try {
								Thread.sleep(1000);
							} catch (InterruptedException e) {
							}
						}
						IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
						DiagramEditor editor = (DiagramEditor) page.getActiveEditor();
			                        Diagram diagram = editor.getDiagram();
			                        DDiagram dDiagram = (DDiagram) diagram.getElement();
                                                // run some code with dDiagram.getDiagramElements()
					}
				  };
		      job.schedule();


However this does not suit my needs because the current diagram retrieved from editor can be from a project which does not reference my viewpoint and anyway it does not seems to be the proper way to go. Could you please advice on the suitable way to listen to viewpoint activation and also retrieve diagram/project which reference the viewpoint ?

Best Regards.

[Updated on: Thu, 26 September 2019 08:04] by Moderator

Re: Viewpoint referencing event [message #1815211 is a reply to message #1815150] Fri, 27 September 2019 03:54 Go to previous message
Eclipse UserFriend
Hi,

You need to setup a single, global SessionManagerListener which will get notified when a new session is opened, and on every new session setup a SessionListener to react to viewpoint selection changes. Something like:

SessionManager.INSTANCE.addSessionsListener(new SessionManagerListener.Stub() {
  @Override
  public void notifyAddSession(Session newSession) {
    newSession.addListener(new SessionListener() {
      @Override
      void notify(int changeKind) {
        if (changeKind == SessionListener.SELECTED_VIEWS_CHANGE_KIND) {
          Collection<Viewpoint> selected = newSession.getSelectedViewpoints(true);
          if (itContainsMyViewpoint(selected)) {
            // Do something if needed
          }
        }
      }
    });
  }
});


Note that the SessionListener.SELECTED_VIEWS_CHANGE_KIND type of event will not tell you what changed; you need to track by yourself whether the change corresponds to the activation of your viewpoint of interest. Also, don't forget to also listen for session closing to do any cleanup needed.

Regards,

[Updated on: Fri, 27 September 2019 03:54] by Moderator

Previous Topic:Code for Model created in Sirius editor
Next Topic:Stacks and Container in containers warning
Goto Forum:
  


Current Time: Mon Jul 14 19:11:52 EDT 2025

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

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

Back to the top