| Home » Modeling » GMF (Graphical Modeling Framework) » problem with synchronizing model changes in different Editor
 Goto Forum:| 
| problem with synchronizing model changes in different Editor [message #1052] | Sun, 30 July 2006 23:27  |  | 
| Eclipse User  |  |  |  |  | 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 161 times)
 Attachment: EditorA.JPG (Size: 86.35KB, Downloaded 161 times)
 |  |  |  |  |  |  | 
| Re: problem with synchronizing model changes in different Editor [message #2251 is a reply to message #1310] | Tue, 01 August 2006 11:03   |  | 
| Eclipse User  |  |  |  |  | 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 #2343 is a reply to message #2282] | Tue, 01 August 2006 21:33   |  | 
| Eclipse User  |  |  |  |  | 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> д
 |  |  |  |  |  |  |  |  |  |  |  | 
 
 
 Current Time: Fri Oct 31 03:29:16 EDT 2025 
 Powered by FUDForum . Page generated in 0.06312 seconds |