gwt-connectors: How to find out which widgets a connector is conntected?

22 views
Skip to first unread message

Janine Joachim

unread,
Jun 18, 2016, 10:27:48 AM6/18/16
to gwt-connectors
I have a panel where i can add widgets and connectors. How can I programmatically find out which widgets are connected to other widgets? I have tried the following:
Connector con = new Connector(x, y, 500, y, null, new SectionDecoration(DecorationType.ARROW_SOLID));
con.style = ConnectorStyle.SOLID;
con.showOnDiagram(diagram);  
.....
//some Shaped Widgets
....
if(con.startEndPoint.isGluedToConnectionPoint())
                    {
                       //add Label to PopUp-Panel
                        pop.addChild(label); 
                    }
.....
the if-condition is not working, but i don't know whats wrong. Can anybody help me? Thanks

Piotr Ostrowski

unread,
Jun 20, 2016, 6:34:02 AM6/20/16
to gwt-connectors
You can try this code:

private List<Widget> getConnectedWidgets(Shape shape) {
    List<Widget> widgets = new ArrayList<Widget>();
    
    for (ConnectionPoint cp : shape.connectionPoints) {
      for (EndPoint endpoint : cp.gluedEndPoints) {
        EndPoint otherSideEndpoint = endpoint.isStart() ? endpoint.connector.endEndPoint : endpoint.connector.startEndPoint;
        
        if (otherSideEndpoint.isGluedToConnectionPoint()) {
          widgets.add(otherSideEndpoint.gluedConnectionPoint.parentWidget);
        }
      }
    }
    
    return widgets;
  }

This method returns list of widgets connected to given Shape. I have also added this code to Example webapp, so you can try it out:

Janine Joachim

unread,
Jun 20, 2016, 7:32:09 AM6/20/16
to gwt-connectors
Hi!

Thank you for your example! I've tried to modify my code, but it did not work. It makes me crazy since 2 days...Maybe you can help me? 

Following you can see my modified code. What i want to do is adding a label to a Pop-Up Panel, depending of which side of the created connector is added to the widget.

final Shape shapeConcrete = new Shape(tes);
shapeConcrete.showOnDiagram(diagram);
shapeConcrete.showConnectionPoints(diagram);
		      		
shapeConcrete.enableConnectionCreate(true);
		
for (Connector c : shapeConcrete.getConnectedConnectors())
	for (ConnectionPoint cp : shapeConcrete.connectionPoints) { 
		for (EndPoint ep : cp.gluedEndPoints) {
		      if(ep.isGluedToConnectionPoint()){
		      		if(c.startEndPoint.equals(ep)){
		      		Label la = new Label ("it works A");
		      		pop.addChild(la);
		      					}
		      else if(c.endEndPoint.equals(ep)){
			      	Label lb = new Label ("it works B");
			      	pop.addChild(lb);
			      				}
		      			
		      						}
		      					
		      				}
		      				}

Thank you in Advance!

Piotr Ostrowski

unread,
Jun 20, 2016, 9:19:21 AM6/20/16
to gwt-connectors
To check which side of connector is connected to any shape, you can do this:

Connector connector = ... // the specified connector

// is start endpoint connected
if (connector.startEndPoint.isGluedToConnectionPoint()) {
  Widget connected = connector.startEndPoint.gluedConnectionPoint.parentWidget;
  LOG.info("-- start endpoint connected to widget: " + connected);
}

// is end endpoint connected
if (connector.endEndPoint.isGluedToConnectionPoint()) {
  Widget connected = connector.endEndPoint.gluedConnectionPoint.parentWidget;
  LOG.info("-- end endpoint connected to widget: " + connected);
}

If you also want to check connector is connected to specified shape, try this code:

Connector connector = ... // the specified connector
Shape shape = ... // the specified shape

if (connector.startEndPoint.isGluedToConnectionPoint()) {
  Widget connected = connector.startEndPoint.gluedConnectionPoint.parentWidget;
      
  if (connected.equals(shape.connectedWidget)) {
    LOG.info("--- start endpoint connected to shape");
  }
}

Janine Joachim

unread,
Jun 20, 2016, 9:47:14 AM6/20/16
to gwt-connectors
 the first example is what i have tried before, but i don't know why...it is not working :( the if-condition is always false! Do you have an idea, what  could be wrong?

Piotr Ostrowski

unread,
Jun 20, 2016, 10:10:54 AM6/20/16
to gwt-connectors
Can you post your code here? Show me, how you are creating shapes and connectors. My code sample works for me, so I have no idea what is wrong.

Janine Joachim

unread,
Jun 20, 2016, 10:27:38 AM6/20/16
to gwt-connectors
some code-snippets: 

	boolean isEndDragged = false;
	
	boolean isSeqDragged = false;
....
 final Window pop = new Window();
...
//drag
	seq.addDragStartHandler(new DragStartHandler() {
								public void onDragStart(DragStartEvent event) {
									event.setData("text", "images/con_sequenz.svg");
									isSeqDragged = true;  	
								      		  }
								      		});
