1 package org.simantics.district.network.ui.participants;
4 import java.util.Iterator;
6 import org.eclipse.e4.core.services.events.IEventBroker;
7 import org.eclipse.jface.viewers.StructuredSelection;
8 import org.simantics.browsing.ui.common.AdaptableHintContext;
9 import org.simantics.db.Resource;
10 import org.simantics.db.layer0.SelectionHints;
11 import org.simantics.diagram.elements.DiagramNodeUtil;
12 import org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElement;
13 import org.simantics.district.network.ui.adapters.DistrictNetworkVertexElement;
14 import org.simantics.district.network.ui.nodes.DistrictNetworkEdgeNode;
15 import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode;
16 import org.simantics.g2d.canvas.ICanvasContext;
17 import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant;
18 import org.simantics.g2d.element.IElement;
19 import org.simantics.scenegraph.g2d.G2DParentNode;
20 import org.simantics.utils.datastructures.hints.IHintContext.Key;
21 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
23 public class DistrictFinderVisualisationParticipant extends AbstractDiagramParticipant {
25 private static final String TOPIC = "org/simantics/district/selection/elementQuerySelection";
27 private IEventBroker broker;
29 public DistrictFinderVisualisationParticipant(IEventBroker broker) {
33 public static final Key COLOR_KEY = new KeyOf(Color.class, "COLOR");
36 public void addedToContext(ICanvasContext ctx) {
37 super.addedToContext(ctx);
39 broker.subscribe(TOPIC, event -> {
40 StructuredSelection selection = (StructuredSelection) event.getProperty(IEventBroker.DATA);
41 Iterator<?> iterator = selection.iterator();
42 while (iterator.hasNext()) {
43 AdaptableHintContext next = (AdaptableHintContext) iterator.next();
44 Resource resource = next.getHint(SelectionHints.KEY_MAIN);
45 Color colorr = next.getHint(COLOR_KEY);
46 IElement element = DiagramNodeUtil.findElement(ctx, resource);
47 final G2DParentNode node = element.getHint(DistrictNetworkEdgeElement.KEY_DN_EDGE_NODE);
49 // color is a bit special - if not present then reset with null value
50 ((DistrictNetworkEdgeNode) node).setDynamicColor(colorr);
53 final G2DParentNode vertexNode = element.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
54 ((DistrictNetworkVertexNode) vertexNode).setDynamicColor(colorr);
62 public void removedFromContext(ICanvasContext ctx) {
63 super.removedFromContext(ctx);