import java.util.Collections;
import java.util.List;
+import org.simantics.Simantics;
import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
import org.simantics.district.route.Route;
import org.simantics.district.route.RouteEvent;
import org.simantics.district.route.Waypoint;
+import org.simantics.utils.threads.ThreadUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class RouteImpl implements Route {
+ private static final Logger LOGGER = LoggerFactory.getLogger(RouteImpl.class);
+
private String name;
private Resource model;
private Resource backend;
@Override
public Waypoint createWaypoint(Object backend) {
- if (backend instanceof Resource)
- return new WaypointImpl((Resource) backend, "Point 1");
+ if (backend instanceof Resource) {
+ Resource waypoint = (Resource) backend;
+ WaypointImpl wp = new WaypointImpl(waypoint, "");
+
+ // Read real label in background
+ ThreadUtils.getBlockingWorkExecutor().submit(() -> {
+ try {
+ Waypoint p = Simantics.getSession().syncRequest(
+ (Read<Waypoint>) graph -> RoutePersistence.toWaypoint(graph, waypoint));
+ if (p != null) {
+ wp.setLabel(p.getLabel());
+ rs.fireEvent(RouteEvent.TYPE_ROUTE_MODIFIED, RouteImpl.this);
+ }
+ } catch (DatabaseException e) {
+ LOGGER.error("Failed to read waypoint {} label", backend, e);
+ }
+ });
+
+ return wp;
+ }
throw new IllegalArgumentException("only Resource type waypoints supported, got " + backend); //$NON-NLS-1$
}