Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to capture elements in a diagram
How to capture elements in a diagram [message #230934] Thu, 21 May 2009 09:19 Go to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member
I want to save the diagram in active editor by user command, so I try to
first I find the current active editor and then the root element in the
editor.
here is part of my code:


1 IWorkbenchWindow window;
2 window = this.window;
3 IWorkbenchPage page = window.getActivePage();
4 URIEditorInput uri = (URIEditorInput)
page.getActiveEditor().getEditorInput();
5 Resource res1 = new XMIResourceImpl(uri.getURI());
6 ...


and I receive following exception on line 4:

java.lang.ClassCastException: org.eclipse.ui.part.FileEditorInput cannot
be cast to org.eclipse.emf.common.ui.URIEditorInput


Any suggestions?
Re: How to capture elements in a diagram [message #230955 is a reply to message #230934] Thu, 21 May 2009 11:09 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Alireza,

> I want to save the diagram in active editor by user command, so I try
You can call IEditorPart.doSave(IProgressMonitor monitor) method.

> java.lang.ClassCastException: org.eclipse.ui.part.FileEditorInput
> cannot be cast to org.eclipse.emf.common.ui.URIEditorInput
> Any suggestions?
Do nto cast it to URIEditorInput - use FileEditorInput instead. ;-)

-----------------
Alex Shatalin
Re: How to capture elements in a diagram [message #230960 is a reply to message #230955] Thu, 21 May 2009 11:38 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member
Thank you for answers,
I have tried to use FileEditorInput, but the problem is how i create a
resource
with the result uri? I tried follwoing, but it does not work:

FileEditorInput uri = (FileEditorInput)
page.getActiveEditor().getEditorInput();
Resource res = new XMIResourceImpl(uri.getURI());
Best,
Re: How to capture elements in a diagram [message #230967 is a reply to message #230955] Thu, 21 May 2009 11:38 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member
BTW, I am saving/loading to/from DB.
Re: How to capture elements in a diagram [message #230973 is a reply to message #230960] Thu, 21 May 2009 11:53 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Alireza,

Try org.eclipse.emf.common.util.URI.createPlatformResourceURI(fi leEditorInput.getPath().toOSString(),
true);

-----------------
Alex Shatalin
Re: How to capture elements in a diagram [message #230979 is a reply to message #230973] Thu, 21 May 2009 12:49 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member
With following code:

1 URI uri =
org.eclipse.emf.common.util.URI.createPlatformResourceURI(fi leEditorInput.getPath().toOSString(),
true);

2 Resource res = new XMIResourceImpl(uri);

3 res.load(Collections.EMPTY_MAP);


I received following error (test77.spm1_diagram is my created diagram file
name):

java.lang.IllegalStateException:
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Resource
'/L/p/test77.spm1_diagram' does not exist.
Re: How to capture elements in a diagram [message #231007 is a reply to message #230979] Thu, 21 May 2009 13:50 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Alireza,

> java.lang.IllegalStateException:
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Resource
> '/L/p/test77.spm1_diagram' does not exist.
Can you check if you have /L/p/test77.spm1_diagram available in your workspace
or not.

-----------------
Alex Shatalin
Re: How to capture elements in a diagram [message #231015 is a reply to message #231007] Thu, 21 May 2009 14:05 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member
This file is located in C:\Documents and
Settings\Alireza\runtime-EclipseApplication\p , so I mean it is not
located in my workspace (C:\Documents and Settings\Alireza\workspace1).
Does it mean that I should the path in the error inside my workspace? what
is L before P in the path?
Re: How to capture elements in a diagram [message #231055 is a reply to message #231015] Fri, 22 May 2009 10:03 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Alireza,

I think you can expect path structure in a debugger.
It should be possible to create proper EMF URI to load a file based on FileEditorInput.
It looks strange you've openned file located outside of your workspace in
Eclipse, nevertheless it is possible, so if you need to handle this situation
choose proper URI.createPlatformResourceURI()/createFileURI() method to construct
appropriate URI.

-----------------
Alex Shatalin
Re: How to capture elements in a diagram [message #231079 is a reply to message #231055] Fri, 22 May 2009 10:19 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member
>It looks strange you've openned file located outside of your workspace in
Eclipse, nevertheless it is possible, so if you need to handle this situation
choose proper URI.createPlatformResourceURI()/createFileURI() method to
construct appropriate URI.


I have created the diagram and then when I used the save button, the
system save it to the corresponding path. I think even without saving it
to the file, there should be some way to capture elements in the active
editor, what do you think?
Re: How to capture elements in a diagram [message #231087 is a reply to message #231079] Fri, 22 May 2009 11:15 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Alireza,

> system save it to the corresponding path. I think even without saving
> it to the file, there should be some way to capture elements in the
> active editor, what do you think?
Sure. There is an EditorInput or you can used selection/editor API to get
some model elements from an editor.

-----------------
Alex Shatalin
Re: How to capture elements in a diagram [message #231109 is a reply to message #231087] Fri, 22 May 2009 12:24 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member
> There is an EditorInput

How can I use it? The page.getActiveEditor().getEditorInput() will give me
the editor input, but how can use it to access elements(root element)?

>or you can used selection/editor API to get some model elements from an
editor.

What is selection/editor API, I could not find nothing useful about it in
google :(
Re: How to capture elements in a diagram [message #231117 is a reply to message #231109] Fri, 22 May 2009 13:04 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member
I used DiagramDocument and now I am able to capture the root element.
Thank you.

Now, my problem is something else, I have a DB that I need to visualize as
gmf diagrams. Now, it seems that loading section work perfect. Also, now I
am able to capture the root element of a new created diagram that should
be saved to the DB. The problem is: suppose user opens a diagram from db
and makes a change on it and want to save it back to db.

How can I found the the corresponding diagram is dirty and the DB must be
update? Is it possible to detect only changed part and update db or ...?
Re: How to capture elements in a diagram [message #231125 is a reply to message #231117] Fri, 22 May 2009 13:29 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Alireza,

See isDirty() method of the Editor.

-----------------
Alex Shatalin
Re: How to capture elements in a diagram [message #555090 is a reply to message #230934] Wed, 25 August 2010 12:38 Go to previous message
Daniel Rippel is currently offline Daniel RippelFriend
Messages: 29
Registered: July 2009
Junior Member
Hi anyone,

sorry for warming up this old thread again, but I have a similar problem.
First the question: Is there a way to open the Papyrus Classdiagram Editor using a URIEditorInput?

Setting: I have a model with several nested UML Diagrams (Everything is contained in one! File (Models / Diagrams). Usually I used an openDiagramPolicy on the GMF Elements to open a new Editor when the element was double-clicked.
As the Diagram-Roots are nested within the file, I cannot access them using the FileEditorInput as far as I know. Therefore the question. Can I somehow use the URIEditorInput to open the diagrams. Acutally I use "PapyrusUMLClassDiagram" as DiagramKind and "org.eclipse.papyrus.core.papyrusEditor" as EditorID.. Always results in the Class Cast Exception (URI -> File)

With best regards,
Daniel
Previous Topic:Hiding palette programatically
Next Topic:Traversing specific parts of the gmf domain model
Goto Forum:
  


Current Time: Sat Sep 21 01:53:39 GMT 2024

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

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

Back to the top