@Override
final public void forEachPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncMultiProcedure<Resource> procedure) {
- throw new UnsupportedOperationException();
+ try {
-// assert(subject != null);
-// assert(procedure != null);
-//
-// final ListenerBase listener = getListenerBase(procedure);
-//
-// IntProcedure ip = new IntProcedure() {
-//
-// AtomicBoolean first = new AtomicBoolean(true);
-//
-// @Override
-// public void execute(ReadGraphImpl graph, int i) {
-// try {
-// if(first.get()) {
-// procedure.execute(graph, querySupport.getResource(i));
-// } else {
-// procedure.execute(impl.newRestart(graph), querySupport.getResource(i));
-// }
-// } catch (Throwable t2) {
-// Logger.defaultLogError(t2);
-// }
-// }
-//
-// @Override
-// public void finished(ReadGraphImpl graph) {
-// try {
-// if(first.compareAndSet(true, false)) {
-// procedure.finished(graph);
-//// impl.state.barrier.dec(this);
-// } else {
-// procedure.finished(impl.newRestart(graph));
-// }
-//
-// } catch (Throwable t2) {
-// Logger.defaultLogError(t2);
-// }
-// }
-//
-// @Override
-// public void exception(ReadGraphImpl graph, Throwable t) {
-// try {
-// if(first.compareAndSet(true, false)) {
-// procedure.exception(graph, t);
-// } else {
-// procedure.exception(impl.newRestart(graph), t);
-// }
-// } catch (Throwable t2) {
-// Logger.defaultLogError(t2);
-// }
-// }
-//
-// };
-//
-// int sId = querySupport.getId(subject);
-//
-// try {
-// QueryCache.runnerPredicates(impl, sId, impl.parent, listener, ip);
-// } catch (DatabaseException e) {
-// Logger.defaultLogError(e);
-// }
+ for(Resource predicate : getPredicates(impl, subject))
+ procedure.execute(impl, predicate);
+
+ procedure.finished(impl);
+
+ } catch (Throwable e) {
+ procedure.exception(impl, e);
+ }
}
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.diagram.content.EdgeResource;
+import org.simantics.diagram.internal.DebugPolicy;
import org.simantics.diagram.stubs.DiagramResource;
import org.simantics.diagram.synchronization.ErrorHandler;
import org.simantics.g2d.canvas.ICanvasContext;
*/
public class EdgeRequest extends BaseRequest2<EdgeResource, IElement> {
+ final GraphToDiagramSynchronizer synchronizer;
final ErrorHandler errorHandler;
final ListenerSupport listenerSupport;
final IDiagram diagram;
final ConnectionSegmentAdapter adapter;
- public EdgeRequest(ICanvasContext canvas, ErrorHandler errorHandler, ListenerSupport listenerSupport, IDiagram diagram, ConnectionSegmentAdapter adapter, EdgeResource resource) {
+ public EdgeRequest(GraphToDiagramSynchronizer synchronizer, ICanvasContext canvas, ErrorHandler errorHandler, ListenerSupport listenerSupport, IDiagram diagram, ConnectionSegmentAdapter adapter, EdgeResource resource) {
super(canvas, resource);
assert(adapter != null);
+ assert(synchronizer != null);
+ this.synchronizer = synchronizer;
this.errorHandler = errorHandler;
this.listenerSupport = listenerSupport;
this.diagram = diagram;
@Override
public void execute(AsyncReadGraph graph, IElement element) {
+
+ if (DebugPolicy.DEBUG_EDGE_LOAD)
+ System.out.println(" SPAWNED EDGE SEGMENT: " + element + " " + data);
+
+ // Register this for updates to work correctly
+ synchronizer.mapElementIfNew(data, element);
+
// task.finish();
// Tell the procedure to use this element
procedure.execute(graph, element);
*/
ConcurrentMap<Object, ConnectionEntityImpl> dataConnection = new ConcurrentHashMap<Object, ConnectionEntityImpl>();
+
+ void mapElementIfNew(final Object data, final IElement element) {
+ IElement mapped = getMappedElement(data);
+ if(mapped == null) {
+ mapElement(data, element);
+ currentUpdater.addedElements.add(element);
+ currentUpdater.addedElementMap.put(data, element);
+ }
+ }
+
+
/**
* @param data
* @param element
@Override
public void execute(Resource connectionType) {
synchronized (GraphToDiagramUpdater.this) {
+ IElement mapped = getMappedElement(element);
+ assert(mapped != null);
+
+ if (DebugPolicy.DEBUG_CONNECTION_LISTENER)
+ System.out.println("CONNECTION ENTITY CREATED " + e + " " + element);
+
//System.out.println("new connection entity " + e);
- ConnectionEntityImpl entity = new ConnectionEntityImpl(element, connectionType, e);
- e.setHint(ElementHints.KEY_CONNECTION_ENTITY, entity);
+ ConnectionEntityImpl entity = new ConnectionEntityImpl(element, connectionType, mapped);
+ mapped.setHint(ElementHints.KEY_CONNECTION_ENTITY, entity);
addedConnectionEntities.put(element, entity);
}
}
}
});
- graph.syncRequest(new EdgeRequest(canvas, errorHandler, canvasListenerSupport, diagram, adapter, seg), new AsyncProcedure<IElement>() {
+ graph.syncRequest(new EdgeRequest(GraphToDiagramSynchronizer.this, canvas, errorHandler, canvasListenerSupport, diagram, adapter, seg), new AsyncProcedure<IElement>() {
@Override
public void execute(AsyncReadGraph graph, IElement e) {
if (DebugPolicy.DEBUG_EDGE_LOAD)
- System.out.println("ADDED EDGE LOADED: " + e);
+ System.out.println("ADDED EDGE LOADED: " + e + " " + seg);
+
if (e != null) {
- mapElement(seg, e);
synchronized (GraphToDiagramUpdater.this) {
addedConnectionSegments.add(e);
addedElementMap.put(seg, e);
@Override
public void execute(IElement loaded) {
// Invoked when the element has been loaded.
- if (DebugPolicy.DEBUG_EDGE_LISTENER)
- System.out.println("EDGE LoadListener for " + loaded);
if (loaded == null) {
disposeListener();
}
Object data = loaded.getHint(ElementHints.KEY_OBJECT);
+
+ if (DebugPolicy.DEBUG_EDGE_LISTENER)
+ System.out.println("EDGE LoadListener for " + loaded + " " + data);
+
if (addedElementMap.containsKey(data)) {
// This element was just loaded, in
// which case its hints need to