X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fscl%2FScriptNodeMap.java;h=fc63fffc381cb2b5cb8da82d4ee349828496aa3d;hb=e7804ee146821cf2ea38e4671c5efdeaf73bf479;hp=d532e1f0557adbf8b93099713bc56732a9e28a66;hpb=790fd1f45553169b0fdc646f85c86d9e933912a4;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java b/org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java index d532e1f0..fc63fffc 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java +++ b/org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java @@ -11,7 +11,7 @@ import java.util.Set; import java.util.Stack; import org.simantics.db.ReadGraph; -import org.simantics.db.Session; +import org.simantics.db.RequestProcessor; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.WriteRequest; @@ -27,6 +27,8 @@ import org.simantics.objmap.graph.IMapping; import org.simantics.objmap.graph.IMappingListener; import org.simantics.utils.datastructures.MapSet; import org.simantics.utils.datastructures.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * NodeMap implementation used with SCL scripts. @@ -44,10 +46,10 @@ import org.simantics.utils.datastructures.Pair; */ public abstract class ScriptNodeMap implements NodeMap, IMappingListener, NodeListener { - private static final boolean DEBUG = false; + private static final Logger LOGGER = LoggerFactory.getLogger(ScriptNodeMap.class); - protected Session session; - protected IMapping mapping; + protected RequestProcessor session; + protected IMapping mapping; protected ParentNode rootNode; @@ -55,7 +57,7 @@ public abstract class ScriptNodeMap implements NodeMap private boolean dirty = false; - public ScriptNodeMap(Session session, IMapping mapping, ParentNode rootNode) { + public ScriptNodeMap(RequestProcessor session, IMapping mapping, ParentNode rootNode) { this.session = session; this.mapping = mapping; this.rootNode = rootNode; @@ -91,10 +93,9 @@ public abstract class ScriptNodeMap implements NodeMap return Collections.EMPTY_LIST; } - @SuppressWarnings("unchecked") @Override public ParentNode getRootNode() { - return (ParentNode)rootNode; + return rootNode; } @@ -120,16 +121,14 @@ public abstract class ScriptNodeMap implements NodeMap private boolean rangeModified = false; - @SuppressWarnings("unchecked") @Override public void updateRenderObjectsFor(E node) { - nodes.add((E)node); - + nodes.add(node); } @SuppressWarnings("unchecked") private void receiveAdd(E node, String id, boolean db) { - if (DEBUG) System.out.println("receiveAdd " + debugString(node) + " " + id + " " + db); + if (LOGGER.isTraceEnabled()) LOGGER.trace("receiveAdd " + debugString(node) + " " + id + " " + db); synchronized (syncMutex) { for (Pair n : added) { if (n.first.equals(node)) @@ -146,7 +145,7 @@ public abstract class ScriptNodeMap implements NodeMap @SuppressWarnings("unchecked") private void receiveRemove(E node, String id, boolean db) { - if (DEBUG) System.out.println("receiveRemove " + debugString(node) + " " + id + " " + db); + if (LOGGER.isTraceEnabled()) LOGGER.trace("receiveRemove " + debugString(node) + " " + id + " " + db); synchronized (syncMutex) { for (Pair n : removed) { if (n.first.equals(node)) @@ -160,9 +159,8 @@ public abstract class ScriptNodeMap implements NodeMap repaint(); } - @SuppressWarnings("unchecked") private void receiveUpdate(E node, String id, boolean db) { - if (DEBUG) System.out.println("receiveUpdate " + debugString(node) + " " + id + " " + db); + if (LOGGER.isTraceEnabled()) LOGGER.trace("receiveUpdate " + debugString(node) + " " + id + " " + db); synchronized (syncMutex) { // for (Pair n : updated) { // if (n.first.equals(node)) @@ -194,7 +192,7 @@ public abstract class ScriptNodeMap implements NodeMap @Override public void perform(WriteGraph graph) throws DatabaseException { - if (DEBUG) System.out.println("Commit " + commitMessage); + if (LOGGER.isTraceEnabled()) LOGGER.trace("Commit " + commitMessage); if (commitMessage != null) { Layer0Utils.addCommentMetadata(graph, commitMessage); graph.markUndoPoint(); @@ -208,12 +206,12 @@ public abstract class ScriptNodeMap implements NodeMap protected void commit(WriteGraph graph) throws DatabaseException { synchronized(syncMutex) { - if (DEBUG) System.out.println("Commit"); + if (LOGGER.isTraceEnabled()) LOGGER.trace("Commit"); graphUpdates = true; mapping.updateDomain(graph); graphUpdates = false; clearDeletes(); - if (DEBUG) System.out.println("Commit done"); + if (LOGGER.isTraceEnabled()) LOGGER.trace("Commit done"); } } @@ -223,7 +221,7 @@ public abstract class ScriptNodeMap implements NodeMap public void domainModified() { if (graphUpdates) return; - if (DEBUG)System.out.println("domainModified"); + if (LOGGER.isTraceEnabled()) LOGGER.trace("domainModified"); // FIXME : this is called by IMapping id DB thread dirty = true; // session.asyncRequest(new ReadRequest() { @@ -238,7 +236,7 @@ public abstract class ScriptNodeMap implements NodeMap } protected void reset(ReadGraph graph) throws MappingException { - if (DEBUG) System.out.println("Reset"); + if (LOGGER.isTraceEnabled()) LOGGER.trace("Reset"); synchronized (syncMutex) { graphUpdates = true; mapping.getRangeModified().clear(); @@ -251,11 +249,12 @@ public abstract class ScriptNodeMap implements NodeMap } protected void update(ReadGraph graph) throws DatabaseException { - if (DEBUG) System.out.println("Graph update start"); + if (LOGGER.isTraceEnabled()) LOGGER.trace("Graph update start"); synchronized (syncMutex) { graphUpdates = true; for (DBObject domainObject : mapping.getDomainModified()) { - E rangeObject = mapping.get(domainObject); + @SuppressWarnings("unchecked") + E rangeObject = (E) mapping.get(domainObject); if (rangeObject != null) graphModified.add(rangeObject); } @@ -270,7 +269,7 @@ public abstract class ScriptNodeMap implements NodeMap //if (mapping.isRangeModified() && !runUndo) // FIXME : redo? if (mapping.isRangeModified()) commit((String)null); - if (DEBUG) System.out.println("Graph update done"); + if (LOGGER.isTraceEnabled()) LOGGER.trace("Graph update done"); } @Override @@ -290,7 +289,6 @@ public abstract class ScriptNodeMap implements NodeMap doCommit(); } session.syncRequest(new ReadRequest() { - @SuppressWarnings("unchecked") @Override public void run(ReadGraph graph) throws DatabaseException { update(graph); @@ -319,6 +317,7 @@ public abstract class ScriptNodeMap implements NodeMap * This code here synchronizes removed and added objects to collect deletable objects. (a deletable object is one which is removed but not added). * */ + @SuppressWarnings("unused") protected void syncDeletes() { deleteUC.clear(); for (Pair n : removed) { @@ -327,10 +326,10 @@ public abstract class ScriptNodeMap implements NodeMap for (Pair n : added) { deleteUC.remove(n.first); } - if (DEBUG && deleteUC.size() > 0) { - System.out.println("Delete sync"); + if (LOGGER.isTraceEnabled() && deleteUC.size() > 0) { + LOGGER.trace("Delete sync"); for (E n : delete) { - System.out.println(debugString(n)); + LOGGER.trace(debugString(n)); } } delete.addAll(deleteUC); @@ -340,10 +339,11 @@ public abstract class ScriptNodeMap implements NodeMap /** * Clears deletable objects from mapping cache. */ + @SuppressWarnings("unused") protected void clearDeletes() { - if (DEBUG && delete.size() > 0) System.out.println("Delete"); + if (LOGGER.isTraceEnabled() && delete.size() > 0) LOGGER.trace("Delete"); for (E n : delete) { - if (DEBUG) System.out.println(debugString(n)); + if (LOGGER.isTraceEnabled()) LOGGER.trace(debugString(n)); mapping.getRange().remove(n); } delete.clear(); @@ -514,7 +514,7 @@ public abstract class ScriptNodeMap implements NodeMap @Override public void nodeAdded(ParentNode node, INode child, String rel) { - if (DEBUG) System.out.println("Node added " + child + " parent " + node); + if (LOGGER.isTraceEnabled()) LOGGER.trace("Node added " + child + " parent " + node); //receiveAdd((E)child, rel ,graphUpdates); receiveAdd((E)child, rel ,graphModified.contains(node)); @@ -524,7 +524,7 @@ public abstract class ScriptNodeMap implements NodeMap @Override public void nodeRemoved(ParentNode node, INode child, String rel) { - if (DEBUG) System.out.println("Node removed " + child + " parent " + node); + if (LOGGER.isTraceEnabled()) LOGGER.trace("Node removed " + child + " parent " + node); //receiveRemove((E)child, rel, graphUpdates); receiveRemove((E)child, rel, graphModified.contains(node)); @@ -561,7 +561,8 @@ public abstract class ScriptNodeMap implements NodeMap } - public IMapping getMapping() { + @Override + public IMapping getMapping() { return mapping; }