Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [Zest] How to add Listener For GraphNode/GraphConnection?
[Zest] How to add Listener For GraphNode/GraphConnection? [message #249209] Fri, 05 June 2009 05:34 Go to next message
jeffty is currently offline jefftyFriend
Messages: 2
Registered: July 2009
Junior Member
Hello,

I try to add listener for GraphNode/GraphConnection but it doens't work.

I.e. I want to print something when user double clicks one of the
GraphNodes and GraphConnections:

public class TestListener {

public static void main(String[] args) {
Display d = new Display();
Shell shell = new Shell(d);
shell.setLayout(new FillLayout());
shell.setSize(400, 400);

Graph g = new Graph(shell, SWT.NONE);

GraphNode n = new GraphNode(g, SWT.NONE, "Paper");
GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock");
GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors");

GraphConnection c1 = new GraphConnection(g, SWT.NONE, n, n2);
GraphConnection c2 = new GraphConnection(g, SWT.NONE, n2, n3);
GraphConnection c3 = new GraphConnection(g, SWT.NONE, n3, n);

n.addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
System.out.println("hello!");
}
});

c1.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
System.out.println("hi!");
}
});

g.setLayoutAlgorithm(new SpringLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);

shell.open();
while (!shell.isDisposed()) {
while (!d.readAndDispatch()) {
d.sleep();
}
}
}
}

Why GraphNode.addListener() doesn't work?

Thanks in advance.
Re: [Zest] How to add Listener For GraphNode/GraphConnection? [message #633785 is a reply to message #249209] Tue, 19 October 2010 13:02 Go to previous messageGo to next message
ouri.maler is currently offline ouri.malerFriend
Messages: 22
Registered: July 2010
Junior Member
*Sigh*
Well, in the face of my continued failure to solve this problem, I'm giving up on the graph-based interaction, and creating a dropdown menu for selecting nodes instead.
Re: [Zest] How to add Listener For GraphNode/GraphConnection? [message #633789 is a reply to message #249209] Tue, 19 October 2010 13:06 Go to previous messageGo to next message
ouri.maler is currently offline ouri.malerFriend
Messages: 22
Registered: July 2010
Junior Member
Whoops. My apologies, wrong thread (though similar problem). Confused it with my own.
Re: [Zest] How to add Listener For GraphNode/GraphConnection? [message #642316 is a reply to message #249209] Tue, 30 November 2010 19:00 Go to previous message
Johan Schulz is currently offline Johan SchulzFriend
Messages: 20
Registered: November 2010
Junior Member
You have to add the listener to the graph and get the selected figure from either graph.getFigureAt(x, y) and the coords of the event or graph.getSelection(), same with all other events.

Johan
Previous Topic:[Zest] All the nodes are in the upper left corner - please help
Next Topic:[Zest] Display SWT controls inside graph nodes
Goto Forum:
  


Current Time: Sun Dec 21 02:41:45 GMT 2014

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

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