+
+ private ScheduledFuture<?> hoverUpdateSchedule;
+
+ public void hoverNode(Resource runtimeDiagram, Resource mapElement, G2DParentNode hoveredNode) {
+ IThreadWorkQueue thread = getThread();
+ Simantics.getSession().asyncRequest(new ReadRequest() {
+
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ DynamicVisualisation visualisation = graph.syncRequest(new RuntimeDynamicVisualisationsRequest(runtimeDiagram));
+ if (visualisation == null)
+ return;
+ if (hoverUpdateSchedule != null && !hoverUpdateSchedule.isDone()) {
+ hoverUpdateSchedule.cancel(false);
+ }
+ hoverUpdateSchedule = ThreadUtils.getNonBlockingWorkExecutor().scheduleWithFixedDelay(() -> {
+
+ CompletableFuture<Object> future = new CompletableFuture<>();
+ try {
+ Simantics.getSession().syncRequest(new ReadRequest() {
+
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ boolean keyVariablesVertexHover = visualisation.isKeyVariablesVertexHover();
+ boolean keyVariablesEdgesHover = visualisation.isKeyVariablesEdgesHover();
+
+ Resource mapElementInstanceOf = graph.getSingleObject(mapElement, Layer0.getInstance(graph).InstanceOf);
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+
+ boolean doHover = true;
+ if (mapElementInstanceOf.equals(DN.Vertex) && !keyVariablesVertexHover) {
+ doHover = false;
+ } else if (mapElementInstanceOf.equals(DN.Edge) && !keyVariablesEdgesHover) {
+ doHover = false;
+ }
+ final boolean finalDoHover = doHover;
+
+ StyleResult results = DistrictNetworkHoverInfoStyle.doCalculateStyleResult(graph, runtimeDiagram, mapElement);
+ if (results != null) {
+ Point2D location = DistrictNetworkHoverInfoStyle.calculatePoint(graph, mapElement);
+ thread.asyncExec(() -> {
+ if (isRemoved())
+ return;
+ if (finalDoHover) {
+ hoverInfoNode.setLabels(results.getLabels());
+ hoverInfoNode.setOrigin(results.getOrigin());
+
+ hoverInfoNode.setMousePosition(location);
+ hoverInfoNode.hover2(hoveredNode);
+ } else {
+ hoverInfoNode.hover2(null);
+ }
+ future.complete(new Object());
+ });
+ } else {
+ future.complete(new Object());
+ }
+ }
+ });
+ } catch (DatabaseException e) {
+ future.completeExceptionally(e);
+ }
+ // this waits until everything is done
+ try {
+ future.get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOGGER.debug("Interrupted hovering", e);
+ }
+ }, 0, visualisation.getInterval(), TimeUnit.MILLISECONDS);
+ }
+ });
+ }
+
+ public boolean doHover(boolean hover, boolean isConnectionTool) {
+ return hoverInfoNode.hover(hover, isConnectionTool);
+ }