Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Highlighting Connection of ConnectionDecorator
Highlighting Connection of ConnectionDecorator [message #1404182] Wed, 30 July 2014 09:43 Go to next message
Simon Sperl is currently offline Simon SperlFriend
Messages: 21
Registered: May 2014
Junior Member
I would really like to have when I mouseover/select a ConnectionDecorator get an indication to which Connection the Decorator belongs.

Currently I tried via by adding ColorDecorator on the connection whenever a decorator becomes selected.
But it seems selection does not trigger a DiagramBehavior.refreshRenderingDecorators() so I am stuck and I don't know how to correctly react/(register a listener) to selection changes.

Can I do this like I tried or some other way?

[Updated on: Wed, 30 July 2014 16:06]

Report message to a moderator

Re: Highlighting Connection of ConnectionDecorator [message #1404227 is a reply to message #1404182] Wed, 30 July 2014 14:43 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Have you tried to register a SingleClickFeature? See
IToolBehaviorProvider.getSingleClickFeature().

Michael
Re: Highlighting Connection of ConnectionDecorator [message #1404259 is a reply to message #1404227] Wed, 30 July 2014 17:32 Go to previous messageGo to next message
Simon Sperl is currently offline Simon SperlFriend
Messages: 21
Registered: May 2014
Junior Member
thank you, I did.
But did not like that to trigger the decorator I had to click-pause-click (also https://bugs.eclipse.org/bugs/show_bug.cgi?id=440760 )

(since single click feature does not get called on the first click (which selects the shape))

currently I use this in DiagramEditor.init
      final GDiagramEditor me = this;
        final DiagramBehavior behav = (DiagramBehavior) this.getDiagramTypeProvider().getDiagramBehavior();

        //Highlight Connection of selected ConnectionDecorator
        selectionListener = new ISelectionListener() {
            HashSet<Connection > lastHighlighted = new HashSet<Connection >();

            @Override
            public void selectionChanged(IWorkbenchPart part, ISelection s) {

                if (part != me)
                    return;

                HashSet<Connection > highlighted = new HashSet<Connection >();

                if (s instanceof IStructuredSelection)
                    for (Object sel : ((IStructuredSelection) s).toArray())
                        if (sel instanceof AbstractEditPart)
                            if (((AbstractEditPart) sel).getModel() instanceof ConnectionDecorator) 
                                // ..jo I heard you like typecasts
                                highlighted.add((Connection) ((ConnectionDecorator) ((AbstractEditPart) sel).getModel()).eContainer());
                            

                for (Connection high : highlighted)
                    if (!lastHighlighted.contains(high)) {
                        // me.getDiagramBehavior().refreshRenderingDecorators(high);
                        GraphicalEditPart p = behav.getEditPartForPictogramElement(high);
                        if (p != null)
                            p.refresh();
                        p.refresh();
                    }

                for (Connection high : lastHighlighted)
                    if (!highlighted.contains(high)) {
                        // me.getDiagramBehavior().refreshRenderingDecorators(high);
                        GraphicalEditPart p = behav.getEditPartForPictogramElement(high);
                        if (p != null)
                            p.refresh();
                    }
                lastHighlighted = highlighted;
            }
        };
        getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(selectionListener);
     


But both ways seemingly run into a bug:

//printed the calls of refresh & ToolBehaviorProvider.getDecorators
//where I click between two ConnectionDecorators belonging to different connections
refresh Connection@1f0f970 (visible: true, active: true)
getDecorators Connection@1f0f970 (visible: true, active: true)
refresh Connection@9dc8ad (visible: true, active: true)
getDecorators Connection@9dc8ad (visible: true, active: true)
refresh Connection@1f0f970 (visible: true, active: true)
refresh Connection@9dc8ad (visible: true, active: true)
refresh Connection@1f0f970 (visible: true, active: true)
refresh Connection@9dc8ad (visible: true, active: true)

I have no idea why getDecorators doesn't get called anymore O.o

edit: after a bit more experimenting getDecorators gets called somewhat randomly on refresh (aka not always on the first refresh)

[Updated on: Wed, 30 July 2014 17:45]

Report message to a moderator

Re: Highlighting Connection of ConnectionDecorator [message #1411040 is a reply to message #1404259] Fri, 22 August 2014 08:36 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi Simon,

> I have no idea why getDecorators doesn't get called anymore

Not really sure about the real cause for that without actually debugging,
but the call to getDecorators is guarded by the following if:
if (pe.isActive() && !(pe instanceof Anchor) &&
graphicsAlgorithm.equals(pe.getGraphicsAlgorithm()))

Especially the GA check might return false...

However, back to your original question: while it might be a misuse of that
method, getSelectionBorder in the tool behavior provider is called when you
hover over a decorator (at least active ones). Might that help?

Michael
Re: Highlighting Connection of ConnectionDecorator [message #1457554 is a reply to message #1411040] Fri, 31 October 2014 12:47 Go to previous messageGo to next message
Simon Sperl is currently offline Simon SperlFriend
Messages: 21
Registered: May 2014
Junior Member
Thanks a lot, getSelectionBorder does what I want.

But my problems persist with getting the decorators to update, I am pretty certain the fault lies;
//in DefaultRefreshBehavior
public void refreshRenderingDecorators(PictogramElement pe) {
	GraphicalEditPart ep = diagramBehavior.getEditPartForPictogramElement(pe);
	if (ep instanceof IShapeEditPart) {
		IShapeEditPart sep = (IShapeEditPart) ep;
		sep.refreshDecorators();
	}
}

ep is a instance of FreeFormConnectionEditPart (which is not a IShapeEditPart)
Even though I know what is wrong I don't really know how to fix it :/
Re: Highlighting Connection of ConnectionDecorator [message #1463128 is a reply to message #1457554] Thu, 06 November 2014 08:35 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Simon,

there's an open enhancement bug for enabling connection decorators for
connections:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=399085

Sorry, I wasn't aware first that you asked about rendering decorators on
connections (on connection decorators - again shapes - they should work).

Have you tried to implenent your own refresh behavior for decorators: Create
and use your own subclass of DefaultRefreshBehavior and override
refreshRenderingDecorators?

Michael
Previous Topic:Create PictogramLink for Diagram object itself.
Next Topic:How can I combine nested feature calls in one command
Goto Forum:
  


Current Time: Sat Apr 27 03:58:09 GMT 2024

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

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

Back to the top