Displaying a GMF-Graph in an Eclipse Viewpart [message #185984] |
Fri, 09 May 2008 06:24  |
Eclipse User |
|
|
|
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 #192158 is a reply to message #186911] |
Wed, 11 June 2008 11:44  |
Eclipse User |
|
|
|
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
>>
>>
|
|
|
Powered by
FUDForum. Page generated in 0.04562 seconds