Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » get the name of the file storing a model(get the name of the file storing a model)
get the name of the file storing a model [message #1424807] Tue, 16 September 2014 12:52 Go to next message
anne-Lise Courbis is currently offline anne-Lise CourbisFriend
Messages: 8
Registered: July 2014
Junior Member
Hi !
I would like to get the name of the file given by the user when he creates a model and use it to automatically name the first created instance. Where and how doing this ?

Thanks for your support.

Anne-Lise
Re: get the name of the file storing a model [message #1425503 is a reply to message #1424807] Wed, 17 September 2014 12:12 Go to previous messageGo to next message
Dat Nguyen is currently offline Dat NguyenFriend
Messages: 34
Registered: July 2014
Member
you are talking about EcoreTools?
In EcoreTools this name is also given to representation file. You can get the name of representation file by this code:

IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IFile file = (IFile) win.getActivePage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
String name = file.getName();
Re: get the name of the file storing a model [message #1426137 is a reply to message #1425503] Thu, 18 September 2014 09:47 Go to previous messageGo to next message
anne-Lise Courbis is currently offline anne-Lise CourbisFriend
Messages: 8
Registered: July 2014
Junior Member
I am talking about the code in my .odesign file, associated with the creation of an instance in a diagram.
I guess I could associate the code you send to me as an "External Java code". However, I do not understand to which window corresponds the getActiveWorkbenchWindow in instruction:
IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

Thanks again for your help.
Anne-Lise
Re: get the name of the file storing a model [message #1426232 is a reply to message #1426137] Thu, 18 September 2014 12:41 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 482
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Anne-Lise

Le 18/09/2014 11:47, anne-Lise Courbis a écrit :
> I am talking about the code in my .odesign file, associated with the
> creation of an instance in a diagram.

If I well understand your need, I think you could create a Java service,
called on the semantic/domain object which will contain the newly
created instance. The service would take an EObject as parameter and it
could make something like eObject.eResource().getUri(). From this uri,
you will remove the file extension and extract the last segment to get
the file name.

> I guess I could associate the code you send to me as an "External Java
> code". However, I do not understand to which window corresponds the
> getActiveWorkbenchWindow in instruction: IWorkbenchWindow win =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow();

This corresponds to the active Eclipse window. By default, when you
launch Eclipse, you see one window (one application in your system), but
if you click on Window > new Window, it opens a new window. Then you
will have two windows (WorkbenchWindow) for the same Eclipse instance
(the Workbench). Only one is active at the same time: the one which has
the focus in your system.

>
> Thanks again for your help.
> Anne-Lise

Regards

--
Maxime - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

Join the Sirius community at SiriusCon. Register for free: Nov. 9th Paris
http://www.siriuscon.org/
Re: get the name of the file storing a model [message #1426273 is a reply to message #1426232] Thu, 18 September 2014 13:53 Go to previous messageGo to next message
anne-Lise Courbis is currently offline anne-Lise CourbisFriend
Messages: 8
Registered: July 2014
Junior Member
Thanks Maxime for the answer. It is exactly what I want to do BUT
I have a problem if I test the formula under Acceleo Interpreter. I can get the resource with : Object.eResource() and I see the uri label, but there is an error (of syntax ?...) with Object.eResource().getUri(). Do you know why ?

Maybe I need a good course about emf. Could you advise to me a good support on internet or a book (I am from the old school), waiting next year to see you again to have a lesson to become an expert on emf Smile ?

I will try to include this code into a java service. I still fail to call a java service. It will be next subject, if my colleague cannot help me.

Regards,
Anne-Lise
Re: get the name of the file storing a model [message #1426752 is a reply to message #1426273] Fri, 19 September 2014 07:03 Go to previous message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 482
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Anne-Lise,

Le 18/09/2014 15:53, anne-Lise Courbis a écrit :
> Thanks Maxime for the answer. It is exactly what I want to do BUT
> I have a problem if I test the formula under Acceleo Interpreter. I can
> get the resource with : Object.eResource() and I see the uri label, but
> there is an error (of syntax ?...) with Object.eResource().getUri(). Do
> you know why ?

It seems you try to interprete some Java code in the Accelo Interpreter
which is able to interprete Acceleo code (+ Sirius supported interpreter
if the Sirius interpreted is selected).

Acceleo will be able to interprete [someEObject.eResource()/] as
eResource is a method on EObject. But then by default you hav no need to
get the uri with an Acceleo expression without using a Java service.


>
> Maybe I need a good course about emf. Could you advise to me a good
> support on internet or a book (I am from the old school), waiting next
> year to see you again to have a lesson to become an expert on emf :) ?

You will find some tuto, docs and book references on EMF docs page (see
[1]).

>
> I will try to include this code into a java service. I still fail to
> call a java service. It will be next subject, if my colleague cannot
> help me.

You will find information about Java services in the Sirius
documentation (see [2]).


>
> Regards,
> Anne-Lise

Regards,

--
Maxime - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius
--

[1] https://www.eclipse.org/modeling/emf/docs/

[2]
https://www.eclipse.org/sirius/doc/specifier/general/Writing_Queries.html#service_methods


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

Join the Sirius community at SiriusCon. Register for free: Nov. 9th Paris
http://www.siriuscon.org/
Previous Topic:Sirius - Capture screenshot programmatically
Next Topic:Documentation / Tutorial
Goto Forum:
  


Current Time: Sun Mar 29 16:37:57 GMT 2020

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

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

Back to the top