| Summary: | [Zest] graphConnection.addListener not working | ||
|---|---|---|---|
| Product: | [Tools] GEF | Reporter: | Lars Vogel <Lars.Vogel> |
| Component: | GEF-Legacy Zest | Assignee: | gef-inbox <gef-inbox> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | Lars.Vogel, steeg |
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
(In reply to comment #0) I believe events on GraphItems are not supported in general, but you could add a SelectionListener to the graph itself and check if the event's item is the connection: graph.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { if(e.item == graphConnection) System.out.println("Selected Connection"); } //... } (In reply to Fabian Steeg from comment #1) > (In reply to comment #0) > > I believe events on GraphItems are not supported in general, but you could > add a SelectionListener to the graph itself and check if the event's item is > the connection: > > graph.addSelectionListener(new SelectionListener() { > public void widgetSelected(SelectionEvent e) { > if(e.item == graphConnection) > System.out.println("Selected Connection"); > } > //... > } Thanks. That is a good workaround. I mark this bug as fixed. |
The selection listener is not called if the connection is selected. Am I'm doing something wrong? graphConnection.addListener(SWT.SELECTED, new Listener() { @Override public void handleEvent(Event event) { System.out.println("Selected"); } }); Full coding example (View): --------------- package de.vogella.zest.first; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.ui.part.ViewPart; import org.eclipse.zest.core.widgets.Graph; import org.eclipse.zest.core.widgets.GraphConnection; import org.eclipse.zest.core.widgets.GraphNode; import org.eclipse.zest.core.widgets.ZestStyles; import org.eclipse.zest.layouts.LayoutStyles; import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; public class View extends ViewPart { public static final String ID = "de.vogella.zest.first.view"; private Graph graph; private int layout = 1; public void createPartControl(Composite parent) { // Graph will hold all other objects graph = new Graph(parent, SWT.NONE); // Now a few nodes GraphNode node1 = new GraphNode(graph, SWT.NONE, "Jim"); GraphNode node2 = new GraphNode(graph, SWT.NONE, "Jack"); GraphNode node3 = new GraphNode(graph, SWT.NONE, "Joe"); GraphNode node4 = new GraphNode(graph, SWT.NONE, "Bill"); // Lets have a directed connection new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node1, node2); // Lets have a dotted graph connection new GraphConnection(graph, ZestStyles.CONNECTIONS_DOT, node2, node3); // Standard connection new GraphConnection(graph, SWT.NONE, node3, node1); // Change line color and line width GraphConnection graphConnection = new GraphConnection(graph, SWT.NONE, node1, node4); graphConnection.changeLineColor(parent.getDisplay().getSystemColor( SWT.COLOR_GREEN)); // Also set a text graphConnection.setText("This is a text"); graphConnection.setHighlightColor(parent.getDisplay().getSystemColor( SWT.COLOR_RED)); graphConnection.setLineWidth(3); graphConnection.addListener(SWT.SELECTED, new Listener() { @Override public void handleEvent(Event event) { System.out.println("Selected"); } }); graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); } public void setLayoutManager() { switch (layout) { case 1: graph.setLayoutAlgorithm(new TreeLayoutAlgorithm( LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); layout++; break; case 2: graph.setLayoutAlgorithm(new SpringLayoutAlgorithm( LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); layout = 1; break; } } /** * Passing the focus request to the viewer's control. */ public void setFocus() { } }