Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 09:00 Go to next message
Mehdi Belatrous is currently offline Mehdi BelatrousFriend
Messages: 6
Registered: September 2019
Junior Member

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
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("") {
					public IStatus runInUIThread(IProgressMonitor monitor) {
						IWorkbenchWindow workbench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
						while (workbench == null){
							workbench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
							try {
							} 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()

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 12:04]

Report message to a moderator

Re: Viewpoint referencing event [message #1815211 is a reply to message #1815150] Fri, 27 September 2019 07:54 Go to previous message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 522
Registered: July 2009
Senior Member

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() {
  public void notifyAddSession(Session newSession) {
    newSession.addListener(new SessionListener() {
      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.


Pierre-Charles David - Obeo

Need training or professional services for Sirius?

[Updated on: Fri, 27 September 2019 07:54]

Report message to a moderator

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

Current Time: Sat Apr 04 19:31:50 GMT 2020

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

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

Back to the top