.....

// drop 
	      		boundaryPanel.addDomHandler(new DropHandler() {
	      			public void onDrop(DropEvent event) {
		      			 event.preventDefault();
		      			final int x = (event.getNativeEvent().getClientX() - boundaryPanel.getAbsoluteLeft());
		                final int y = (event.getNativeEvent().getClientY() - boundaryPanel.getAbsoluteTop());
		      			boundaryPanel.getElement().getStyle().clearBackgroundColor();
.....
if (isEndDragged) {		   
						Image end2 = new Image("images/end.svg");
						end2.setSize("90", "90");		 
					 	boundaryPanel.add(end2, x, y);
					
		      			Shape shapeConcrete = new Shape(end2);
		      			shapeConcrete.showOnDiagram(diagram);   
		      			shapeConcrete.showConnectionPoints(diagram);
		      	
		      			isEndDragged = false;	
		  
		      		   }
		      		else if (isSeqDragged) {	
		      			Connector con_sequenz = new Connector(x, y, 500, y, null, new SectionDecoration(DecorationType.ARROW_SOLID));
		     	       	con_sequenz.style = ConnectorStyle.SOLID;
      		        	con_sequenz.showOnDiagram(diagram);    
	      	
      		        	if(con_sequenz.startEndPoint.isGluedToConnectionPoint()){
	      				Label a = new Label("it works");
	      				pop.addChild(a);
	      				isSeqDragged = false;
	      			};

Janine Joachim

unread,
Jun 20, 2016, 5:01:02 PM6/20/16
to gwt-connectors
for a better overview, i have tried to implement a short test-example:
 
package com.exa.projekt.client;

import pl.tecna.gwt.connectors.client.Diagram;
import pl.tecna.gwt.connectors.client.elements.Connector;
import pl.tecna.gwt.connectors.client.elements.Shape;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;


public class Projekt implements EntryPoint {
	
	private RootPanel rootPanel;

	public void onModuleLoad() {
	
	     rootPanel = RootPanel.get("gwtContainer");
	     rootPanel.setSize("1902", "868");

	     AbsolutePanel boundaryPanel = new AbsolutePanel();
	     boundaryPanel.setStyleName("frame1");
	     boundaryPanel.setSize("1455px", "600px");    	 

	     Diagram diagram = new Diagram(boundaryPanel);
	      
	     RootPanel.get().add(boundaryPanel, 446, 242);
	      
	     Connector con = new Connector(100, 300, 300, 500);
	     con.showOnDiagram(diagram);
	     
	     
	     Image img = new Image("images/concrete.svg");
	     img.setSize("200", "200");
	     boundaryPanel.add(img, 100,100);
	     
	     Shape shapei = new Shape(img);
	     shapei.showOnDiagram(diagram);
	
	     if(con.startEndPoint.isGluedToConnectionPoint()){
	    		  Image logo = new Image("images/xor.svg");
	    		  logo.setSize("100", "100");
	    		  boundaryPanel.add(logo);
	    };
}}
the if-condition is not working yet :( when i add  con.startEndPoint.setGluedToConnectionPoint(true) it is working. but that is not what i want...
 
i am using gwt-connectors 2.4. and gwt-2.5.1. Which Configuration do you use?

Piotr Ostrowski

unread,
Jun 21, 2016, 2:41:28 AM6/21/16
to gwt-connectors
Can you update gwt-connectors to version 2.7? I have used it with GWT 2.5.1 and 2.7.0 versions.

Janine Joachim

unread,
Jun 21, 2016, 2:50:16 AM6/21/16
to gwt-con...@googlegroups.com

I have tried this, but it is also not working...did you reviewed my new code-example? Anything wrong? Or Is it maybe a browser problem? Which Browser do you use?

--
You received this message because you are subscribed to a topic in the Google Groups "gwt-connectors" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gwt-connectors/QuUEMUcBQ6E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gwt-connector...@googlegroups.com.
To post to this group, send email to gwt-con...@googlegroups.com.
Visit this group at https://groups.google.com/group/gwt-connectors.
For more options, visit https://groups.google.com/d/optout.

Piotr Ostrowski

unread,
Jun 21, 2016, 3:17:15 AM6/21/16
to gwt-connectors
It not works, because you call "isGluedToConnectionPoint()" method synchronously. You can try to handle "ElementConnectEvent":

diagram.addDiagramListener(new DiagramListenerAdapter() {
      
  @Override
  public void onElementConnect(ElementConnectEvent event) {
    if (con.startEndPoint.isGluedToConnectionPoint()) {
      Image logo = new Image("images/xor.svg");
      logo.setSize("100", "100");
      boundaryPanel.add(logo);
    };
  }
});


Janine Joachim

unread,
Jun 21, 2016, 6:22:30 AM6/21/16
to gwt-connectors
Wow, that's it! Thank you very very much! You saved me from a nervous breakdown :)) 
 But one last Question...when i write: shape.enableConnection(true), how can i call this created Connector?
Reply all
Reply to author
Forward
0 new messages