import java.util.function.Consumer;
import java.util.function.Supplier;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.services.events.IEventBroker;
+import org.eclipse.ui.PlatformUI;
import org.simantics.datatypes.literal.RGB;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.district.network.ui.nodes.DistrictRenderingPreparationNode;
import org.simantics.district.network.ui.nodes.DistrictSelectionNode;
import org.simantics.district.network.ui.participants.DNPointerInteractor;
+import org.simantics.district.network.ui.participants.DistrictFinderVisualisationParticipant;
import org.simantics.district.network.ui.participants.DynamicVisualisationContributionsParticipant;
import org.simantics.district.network.ui.participants.MapRulerPainter;
import org.simantics.district.network.visualisations.DynamicVisualisations;
DistrictRenderingPreparationNode prepNode = new DistrictRenderingPreparationNode();
prepNode.setZIndex(Integer.MIN_VALUE / 2);
spatialRoot.addNode("districtRenderingPrepareNode", prepNode);
+
+
+ IEclipseContext workbenchContext = getWorkbenchContext();
+ IEventBroker eventBroker = workbenchContext.get(IEventBroker.class);
+ DistrictFinderVisualisationParticipant districtFinderVisualisationParticipant = new DistrictFinderVisualisationParticipant(eventBroker);
+ ctx.add(districtFinderVisualisationParticipant);
+
}
-
+
+ public static IEclipseContext getWorkbenchContext(){
+ return PlatformUI.getWorkbench().getService(IEclipseContext.class);
+ }
+
protected String getPopupId() {
return "#DistrictDiagramPopup";
}
--- /dev/null
+package org.simantics.district.network.ui.participants;
+
+import java.awt.Color;
+import java.util.Iterator;
+
+import org.eclipse.e4.core.services.events.IEventBroker;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
+import org.simantics.db.Resource;
+import org.simantics.db.layer0.SelectionHints;
+import org.simantics.diagram.elements.DiagramNodeUtil;
+import org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElement;
+import org.simantics.district.network.ui.adapters.DistrictNetworkVertexElement;
+import org.simantics.district.network.ui.nodes.DistrictNetworkEdgeNode;
+import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant;
+import org.simantics.g2d.element.IElement;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
+
+public class DistrictFinderVisualisationParticipant extends AbstractDiagramParticipant {
+
+ private static final String TOPIC = "org/simantics/district/selection/elementQuerySelection";
+
+ private IEventBroker broker;
+
+ public DistrictFinderVisualisationParticipant(IEventBroker broker) {
+ this.broker = broker;
+ }
+
+ public static final Key COLOR_KEY = new KeyOf(Color.class, "COLOR");
+
+ @Override
+ public void addedToContext(ICanvasContext ctx) {
+ super.addedToContext(ctx);
+
+ broker.subscribe(TOPIC, event -> {
+ StructuredSelection selection = (StructuredSelection) event.getProperty(IEventBroker.DATA);
+ Iterator<?> iterator = selection.iterator();
+ while (iterator.hasNext()) {
+ AdaptableHintContext next = (AdaptableHintContext) iterator.next();
+ Resource resource = next.getHint(SelectionHints.KEY_MAIN);
+ Color colorr = next.getHint(COLOR_KEY);
+ IElement element = DiagramNodeUtil.findElement(ctx, resource);
+ final G2DParentNode node = element.getHint(DistrictNetworkEdgeElement.KEY_DN_EDGE_NODE);
+ if (node != null) {
+ // color is a bit special - if not present then reset with null value
+ ((DistrictNetworkEdgeNode) node).setDynamicColor(colorr);
+ node.repaint();
+ } else {
+ final G2DParentNode vertexNode = element.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
+ ((DistrictNetworkVertexNode) vertexNode).setDynamicColor(colorr);
+ vertexNode.repaint();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void removedFromContext(ICanvasContext ctx) {
+ super.removedFromContext(ctx);
+ }
+}