Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Displaying a GMF-Graph in an Eclipse Viewpart
Displaying a GMF-Graph in an Eclipse Viewpart [message #185984] Fri, 09 May 2008 10:24 Go to next message
Tobias Jaehnel is currently offline Tobias JaehnelFriend
Messages: 6
Registered: July 2009
Junior Member
Hi,

I'm using the mindmap example (http://wiki.eclipse.org/GMF_Tutorial) and
tried to create a minimalistic view, which only displays the graph (see
Code below).

All shapes already get displayed and are connected properly. The problen
is that they do show up on the position and the size specified in the
..mindmap_diagram file. Instead they appear in the upper left corner of
the view just fits the size of the text inside. It is possible to drag
the shapes around and resize them.
When I open the same file using the editor, which was created using GMF,
everything works fine.

Does anyone have a smarter solution than mine, or can tell me what I forgot?

Thanks in advance
Toby

//// Code inside my ViewPart class

// I only implemented this method
public void createPartControl(Composite parent) {
// by now the filename is harcoded and the model loaded "by hand"
URI uri = URI.createURI("file://c:/TEMP/default.mindmap_diagram");
ResourceSetImpl resourceset = new ResourceSetImpl();
DiagramEditingDomainFactory.getInstance()
.createEditingDomain(resourceset);
Resource resource = resourceset.createResource(uri);
try {
resource.load(null);
} catch (IOException e) {
e.printStackTrace();
}
Diagram diag = null;
if (uri.fragment() != null)
{
EObject rootElement = resource.getEObject(uri.fragment());
if(rootElement instanceof Diagram)
diag = (Diagram)rootElement;
}
else
for(Object rootElement : resource.getContents())
if(rootElement instanceof Diagram)
diag = (Diagram) rootElement;

DiagramGraphicalViewer viewer = new DiagramGraphicalViewer();
viewer.setEditDomain(new DefaultEditDomain(null));
viewer.setEditPartFactory(new MindmapEditPartFactory());
viewer.createControl(parent);
viewer.setRootEditPart(new DiagramRootEditPart());

viewer.setContents(diag);
}
Re: Displaying a GMF-Graph in an Eclipse Viewpart [message #186725 is a reply to message #185984] Tue, 13 May 2008 15:40 Go to previous messageGo to next message
Tobias Jaehnel is currently offline Tobias JaehnelFriend
Messages: 6
Registered: July 2009
Junior Member
Hi,

I just solved my problem.
After very much debugging and testing I found out, that the default
MapMode is HiMetricMapMode and I need IdentityMapMode.
So I added the line:

viewer.setRootEditPart(new
DiagramRootEditPart(MeasurementUnit.PIXEL_LITERAL));

and it works.

Problem solved - I wonder about what would be the next one... :)

Toby

Tobias Jähnel schrieb:
> Hi,
>
> I'm using the mindmap example (http://wiki.eclipse.org/GMF_Tutorial) and
> tried to create a minimalistic view, which only displays the graph (see
> Code below).
>
> All shapes already get displayed and are connected properly. The problen
> is that they do show up on the position and the size specified in the
> .mindmap_diagram file. Instead they appear in the upper left corner of
> the view just fits the size of the text inside. It is possible to drag
> the shapes around and resize them.
> When I open the same file using the editor, which was created using GMF,
> everything works fine.
>
> Does anyone have a smarter solution than mine, or can tell me what I
> forgot?
>
> Thanks in advance
> Toby
>
> //// Code inside my ViewPart class
>
> // I only implemented this method
> public void createPartControl(Composite parent) {
> // by now the filename is harcoded and the model loaded "by hand"
> URI uri = URI.createURI("file://c:/TEMP/default.mindmap_diagram");
> ResourceSetImpl resourceset = new ResourceSetImpl();
> DiagramEditingDomainFactory.getInstance()
> .createEditingDomain(resourceset);
> Resource resource = resourceset.createResource(uri);
> try {
> resource.load(null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> Diagram diag = null;
> if (uri.fragment() != null)
> {
> EObject rootElement = resource.getEObject(uri.fragment());
> if(rootElement instanceof Diagram)
> diag = (Diagram)rootElement;
> }
> else
> for(Object rootElement : resource.getContents())
> if(rootElement instanceof Diagram)
> diag = (Diagram) rootElement;
>
> DiagramGraphicalViewer viewer = new DiagramGraphicalViewer();
> viewer.setEditDomain(new DefaultEditDomain(null));
> viewer.setEditPartFactory(new MindmapEditPartFactory());
> viewer.createControl(parent);
> viewer.setRootEditPart(new DiagramRootEditPart());
>
> viewer.setContents(diag);
> }
Re: Displaying a GMF-Graph in an Eclipse Viewpart [message #186755 is a reply to message #186725] Tue, 13 May 2008 16:48 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Tobias,

> So I added the line:
> viewer.setRootEditPart(new
> DiagramRootEditPart(MeasurementUnit.PIXEL_LITERAL));
You can modiry "Units" property of GenDiagram element in your .gmfgen model
and set "Pixel" value there to get corresponding code generated.

-----------------
Alex Shatalin
Re: Displaying a GMF-Graph in an Eclipse Viewpart [message #186911 is a reply to message #186755] Wed, 14 May 2008 12:24 Go to previous messageGo to next message
Tobias Jaehnel is currently offline Tobias JaehnelFriend
Messages: 6
Registered: July 2009
Junior Member
Hi Alex,

thank you for this information.
I found this option and tested it. It seems to only effect the editor
default for new diagrams.

There is a measurementUnit parameter in each _diagram file. The editor
takes care of it an interpretes the coordinates according to its value
(either Pixel or HiMetric).

From the Diagram object, I can get this parameter using the method
getMeasurementUnit().
To make my view also interpret the coordinates according to this value,
I created the RootEditPart as follows:

new DiagramRootEditPart(diag.getMeasurementUnit());

I wonder why this is not done automatically.

Thanks again for pointing into the right direction. :)

Toby

Alex Shatalin schrieb:
> Hello Tobias,
>
>> So I added the line:
>> viewer.setRootEditPart(new
>> DiagramRootEditPart(MeasurementUnit.PIXEL_LITERAL));
> You can modiry "Units" property of GenDiagram element in your .gmfgen
> model and set "Pixel" value there to get corresponding code generated.
>
> -----------------
> Alex Shatalin
>
>
Re: Displaying a GMF-Graph in an Eclipse Viewpart [message #192158 is a reply to message #186911] Wed, 11 June 2008 15:44 Go to previous message
Eclipse UserFriend
Originally posted by: javier.roca.planningforce.com

Hello There,

Did somebody try to use a GMF-Graph in a ViewPart with the edition
enabled (e.g. able to delete the objects)? Is there a way to
"short-circuit" this? Moreover, Can we have a GMF Editor in a composite
without using a WorkbenchPage?

Regards

Tobias Jähnel wrote:
> Hi Alex,
>
> thank you for this information.
> I found this option and tested it. It seems to only effect the editor
> default for new diagrams.
>
> There is a measurementUnit parameter in each _diagram file. The editor
> takes care of it an interpretes the coordinates according to its value
> (either Pixel or HiMetric).
>
> From the Diagram object, I can get this parameter using the method
> getMeasurementUnit().
> To make my view also interpret the coordinates according to this value,
> I created the RootEditPart as follows:
>
> new DiagramRootEditPart(diag.getMeasurementUnit());
>
> I wonder why this is not done automatically.
>
> Thanks again for pointing into the right direction. :)
>
> Toby
>
> Alex Shatalin schrieb:
>> Hello Tobias,
>>
>>> So I added the line:
>>> viewer.setRootEditPart(new
>>> DiagramRootEditPart(MeasurementUnit.PIXEL_LITERAL));
>> You can modiry "Units" property of GenDiagram element in your .gmfgen
>> model and set "Pixel" value there to get corresponding code generated.
>>
>> -----------------
>> Alex Shatalin
>>
>>
Previous Topic:[gmf] Using one diagram editor for two child objects
Next Topic:Opening a diagram with a model (EObject) input
Goto Forum:
  


Current Time: Tue Apr 23 17:55:13 GMT 2024

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

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

Back to the top