-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.diagram.content;\r
-\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.adapter.DiagramContentRequest;\r
-import org.simantics.diagram.synchronization.ErrorHandler;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-/**\r
- * A utility for requesting a diagram's contents and keeping track of them and\r
- * obtaining differences.\r
- * \r
- * <p>\r
- * This class is not thread-safe.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class DiagramContentTracker {\r
-\r
- private final ErrorHandler errorHandler = new ErrorHandler() {\r
- @Override\r
- public void warning(String message, Exception e) {\r
- ErrorLogger.defaultLogWarning(message, e);\r
- }\r
- @Override\r
- public void error(String message, Throwable t) {\r
- ErrorLogger.defaultLogError(message, t);\r
- }\r
- };\r
-\r
- private DiagramContents lastContents = new DiagramContents();\r
- private DiagramContentChanges lastDifference = DiagramContentChanges.EMPTY;\r
-\r
- private final ICanvasContext context;\r
- private final Session session;\r
- private final Resource diagram;\r
-\r
- public static DiagramContentTracker start(ICanvasContext context, RequestProcessor processor, Resource diagram) throws DatabaseException {\r
- DiagramContentTracker tracker = new DiagramContentTracker(context, processor.getSession(), diagram);\r
- tracker.update(processor);\r
- return tracker;\r
- }\r
-\r
- private DiagramContentTracker(ICanvasContext context, Session session, Resource diagram) {\r
- if (context == null)\r
- throw new NullPointerException("null canvas context");\r
- if (session == null)\r
- throw new NullPointerException("null session");\r
- if (diagram == null)\r
- throw new NullPointerException("null diagram");\r
- this.context = context;\r
- this.session = session;\r
- this.diagram = diagram;\r
- }\r
-\r
- public DiagramContentChanges update() throws DatabaseException {\r
- return update(session);\r
- }\r
-\r
- public DiagramContentChanges update(RequestProcessor processor) throws DatabaseException {\r
- DiagramContents contents = processor.syncRequest(new DiagramContentRequest(context, diagram, errorHandler));\r
- DiagramContentChanges changes = contents.differenceFrom(lastContents);\r
- this.lastDifference = changes;\r
- this.lastContents = contents;\r
- return changes;\r
- }\r
-\r
- public DiagramContents getLastContents() {\r
- return lastContents;\r
- }\r
-\r
- public DiagramContentChanges getLastDifference() {\r
- return lastDifference;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.diagram.content;
+
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.adapter.DiagramContentRequest;
+import org.simantics.diagram.synchronization.ErrorHandler;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.utils.ui.ErrorLogger;
+
+/**
+ * A utility for requesting a diagram's contents and keeping track of them and
+ * obtaining differences.
+ *
+ * <p>
+ * This class is not thread-safe.
+ *
+ * @author Tuukka Lehtonen
+ */
+public class DiagramContentTracker {
+
+ private final ErrorHandler errorHandler = new ErrorHandler() {
+ @Override
+ public void warning(String message, Exception e) {
+ ErrorLogger.defaultLogWarning(message, e);
+ }
+ @Override
+ public void error(String message, Throwable t) {
+ ErrorLogger.defaultLogError(message, t);
+ }
+ };
+
+ private DiagramContents lastContents = new DiagramContents();
+ private DiagramContentChanges lastDifference = DiagramContentChanges.EMPTY;
+
+ private final ICanvasContext context;
+ private final Session session;
+ private final Resource diagram;
+
+ public static DiagramContentTracker start(ICanvasContext context, RequestProcessor processor, Resource diagram) throws DatabaseException {
+ DiagramContentTracker tracker = new DiagramContentTracker(context, processor.getSession(), diagram);
+ tracker.update(processor);
+ return tracker;
+ }
+
+ private DiagramContentTracker(ICanvasContext context, Session session, Resource diagram) {
+ if (context == null)
+ throw new NullPointerException("null canvas context");
+ if (session == null)
+ throw new NullPointerException("null session");
+ if (diagram == null)
+ throw new NullPointerException("null diagram");
+ this.context = context;
+ this.session = session;
+ this.diagram = diagram;
+ }
+
+ public DiagramContentChanges update() throws DatabaseException {
+ return update(session);
+ }
+
+ public DiagramContentChanges update(RequestProcessor processor) throws DatabaseException {
+ DiagramContents contents = processor.syncRequest(new DiagramContentRequest(context, diagram, errorHandler));
+ DiagramContentChanges changes = contents.differenceFrom(lastContents);
+ this.lastDifference = changes;
+ this.lastContents = contents;
+ return changes;
+ }
+
+ public DiagramContents getLastContents() {
+ return lastContents;
+ }
+
+ public DiagramContentChanges getLastDifference() {
+ return lastDifference;
+ }
+
+}