Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to create views on a diagram (MVC pattern in GMF)
How to create views on a diagram (MVC pattern in GMF) [message #530036] Wed, 28 April 2010 08:51 Go to next message
Markus is currently offline MarkusFriend
Messages: 2
Registered: April 2010
Junior Member
Hello everyone,

Here is the outline of my email:

  1. Problem
  2. First Approach
  3. Result
  4. Questions




  1. Problem:

    I wanted to implement an Eclipse view for my GMF diagram editor. It should show exactly the same things I see on the editor and if I add new elements on the editor it should be updatet. Because GMF implements the MVC design pattern there should be no problems to handle this.







  2. First Approach:

    There is a 'howto' in the 'GMF Developer Guide' (see the section 'How to open multiple read-only views on a diagram') written 5 years ago that describes how to do that. This was my first approach. In the following you see the code of my adjusted view:



    public class MyView extends ViewPart {
    
        private GraphicalViewer viewer;
    
        @Override
        public void createPartControl(Composite parent) {
    
            viewer = new DiagramGraphicalViewer();
            viewer.createControl(parent).setBackground( ColorConstants.listBackground );
    
            DiagramEditDomain editDomain = new DiagramEditDomain (null); 
            editDomain.setCommandStack ( new DiagramCommandStack( editDomain ) ); 
            viewer.setEditDomain( editDomain );
    
            viewer.setRootEditPart ( new DiagramRootEditPart() ); 
            viewer.setEditPartFactory ( new MyEditPartFactory() );
            
            // MyEditPart is the top most EditPart in the Hierarchy. It extends DiagramEditPart.
            // MyEditPart.element contains the last MyEditPart object that was created.
            viewer.setContents( MyEditPart.element );
            viewer.flush();
        }
    
    
    
        @Override
        public void setFocus() {
    
        }
    }








  3. Result:

    After I created 2 graphical elements and 1 connection in my editor...

    I tried to open the view (right hand side) and got the following:

    The circles in the view became very tiny, the circles in the editor disappeared and a part of the connection was only outlined in the editor.

    But when I tried to add new circles in the editor (left hand side) using the palette they were only visible in the view (right hand side):







  4. Questions:

    • What is the right way to create such views?
    • Or what is the right way to add several 'views' to the 'controllers' (EditParts) regarding the MVC pattern?

    It seems that the EditParts (controllers) did not manage several views as they should by the design pattern 'MVC'. Instead the RootEditPart changed such that we can only see the figures (views) in the Eclipse view.






Best regards,

Markus

[Updated on: Thu, 29 April 2010 13:35]

Report message to a moderator

Re: How to create views on a diagram (MVC pattern in GMF) [message #530258 is a reply to message #530036] Thu, 29 April 2010 06:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kluepfel.cs.tu-berlin.de

Hello Markus,

have you thought about using the eclipse Outline view (id:
org.eclipse.ui.views.ContentOutline)? It shows the same things as your
GMF editor does and the update mechanism works well. Just in case you
have not noticed the view yourself...

Steffen


Am 28.04.2010 10:51, schrieb Markus Johannes:
> Hello everyone,
> Here is the outline of my email:
>
> 1. Problem <#Problem>
> 2. First Approach <#First Approach>
> 3. Result <#Result>
> 4. Questions <#Question>
>
> *__*
> *__*
> *__*
> *__*
> *__*
> *_1. Problem:_*
> [back to top <#top>]
> I wanted to implement an Eclipse view for my GMF diagram editor. It
> should show exactly the same things I see on the editor and if I add new
> elements on the editor it should be updatet. Because GMF implements the
> MVC design pattern there should be no problems to handle this.
> *_2. First Approach:_*
> [back to top <#top>]
> There is a 'howto' in the 'GMF Developer Guide' (see the section 'How to
> open multiple read-only views on a diagram
> < http://help.eclipse.org/galileo/topic/org.eclipse.gmf.doc/ho wto/diagram/howto.html#readOnlyViews>')
> written 5 years ago that describes how to do that. This was my first
> approach. In the following you see the code of my adjusted view:
> * *
> *public* *class* MyView *extends* ViewPart {
> * private* GraphicalViewer viewer;
> @Override
> * public* *void* createPartControl(Composite parent) {
> viewer = *new* DiagramGraphicalViewer();
> viewer.createControl(parent).setBackground(
> ColorConstants./listBackground /);
> DiagramEditDomain editDomain = *new* DiagramEditDomain (*null*);
> editDomain.setCommandStack ( *new* DiagramCommandStack( editDomain ) );
> viewer.setEditDomain( editDomain );
> viewer.setRootEditPart ( *new* DiagramRootEditPart() );
> viewer.setEditPartFactory ( *new* MyEditPartFactory() );
> // MyEditPart is the top most EditPart in the Hierarchy. It extends
> DiagramEditPart.
> // MyEditPart./element /contains the last MyEditPart object that was
> created.
> viewer.setContents( MyEditPart./element/ );
> viewer.flush();
> }
> @Override
> * public* *void* setFocus() {
> }
> }
> *_3. Result:_*
> [back to top <#top>]
> After I created 2 graphical elements and 1 connection in my editor...
> I tried to open the view (right hand side) and got the following:
> The circles in the view became very tiny, the circles in the editor
> disappeared and a part of the connection was only outlined in the editor.
> But when I tried to add new circles in the editor (left hand side) using
> the palette they were only visible in the view (right hand side):
> *_4. Questions:_*
> [back to top <#top>]
>
> * What is the right way to create such views?
> * Or what is the right way to add several 'views' to the
> 'controllers' (EditParts) regarding the MVC pattern?
>
> It seems that the EditParts (controllers) did not manage several views
> as they should by the design pattern 'MVC'. Instead the RootEditPart
> changed such that we can only see the figures (views) in the Eclipse view.
> Best regards,
> Markus
Re: How to create views on a diagram (MVC pattern in GMF) [message #530684 is a reply to message #530258] Fri, 30 April 2010 13:57 Go to previous messageGo to next message
Markus is currently offline MarkusFriend
Messages: 2
Registered: April 2010
Junior Member
Hello Steffen,

thank you for your reply. What do you mean by 'not noticed the view'? I
think it is sufficient to create a control by using the parent 'Composite'
such that the viewer gets 'attached' to the view.



*************************
OUTLINE VIEW
*************************

You are right. At the first sight the outline view is the appropriate tool
to handle my problem I described in the first email. But in my situation
there are several reasons to avoid the usage of the outline view. In the
following I will describe them shortly:


I think (at least) there are 2 options to use the outline view:

1. To subclass the outline view (by usage of extension points and a
subclass) to get additional views, separated from the outline view itself:

a. The developers of the outline view did not intend the user to
subclass this one (see javadoc tags: @noinstantiate, @noextend).

b. I want to get (not read-only) views to my editor. It should be
possible to select and to move the elements on the view too such that the
editor updates its figures. But the outline view reads only.



2. To provide an 'outline view page' in the generated method 'getAdapter' in
generated subclass of 'DiagramDocumentEditor' (in my editor this is:
MyDiagramEditor). I found out how this works and maybe I will provide some
kind of recipe in the next email.
A reason to avoid this way: I want to add additional views (more than 1) to
present and to alter different parts of my diagram and do not want to affect
the outline view itself.







*************************
SECOND APPROACH
*************************
When I exchange this line (from the code of my first email):

viewer.setRootEditPart ( new DiagramRootEditPart() );

for:

viewer.setRootEditPart( MyEditPart.element.getRoot() );

and open the view, I can see my diagram in the view, but all elements in the
editor disappear. And if I create new elements on the editor I can see and
move them and change their sizes in the view. I think the crux is that by
changing the RootEditPart the connection between the editor and the figures
erases because the RootEditPart gets a new viewer.
But this is not what I wanted to get. I wanted to get several views for the
same model as in MVC.







*************************
NEXT IDEA
*************************
I think the problem is that it is not possible to attach the same
RootEditPart to several viewers. Is it right?
Maybe it is possible to implement a viewer adapter which delegates all
requests to the original RootEditPart or something like that.






Best regards,

Markus





"Steffen Klüpfel" <kluepfel@cs.tu-berlin.de> schrieb im Newsbeitrag
news:hrb9dn$vdl$1@build.eclipse.org...
> Hello Markus,
>
> have you thought about using the eclipse Outline view (id:
> org.eclipse.ui.views.ContentOutline)? It shows the same things as your GMF
> editor does and the update mechanism works well. Just in case you have not
> noticed the view yourself...
>
> Steffen
Re: How to create views on a diagram (MVC pattern in GMF) [message #531796 is a reply to message #530684] Thu, 06 May 2010 08:04 Go to previous message
Eclipse UserFriend
Originally posted by: kluepfel.cs.tu-berlin.de

Hello Markus,


> thank you for your reply. What do you mean by 'not noticed the view'? I
> think it is sufficient to create a control by using the parent 'Composite'
> such that the viewer gets 'attached' to the view.

By "not noticed the view" I just meant that you might know it yet. I did
not use "notify" in the sense of a message notification :-)

> I think (at least) there are 2 options to use the outline view:
>
> 1. To subclass the outline view (by usage of extension points and a
> subclass) to get additional views, separated from the outline view itself:
>
> a. The developers of the outline view did not intend the user to
> subclass this one (see javadoc tags: @noinstantiate, @noextend).

Right! You should instead customize the outline view by implementing a
ContentOutlinePage for your editor.

.... and open the view, I can see my diagram in the view, but all
elements in
> the
> editor disappear. And if I create new elements on the editor I can see and
> move them and change their sizes in the view. I think the crux is that by
> changing the RootEditPart the connection between the editor and the figures
> erases because the RootEditPart gets a new viewer.
> But this is not what I wanted to get. I wanted to get several views for the
> same model as in MVC.
>
>
Have you had a look at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.Diagr amOutlinePage?
This class is used in gmf as outline page for gmf editors. Perhaps you
get some hints from this class.
>
> I think the problem is that it is not possible to attach the same
> RootEditPart to several viewers. Is it right?
> Maybe it is possible to implement a viewer adapter which delegates all
> requests to the original RootEditPart or something like that.
>
Good question. I would have a look at the implementation of
DiagramOutlinePage.

Kind regards,

Steffen
Previous Topic:Load Resource and Traverse it
Next Topic:Context Menu in GMF
Goto Forum:
  


Current Time: Fri Mar 29 13:48:55 GMT 2024

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

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

Back to the top