Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » problem with synchronizing model changes in different Editor
problem with synchronizing model changes in different Editor [message #1052] Sun, 30 July 2006 23:27 Go to next message
Eclipse UserFriend
Originally posted by: dzhpingbo.sohu.com

I want to to fulfill this fuction: In EditorA, I create a view with an
element called "data", when I double click this View, it will create a new
Editor EditorB, and create another view with the same element "data" In
EditorB.But it seems like that the view in EditorB does not listen to the
change of its element "data".


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) {

//Use ProcessDiagramEditorUtil to create a new Editor EditorB and it will be
ActiveEditor.
ProcessDiagramEditorUtil.createAndOpenDiagram(
ProcessDiagramFileCreator.getInstance(),
(new Path("testActionByProcess"))
.makeAbsolute(),
"dzh.diagram", EditorUtil
.getInitialContents(), "Process",
window, subProgressMonitor, true, true);

IWorkbenchWindow window = ProcessDiagramEditorPlugin.getInstance()
.getWorkbench().getActiveWorkbenchWindow();

//get EditorB
FileDiagramEditor targetDiagramEditor = (FileDiagramEditor) window
.getActivePage().getActiveEditor();

CreateViewRequest.ViewDescriptor viewDescriptor = new
CreateViewRequest.ViewDescriptor(new EObjectAdapter(data), Node.class, null,
ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT); //the element data is
the element I had just created in EditorA

CreateViewRequest cvRequest = new CreateViewRequest((viewDescriptor));

Command cmd =
targetDiagramEditor.getDiagramEditPart().getCommand(cvReques t);

return cmd;

}

By doing so ,I can create different view in two Editor with the same element
..
The problem is that,in EditorA, when I change the name of element "data" in
its property view ,the view changes immediately, but in EditorB, when I
change the name of element "data" in its property view, the view didn't
change at all, unless I refresh the EditorB manually.
It seems like that the view in EditorB 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: EditorB.JPG
    (Size: 86.08KB, Downloaded 148 times)
  • Attachment: EditorA.JPG
    (Size: 86.35KB, Downloaded 153 times)
