Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » One diagram per file with an unsynchronized model
One diagram per file with an unsynchronized model [message #188182] Wed, 21 May 2008 12:17 Go to next message
exquisitus is currently offline exquisitusFriend
Messages: 18
Registered: July 2009
Junior Member
Hi all,

I'm using GMF 2.0 with Eclipse 3.3.

My needs :
- I have my model loaded in a TreeViewer in my home-made explorer
and I want many diagrams representing everything or a part of
this model.

My solution :
- I've developped diagram editors unsynchronized from the model
and sharing a same transactional editing domain as described
in Tips section of the wiki.
- Then, I have no CanonicalEditPolicy installed in my EditParts.

My problem :
- When a model element is deleted from the TreeViewer or from one
diagram, the others diagrams are not updated when I reopen them.
- I get two situations with such EditPart which references an
unexisted model element :
1) The graphical view is marked with a cross
=> normal process I guess
2) The graphical view seems to reference the parent model element
and then show the name and icon of the parent for example
=> is it a bug from GMF or from my customization ?
This second situation seems to appear randomly when the
diagram was open during deletion.

Finaly, I would like to update diagrams as if I had a CanonicalEditPolicy.
If they are open during deletion or when I open them if they were closed.

Your solution :
- ??? :)

Thank you for your great job !
Sylvain
Re: One diagram per file with an unsynchronized model [message #188209 is a reply to message #188182] Wed, 21 May 2008 13:41 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Sylvain,

> 2) The graphical view seems to reference the parent model element
> and then show the name and icon of the parent for example
I suppose this means, corresponding View has no element set - see ViewImpl.getElement()
for the details.

-----------------
Alex Shatalin
Re: One diagram per file with an unsynchronized model [message #188233 is a reply to message #188209] Wed, 21 May 2008 14:14 Go to previous messageGo to next message
exquisitus is currently offline exquisitusFriend
Messages: 18
Registered: July 2009
Junior Member
As I see in the code below ... if the model element is not set,
the View gets the parent element ?

This is why the label and icon of the child shows parent model element
attributes ? Am I right ?

Why such a behaviour ??

Do you know how I could mark the View with cross to avoid this behaviour ?

Thanks,
Sylvain

------------------------------------------------------
from ViewImpl GMF 2.0


public EObject getElement() {
if (!isSetElement()) {
EObject container = eContainer();
if (container instanceof View) {
View view = (View) container;
element = view.getElement();
}
}
if (element != null && element.eIsProxy()) {
EObject oldElement = element;
element = eResolveProxy((InternalEObject) element);
if (element != oldElement) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this,
Notification.RESOLVE,
NotationPackage.VIEW__ELEMENT, oldElement,
element));
}
}

