- Simantics.getSession().asyncRequest(new Write() {
-
- @Override
- public void perform(WriteGraph graph) throws DatabaseException {
- graph.markUndoPoint();
- Resource defaultMapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).VertexDefaultMapping);
- DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, 0, defaultMapping); // TODO: elevation can be fetched from e.g. elevation API
- }
- });
+
+ boolean leftButton = e.button == MouseEvent.LEFT_BUTTON;
+
+ ThreadUtils.getNonBlockingWorkExecutor().schedule(() -> {
+ Simantics.getSession().asyncRequest(new Write() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ graph.markUndoPoint();
+ Resource mapping = null;
+ if (leftButton) {
+ mapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).LeftClickDefaultMapping);
+ } else {
+ mapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).RightClickDefaultMapping);
+ }
+ if (mapping == null) {
+ mapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).VertexDefaultMapping);
+ }
+ DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, Double.MAX_VALUE, mapping);
+ }
+ });
+ }, 100, TimeUnit.MILLISECONDS);