*******************************************************************************/
package org.simantics.diagram.adapter;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.awt.geom.AffineTransform;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayDeque;
import org.simantics.utils.threads.ThreadUtils;
import org.simantics.utils.threads.logger.ITask;
import org.simantics.utils.threads.logger.ThreadLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
/**
* This class loads a diagram contained in the graph database into the runtime
*/
public class GraphToDiagramSynchronizer extends AbstractDisposable implements IDiagramLoader, IModifiableSynchronizationContext {
+ private static final Logger LOGGER = LoggerFactory.getLogger(GraphToDiagramSynchronizer.class);
+
/**
* Controls whether the class adds hint listeners to each diagram element
* that try to perform basic sanity checks on changes happening in 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
}
} catch (InterruptedException e) {
// Shouldn't happen.
- e.printStackTrace();
+ LOGGER.error("Dispose interrupted!", e);
} finally {
detachSessionListener();
g.getSession().asyncRequest(new AsyncReadRequest() {
@Override
public void run(AsyncReadGraph graph) {
- profileObserver.listen(graph, GraphToDiagramSynchronizer.this);
+ ProfileObserver po = profileObserver;
+ if (po != null)
+ po.listen(graph, GraphToDiagramSynchronizer.this);
+ else
+ LOGGER.info("profileObserver has been disposed already!");
}
});
@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
Resource resource = ElementUtils.adapt(ec, Resource.class);
if (resource == null) {
pass = false;
- new Exception("Attempted to add an element to the diagram that is not adaptable to Resource: " + e + ", class: " + ec).printStackTrace();
+ LOGGER.error("", new Exception("Attempted to add an element to the diagram that is not adaptable to Resource: " + e + ", class: " + ec));
}
// Sanity check connection hints