Home » Modeling » GMF (Graphical Modeling Framework) » problem with synchronizing model change in different diagram
problem with synchronizing model change in different diagram [message #963] |
Sun, 30 July 2006 11:37  |
Eclipse User |
|
|
|
Originally posted by: dzhpingbo.sohu.com
I created two Diagrams , DiagramA and DigramB with the same metamodel. I
want to to fulfill this fuction: In DiagramA, I create a view with an
element called "data", when I double click this View, it will create another
view with the same element "data" In DigarmB.
The code is listed below:
first, I installed the editorPolicy in NodeEditPart:
installEditPolicy(EditPolicyRoles.OPEN_ROLE, new OpenEditorEditPolicy());
Second, I overwrite the getOpenCommand() method of OpenEditorEditPolicy:
protected Command getOpenCommand(Request request) {
CreateViewRequest.ViewDescriptor viewDescriptor = new
CreateViewRequest.ViewDescriptor(new EObjectAdapter(data), Node.class, null,
ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
CreateViewRequest cvRequest = new CreateViewRequest((viewDescriptor));
Command cmd =
targetDiagramEditor.getDiagramEditPart().getCommand(cvReques t);
return cmd;
}
By doing so ,I can create different view in two diagram with the same
element .
The problem is that,in DiagramA, when I change the name of element "data" in
its property view ,the view changes immediately, but in diagram B, when I
change the name of element "data" in its property view, the view didn't
change at all, unless I refresh the DiagramB manually.
It seems like that the view in Diagram B does not listen to the change of
its element "data".
It must be something wrong. And I was hold up by this for quite a few days,
looking forward to your answers.
By the way, does I set the parameter 'new EObjectAdater(selectedElement)'
right, or it should be something else?
I had follow the suggestion of this news listed below.
----- Original Message -----
Re: Building a diagram programmatically
From: "Alex Shatalin" <vano@borland.com>
Newsgroups: eclipse.technology.gmf
Sent: Tuesday, January 31, 2006 1:34 AM
Subject: Re: Building a diagram programmatically
> Hi!
>>> To get your domain model element created on step 1. you have to call
>>> " viewDescriptor.getElementAdapter().getAdapter(EObject.class) ". You will
>>> receive an element created on step 1 (returned from
>>> doDefaultElementCreation() method of your createCommand).
>> I do this in the execute of the CreateCommand, right? (I need to
>> override)
> In overriden getCreateCommand() method, before creating new instances
> of
> CreateCommand for your additional notation model elements.
>
>>> Finally, you have to create several additional instances of
>>> ViewDescriptor and corresponding CreateCommands. To create
>>> ViewDescriptor
>>> you have to pass IAdaptable implementation I think, EObjectAdapter()
>>> will
>>> help in this case.
>> In the createCreateCommand(), don't I need to pass to these descriptors
>> the object adapter obtained from the CreateViewRequest request? Or will
>> this be filled properly before the execution of the commands' execute?
> Object adapter from each descriptor (will be only one) from
> CreateViewRequest will hold only one EObject which was create in your
> model
> by your "semantic" command. From this adapter you can get an object,
> determine all the rest of the objects which was created and wrap them into
> new adapters which you have to pass to new "descriptors" which will be a
> parameters of CreateCommand. I suppose that you can override this method
> in
> a following way:
>
> protected Command getCreateCommand(CreateViewRequest request) {
> CompositeModelCommand cc = new
> CompositeModelCommand(DiagramUIMessages.AddCommand_Label);
> Iterator descriptors = request.getViewDescriptors().iterator();
> while (descriptors.hasNext()) {
> CreateViewRequest.ViewDescriptor descriptor =
> (CreateViewRequest.ViewDescriptor)descriptors.next();
> CreateCommand createCommand = new CreateCommand(descriptor,
> (View)(getHost().getModel()));
> cc.compose(createCommand);
>
> // Creating the rest of the notation model elements:
> EObject createdObject = (EObject)
> descriptor.getAdapter(EObject.class);
> EObject firstAdditionalObject =
> getFirstAdditionalObject(createdObject);
> CreateViewRequest.ViewDescriptor firstAdditionalDescriptor = new
> CreateViewRequest.ViewDescriptor(new
> EObjectAdapter(firstAdditionalObject),
> EcoreDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
> cc.compose(new CreateCommand(firstAdditionalDescriptor,
> (View)(getHost().getModel())));
> // Process the rest of additional objects...
> }
> return new EtoolsProxyCommand(cc.unwrap());
> }
>
> The only one problem is getFirstAdditionalObject() method.
>
> --
> Alex Shatalin
>
>
Attachment: DiagramB.JPG
(Size: 86.21KB, Downloaded 176 times)
Attachment: DiagramA.JPG
(Size: 87.77KB, Downloaded 158 times)
|
|
| |
Goto Forum:
Current Time: Thu Jun 05 18:39:02 EDT 2025
Powered by FUDForum. Page generated in 0.02757 seconds
|