Re: problem with synchronizing model changes in different Editor [message #1310 is a reply to message #1052] Tue, 01 August 2006 07:28 Go to previous messageGo to next message
Eclipse UserFriend
Hello dzh,

First of all, m.b. you can try to reuse EditingDomain across your two editors
as it was described in the following newsgroup postings:
news://news.eclipse.org/e148d36b6112cec24dd2abcb1b940ec6$1@w ww.eclipse.org
( http://dev.eclipse.org/newslists/news.eclipse.technology.gmf /msg04116.html)

> It seems like that the view in EditorB does not listen to the change
> of its element "data".
Looks like you are doing everything correctly. I can suggest only debugging
your code to get to the reason of these differences in the editor update
behavior. BTW, you can use ViewService interface to create view for an existing
domain model element.

-----------------
Alex Shatalin
Re: problem with synchronizing model changes in different Editor [message #2251 is a reply to message #1310] Tue, 01 August 2006 11:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dzhpingbo.sohu.com

I found that if I create Shortcut programmatically in the same editor, it
works fine:) The code below :

protected Command getOpenCommand(Request request) {


//Use the same Editor

targetDiagramEditor=(FileDiagramEditor)window.getActivePage( ).getActiveEditor();
DiagramImpl
targetdiagramImpl=(DiagramImpl)targetDiagramEditor.getDiagra mEditPart().getModel();
TransactionalEditingDomain
editingDomain=targetDiagramEditor.getEditingDomain();

CreateViewRequest.ViewDescriptor viewDescriptor = new
CreateViewRequest.ViewDescriptor(
new EObjectAdapter(eclEntityImpl), Node.class, null,
ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
CreateCommand command = new CreateCommand(editingDomain, viewDescriptor,
targetdiagramImpl) {

protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
CommandResult result = super.doExecuteWithResult(monitor, info);
View view = (View) ((IAdaptable) result.getReturnValue())
.getAdapter(View.class);
if (view != null && view.getEAnnotation("Shortcut") == null) {
//$NON-NLS-1$
EAnnotation shortcutAnnotation = EcoreFactory.eINSTANCE
.createEAnnotation();
shortcutAnnotation.setSource("Shortcut"); //$NON-NLS-1$
shortcutAnnotation.getDetails().put(
"modelID", ProcessDiagramEditPart.MODEL_ID); //$NON-NLS-1$
view.getEAnnotations().add(shortcutAnnotation);
}
return result;
}

};
try {
OperationHistoryFactory.getOperationHistory().execute(comman d,
new NullProgressMonitor(), null);
} catch (ExecutionException e) {
ProcessDiagramEditorPlugin.getInstance().logError(
"Unable to create shortcut", e); //$NON-NLS-1$
}


}


But if I create Shortcut programmatically in different editors, it come out
the problem, the view does not listen to the change of the element. The code
below:
protected Command getOpenCommand(Request request) {

//create new Editor
IProgressMonitor progressMonitor = new NullProgressMonitor();
progressMonitor.beginTask("Creating diagram and model files", 4);
//$NON-NLS-1$
final IProgressMonitor subProgressMonitor = new SubProgressMonitor(
progressMonitor, 1);
ProcessDiagramEditorUtil.createAndOpenDiagram(
ProcessDiagramFileCreator.getInstance(), (new
Path("testActionByProcess")).makeAbsolute(), "dzhprocess_process.diagram",
EditorUtil.getInitialContents(), "Process", window,
subProgressMonitor,
true, true);

targetDiagramEditor=(FileDiagramEditor)window.getActivePage( ).getActiveEditor();
DiagramImpl
targetdiagramImpl=(DiagramImpl)targetDiagramEditor.getDiagra mEditPart().getModel();
TransactionalEditingDomain
editingDomain=targetDiagramEditor.getEditingDomain();

CreateViewRequest.ViewDescriptor viewDescriptor = new
CreateViewRequest.ViewDescriptor(
new EObjectAdapter(eclEntityImpl), Node.class, null,
ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
CreateCommand command = new CreateCommand(editingDomain, viewDescriptor,
targetdiagramImpl) {

protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
CommandResult result = super.doExecuteWithResult(monitor, info);
View view = (View) ((IAdaptable) result.getReturnValue())
.getAdapter(View.class);
if (view != null && view.getEAnnotation("Shortcut") == null) {
//$NON-NLS-1$
EAnnotation shortcutAnnotation = EcoreFactory.eINSTANCE
.createEAnnotation();
shortcutAnnotation.setSource("Shortcut"); //$NON-NLS-1$
shortcutAnnotation.getDetails().put(
"modelID", ProcessDiagramEditPart.MODEL_ID); //$NON-NLS-1$
view.getEAnnotations().add(shortcutAnnotation);
}
return result;
}

};
try {
OperationHistoryFactory.getOperationHistory().execute(comman d,
new NullProgressMonitor(), null);
} catch (ExecutionException e) {
ProcessDiagramEditorPlugin.getInstance().logError(
"Unable to create shortcut", e); //$NON-NLS-1$
}

}

so I think i t must be "they are not using the same ResoureSet by both
diagrams" refers to Alex mentioned in
http://dev.eclipse.org/newslists/news.eclipse.technology.gmf /msg04116.html ,
am I right?

"Alex Shatalin" <vano@borland.com> д
Re: problem with synchronizing model changes in different Editor [message #2282 is a reply to message #2251] Tue, 01 August 2006 11:48 Go to previous messageGo to next message
Eclipse UserFriend
Hello dzh,

> so I think i t must be "they are not using the same ResoureSet by
> both diagrams" refers to Alex mentioned in
> http://dev.eclipse.org/newslists/news.eclipse.technology.gmf /msg04116.
> html , am I right?
This could be the reason. In case there are two different editors keeping
referenceing the same model element(s) you'll get two copies of the model
loaded into the memory and changes will not be propagated from one copy to
another one. I.e. if you select element on first diagram and change something
in a properties view for this element - first diagram should be updated,
but second one will not. If you select an element on second diagram and change
it in properties view - second diagram should be updated. Selected element
could be shortcutted.

-----------------
Alex Shatalin
Re: problem with synchronizing model changes in different Editor [message #2343 is a reply to message #2282] Tue, 01 August 2006 21:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dzhpingbo.sohu.com

Let me call my default.process_diagram as DiagramA and
dzhprocess_process.diagram.process_diagram as DiagramB.

> This could be the reason. In case there are two different editors keeping
> referenceing the same model element(s) you'll get two copies of the model
> loaded into the memory and changes will not be propagated from one copy to
> another one.
yes , I notice that, and in second situation - using shortcut in different
editor, I set the shortcut in DiagramB with the element which I just
created in DiagramA.
Sorry for not explaining clearly in my previous news.

CreateViewRequest.ViewDescriptor viewDescriptor = new
CreateViewRequest.ViewDescriptor( new EObjectAdapter(actImpl ), Node.class,
null,
//the actImpl is the element I just created in default.process_diagram, I
want to creat the shortcut using the element from DiagramA
ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);


If I select element on DiagramA and change something in a properties view
for this element , the shortcut( I create it programmatically using the
element in DiagramA) in DiagramB does not listen to the change, unless I
refresh it manually( I have to double click on the shortcut's name and it
will reflect the change of element in DiagramA).
If I select shortcut on DiagramB and change something in a properties view
for this shortcut , the element in DiagramA is updated immediately without
needing to update it manually, but the shortcut I selected in DiagramB does
not listen to the change in the properties view.
But if I create the shortcut using the element I just created in the same
editor, it works perfectly, either change something in a properties view
for this shortcut or in a properties view for the element, both the shortcut
and the element update immediately.
I don't know why?

the complete code:
protected Command getOpenCommand(Request request) {

//create new Editor
IProgressMonitor progressMonitor = new NullProgressMonitor();
progressMonitor.beginTask("Creating diagram and model files", 4);

final IProgressMonitor subProgressMonitor = new SubProgressMonitor(
progressMonitor, 1);
ProcessDiagramEditorUtil.createAndOpenDiagram(
ProcessDiagramFileCreator.getInstance(), (new
Path("testActionByProcess")).makeAbsolute(), "dzhprocess_process.diagram",
EditorUtil.getInitialContents(), "Process", window,
subProgressMonitor,
true, true);

targetDiagramEditor=(FileDiagramEditor)window.getActivePage( ).getActiveEditor();
DiagramImpl
targetdiagramImpl=(DiagramImpl)targetDiagramEditor.getDiagra mEditPart().getModel();
TransactionalEditingDomain
editingDomain=targetDiagramEditor.getEditingDomain();

ActivityImpl actImpl = ... ; //get the ActivityImpl is the element I just
created in DiagramA

CreateViewRequest.ViewDescriptor viewDescriptor = new
CreateViewRequest.ViewDescriptor( new EObjectAdapter(actImpl ), Node.class,
null,
//the actImpl is the element I just created in DiagramA, I want to creat the
shortcut in DiagramB using the element from DiagramA
ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT); CreateCommand
command = new CreateCommand(editingDomain, viewDescriptor,
targetdiagramImpl) {

protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
CommandResult result = super.doExecuteWithResult(monitor, info);
View view = (View) ((IAdaptable) result.getReturnValue())
.getAdapter(View.class);
if (view != null && view.getEAnnotation("Shortcut") == null) {
//$NON-NLS-1$
EAnnotation shortcutAnnotation = EcoreFactory.eINSTANCE
.createEAnnotation();
shortcutAnnotation.setSource("Shortcut"); //$NON-NLS-1$
shortcutAnnotation.getDetails().put(
"modelID", ProcessDiagramEditPart.MODEL_ID); //$NON-NLS-1$
view.getEAnnotations().add(shortcutAnnotation);
}
return result;
}

};
try {
OperationHistoryFactory.getOperationHistory().execute(comman d,
new NullProgressMonitor(), null);
} catch (ExecutionException e) {
ProcessDiagramEditorPlugin.getInstance().logError(
"Unable to create shortcut", e); //$NON-NLS-1$
}

}


"Alex Shatalin" <vano@borland.com> д
Re: problem with synchronizing model changes in different Editor [message #2498 is a reply to message #2343] Wed, 02 August 2006 08:06 Go to previous messageGo to next message
Eclipse UserFriend
Hello dzh,

Looks like currently I understand what’s happening in your situation. I’ll
try to explain it below.

> ActivityImpl actImpl = ... ; //get the ActivityImpl is the element I
> just created in DiagramA
I suppose that here you’ll just get an element you have received from CreateCommand.
This element was loaded into ResourceSetA associated with DiagramA and has
no connection with ResourceSetB associated with DiagramB. In the same time,
DiagramB is listening only for a changes made in ResourceSetB. To create
shortcut working as GMF shortcuts you have to load created ActivityImpl into
ResourceSetB, get corresponding EObject and pass it to the CreateView command.
You can take a look on generated ?CreateShortcutAction. run(IAction action)
method (see http://wiki.eclipse.org/index.php/GMF_GenModel_Hints#GenDiag ram,
“Contains Shortcuts To” and “Shortcuts Provided For” properties). In this
method selected element will be loaded using it’s URI into the correct ResourceSet.

I have to mention that even if you correct this inconsistency, you’ll get
the situation which I’ve described in prev. post (element modified on diagramA
will be updated only on diagramA same with diagramB). If you’d like to synchronize
changes across diagramA-diagramB you should either write your synchronization
code manually or share same EditingDomain instance across diagramA-diagramB
editors (see http://dev.eclipse.org/newslists/news.eclipse.technology.gmf /msg04116.html).

-----------------
Alex Shatalin
Re: problem with synchronizing model changes in different Editor [message #2701 is a reply to message #2498] Wed, 02 August 2006 14:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dzhpingbo.sohu.com

"Alex Shatalin" <vano@borland.com> д
Re: problem with synchronizing model changes in different Editor [message #4834 is a reply to message #2701] Thu, 03 August 2006 08:58 Go to previous messageGo to next message
Eclipse UserFriend
Hello dzh,

> But, because of using the Editing Domain Id of DiagramA, I can not use
> the
> palette tools to create element in DiagramB any more. The case is
I remember similar problems where caused by two different ElementTypes with
the same eClass bound to the same instance of editing domain. To ensure that
this is the reason in your case too you can:

1. Execute runtime workspace with ONLY DiagramB diagramming plugins (just
remove plugins generated by GMF for DiagramA and restart runtime eclipse
instance) - I suppose that in this case you will be able to use palette on
DiagramB.

2. Try to create using palette diagram elements owned only by DiagramA/DiagramB?
In your MM it is Flow+Activity/DataPackage. I suppose that creation of these
elements from the palette should not be broken in case of simultaneous usage
of genrated DiagramA + DiagramB diagramming plugins.

If the situations described above could be reproduced in your case you can
try modifying generated plugin.xml for DiagramB and specify following metamodel
type description for “Data” metaclass:

<metamodel nsURI="<keepGeneratedValue>">
<specializationType
id="<keepGeneratedValue>"
kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"
edithelperadvice="<keepGeneratedValue>">
<specializes id="<id for "Data" metamodelType from plugin.xml generated
for DiagramA>"/>
<param name="semanticHint" value="<keepGeneratedValue>"/>
</specializationType>
</metamodel>

Instead of:
<metamodel nsURI="<GeneratedValue>">
<metamodelType
id="<GeneratedValue>"
kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"
eclass="<GeneratedValue>"
edithelper="<GeneratedValue>">
<param name="semanticHint" value="<GeneratedValue>"/>
</metamodelType>
</metamodel>

-----------------
Alex Shatalin
Re: problem with synchronizing model changes in different Editor [message #6341 is a reply to message #4834] Thu, 03 August 2006 13:19 Go to previous message
Eclipse UserFriend
Originally posted by: dzhpingbo.sohu.com

"Alex Shatalin" <vano@borland.com> д
Previous Topic:Re: Refresh Editor After Executing Commands
Next Topic:Is it possible to modify the position of Diagram menu on main menu bar?
Goto Forum:
  


Current Time: Sat Jun 07 19:14:23 EDT 2025

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

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

Back to the top