Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to open the editor on given element in given diagram ?
How to open the editor on given element in given diagram ? [message #1632852] Tue, 24 February 2015 14:24 Go to next message
Sami MADDOURI is currently offline Sami MADDOURIFriend
Messages: 7
Registered: November 2014
Junior Member
Hi,
Starting from an instance of papyrusmultidiagrameditor, I would like to select a given diagram, to select a list of elements in this diagram and to reveal them.

Is there an API for this ? If not, how can I achieve it ?
I want to select SysML elements existing in the model and make them appear programmatically in a diagram .


Sami.
Re: How to open the editor on given element in given diagram ? [message #1724306 is a reply to message #1632852] Mon, 22 February 2016 23:47 Go to previous messageGo to next message
András Dobreff is currently offline András DobreffFriend
Messages: 9
Registered: September 2014
Junior Member
Hi!

I can list the existing diagrams with the following function

public List<Diagram> getDiagrams(){
		try{
			Resource notationResource;
			notationResource = NotationUtils.getNotationModel(this.editor.getServicesRegistry().getService(ModelSet.class)).getResource();
			@SuppressWarnings("unchecked")
			List<Diagram> list = (List<Diagram>)(List<?>) notationResource.getContents();
			return list;
		}catch(ServiceException e){
			throw new RuntimeException(e);
		}
	}


Here the editor is your IMultiDiagramEditor instance.

András
Re: How to open the editor on given element in given diagram ? [message #1724371 is a reply to message #1724306] Tue, 23 February 2016 11:50 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1206
Registered: July 2009
Location: Canada
Senior Member

Hi, András,

A bit of care is needed, here. The notation resource can also have as roots:

* tables, instances of the NattablePackage.Literals.TABLE class
* embedded stylesheets, instances of the
StylesheetsPackage.Literals.STYLESHEET class

and possibly other things (I think I've seen other objects, but I
forget what). In any case, some judicious filtering of the resource's
contents is recommended.

Coming in the M6 milestone of the Neon release will be a new API of the
IEMFModel interface (which the NotationModel implements): the
getRootElements() operation provides an iteration of all the logical
roots of the model, which in this case is notations. That includes
both diagrams and tables, but not other things like stylesheets. So,
some filtering still needed, but perhaps your use case does actually
need to account for tables, too (I don't know).

Cheers,

Christian


On 2016-02-22 23:47:57 +0000, András Dobreff said:

> Hi!
>
> I can list the existing diagrams with the following function
>
>
> public List<Diagram> getDiagrams(){
> try{
> Resource notationResource;
> notationResource =
> NotationUtils.getNotationModel(this.editor.getServicesRegistry().getService(ModelSet.class)).getResource();
>
> @SuppressWarnings("unchecked")
> List<Diagram> list = (List<Diagram>)(List<?>)
> notationResource.getContents();
> return list;
> }catch(ServiceException e){
> throw new RuntimeException(e);
> }
> }
>
>
> Here the editor is your IMultiDiagramEditor instance.
>
> András
Re: How to open the editor on given element in given diagram ? [message #1724378 is a reply to message #1724371] Tue, 23 February 2016 13:17 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 926
Registered: February 2011
Senior Member
Hi,

The OpenElementService (Used to open e.g. Search Results in Papyrus) can help here. If you give it either a Semantic element (UML) or graphical element (Notation), it will:

- Find representations of this element (This step can be skipped if you use a graphical element directly)
- Open or focus the proper editor for this representation (Usually a Diagram editor)
- Select and Focus the representation (Ensuring it is visible on screen, moving the scrollbars as necessary)

The code looks like:

IMultiDiagramEditor editor;
OpenElementService openService = editor.getServicesRegistry().getService(OpenElementService.class);
openService.openElement(viewElement); //If you already have the representation (notation::View)
openService.openSemanticElement(semanticElement); //If you only know the semantic (UML) element


HTH,
Camille


Camille Letavernier
Re: How to open the editor on given element in given diagram ? [message #1724426 is a reply to message #1724378] Tue, 23 February 2016 20:36 Go to previous message
András Dobreff is currently offline András DobreffFriend
Messages: 9
Registered: September 2014
Junior Member
Thanks the warning Christian, I'll include the filtering.
Previous Topic:Programmatically generate Papyrus model from existing UML diagrams
Next Topic:[CSS] Filter on fields of type
Goto Forum:
  


Current Time: Sat Jul 04 06:50:50 GMT 2020

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

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

Back to the top