return element;
}
Re: One diagram per file with an unsynchronized model [message #188297 is a reply to message #188233] Wed, 21 May 2008 16:06 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Sylvain,

> This is why the label and icon of the child shows parent model element
> attributes ? Am I right ?
Yes.

> Why such a behaviour ??
This was in GMf from the very beggining.

> Do you know how I could mark the View with cross to avoid this
> behaviour ?
Well, isSetElement() should return true if setElement() was called for this
View instance. This means, in your situation all the elements should be set
AFAIU..
So, I suggest you to debug this method in case you have "cross" and you have
no "cross" and compare these two situations. As a result you'll be able to
find a reason of this problem.

-----------------
Alex Shatalin
Re: One diagram per file with an unsynchronized model [message #188742 is a reply to message #188297] Thu, 22 May 2008 12:07 Go to previous messageGo to next message
exquisitus is currently offline exquisitusFriend
Messages: 18
Registered: July 2009
Junior Member
Thx Alex, I will debug to understand this point.

What about the way to update old diagrams by removing useless views ?
Could you give me some help to understand how I could implement a kind of
CanonicalEditPolicy ?

Sylvain


Alex Shatalin wrote:

>> Do you know how I could mark the View with cross to avoid this
>> behaviour ?
> Well, isSetElement() should return true if setElement() was called for this
> View instance. This means, in your situation all the elements should be set
> AFAIU..
> So, I suggest you to debug this method in case you have "cross" and you have
> no "cross" and compare these two situations. As a result you'll be able to
> find a reason of this problem.
Re: One diagram per file with an unsynchronized model [message #188823 is a reply to message #188742] Thu, 22 May 2008 14:11 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Sylvain,

> Could you give me some help to understand how I could implement a kind
> of CanonicalEditPolicy ?
Just try to subclass it and iplement required abstract methods - it should
not be quite simple - you have to check if referenced model element is Proxy
or not.

-----------------
Alex Shatalin
Re: One diagram per file with an unsynchronized model [message #189312 is a reply to message #188742] Mon, 26 May 2008 11:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.herriger.gmx.de

You could generate your editor with 'synchronized' set to true. Then,
modify generated CEP:

1) getSemanticChildrenList():

This is the list of element types, which will be created, if there is no
corresponding view. Return an empty list here.

2) isOrphaned(...):

Replace method body with
return MyDiagramUpdater.isShortcutOrphaned(view);


This way, views are removed automatically. But view creation is still up
to the user. Connections are still fully synchronized. But, there are
two more things to consider:

DeleteFromDiagramAction won't let you delete views. It checks, if the
parent is canonical. Which is true, because there is a canonical edit
policy installed. You have to write your own action, which ignores CEPs.
Add this action inside generated ContributionItemProvider. Inside
Plug-in manifest, remove predefined 'deleteFromDiagramAction' (if
exists) and declare your own.

Last thing is: pressing 'del' will delete both, view and semantic
element. To prevent this, you can install a modified ComponentEditPolicy
inside your edit parts:

installEditPolicy(EditPolicy.COMPONENT_ROLE, new ComponentEditPolicy() {
protected boolean shouldDeleteSemantic() {
return false;
}});

May be, there are other/better solutions. But it works for me. Since I'm
still using 2.0, I wonder if there were any changes in GMF 2.1 regarding
the synchronization behavior?

Regards,
Jan

Sylvain Dudoit schrieb:
>
> Thx Alex, I will debug to understand this point.
>
> What about the way to update old diagrams by removing useless views ?
> Could you give me some help to understand how I could implement a kind
> of CanonicalEditPolicy ?
>
> Sylvain
>
>
> Alex Shatalin wrote:
>
>>> Do you know how I could mark the View with cross to avoid this
>>> behaviour ?
>> Well, isSetElement() should return true if setElement() was called for
>> this View instance. This means, in your situation all the elements
>> should be set AFAIU..
>> So, I suggest you to debug this method in case you have "cross" and
>> you have no "cross" and compare these two situations. As a result
>> you'll be able to find a reason of this problem.
>
>
>
Re: One diagram per file with an unsynchronized model [message #190613 is a reply to message #189312] Tue, 03 June 2008 07:56 Go to previous messageGo to next message
exquisitus is currently offline exquisitusFriend
Messages: 18
Registered: July 2009
Junior Member
Hi Jan,

Thank you so much for your help !

I have applied your indications with sucess. Well, I didn't found the
method "isShortcutOrphaned(view)" in my generated "DiagramUpdater" but
I've replaced it with a home-made one which checks for model element
validity.
For now, with a small example, it seems to work.

My last problem is how to replace the DeleteFromDiagramAction inside
generated ContributionItemProvider.

The only way I've seen in this forum to add a custom action in the
contextual menu is to contribute to the extension
"org.eclipse.ui.popupMenus" as usual and to specify the selected item to
" org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art ".

Could you give me more details about the way to add a custom action ? If
this information is explained somewhere, could you simply copy/paste the
URL ?

Thanks,
Sylvain
Re: One diagram per file with an unsynchronized model [message #190655 is a reply to message #190613] Tue, 03 June 2008 12:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.herriger.gmx.de

Hi Sylvain,

this should be explained somewhere. But I don't know where right know.

This contributes your own action for a specific edit part and removes a
predefined one:

<extension point="org.eclipse.gmf.runtime.common.
ui.services.action.contributionItemProviders">
<?gmfgen generated="false"?>
<contributionItemProvider
class="yourPackage.diagram.providers.XxxContributionItemProvider "
checkPluginLoaded="false">
<Priority name="Low"/>
<popupContribution class="org.eclipse.gmf.runtime.diagram.ui.
providers.DiagramContextMenuProvider">
<popupStructuredContributionCriteria
objectClass="yourPackage.diagram.
edit.parts.XxxEditPart"/>
<popupAction
id="deleteFromDiagramAction"
path="/editGroup">
</popupAction>
<popupPredefinedItem
id="deleteFromDiagramAction"
remove="true">
</popupPredefinedItem>
</popupContribution>
.....

Your contribution provider should look like this:

protected IAction createAction(String actionId,
IWorkbenchPartDescriptor partDescriptor) {
if (actionId.equals(PrintPreviewAction.ID)) {
return new RenderedPrintPreviewAction(
new EnhancedPrintActionHelper());
} else if (actionId.equals(ActionIds.ACTION_DELETE_FROM_MODEL)) {
IWorkbenchPage workbenchPage = partDescriptor.getPartPage();
return new DeleteFromModelAction(workbenchPage);
} else if (actionId.equals(ActionIds.ACTION_DELETE_FROM_DIAGRAM)) {
IWorkbenchPage workbenchPage = partDescriptor.getPartPage();
return new DeleteFromDiagramAction(workbenchPage);
}
return super.createAction(actionId, partDescriptor);
}

Seems like I have my own delete from model action too... but I don't
remember why ;-)

btw: you don't use 'org.eclipse.ui.popupMenus' extension point here.

Sylvain Dudoit schrieb:
> Hi Jan,
>
> Thank you so much for your help !
>
> I have applied your indications with sucess. Well, I didn't found the
> method "isShortcutOrphaned(view)" in my generated "DiagramUpdater" but
> I've replaced it with a home-made one which checks for model element
> validity.
> For now, with a small example, it seems to work.
>
> My last problem is how to replace the DeleteFromDiagramAction inside
> generated ContributionItemProvider.
>
> The only way I've seen in this forum to add a custom action in the
> contextual menu is to contribute to the extension
> "org.eclipse.ui.popupMenus" as usual and to specify the selected item to
> " org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art ".
>
> Could you give me more details about the way to add a custom action ? If
> this information is explained somewhere, could you simply copy/paste the
> URL ?
>
> Thanks,
> Sylvain
>
>
Re: One diagram per file with an unsynchronized model [message #196051 is a reply to message #190655] Tue, 08 July 2008 09:30 Go to previous message
Eclipse UserFriend
Originally posted by: janiko.gmx.de

Hi, i applied your solution successfully, thanks a lot. But the
contributionItemProviders extension pint dont have any effect. The
yourPackage.diagram.providers.XxxContributionItemProvider is never
called. May you or anyone else can help me here.



Jan Herriger schrieb:
> Hi Sylvain,
>
> this should be explained somewhere. But I don't know where right know.
>
> This contributes your own action for a specific edit part and removes a
> predefined one:
>
> <extension point="org.eclipse.gmf.runtime.common.
> ui.services.action.contributionItemProviders">
> <?gmfgen generated="false"?>
> <contributionItemProvider
> class="yourPackage.diagram.providers.XxxContributionItemProvider "
> checkPluginLoaded="false">
> <Priority name="Low"/>
> <popupContribution class="org.eclipse.gmf.runtime.diagram.ui.
> providers.DiagramContextMenuProvider">
> <popupStructuredContributionCriteria
> objectClass="yourPackage.diagram.
> edit.parts.XxxEditPart"/>
> <popupAction
> id="deleteFromDiagramAction"
> path="/editGroup">
> </popupAction>
> <popupPredefinedItem
> id="deleteFromDiagramAction"
> remove="true">
> </popupPredefinedItem>
> </popupContribution>
> ....
>
> Your contribution provider should look like this:
>
> protected IAction createAction(String actionId,
> IWorkbenchPartDescriptor partDescriptor) {
> if (actionId.equals(PrintPreviewAction.ID)) {
> return new RenderedPrintPreviewAction(
> new EnhancedPrintActionHelper());
> } else if (actionId.equals(ActionIds.ACTION_DELETE_FROM_MODEL)) {
> IWorkbenchPage workbenchPage = partDescriptor.getPartPage();
> return new DeleteFromModelAction(workbenchPage);
> } else if (actionId.equals(ActionIds.ACTION_DELETE_FROM_DIAGRAM)) {
> IWorkbenchPage workbenchPage = partDescriptor.getPartPage();
> return new DeleteFromDiagramAction(workbenchPage);
> }
> return super.createAction(actionId, partDescriptor);
> }
>
> Seems like I have my own delete from model action too... but I don't
> remember why ;-)
>
> btw: you don't use 'org.eclipse.ui.popupMenus' extension point here.
>
> Sylvain Dudoit schrieb:
>> Hi Jan,
>>
>> Thank you so much for your help !
>>
>> I have applied your indications with sucess. Well, I didn't found the
>> method "isShortcutOrphaned(view)" in my generated "DiagramUpdater" but
>> I've replaced it with a home-made one which checks for model element
>> validity.
>> For now, with a small example, it seems to work.
>>
>> My last problem is how to replace the DeleteFromDiagramAction inside
>> generated ContributionItemProvider.
>>
>> The only way I've seen in this forum to add a custom action in the
>> contextual menu is to contribute to the extension
>> "org.eclipse.ui.popupMenus" as usual and to specify the selected item
>> to " org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art ".
>>
>> Could you give me more details about the way to add a custom action ?
>> If this information is explained somewhere, could you simply
>> copy/paste the URL ?
>>
>> Thanks,
>> Sylvain
>>
>>
Previous Topic:Replacing DiagramContributionItemProvider
Next Topic:Canvas mapping
Goto Forum:
  


Current Time: Sat Jun 06 12:06:38 GMT 2020

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

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

Back to the top