-/*******************************************************************************\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.adapter;\r
-\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.procedure.adapter.AsyncProcedureAdapter;\r
-import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.synchronization.SynchronizationHints;\r
-import org.simantics.diagram.synchronization.graph.TransformSynchronizer;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
-import org.simantics.g2d.elementclass.BranchPoint;\r
-import org.simantics.g2d.elementclass.BranchPoint.Direction;\r
-import org.simantics.g2d.elementclass.BranchPointClass;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class BranchPointClassFactory extends ElementFactoryAdapter {\r
-\r
- public static ElementClass create(Resource elementClass) {\r
- return BranchPointClass.CLASS.newClassWith(false, new StaticObjectAdapter(elementClass));\r
- }\r
-\r
- @Override\r
- public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {\r
- procedure.execute(graph, BranchPointClass.CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));\r
- }\r
-\r
- @Override\r
- public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, final Resource element, final IElement e, final AsyncProcedure<IElement> procedure) {\r
- e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, TransformSynchronizer.INSTANCE);\r
-\r
- final AsyncProcedure<IElement> guard = new GuardedAsyncProcedureWrapper<IElement>(procedure, 2);\r
-\r
- final BranchPoint bp = e.getElementClass().getAtMostOneItemOfClass(BranchPoint.class);\r
- if (bp != null) {\r
- final DiagramResource dr = graph.getService(DiagramResource.class);\r
- graph.forHasStatement(element, dr.Horizontal, element, new AsyncProcedureAdapter<Boolean>() {\r
- @Override\r
- public void exception(AsyncReadGraph graph, Throwable throwable) {\r
- guard.exception(graph, throwable);\r
- }\r
- @Override\r
- public void execute(AsyncReadGraph graph, final Boolean horizontal) {\r
- graph.forHasStatement(element, dr.Vertical, element, new AsyncProcedure<Boolean>() {\r
- @Override\r
- public void exception(AsyncReadGraph graph, Throwable throwable) {\r
- guard.exception(graph, throwable);\r
- }\r
- @Override\r
- public void execute(AsyncReadGraph graph, Boolean vertical) {\r
- Direction direction = Direction.Any;\r
- if (horizontal ^ vertical)\r
- direction = horizontal ? Direction.Horizontal : Direction.Vertical;\r
- bp.setDirectionPreference(e, direction);\r
-\r
- guard.execute(graph, e);\r
- }\r
- });\r
- }\r
- });\r
- }\r
-\r
- ElementFactoryUtil.readTransform(graph, element, e, guard);\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.adapter;
+
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.procedure.adapter.AsyncProcedureAdapter;
+import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.diagram.synchronization.SynchronizationHints;
+import org.simantics.diagram.synchronization.graph.TransformSynchronizer;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
+import org.simantics.g2d.elementclass.BranchPoint;
+import org.simantics.g2d.elementclass.BranchPoint.Direction;
+import org.simantics.g2d.elementclass.BranchPointClass;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class BranchPointClassFactory extends ElementFactoryAdapter {
+
+ public static ElementClass create(Resource elementClass) {
+ return BranchPointClass.CLASS.newClassWith(false, new StaticObjectAdapter(elementClass));
+ }
+
+ @Override
+ public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {
+ procedure.execute(graph, BranchPointClass.CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));
+ }
+
+ @Override
+ public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, final Resource element, final IElement e, final AsyncProcedure<IElement> procedure) {
+ e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, TransformSynchronizer.INSTANCE);
+
+ final AsyncProcedure<IElement> guard = new GuardedAsyncProcedureWrapper<IElement>(procedure, 2);
+
+ final BranchPoint bp = e.getElementClass().getAtMostOneItemOfClass(BranchPoint.class);
+ if (bp != null) {
+ final DiagramResource dr = graph.getService(DiagramResource.class);
+ graph.forHasStatement(element, dr.Horizontal, element, new AsyncProcedureAdapter<Boolean>() {
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ guard.exception(graph, throwable);
+ }
+ @Override
+ public void execute(AsyncReadGraph graph, final Boolean horizontal) {
+ graph.forHasStatement(element, dr.Vertical, element, new AsyncProcedure<Boolean>() {
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ guard.exception(graph, throwable);
+ }
+ @Override
+ public void execute(AsyncReadGraph graph, Boolean vertical) {
+ Direction direction = Direction.Any;
+ if (horizontal ^ vertical)
+ direction = horizontal ? Direction.Horizontal : Direction.Vertical;
+ bp.setDirectionPreference(e, direction);
+
+ guard.execute(graph, e);
+ }
+ });
+ }
+ });
+ }
+
+ ElementFactoryUtil.readTransform(graph, element, e, guard);
+ }
+