Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Connections to elements in collapsed compartments
Connections to elements in collapsed compartments [message #75235] Tue, 07 November 2006 13:17 Go to next message
Eclipse UserFriend
Originally posted by: tobk.gmx.de

Hello,

can you tell me if the following problem [1] is already solved? The request
was posted about half a year ago.

It's about connections with source or target feature being child of a
collapsed compartment. It would be nice, if those connections would be
reconnected to the collapsed compartment. Currently such connections just
disappear.

Could you give me a short advice or reference how to do this manually? I
think I'd have to override the
ResizableCompartmentEditPolicy.getResizeCommand and return a
CompositeCommand with the super-command and some reorientConnectionCommands
for all the children's connections. But how can I just reorient the
connection's view, without changing it's source/target features?

Thanks,
tobias

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=142270
Re: Connections to elements in collapsed compartments [message #75472 is a reply to message #75235] Tue, 07 November 2006 16:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

Hi Tobias,

You have to modify the canonical connection policy in two places.
Assuming this policy is not installed on the collapsed compartment.

My best experience is with a single canonical connection policy and
disabled view creation command in GraphicalNodeEditPolicy - to avoid
duplication of edges.

Note however that some of useful methods are final or private in the base
class so you will end up with some form of code duplication:

protected EditPart getTargetEditPartFor(EObject connection) {
EObject tel;
EditPart tep;
tel = getTargetElement(connection);
tep = getEditPartFor(tel, connection);
return tep;
}


protected EditPart getSourceEditPartFor(EObject connection) {
EObject sel;
EditPart sep;
sel = getSourceElement(connection);
sep = getEditPartFor(sel, connection);
return sep;
}

So basically, check the edit part that super returns and see whether its
parent/ancestor view is collapsed, if so return some other ShapeNode edit
part.


You also have to invalidate these edges when the compartments are expanded:

`extend '

final protected List cleanCanonicalSemanticChildren(Collection
viewChildren, Collection semanticChildren)

Here's an example:

protected List cleanCanonicalSemanticChildren(Collection viewChildren, Collection semanticChildren) {

List orphaned = super.cleanCanonicalSemanticChildren(viewChildren, semanticChildren);

//certain connections might be invalid because of the position of the port border items

for (Object child : viewChildren) {
Edge edge = (Edge) child;
EObject connection = edge.getElement();
View src = edge.getSource();
View dst = edge.getTarget();

EditPart srcEditPart = (EditPart) getHost().getViewer().getEditPartRegistry().get(src);
EditPart dstEditPart = (EditPart) getHost().getViewer().getEditPartRegistry().get(dst);

if (srcEditPart != getSourceEditPartFor(connection) || dstEditPart != getTargetEditPartFor(connection))
if (orphaned.contains(edge) == false)
orphaned.add(edge);


}

return orphaned;
}



On Tue, 07 Nov 2006 14:17:04 +0100, tobias wrote:

> Hello,
>
> can you tell me if the following problem [1] is already solved? The request
> was posted about half a year ago.
>
> It's about connections with source or target feature being child of a
> collapsed compartment. It would be nice, if those connections would be
> reconnected to the collapsed compartment. Currently such connections just
> disappear.
>
> Could you give me a short advice or reference how to do this manually? I
> think I'd have to override the
> ResizableCompartmentEditPolicy.getResizeCommand and return a
> CompositeCommand with the super-command and some reorientConnectionCommands
> for all the children's connections. But how can I just reorient the
> connection's view, without changing it's source/target features?
>
> Thanks,
> tobias
>
> [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=142270
Re: Connections to elements in collapsed compartments [message #77132 is a reply to message #75472] Mon, 13 November 2006 12:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tobk.gmx.de

Finally found time to try this... but it does not work yet.

Maybe I'm misunderstood you and did something wrong:
- I created a class extending CanonicalConnectionEditPolicy
- I implemented the getSource/TargetElement methods
- I changed the getSource/TargetEditPartFor methods so they return the
parent edit part's parent edit part, if the parent edit part's figure is
not extended
- I installed this edit policy on the
[ContainerElement]CompartmentEditPolicy
- I tried with CanonicalRole, ConnectionRole and RefreshConnectionsRole
- I did not yet change that one final method and the GraphicalNodesRole,
since - if I understood you right - these do only change/delete duplicate
and badly positioned connections

However, the getSource/TargetEditPartFor-method are not even called when I
expand/collapse the compartment...

Could you please tell me where I made a mistake?

thanks,
tobias


Vlad Ciubotariu wrote:
> Hi Tobias,
>
> You have to modify the canonical connection policy in two places.
> Assuming this policy is not installed on the collapsed compartment.
>
> My best experience is with a single canonical connection policy and
> disabled view creation command in GraphicalNodeEditPolicy - to avoid
> duplication of edges.
>
> Note however that some of useful methods are final or private in the base
> class so you will end up with some form of code duplication:
>
> protected EditPart getTargetEditPartFor(EObject connection) {
> EObject tel;
> EditPart tep;
> tel = getTargetElement(connection);
> tep = getEditPartFor(tel, connection);
> return tep;
> }
>
>
> protected EditPart getSourceEditPartFor(EObject connection) {
> EObject sel;
> EditPart sep;
> sel = getSourceElement(connection);
> sep = getEditPartFor(sel, connection);
> return sep;
> }
>
> So basically, check the edit part that super returns and see whether its
> parent/ancestor view is collapsed, if so return some other ShapeNode edit
> part.
>
>
> You also have to invalidate these edges when the compartments are
> expanded:
>
> `extend '
>
> final protected List cleanCanonicalSemanticChildren(Collection
> viewChildren, Collection semanticChildren)
>
> Here's an example:
>
> protected List cleanCanonicalSemanticChildren(Collection viewChildren,
> Collection semanticChildren) {
>
> List orphaned = super.cleanCanonicalSemanticChildren(viewChildren,
> semanticChildren);
>
> //certain connections might be invalid because of the position of the port
> border items
>
> for (Object child : viewChildren) {
> Edge edge = (Edge) child;
> EObject connection = edge.getElement();
> View src = edge.getSource();
> View dst = edge.getTarget();
>
> EditPart srcEditPart = (EditPart)
> getHost().getViewer().getEditPartRegistry().get(src); EditPart dstEditPart
> = (EditPart) getHost().getViewer().getEditPartRegistry().get(dst);
>
> if (srcEditPart != getSourceEditPartFor(connection) || dstEditPart !=
> getTargetEditPartFor(connection)) if (orphaned.contains(edge) == false)
> orphaned.add(edge);
>
>
> }
>
> return orphaned;
> }
>
>
>
> On Tue, 07 Nov 2006 14:17:04 +0100, tobias wrote:
>
>> Hello,
>>
>> can you tell me if the following problem [1] is already solved? The
>> request was posted about half a year ago.
>>
>> It's about connections with source or target feature being child of a
>> collapsed compartment. It would be nice, if those connections would be
>> reconnected to the collapsed compartment. Currently such connections just
>> disappear.
>>
>> Could you give me a short advice or reference how to do this manually? I
>> think I'd have to override the
>> ResizableCompartmentEditPolicy.getResizeCommand and return a
>> CompositeCommand with the super-command and some
>> reorientConnectionCommands for all the children's connections. But how
>> can I just reorient the connection's view, without changing it's
>> source/target features?
>>
>> Thanks,
>> tobias
>>
>> [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=142270
Re: Connections to elements in collapsed compartments [message #77165 is a reply to message #77132] Mon, 13 November 2006 15:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

You should have one CanononicalConnection policy per diagram. That's how
the generated code works, too.

You have to modify that policy to return different edit parts depending on
whether the containing compartment is collapsed or not. That policy must
refresh whenever a compartment is collapsed or extended.

You have to handle that event (DrawerStyle) in a subclass of
ResizeableCompartmentEditPart:

protected void handleNotificationEvent(Notification event ) {
Object feature = event.getFeature();
if (NotationPackage.eINSTANCE.getRatio_Value().equals(feature)
|| event.getOldValue()instanceof Ratio
|| event.getNewValue() instanceof Ratio)
refreshRatio();
else if (NotationPackage.eINSTANCE.getDrawerStyle_Collapsed().equals (feature)){
setCollapsed(event.getNewBooleanValue(), true);
this.getFigure().revalidate();
} else if (NotationPackage.eINSTANCE.getTitleStyle_ShowTitle().equals( feature))
setShowCompartmentTitle(event.getNewBooleanValue());
else if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(f eature)){
Integer c = (Integer) event.getNewValue();
setFontColor(DiagramColorRegistry.getInstance().getColor(c)) ;
}
else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals( feature) ||
NotationPackage.eINSTANCE.getFontStyle_FontName().equals(fea ture) ||
NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature ) ||
NotationPackage.eINSTANCE.getFontStyle_Italic().equals(featu re)) {
refreshFont();
} else
super.handleNotificationEvent(event);
}


That's where you have to refresh the CanonicalConnection policy.

Note: you can't have this canonical policy installed on the compartment
being collapsed:

public boolean isEnabled() {
// if the editing domain is null then there is no point in enabling the edit policy
// the editing domain could be null because the view is detached or if the host is detached
if ( TransactionUtil.getEditingDomain((EObject)getHost().getModel ())==null){
return false;
}
DrawerStyle dstyle = (DrawerStyle) ((View)host().getModel()).getStyle(NotationPackage.eINSTANCE .getDrawerStyle());
boolean isCollapsed = dstyle == null ? false : dstyle.isCollapsed();

if ( isCollapsed ) {
return false;
}

CanonicalStyle style = getCanonicalStyle();
boolean enabled = _enabled && ((View)host().getModel()).isVisible();

return style == null
? enabled
: style.isCanonical() && enabled;
}


On Mon, 13 Nov 2006 13:08:23 +0100, tobias wrote:

> Finally found time to try this... but it does not work yet.
>
> Maybe I'm misunderstood you and did something wrong:
> - I created a class extending CanonicalConnectionEditPolicy
> - I implemented the getSource/TargetElement methods
> - I changed the getSource/TargetEditPartFor methods so they return the
> parent edit part's parent edit part, if the parent edit part's figure is
> not extended
> - I installed this edit policy on the
> [ContainerElement]CompartmentEditPolicy
> - I tried with CanonicalRole, ConnectionRole and RefreshConnectionsRole
> - I did not yet change that one final method and the GraphicalNodesRole,
> since - if I understood you right - these do only change/delete duplicate
> and badly positioned connections
>
> However, the getSource/TargetEditPartFor-method are not even called when I
> expand/collapse the compartment...
>
> Could you please tell me where I made a mistake?
>
> thanks,
> tobias
>
>
> Vlad Ciubotariu wrote:
>> Hi Tobias,
>>
>> You have to modify the canonical connection policy in two places.
>> Assuming this policy is not installed on the collapsed compartment.
>>
>> My best experience is with a single canonical connection policy and
>> disabled view creation command in GraphicalNodeEditPolicy - to avoid
>> duplication of edges.
>>
>> Note however that some of useful methods are final or private in the base
>> class so you will end up with some form of code duplication:
>>
>> protected EditPart getTargetEditPartFor(EObject connection) {
>> EObject tel;
>> EditPart tep;
>> tel = getTargetElement(connection);
>> tep = getEditPartFor(tel, connection);
>> return tep;
>> }
>>
>>
>> protected EditPart getSourceEditPartFor(EObject connection) {
>> EObject sel;
>> EditPart sep;
>> sel = getSourceElement(connection);
>> sep = getEditPartFor(sel, connection);
>> return sep;
>> }
>>
>> So basically, check the edit part that super returns and see whether its
>> parent/ancestor view is collapsed, if so return some other ShapeNode edit
>> part.
>>
>>
>> You also have to invalidate these edges when the compartments are
>> expanded:
>>
>> `extend '
>>
>> final protected List cleanCanonicalSemanticChildren(Collection
>> viewChildren, Collection semanticChildren)
>>
>> Here's an example:
>>
>> protected List cleanCanonicalSemanticChildren(Collection viewChildren,
>> Collection semanticChildren) {
>>
>> List orphaned = super.cleanCanonicalSemanticChildren(viewChildren,
>> semanticChildren);
>>
>> //certain connections might be invalid because of the position of the port
>> border items
>>
>> for (Object child : viewChildren) {
>> Edge edge = (Edge) child;
>> EObject connection = edge.getElement();
>> View src = edge.getSource();
>> View dst = edge.getTarget();
>>
>> EditPart srcEditPart = (EditPart)
>> getHost().getViewer().getEditPartRegistry().get(src); EditPart dstEditPart
>> = (EditPart) getHost().getViewer().getEditPartRegistry().get(dst);
>>
>> if (srcEditPart != getSourceEditPartFor(connection) || dstEditPart !=
>> getTargetEditPartFor(connection)) if (orphaned.contains(edge) == false)
>> orphaned.add(edge);
>>
>>
>> }
>>
>> return orphaned;
>> }
>>
>>
>>
>> On Tue, 07 Nov 2006 14:17:04 +0100, tobias wrote:
>>
>>> Hello,
>>>
>>> can you tell me if the following problem [1] is already solved? The
>>> request was posted about half a year ago.
>>>
>>> It's about connections with source or target feature being child of a
>>> collapsed compartment. It would be nice, if those connections would be
>>> reconnected to the collapsed compartment. Currently such connections just
>>> disappear.
>>>
>>> Could you give me a short advice or reference how to do this manually? I
>>> think I'd have to override the
>>> ResizableCompartmentEditPolicy.getResizeCommand and return a
>>> CompositeCommand with the super-command and some
>>> reorientConnectionCommands for all the children's connections. But how
>>> can I just reorient the connection's view, without changing it's
>>> source/target features?
>>>
>>> Thanks,
>>> tobias
>>>
>>> [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=142270
Re: Connections to elements in collapsed compartments [message #77247 is a reply to message #77165] Mon, 13 November 2006 19:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tobk.gmx.de

Thank you for all your help, Vlad, but I'm still not so sure whether I'm on
the right way...

Here again what I did now (and which shows no results):
I finally found the one CanonicalConnectionEditPolicy (the given name is a
little bit irritating...) and added the following (and nothing more):

protected EObject getSourceElement(EObject relationship) {
EObject source= null;
if (relationship instanceof [ConnectionType]) {
source= (([ConnectionType]relationship).getSource();
}
[other connection types...]
return source;
}
(accordingly for target)

@Override
protected EditPart getSourceEditPartFor(EObject connection) {
EditPart editPart= super.getSourceEditPartFor(connection);
return getEditPartToAttachTo(editPart);
}
(same for target)

private EditPart getEditPartToAttachTo(EditPart editPart) {
EditPart parent= editPart.getParent();
if (parent instanceof ResizableCompartmentEditPart) {
ResizableCompartmentEditPart cep= (ResizableCompartmentEditPart) parent;
if (! cep.getCompartmentFigure().isExpanded()) {
return parent.getParent(); //since the compartmenteditpart is also
contained in the parent element's edit part
}
}
return editPart;
}

Further I added your handleNotificationEvent-snipplet to the
ResizableCompartmentEditPart that all this fuss is about.

Nothing more. Especially I did not install any additional EditPolicys to
that or another EditPart (except for the usual GraphicalNodeEditPolicy with
that one line removed to avoid duplicate edges). I did not yet regard the
given improvement for removing too many edges, since there is nothing to
remove yet.

When minimizing the Compartment none of the above shown methods is entered
(according to debugging) and the connection just disappears.

Please, could you tell me what _exactly_ to do in which file? I know this
must sound really stupid, but sometimes I'm having trouble looking behind
all the things happening (and happening not) in GMF "behind my back". ^^;;

I'd really appreciate your help in this issue.
tobias


Vlad Ciubotariu wrote:
> You should have one CanononicalConnection policy per diagram. That's how
> the generated code works, too.
>
> You have to modify that policy to return different edit parts depending on
> whether the containing compartment is collapsed or not. That policy must
> refresh whenever a compartment is collapsed or extended.
>
> You have to handle that event (DrawerStyle) in a subclass of
> ResizeableCompartmentEditPart:
>
> protected void handleNotificationEvent(Notification event ) {
> Object feature = event.getFeature();
> if (NotationPackage.eINSTANCE.getRatio_Value().equals(feature)
> || event.getOldValue()instanceof Ratio
> || event.getNewValue() instanceof Ratio)
> refreshRatio();
> else if
> (NotationPackage.eINSTANCE.getDrawerStyle_Collapsed().equals (feature)){
> setCollapsed(event.getNewBooleanValue(), true);
> this.getFigure().revalidate(); } else if
> (NotationPackage.eINSTANCE.getTitleStyle_ShowTitle().equals( feature))
> setShowCompartmentTitle(event.getNewBooleanValue()); else if
> (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(f eature)){
> Integer c = (Integer) event.getNewValue();
> setFontColor(DiagramColorRegistry.getInstance().getColor(c)) ; }
> else if
> (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals( feature) ||
>
NotationPackage.eINSTANCE.getFontStyle_FontName().equals(fea ture)
> ||
>
NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature )
> ||
>
NotationPackage.eINSTANCE.getFontStyle_Italic().equals(featu re))
> {
> refreshFont();
> } else
> super.handleNotificationEvent(event);
> }
>
>
> That's where you have to refresh the CanonicalConnection policy.
>
> Note: you can't have this canonical policy installed on the compartment
> being collapsed:
>
> public boolean isEnabled() {
> // if the editing domain is null then there is no point in
> enabling the edit policy // the editing domain could be null
> because the view is detached or if the host is detached if (
>
TransactionUtil.getEditingDomain((EObject)getHost().getModel ())==null){
> return false;
> }
> DrawerStyle dstyle = (DrawerStyle)
>
((View)host().getModel()).getStyle(NotationPackage.eINSTANCE .getDrawerStyle());
> boolean isCollapsed = dstyle == null ? false : dstyle.isCollapsed();
>
> if ( isCollapsed ) {
> return false;
> }
>
> CanonicalStyle style = getCanonicalStyle();
> boolean enabled = _enabled && ((View)host().getModel()).isVisible();
>
> return style == null
> ? enabled
> : style.isCanonical() && enabled;
> }
>
>
> On Mon, 13 Nov 2006 13:08:23 +0100, tobias wrote:
>
>> Finally found time to try this... but it does not work yet.
>>
>> Maybe I'm misunderstood you and did something wrong:
>> - I created a class extending CanonicalConnectionEditPolicy
>> - I implemented the getSource/TargetElement methods
>> - I changed the getSource/TargetEditPartFor methods so they return the
>> parent edit part's parent edit part, if the parent edit part's figure is
>> not extended
>> - I installed this edit policy on the
>> [ContainerElement]CompartmentEditPolicy
>> - I tried with CanonicalRole, ConnectionRole and RefreshConnectionsRole
>> - I did not yet change that one final method and the GraphicalNodesRole,
>> since - if I understood you right - these do only change/delete duplicate
>> and badly positioned connections
>>
>> However, the getSource/TargetEditPartFor-method are not even called when
>> I expand/collapse the compartment...
>>
>> Could you please tell me where I made a mistake?
>>
>> thanks,
>> tobias
>>
>>
>> Vlad Ciubotariu wrote:
>>> Hi Tobias,
>>>
>>> You have to modify the canonical connection policy in two places.
>>> Assuming this policy is not installed on the collapsed compartment.
>>>
>>> My best experience is with a single canonical connection policy and
>>> disabled view creation command in GraphicalNodeEditPolicy - to avoid
>>> duplication of edges.
>>>
>>> Note however that some of useful methods are final or private in the
>>> base class so you will end up with some form of code duplication:
>>>
>>> protected EditPart getTargetEditPartFor(EObject connection) {
>>> EObject tel;
>>> EditPart tep;
>>> tel = getTargetElement(connection);
>>> tep = getEditPartFor(tel, connection);
>>> return tep;
>>> }
>>>
>>>
>>> protected EditPart getSourceEditPartFor(EObject connection) {
>>> EObject sel;
>>> EditPart sep;
>>> sel = getSourceElement(connection);
>>> sep = getEditPartFor(sel, connection);
>>> return sep;
>>> }
>>>
>>> So basically, check the edit part that super returns and see whether its
>>> parent/ancestor view is collapsed, if so return some other ShapeNode
>>> edit part.
>>>
>>>
>>> You also have to invalidate these edges when the compartments are
>>> expanded:
>>>
>>> `extend '
>>>
>>> final protected List cleanCanonicalSemanticChildren(Collection
>>> viewChildren, Collection semanticChildren)
>>>
>>> Here's an example:
>>>
>>> protected List cleanCanonicalSemanticChildren(Collection viewChildren,
>>> Collection semanticChildren) {
>>>
>>> List orphaned = super.cleanCanonicalSemanticChildren(viewChildren,
>>> semanticChildren);
>>>
>>> //certain connections might be invalid because of the position of the
>>> port border items
>>>
>>> for (Object child : viewChildren) {
>>> Edge edge = (Edge) child;
>>> EObject connection = edge.getElement();
>>> View src = edge.getSource();
>>> View dst = edge.getTarget();
>>>
>>> EditPart srcEditPart = (EditPart)
>>> getHost().getViewer().getEditPartRegistry().get(src); EditPart
>>> dstEditPart = (EditPart)
>>> getHost().getViewer().getEditPartRegistry().get(dst);
>>>
>>> if (srcEditPart != getSourceEditPartFor(connection) || dstEditPart !=
>>> getTargetEditPartFor(connection)) if (orphaned.contains(edge) == false)
>>> orphaned.add(edge);
>>>
>>>
>>> }
>>>
>>> return orphaned;
>>> }
>>>
>>>
>>>
>>> On Tue, 07 Nov 2006 14:17:04 +0100, tobias wrote:
>>>
>>>> Hello,
>>>>
>>>> can you tell me if the following problem [1] is already solved? The
>>>> request was posted about half a year ago.
>>>>
>>>> It's about connections with source or target feature being child of a
>>>> collapsed compartment. It would be nice, if those connections would be
>>>> reconnected to the collapsed compartment. Currently such connections
>>>> just disappear.
>>>>
>>>> Could you give me a short advice or reference how to do this manually?
>>>> I think I'd have to override the
>>>> ResizableCompartmentEditPolicy.getResizeCommand and return a
>>>> CompositeCommand with the super-command and some
>>>> reorientConnectionCommands for all the children's connections. But how
>>>> can I just reorient the connection's view, without changing it's
>>>> source/target features?
>>>>
>>>> Thanks,
>>>> tobias
>>>>
>>>> [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=142270
Re: Connections to elements in collapsed compartments [message #77263 is a reply to message #77247] Mon, 13 November 2006 20:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

You're right, those methods don't get called in the generated policy.

In my case I directly subclass CanonicalConnectionEditPolicy. In my setup
all the connections in the model are owned by the top level element of the
diagram.

The new policy has to override all the abstract methods that you inherit
(plus the ones that we talked about):

abstract protected List getSemanticConnectionsList();

/**
* Return the supplied relationship's source element
* @param relationship semantic connection
* @return EObject the source EObject
*/
abstract protected EObject getSourceElement(EObject relationship);

/**
* Return the supplied relationship's target element.
*
* @param relationship semantic connection
* @return EObject the target EObject
*/
abstract protected EObject getTargetElement(EObject relationship);

plus this one, which by default returns an emtpy list.


protected List getSemanticChildrenList()


You also have to override this other one:

/**
* Manages all connections of the diagram.
*/
protected Collection getConnectionViews() {
Diagram diagram = (Diagram) getHost().getModel();
return diagram.getEdges();
}


I will send you by email the contents of my policy.

vlad






On Mon, 13 Nov 2006 20:24:23 +0100, tobias wrote:

> Thank you for all your help, Vlad, but I'm still not so sure whether I'm on
> the right way...
>
> Here again what I did now (and which shows no results):
> I finally found the one CanonicalConnectionEditPolicy (the given name is a
> little bit irritating...) and added the following (and nothing more):
>
> protected EObject getSourceElement(EObject relationship) {
> EObject source= null;
> if (relationship instanceof [ConnectionType]) {
> source= (([ConnectionType]relationship).getSource();
> }
> [other connection types...]
> return source;
> }
> (accordingly for target)
>
> @Override
> protected EditPart getSourceEditPartFor(EObject connection) {
> EditPart editPart= super.getSourceEditPartFor(connection);
> return getEditPartToAttachTo(editPart);
> }
> (same for target)
>
> private EditPart getEditPartToAttachTo(EditPart editPart) {
> EditPart parent= editPart.getParent();
> if (parent instanceof ResizableCompartmentEditPart) {
> ResizableCompartmentEditPart cep= (ResizableCompartmentEditPart) parent;
> if (! cep.getCompartmentFigure().isExpanded()) {
> return parent.getParent(); //since the compartmenteditpart is also
> contained in the parent element's edit part
> }
> }
> return editPart;
> }
>
> Further I added your handleNotificationEvent-snipplet to the
> ResizableCompartmentEditPart that all this fuss is about.
>
> Nothing more. Especially I did not install any additional EditPolicys to
> that or another EditPart (except for the usual GraphicalNodeEditPolicy with
> that one line removed to avoid duplicate edges). I did not yet regard the
> given improvement for removing too many edges, since there is nothing to
> remove yet.
>
> When minimizing the Compartment none of the above shown methods is entered
> (according to debugging) and the connection just disappears.
>
> Please, could you tell me what _exactly_ to do in which file? I know this
> must sound really stupid, but sometimes I'm having trouble looking behind
> all the things happening (and happening not) in GMF "behind my back". ^^;;
>
> I'd really appreciate your help in this issue.
> tobias
>
>
> Vlad Ciubotariu wrote:
>> You should have one CanononicalConnection policy per diagram. That's how
>> the generated code works, too.
>>
>> You have to modify that policy to return different edit parts depending on
>> whether the containing compartment is collapsed or not. That policy must
>> refresh whenever a compartment is collapsed or extended.
>>
>> You have to handle that event (DrawerStyle) in a subclass of
>> ResizeableCompartmentEditPart:
>>
>> protected void handleNotificationEvent(Notification event ) {
>> Object feature = event.getFeature();
>> if (NotationPackage.eINSTANCE.getRatio_Value().equals(feature)
>> || event.getOldValue()instanceof Ratio
>> || event.getNewValue() instanceof Ratio)
>> refreshRatio();
>> else if
>> (NotationPackage.eINSTANCE.getDrawerStyle_Collapsed().equals (feature)){
>> setCollapsed(event.getNewBooleanValue(), true);
>> this.getFigure().revalidate(); } else if
>> (NotationPackage.eINSTANCE.getTitleStyle_ShowTitle().equals( feature))
>> setShowCompartmentTitle(event.getNewBooleanValue()); else if
>> (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(f eature)){
>> Integer c = (Integer) event.getNewValue();
>> setFontColor(DiagramColorRegistry.getInstance().getColor(c)) ; }
>> else if
>> (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals( feature) ||
>>
> NotationPackage.eINSTANCE.getFontStyle_FontName().equals(fea ture)
>> ||
>>
> NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature )
>> ||
>>
> NotationPackage.eINSTANCE.getFontStyle_Italic().equals(featu re))
>> {
>> refreshFont();
>> } else
>> super.handleNotificationEvent(event);
>> }
>>
>>
>> That's where you have to refresh the CanonicalConnection policy.
>>
>> Note: you can't have this canonical policy installed on the compartment
>> being collapsed:
>>
>> public boolean isEnabled() {
>> // if the editing domain is null then there is no point in
>> enabling the edit policy // the editing domain could be null
>> because the view is detached or if the host is detached if (
>>
> TransactionUtil.getEditingDomain((EObject)getHost().getModel ())==null){
>> return false;
>> }
>> DrawerStyle dstyle = (DrawerStyle)
>>
> ((View)host().getModel()).getStyle(NotationPackage.eINSTANCE .getDrawerStyle());
>> boolean isCollapsed = dstyle == null ? false : dstyle.isCollapsed();
>>
>> if ( isCollapsed ) {
>> return false;
>> }
>>
>> CanonicalStyle style = getCanonicalStyle();
>> boolean enabled = _enabled && ((View)host().getModel()).isVisible();
>>
>> return style == null
>> ? enabled
>> : style.isCanonical() && enabled;
>> }
>>
>>
>> On Mon, 13 Nov 2006 13:08:23 +0100, tobias wrote:
>>
>>> Finally found time to try this... but it does not work yet.
>>>
>>> Maybe I'm misunderstood you and did something wrong:
>>> - I created a class extending CanonicalConnectionEditPolicy
>>> - I implemented the getSource/TargetElement methods
>>> - I changed the getSource/TargetEditPartFor methods so they return the
>>> parent edit part's parent edit part, if the parent edit part's figure is
>>> not extended
>>> - I installed this edit policy on the
>>> [ContainerElement]CompartmentEditPolicy
>>> - I tried with CanonicalRole, ConnectionRole and RefreshConnectionsRole
>>> - I did not yet change that one final method and the GraphicalNodesRole,
>>> since - if I understood you right - these do only change/delete duplicate
>>> and badly positioned connections
>>>
>>> However, the getSource/TargetEditPartFor-method are not even called when
>>> I expand/collapse the compartment...
>>>
>>> Could you please tell me where I made a mistake?
>>>
>>> thanks,
>>> tobias
>>>
>>>
>>> Vlad Ciubotariu wrote:
>>>> Hi Tobias,
>>>>
>>>> You have to modify the canonical connection policy in two places.
>>>> Assuming this policy is not installed on the collapsed compartment.
>>>>
>>>> My best experience is with a single canonical connection policy and
>>>> disabled view creation command in GraphicalNodeEditPolicy - to avoid
>>>> duplication of edges.
>>>>
>>>> Note however that some of useful methods are final or private in the
>>>> base class so you will end up with some form of code duplication:
>>>>
>>>> protected EditPart getTargetEditPartFor(EObject connection) {
>>>> EObject tel;
>>>> EditPart tep;
>>>> tel = getTargetElement(connection);
>>>> tep = getEditPartFor(tel, connection);
>>>> return tep;
>>>> }
>>>>
>>>>
>>>> protected EditPart getSourceEditPartFor(EObject connection) {
>>>> EObject sel;
>>>> EditPart sep;
>>>> sel = getSourceElement(connection);
>>>> sep = getEditPartFor(sel, connection);
>>>> return sep;
>>>> }
>>>>
>>>> So basically, check the edit part that super returns and see whether its
>>>> parent/ancestor view is collapsed, if so return some other ShapeNode
>>>> edit part.
>>>>
>>>>
>>>> You also have to invalidate these edges when the compartments are
>>>> expanded:
>>>>
>>>> `extend '
>>>>
>>>> final protected List cleanCanonicalSemanticChildren(Collection
>>>> viewChildren, Collection semanticChildren)
>>>>
>>>> Here's an example:
>>>>
>>>> protected List cleanCanonicalSemanticChildren(Collection viewChildren,
>>>> Collection semanticChildren) {
>>>>
>>>> List orphaned = super.cleanCanonicalSemanticChildren(viewChildren,
>>>> semanticChildren);
>>>>
>>>> //certain connections might be invalid because of the position of the
>>>> port border items
>>>>
>>>> for (Object child : viewChildren) {
>>>> Edge edge = (Edge) child;
>>>> EObject connection = edge.getElement();
>>>> View src = edge.getSource();
>>>> View dst = edge.getTarget();
>>>>
>>>> EditPart srcEditPart = (EditPart)
>>>> getHost().getViewer().getEditPartRegistry().get(src); EditPart
>>>> dstEditPart = (EditPart)
>>>> getHost().getViewer().getEditPartRegistry().get(dst);
>>>>
>>>> if (srcEditPart != getSourceEditPartFor(connection) || dstEditPart !=
>>>> getTargetEditPartFor(connection)) if (orphaned.contains(edge) == false)
>>>> orphaned.add(edge);
>>>>
>>>>
>>>> }
>>>>
>>>> return orphaned;
>>>> }
>>>>
>>>>
>>>>
>>>> On Tue, 07 Nov 2006 14:17:04 +0100, tobias wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> can you tell me if the following problem [1] is already solved? The
>>>>> request was posted about half a year ago.
>>>>>
>>>>> It's about connections with source or target feature being child of a
>>>>> collapsed compartment. It would be nice, if those connections would be
>>>>> reconnected to the collapsed compartment. Currently such connections
>>>>> just disappear.
>>>>>
>>>>> Could you give me a short advice or reference how to do this manually?
>>>>> I think I'd have to override the
>>>>> ResizableCompartmentEditPolicy.getResizeCommand and return a
>>>>> CompositeCommand with the super-command and some
>>>>> reorientConnectionCommands for all the children's connections. But how
>>>>> can I just reorient the connection's view, without changing it's
>>>>> source/target features?
>>>>>
>>>>> Thanks,
>>>>> tobias
>>>>>
>>>>> [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=142270
Re: Connections to elements in collapsed compartments [message #77359 is a reply to message #77263] Tue, 14 November 2006 10:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tobk.gmx.de

Hello Vlad,

finally some progress:
I really forgot to implement the getSemanticConnections method...
Now I implemented it and all the methods are called - unfortunately only
when I close and reopen the diagram. If the compartment was collapsed when
I saved the diagram, there is an additional connection view attached to the
parent node, which stays in place when I expand/collapse the compartment,
leading to a second edge. So in fact the collapse/extend behavior is
exactly the same, just with an additional edge to the parent node if the
node was collapsed when the diagram was opened.

My getSemanticConnectionsList return a list with the connections and my
getSemanticChildrenList returns all the nodes (generator-default). Adding
the connections to he list showed no difference. My getConnectionViews is
just like yours. The implementation of the other methods did not change
since my last post.

I think the error must be somewhere else, e.g. in the refreshing/event
handling, since it works fine when closing/reopening.

As I said I copied your handleNotificationEvent method in my
ResizableCompartmentEditPart and it is called and branches correctly when I
collapse the compartment, too. However, the methods implemented in the
CanonicalConnectionEditPolicy are not called...

BTW, how did you override the cleanCanonicalChildrenMethod? I can not do
so...

tobias


Vlad Ciubotariu wrote:
> You're right, those methods don't get called in the generated policy.
>
> In my case I directly subclass CanonicalConnectionEditPolicy. In my setup
> all the connections in the model are owned by the top level element of the
> diagram.
>
> The new policy has to override all the abstract methods that you inherit
> (plus the ones that we talked about):
>
> abstract protected List getSemanticConnectionsList();
>
> /**
> * Return the supplied relationship's source element
> * @param relationship semantic connection
> * @return EObject the source EObject
> */
> abstract protected EObject getSourceElement(EObject relationship);
>
> /**
> * Return the supplied relationship's target element.
> *
> * @param relationship semantic connection
> * @return EObject the target EObject
> */
> abstract protected EObject getTargetElement(EObject relationship);
>
> plus this one, which by default returns an emtpy list.
>
>
> protected List getSemanticChildrenList()
>
>
> You also have to override this other one:
>
> /**
> * Manages all connections of the diagram.
> */
> protected Collection getConnectionViews() {
> Diagram diagram = (Diagram) getHost().getModel();
> return diagram.getEdges();
> }
>
>
> I will send you by email the contents of my policy.
>
> vlad
Re: Connections to elements in collapsed compartments [message #77427 is a reply to message #77359] Tue, 14 November 2006 15:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

On Tue, 14 Nov 2006 11:28:12 +0100, tobias wrote:

> As I said I copied your handleNotificationEvent method in my
> ResizableCompartmentEditPart and it is called and branches correctly when I
> collapse the compartment, too. However, the methods implemented in the
> CanonicalConnectionEditPolicy are not called...

You have to call a refresh explicitly. From the compartment editPart, do
smth like this:

EditPart diagramEditPart = this.getViewer().getContents();

policy = (B2CanonicalConnectionEditPolicy) diagramEditPart
.getEditPolicy(Bluenose2EditPolicyRoles.CANONICAL_CONNECTION _ROLE);
policy.refresh();

substituting with your appropriate choices.

If refresh still doesn't do anything, let me know. The refresh might not
work right away if the policy is temporarily disabled by a
ToggleCanonicalModeCommand. But it should be done, at the end of the
current command.

For more on this look at the gmf GraphicalEditPart#disableCanonicalFor.


>
> BTW, how did you override the cleanCanonicalChildrenMethod? I can not do
> so...

I couldn't either so that's how I ended up copy & pasting the canonical
policies in my own code. If you do that the best way is to install a
canonical policy on the canonical role that only synchs the children. And
then install the customized one on a different role, other than
CANONICAL_ROLE.

In cleanCanonical you have to remove the stale diagram edge, and add
the connection corresponding to that edge back to the connection list
- it's in the code I sent you.

So basically, if you make sure the refresh works, and find some way to
override cleanCanononicalChildren() then the whole thing should work. My
implementation does smth similar and it works fine.

vlad
Re: Connections to elements in collapsed compartments [message #77736 is a reply to message #77427] Wed, 15 November 2006 12:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tobk.gmx.de

I made the refresh and all my methods _would_ get called if the
cleanCanononicalChildren() method did not remove all the edges from the
semantic children list. The refresh is called before the views attached to
the inner node were deleted, so all of them had a view and did not need to
be refreshed... isn't this kinda strange behaviour?

Further the behavior seems to be more or less random! In the current
configuration, sometimes it works at least when closing and reopening a
diagram. And then, five minutes later, without having changed anything
noteworthy, it doesn't work anymore even when closing and reopening the
diagram... this might be due to the fact that when opening a diagram with a
collapsed compartment, for a very short time the connection can be seen
pointing to some point inside the compartment (where the inner node was
located), and then disappears (see above pararaph)

I tried to Copy-Paste the whole Canonical(Connection)EditPolicy in my own
project for adapting the cleanCanononicalChildren() in some way, but after
doing so there were some severe problems with the editor resulting in the
inability to draw any diagram elements. Maybe caused by a failed casting to
the 'real' Canonical(Connection)EditPolicy somewhere in the code...

Whew, if I knew this would be so much effort... I think I'll put this
problem on the heap and focus on something else for now. Thank you for all
your help and incredible patience. :-)

tobias

PS.: Your mail did not arrive here. Maybe my eMail-providers Spam-protection
got it...


Vlad Ciubotariu wrote:
> On Tue, 14 Nov 2006 11:28:12 +0100, tobias wrote:
>
>> As I said I copied your handleNotificationEvent method in my
>> ResizableCompartmentEditPart and it is called and branches correctly when
>> I collapse the compartment, too. However, the methods implemented in the
>> CanonicalConnectionEditPolicy are not called...
>
> You have to call a refresh explicitly. From the compartment editPart, do
> smth like this:
>
> EditPart diagramEditPart = this.getViewer().getContents();
>
> policy = (B2CanonicalConnectionEditPolicy) diagramEditPart
> .getEditPolicy(Bluenose2EditPolicyRoles.CANONICAL_CONNECTION _ROLE);
> policy.refresh();
>
> substituting with your appropriate choices.
>
> If refresh still doesn't do anything, let me know. The refresh might not
> work right away if the policy is temporarily disabled by a
> ToggleCanonicalModeCommand. But it should be done, at the end of the
> current command.
>
> For more on this look at the gmf GraphicalEditPart#disableCanonicalFor.
>
>
>>
>> BTW, how did you override the cleanCanonicalChildrenMethod? I can not do
>> so...
>
> I couldn't either so that's how I ended up copy & pasting the canonical
> policies in my own code. If you do that the best way is to install a
> canonical policy on the canonical role that only synchs the children. And
> then install the customized one on a different role, other than
> CANONICAL_ROLE.
>
> In cleanCanonical you have to remove the stale diagram edge, and add
> the connection corresponding to that edge back to the connection list
> - it's in the code I sent you.
>
> So basically, if you make sure the refresh works, and find some way to
> override cleanCanononicalChildren() then the whole thing should work. My
> implementation does smth similar and it works fine.
>
> vlad
Re: Connections to elements in collapsed compartments [message #77956 is a reply to message #77736] Wed, 15 November 2006 17:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

On Wed, 15 Nov 2006 13:02:21 +0100, tobias wrote:

> I made the refresh and all my methods _would_ get called if the
> cleanCanononicalChildren() method did not remove all the edges from the
> semantic children list. The refresh is called before the views attached to
> the inner node were deleted, so all of them had a view and did not need to
> be refreshed... isn't this kinda strange behaviour?

I think those views aren't deleted, their edit parts are hidden.

>
> Further the behavior seems to be more or less random! In the current
> configuration, sometimes it works at least when closing and reopening a
> diagram. And then, five minutes later, without having changed anything
> noteworthy, it doesn't work anymore even when closing and reopening the
> diagram... this might be due to the fact that when opening a diagram with a
> collapsed compartment, for a very short time the connection can be seen
> pointing to some point inside the compartment (where the inner node was
> located), and then disappears (see above pararaph)
>
> I tried to Copy-Paste the whole Canonical(Connection)EditPolicy in my own
> project for adapting the cleanCanononicalChildren() in some way, but after
> doing so there were some severe problems with the editor resulting in the
> inability to draw any diagram elements. Maybe caused by a failed casting to
> the 'real' Canonical(Connection)EditPolicy somewhere in the code...

This won't work. Split it in two. One policy derived from the gmf
CanonicalEditPolicy handles only the semanticChildren and is installed on
the canonical role.

The copy pasted one, since it won't be a gmf canonical policy anymore,
installed it on some other role eg. My_Canonical_Role and have it refresh
connections only. Finally, in the one method similarly:

protected List cleanCanonicalSemanticChildren(Collection viewChildren,
Collection semanticChildren) {

List orphaned = super.cleanCanonicalSemanticChildren(viewChildren,
semanticChildren);

for (Object child : viewChildren) {
Edge edge = (Edge) child;
EObject connection = edge.getElement();
View src = edge.getSource();
View dst = edge.getTarget();

EditPart srcEditPart = (EditPart) getHost().getViewer()
.getEditPartRegistry().get(src);
EditPart dstEditPart = (EditPart) getHost().getViewer()
.getEditPartRegistry().get(dst);

if (srcEditPart != getSourceEditPartFor(connection)
|| dstEditPart != getTargetEditPartFor(connection))
if (orphaned.contains(edge) == false) {
orphaned.add(edge);
semanticChildren.add(edge.getElement());
}

}

return orphaned;
}



>
> Whew, if I knew this would be so much effort... I think I'll put this
> problem on the heap and focus on something else for now. Thank you for all
> your help and incredible patience. :-)
>
> tobias
>
> PS.: Your mail did not arrive here. Maybe my eMail-providers Spam-protection
> got it...
>
>
> Vlad Ciubotariu wrote:
>> On Tue, 14 Nov 2006 11:28:12 +0100, tobias wrote:
>>
>>> As I said I copied your handleNotificationEvent method in my
>>> ResizableCompartmentEditPart and it is called and branches correctly when
>>> I collapse the compartment, too. However, the methods implemented in the
>>> CanonicalConnectionEditPolicy are not called...
>>
>> You have to call a refresh explicitly. From the compartment editPart, do
>> smth like this:
>>
>> EditPart diagramEditPart = this.getViewer().getContents();
>>
>> policy = (B2CanonicalConnectionEditPolicy) diagramEditPart
>> .getEditPolicy(Bluenose2EditPolicyRoles.CANONICAL_CONNECTION _ROLE);
>> policy.refresh();
>>
>> substituting with your appropriate choices.
>>
>> If refresh still doesn't do anything, let me know. The refresh might not
>> work right away if the policy is temporarily disabled by a
>> ToggleCanonicalModeCommand. But it should be done, at the end of the
>> current command.
>>
>> For more on this look at the gmf GraphicalEditPart#disableCanonicalFor.
>>
>>
>>>
>>> BTW, how did you override the cleanCanonicalChildrenMethod? I can not do
>>> so...
>>
>> I couldn't either so that's how I ended up copy & pasting the canonical
>> policies in my own code. If you do that the best way is to install a
>> canonical policy on the canonical role that only synchs the children. And
>> then install the customized one on a different role, other than
>> CANONICAL_ROLE.
>>
>> In cleanCanonical you have to remove the stale diagram edge, and add
>> the connection corresponding to that edge back to the connection list
>> - it's in the code I sent you.
>>
>> So basically, if you make sure the refresh works, and find some way to
>> override cleanCanononicalChildren() then the whole thing should work. My
>> implementation does smth similar and it works fine.
>>
>> vlad
Re: Connections to elements in collapsed compartments [message #78024 is a reply to message #77956] Wed, 15 November 2006 21:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tobk.gmx.de

Right, you wrote this before. Sorry, I somehow lost the view on this. Ok, so
I'll give it one last try... tomorrow. ;-)

Again, thank you for all your help. I'll let you know if it works.
tobias

Vlad Ciubotariu wrote:
> On Wed, 15 Nov 2006 13:02:21 +0100, tobias wrote:
>
>> I made the refresh and all my methods _would_ get called if the
>> cleanCanononicalChildren() method did not remove all the edges from the
>> semantic children list. The refresh is called before the views attached
>> to the inner node were deleted, so all of them had a view and did not
>> need to be refreshed... isn't this kinda strange behaviour?
>
> I think those views aren't deleted, their edit parts are hidden.
>
>>
>> Further the behavior seems to be more or less random! In the current
>> configuration, sometimes it works at least when closing and reopening a
>> diagram. And then, five minutes later, without having changed anything
>> noteworthy, it doesn't work anymore even when closing and reopening the
>> diagram... this might be due to the fact that when opening a diagram with
>> a collapsed compartment, for a very short time the connection can be seen
>> pointing to some point inside the compartment (where the inner node was
>> located), and then disappears (see above pararaph)
>>
>> I tried to Copy-Paste the whole Canonical(Connection)EditPolicy in my own
>> project for adapting the cleanCanononicalChildren() in some way, but
>> after doing so there were some severe problems with the editor resulting
>> in the inability to draw any diagram elements. Maybe caused by a failed
>> casting to the 'real' Canonical(Connection)EditPolicy somewhere in the
>> code...
>
> This won't work. Split it in two. One policy derived from the gmf
> CanonicalEditPolicy handles only the semanticChildren and is installed on
> the canonical role.
>
> The copy pasted one, since it won't be a gmf canonical policy anymore,
> installed it on some other role eg. My_Canonical_Role and have it refresh
> connections only. Finally, in the one method similarly:
>
> protected List cleanCanonicalSemanticChildren(Collection viewChildren,
> Collection semanticChildren) {
>
> List orphaned = super.cleanCanonicalSemanticChildren(viewChildren,
> semanticChildren);
>
> for (Object child : viewChildren) {
> Edge edge = (Edge) child;
> EObject connection = edge.getElement();
> View src = edge.getSource();
> View dst = edge.getTarget();
>
> EditPart srcEditPart = (EditPart) getHost().getViewer()
> .getEditPartRegistry().get(src);
> EditPart dstEditPart = (EditPart) getHost().getViewer()
> .getEditPartRegistry().get(dst);
>
> if (srcEditPart != getSourceEditPartFor(connection)
> || dstEditPart != getTargetEditPartFor(connection))
> if (orphaned.contains(edge) == false) {
> orphaned.add(edge);
> semanticChildren.add(edge.getElement());
> }
>
> }
>
> return orphaned;
> }
>
>
>
>>
>> Whew, if I knew this would be so much effort... I think I'll put this
>> problem on the heap and focus on something else for now. Thank you for
>> all your help and incredible patience. :-)
>>
>> tobias
>>
>> PS.: Your mail did not arrive here. Maybe my eMail-providers
>> Spam-protection got it...
>>
>>
>> Vlad Ciubotariu wrote:
>>> On Tue, 14 Nov 2006 11:28:12 +0100, tobias wrote:
>>>
>>>> As I said I copied your handleNotificationEvent method in my
>>>> ResizableCompartmentEditPart and it is called and branches correctly
>>>> when I collapse the compartment, too. However, the methods implemented
>>>> in the CanonicalConnectionEditPolicy are not called...
>>>
>>> You have to call a refresh explicitly. From the compartment editPart, do
>>> smth like this:
>>>
>>> EditPart diagramEditPart = this.getViewer().getContents();
>>>
>>> policy = (B2CanonicalConnectionEditPolicy) diagramEditPart
>>> .getEditPolicy(Bluenose2EditPolicyRoles.CANONICAL_CONNECTION _ROLE);
>>> policy.refresh();
>>>
>>> substituting with your appropriate choices.
>>>
>>> If refresh still doesn't do anything, let me know. The refresh might not
>>> work right away if the policy is temporarily disabled by a
>>> ToggleCanonicalModeCommand. But it should be done, at the end of the
>>> current command.
>>>
>>> For more on this look at the gmf GraphicalEditPart#disableCanonicalFor.
>>>
>>>
>>>>
>>>> BTW, how did you override the cleanCanonicalChildrenMethod? I can not
>>>> do so...
>>>
>>> I couldn't either so that's how I ended up copy & pasting the canonical
>>> policies in my own code. If you do that the best way is to install a
>>> canonical policy on the canonical role that only synchs the children.
>>> And then install the customized one on a different role, other than
>>> CANONICAL_ROLE.
>>>
>>> In cleanCanonical you have to remove the stale diagram edge, and add
>>> the connection corresponding to that edge back to the connection list
>>> - it's in the code I sent you.
>>>
>>> So basically, if you make sure the refresh works, and find some way to
>>> override cleanCanononicalChildren() then the whole thing should work. My
>>> implementation does smth similar and it works fine.
>>>
>>> vlad
Re: Connections to elements in collapsed compartments [message #78403 is a reply to message #78024] Fri, 17 November 2006 11:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tobk.gmx.de

It still doesn't work. I must be doing something terribly wrong...
Could you please try to send me that file again? Please try this adress:
tobias.kuester [at] t-online.de to avoid the spam catcher.

I now restored the generated canonicalconnectioneditpolicy and created a new
one. The getSemanticConnections returns an empty list, so this one should
not mess with the connections, right?

Then I copied that Policy [1], made it extend copies of the parent edit
policies and added all the customizations, including the overridden
cleanCanonicalSemanticChildren. I added a conditon, to add the edge's
elements only then to semanticChildren (where it has been removed from
earlier) if it is not already contained in there.

However, while the refreshing seems to work, the edges connected to the
container do not disappear (and by this grow more and more).

I even tried to advice the refreshSemanticConnections to remove all the
edges (skipping the cleanCanSemChildren) and then create new Connections
for all the semantic connections. No luck.

What makes me wonder most is that the diagram is fine and all the duplicate
edges gone, when I close and reopen it. Can't I somehow just fake a
close-reopen cycle?

tobias

[1] I also tried to create a new one from scratch, which behaved even
worse...

tobias wrote:
> Right, you wrote this before. Sorry, I somehow lost the view on this. Ok,
> so I'll give it one last try... tomorrow. ;-)
>
> Again, thank you for all your help. I'll let you know if it works.
> tobias
>
> Vlad Ciubotariu wrote:
>> On Wed, 15 Nov 2006 13:02:21 +0100, tobias wrote:
>>
>>> I made the refresh and all my methods _would_ get called if the
>>> cleanCanononicalChildren() method did not remove all the edges from the
>>> semantic children list. The refresh is called before the views attached
>>> to the inner node were deleted, so all of them had a view and did not
>>> need to be refreshed... isn't this kinda strange behaviour?
>>
>> I think those views aren't deleted, their edit parts are hidden.
>>
>>>
>>> Further the behavior seems to be more or less random! In the current
>>> configuration, sometimes it works at least when closing and reopening a
>>> diagram. And then, five minutes later, without having changed anything
>>> noteworthy, it doesn't work anymore even when closing and reopening the
>>> diagram... this might be due to the fact that when opening a diagram
>>> with a collapsed compartment, for a very short time the connection can
>>> be seen pointing to some point inside the compartment (where the inner
>>> node was located), and then disappears (see above pararaph)
>>>
>>> I tried to Copy-Paste the whole Canonical(Connection)EditPolicy in my
>>> own project for adapting the cleanCanononicalChildren() in some way, but
>>> after doing so there were some severe problems with the editor resulting
>>> in the inability to draw any diagram elements. Maybe caused by a failed
>>> casting to the 'real' Canonical(Connection)EditPolicy somewhere in the
>>> code...
>>
>> This won't work. Split it in two. One policy derived from the gmf
>> CanonicalEditPolicy handles only the semanticChildren and is installed on
>> the canonical role.
>>
>> The copy pasted one, since it won't be a gmf canonical policy anymore,
>> installed it on some other role eg. My_Canonical_Role and have it refresh
>> connections only. Finally, in the one method similarly:
>>
>> protected List cleanCanonicalSemanticChildren(Collection viewChildren,
>> Collection semanticChildren) {
>>
>> List orphaned = super.cleanCanonicalSemanticChildren(viewChildren,
>> semanticChildren);
>>
>> for (Object child : viewChildren) {
>> Edge edge = (Edge) child;
>> EObject connection = edge.getElement();
>> View src = edge.getSource();
>> View dst = edge.getTarget();
>>
>> EditPart srcEditPart = (EditPart) getHost().getViewer()
>> .getEditPartRegistry().get(src);
>> EditPart dstEditPart = (EditPart) getHost().getViewer()
>> .getEditPartRegistry().get(dst);
>>
>> if (srcEditPart != getSourceEditPartFor(connection)
>> || dstEditPart != getTargetEditPartFor(connection))
>> if (orphaned.contains(edge) == false) {
>> orphaned.add(edge);
>> semanticChildren.add(edge.getElement());
>> }
>>
>> }
>>
>> return orphaned;
>> }
>>
>>
>>
>>>
>>> Whew, if I knew this would be so much effort... I think I'll put this
>>> problem on the heap and focus on something else for now. Thank you for
>>> all your help and incredible patience. :-)
>>>
>>> tobias
>>>
>>> PS.: Your mail did not arrive here. Maybe my eMail-providers
>>> Spam-protection got it...
>>>
>>>
>>> Vlad Ciubotariu wrote:
>>>> On Tue, 14 Nov 2006 11:28:12 +0100, tobias wrote:
>>>>
>>>>> As I said I copied your handleNotificationEvent method in my
>>>>> ResizableCompartmentEditPart and it is called and branches correctly
>>>>> when I collapse the compartment, too. However, the methods implemented
>>>>> in the CanonicalConnectionEditPolicy are not called...
>>>>
>>>> You have to call a refresh explicitly. From the compartment editPart,
>>>> do smth like this:
>>>>
>>>> EditPart diagramEditPart = this.getViewer().getContents();
>>>>
>>>> policy = (B2CanonicalConnectionEditPolicy) diagramEditPart
>>>> .getEditPolicy(Bluenose2EditPolicyRoles.CANONICAL_CONNECTION _ROLE);
>>>> policy.refresh();
>>>>
>>>> substituting with your appropriate choices.
>>>>
>>>> If refresh still doesn't do anything, let me know. The refresh might
>>>> not work right away if the policy is temporarily disabled by a
>>>> ToggleCanonicalModeCommand. But it should be done, at the end of the
>>>> current command.
>>>>
>>>> For more on this look at the gmf GraphicalEditPart#disableCanonicalFor.
>>>>
>>>>
>>>>>
>>>>> BTW, how did you override the cleanCanonicalChildrenMethod? I can not
>>>>> do so...
>>>>
>>>> I couldn't either so that's how I ended up copy & pasting the canonical
>>>> policies in my own code. If you do that the best way is to install a
>>>> canonical policy on the canonical role that only synchs the children.
>>>> And then install the customized one on a different role, other than
>>>> CANONICAL_ROLE.
>>>>
>>>> In cleanCanonical you have to remove the stale diagram edge, and add
>>>> the connection corresponding to that edge back to the connection list
>>>> - it's in the code I sent you.
>>>>
>>>> So basically, if you make sure the refresh works, and find some way to
>>>> override cleanCanononicalChildren() then the whole thing should work.
>>>> My implementation does smth similar and it works fine.
>>>>
>>>> vlad
Re: Connections to elements in collapsed compartments [message #656624 is a reply to message #75235] Sun, 27 February 2011 17:13 Go to previous message
Artjom is currently offline ArtjomFriend
Messages: 9
Registered: December 2010
Junior Member
Have somebody implement this crucial feature?
Previous Topic:Fire ValidateAction after each change
Next Topic:Show editor in view
Goto Forum:
  


Current Time: Thu Apr 25 00:43:58 GMT 2024

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

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

Back to the top