X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fcontent%2FDiagramContentTracker.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fcontent%2FDiagramContentTracker.java;h=e2f393ed9023620d02863bd01eda388425508e07;hp=1cd506e169b1e5e9238822bf9770045affa8ca06;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/content/DiagramContentTracker.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/content/DiagramContentTracker.java index 1cd506e16..e2f393ed9 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/content/DiagramContentTracker.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/content/DiagramContentTracker.java @@ -1,90 +1,90 @@ -/******************************************************************************* - * 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. - * - *

- * 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; - } - -} +/******************************************************************************* + * 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. + * + *

+ * 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; + } + +}