]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Some enhancements to GraphLayer-related utilities for Diagram layers 64/264/4
authorjsimomaa <jani.simomaa@gmail.com>
Thu, 12 Jan 2017 11:21:00 +0000 (13:21 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 13 Jan 2017 07:30:07 +0000 (09:30 +0200)
* Fixes suggested by Tuukka
* Use forEachTag-functional method
* getPossibleAdapter -> adapt

refs #6953

Change-Id: I322ab90fbb228e4540414fd175582466d4ccb9d3

bundles/org.simantics.diagram/adapters.xml
bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayer.java
bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerManager.java
bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java
bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/IGraphLayerUtil.java [new file with mode: 0644]

index 4b0463102d14950b00ee2e88a65873a6d38dec0c..f4baea1c4a7acfc027e9714d4780a15f826f6511 100644 (file)
@@ -1,72 +1 @@
-<?xml version="1.0" encoding="UTF-8"?>\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
- -->
-
-<adapters>
-
-       <target interface="org.simantics.scenegraph.profile.ProfileEntry">\r             <type\r                  uri="http://www.simantics.org/Diagram-0.0/GroupStyleProfileEntry"\r                      class="org.simantics.diagram.adapter.GroupStyleProfileEntry">\r                  <graph />\r                      <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.scenegraph.profile.Style">\r            <type\r                  uri="http://www.simantics.org/Diagram-0.0/ConstantStyle"\r                       class="org.simantics.diagram.adapter.ConstantStyle">\r                   <graph />\r                      <this />\r               </type>\r                <type\r                  uri="http://www.simantics.org/Diagram-0.0/ExpressionStyle"\r                     class="org.simantics.diagram.adapter.ExpressionStyle">\r                 <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.scenegraph.profile.Group">\r            <type\r                  uri="http://www.simantics.org/Diagram-0.0/TypeGroup"\r                   class="org.simantics.diagram.adapter.TypeGroup">\r                       <graph />\r                      <this />\r               </type>\r                <type\r                  uri="http://www.simantics.org/Diagram-0.0/MappedTypeGroup"\r                     class="org.simantics.diagram.adapter.MappedTypeGroup">\r                 <graph />\r                      <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.g2d.diagram.DiagramClass">
-               <baseType uri="http://www.simantics.org/Diagram-0.0/Composite" />
-               <adapter uri="http://www.simantics.org/Diagram-0.0/Composite"
-                       adapterClass="org.simantics.diagram.adapter.DiagramClassAdapter" />
-       </target>
-
-       <target interface="org.simantics.diagram.adapter.ElementFactory">
-               <resource uri="http://www.simantics.org/Diagram-0.0/Flag"
-                       class="org.simantics.diagram.adapter.FlagClassFactory" />
-               <resource uri="http://www.simantics.org/Diagram-0.0/Composite"
-                       class="org.simantics.diagram.adapter.CompositeClassFactory" />
-               <resource uri="http://www.simantics.org/Diagram-0.0/DefinedElement"
-                       class="org.simantics.diagram.adapter.DefinedElementFactory" />
-               <resource uri="http://www.simantics.org/Diagram-0.0/SVGElement"
-                       class="org.simantics.diagram.adapter.SVGElementClassFactory" />
-               <resource uri="http://www.simantics.org/Diagram-0.0/RasterElement"\r                     class="org.simantics.diagram.adapter.RasterElementClassFactory" />\r             <resource uri="http://www.simantics.org/Diagram-0.0/AnimatedSVGElement"
-                       class="org.simantics.diagram.adapter.AnimatedSVGElementClassFactory" />
-               <resource uri="http://www.simantics.org/Diagram-0.0/BranchPoint"
-                       class="org.simantics.diagram.adapter.BranchPointClassFactory" />
-               <resource uri="http://www.simantics.org/Diagram-0.0/Connection"
-                       class="org.simantics.diagram.adapter.DefaultConnectionEdgeClassFactory" />
-               <resource uri="http://www.simantics.org/Diagram-0.0/TextElement"
-                       class="org.simantics.diagram.adapter.TextElementClassFactory" />
-
-               <type uri="http://www.simantics.org/Diagram-0.0/Connection"
-                       class="org.simantics.diagram.adapter.DefaultConnectionClassFactory" />\r\r                <resource uri="http://www.simantics.org/Diagram-0.0/RouteGraphConnection"\r                      class="org.simantics.diagram.adapter.RouteGraphConnectionClassFactory">\r                        <graph />\r              </resource>\r            <type uri="http://www.simantics.org/Diagram-0.0/RouteGraphConnection"\r                  class="org.simantics.diagram.adapter.RouteGraphConnectionClassFactory">\r                        <graph/>\r               </type>\r
-               <type uri="http://www.simantics.org/Diagram-0.0/Flag"
-                       class="org.simantics.diagram.adapter.FlagClassFactory" />
-               <type uri="http://www.simantics.org/Diagram-0.0/Composite"
-                       class="org.simantics.diagram.adapter.CompositeClassFactory" />
-               <type uri="http://www.simantics.org/Diagram-0.0/RasterElement"\r                 class="org.simantics.diagram.adapter.RasterElementClassFactory" />\r             <type uri="http://www.simantics.org/Diagram-0.0/SVGElement"
-                       class="org.simantics.diagram.adapter.SVGElementClassFactory" />
-               <type uri="http://www.simantics.org/Diagram-0.0/AnimatedSVGElement"
-                       class="org.simantics.diagram.adapter.AnimatedSVGElementClassFactory" />
-               <type uri="http://www.simantics.org/Diagram-0.0/DefinedElement"
-                       class="org.simantics.diagram.adapter.DefinedElementFactory" />
-               <type uri="http://www.simantics.org/Diagram-0.0/BranchPoint"
-                       class="org.simantics.diagram.adapter.BranchPointClassFactory" />
-               <type uri="http://www.simantics.org/Diagram-0.0/TextElement"
-                       class="org.simantics.diagram.adapter.TextElementClassFactory" />
-       </target>
-
-       <target interface="org.simantics.diagram.synchronization.graph.ElementWriter">
-               <type uri="http://www.simantics.org/Layer0-0.0/Entity"
-                       class="org.simantics.diagram.adapter.DummyElementWriter" />
-               <resource uri="http://www.simantics.org/Diagram-0.0/Flag"
-                       class="org.simantics.diagram.adapter.FlagWriter" />
-               <resource uri="http://www.simantics.org/Diagram-0.0/TextElement"
-                       class="org.simantics.diagram.adapter.TextElementWriter" />
-       </target>
-
-       <target interface="org.simantics.diagram.symbolcontribution.SymbolContribution">
-               <type uri="http://www.simantics.org/Diagram-0.0/BasicSymbolContribution"
-                       class="org.simantics.diagram.symbolcontribution.BasicSymbolContribution">
-                       <this />
-               </type>
-               <type uri="http://www.simantics.org/Diagram-0.0/IndexRootSymbolContribution"\r                   class="org.simantics.diagram.symbolcontribution.IndexRootSymbolContribution">\r          </type>\r        </target>\r\r     <target interface="org.simantics.diagram.symbolcontribution.SymbolContributionFilter">\r         <resource uri="http://www.simantics.org/Diagram-0.0/DenyFilter"\r                        class="org.simantics.diagram.symbolcontribution.DenyFilter"\r                    constructor="get">\r             </resource>\r            <type uri="http://www.simantics.org/Diagram-0.0/SCLFilter"\r                     class="org.simantics.diagram.symbolcontribution.SCLFilter">\r                    <this />\r               </type>\r        </target>\r\r\r    <target interface="org.simantics.g2d.routing.IRouter2">\r                <resource uri="http://www.simantics.org/Diagram-0.0/LinearRouting"\r                     class="org.simantics.g2d.routing.TrivialRouter2" />\r            <resource uri="http://www.simantics.org/Diagram-0.0/RightAngledRouting"\r                        class="org.simantics.g2d.routing.algorithm2.Router4" />\r        </target>\r\r     <target interface="org.simantics.ui.icons.ImageDescriptorProvider">\r            <type uri="http://www.simantics.org/Diagram-0.0/Diagram"\r                       class="org.simantics.ui.icons.BundleImageDescriptorProvider">\r                  <bundle />\r                     <string>icons/diagram.png</string>\r             </type>\r                <resource uri="http://www.simantics.org/Diagram-0.0/Diagram"\r                   class="org.simantics.ui.icons.BundleImageDescriptorProvider">\r                  <bundle />\r                     <string>icons/diagram.png</string>\r             </resource>\r    </target>\r\r     <target interface="org.simantics.db.layer0.adapter.StringModifierFactory">\r             <type uri="http://www.simantics.org/Diagram-0.0/Flag" class="org.simantics.diagram.flag.FlagStringModifierFactory">\r                    <graph />\r                      <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.diagram.flag.FlagLabelingScheme">\r             <baseType uri="http://www.simantics.org/Diagram-0.0/FlagLabelingScheme" />\r             <resource\r                      uri="http://www.simantics.org/Diagram-0.0/FlagLabelingScheme/Alphabetical"\r                     class="org.simantics.diagram.flag.PermutativeFlagLabelingScheme">\r                      <string>A</string>\r                     <string>A</string>\r                     <string>Z</string>\r             </resource>\r            <resource\r                      uri="http://www.simantics.org/Diagram-0.0/FlagLabelingScheme/Numeric"\r                  class="org.simantics.diagram.flag.PermutativeFlagLabelingScheme">\r                      <string>1</string>\r                     <string>1</string>\r                     <string>9</string>\r             </resource>\r    </target>\r\r     <target interface="org.simantics.scenegraph.loader.ScenegraphLoader">\r          <type uri="http://www.simantics.org/Diagram-0.0/Scenegraph/AbstractText" class="org.simantics.scenegraph.loader.StandardScenegraphLoader">\r                     <this/>\r                        <bundle />\r                     <string>org.simantics.diagram.elements.TextNode</string>\r               </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Scenegraph/SVGImage" class="org.simantics.scenegraph.loader.StandardScenegraphLoader">\r                 <this/>\r                        <bundle />\r                     <string>org.simantics.scenegraph.g2d.nodes.SVGNode</string>\r            </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Scenegraph/Composite" class="org.simantics.scenegraph.loader.StandardScenegraphLoader">\r                        <this/>\r                        <bundle />\r                     <string>org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode</string>\r          </type>\r        </target>\r      <target\r                interface="org.simantics.db.layer0.adapter.PasteHandler">\r              <type\r                  uri="http://www.simantics.org/Diagram-0.0/Scenegraph/Composite"\r                        class="org.simantics.diagram.adapter.ScenegraphCompositePasteHandler">\r                 <this />\r               </type>\r        </target>\r
-</adapters>
+<?xml version="1.0" encoding="UTF-8"?>\r<!--\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\r<adapters>\r\r    <target interface="org.simantics.scenegraph.profile.ProfileEntry">\r             <type\r                  uri="http://www.simantics.org/Diagram-0.0/GroupStyleProfileEntry"\r                      class="org.simantics.diagram.adapter.GroupStyleProfileEntry">\r                  <graph />\r                      <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.scenegraph.profile.Style">\r            <type\r                  uri="http://www.simantics.org/Diagram-0.0/ConstantStyle"\r                       class="org.simantics.diagram.adapter.ConstantStyle">\r                   <graph />\r                      <this />\r               </type>\r                <type\r                  uri="http://www.simantics.org/Diagram-0.0/ExpressionStyle"\r                     class="org.simantics.diagram.adapter.ExpressionStyle">\r                 <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.scenegraph.profile.Group">\r            <type\r                  uri="http://www.simantics.org/Diagram-0.0/TypeGroup"\r                   class="org.simantics.diagram.adapter.TypeGroup">\r                       <graph />\r                      <this />\r               </type>\r                <type\r                  uri="http://www.simantics.org/Diagram-0.0/MappedTypeGroup"\r                     class="org.simantics.diagram.adapter.MappedTypeGroup">\r                 <graph />\r                      <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.g2d.diagram.DiagramClass">\r            <baseType uri="http://www.simantics.org/Diagram-0.0/Composite" />\r              <adapter uri="http://www.simantics.org/Diagram-0.0/Composite"\r                  adapterClass="org.simantics.diagram.adapter.DiagramClassAdapter" />\r    </target>\r\r     <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <resource uri="http://www.simantics.org/Diagram-0.0/Flag"\r                      class="org.simantics.diagram.adapter.FlagClassFactory" />\r              <resource uri="http://www.simantics.org/Diagram-0.0/Composite"\r                 class="org.simantics.diagram.adapter.CompositeClassFactory" />\r         <resource uri="http://www.simantics.org/Diagram-0.0/DefinedElement"\r                    class="org.simantics.diagram.adapter.DefinedElementFactory" />\r         <resource uri="http://www.simantics.org/Diagram-0.0/SVGElement"\r                        class="org.simantics.diagram.adapter.SVGElementClassFactory" />\r                <resource uri="http://www.simantics.org/Diagram-0.0/RasterElement"\r                     class="org.simantics.diagram.adapter.RasterElementClassFactory" />\r             <resource uri="http://www.simantics.org/Diagram-0.0/AnimatedSVGElement"\r                        class="org.simantics.diagram.adapter.AnimatedSVGElementClassFactory" />\r                <resource uri="http://www.simantics.org/Diagram-0.0/BranchPoint"\r                       class="org.simantics.diagram.adapter.BranchPointClassFactory" />\r               <resource uri="http://www.simantics.org/Diagram-0.0/Connection"\r                        class="org.simantics.diagram.adapter.DefaultConnectionEdgeClassFactory" />\r             <resource uri="http://www.simantics.org/Diagram-0.0/TextElement"\r                       class="org.simantics.diagram.adapter.TextElementClassFactory" />\r\r              <type uri="http://www.simantics.org/Diagram-0.0/Connection"\r                    class="org.simantics.diagram.adapter.DefaultConnectionClassFactory" />\r\r                <resource uri="http://www.simantics.org/Diagram-0.0/RouteGraphConnection"\r                      class="org.simantics.diagram.adapter.RouteGraphConnectionClassFactory">\r                        <graph />\r              </resource>\r            <type uri="http://www.simantics.org/Diagram-0.0/RouteGraphConnection"\r                  class="org.simantics.diagram.adapter.RouteGraphConnectionClassFactory">\r                        <graph/>\r               </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Flag"\r                  class="org.simantics.diagram.adapter.FlagClassFactory" />\r              <type uri="http://www.simantics.org/Diagram-0.0/Composite"\r                     class="org.simantics.diagram.adapter.CompositeClassFactory" />\r         <type uri="http://www.simantics.org/Diagram-0.0/RasterElement"\r                 class="org.simantics.diagram.adapter.RasterElementClassFactory" />\r             <type uri="http://www.simantics.org/Diagram-0.0/SVGElement"\r                    class="org.simantics.diagram.adapter.SVGElementClassFactory" />\r                <type uri="http://www.simantics.org/Diagram-0.0/AnimatedSVGElement"\r                    class="org.simantics.diagram.adapter.AnimatedSVGElementClassFactory" />\r                <type uri="http://www.simantics.org/Diagram-0.0/DefinedElement"\r                        class="org.simantics.diagram.adapter.DefinedElementFactory" />\r         <type uri="http://www.simantics.org/Diagram-0.0/BranchPoint"\r                   class="org.simantics.diagram.adapter.BranchPointClassFactory" />\r               <type uri="http://www.simantics.org/Diagram-0.0/TextElement"\r                   class="org.simantics.diagram.adapter.TextElementClassFactory" />\r       </target>\r\r     <target interface="org.simantics.diagram.synchronization.graph.ElementWriter">\r         <type uri="http://www.simantics.org/Layer0-0.0/Entity"\r                 class="org.simantics.diagram.adapter.DummyElementWriter" />\r            <resource uri="http://www.simantics.org/Diagram-0.0/Flag"\r                      class="org.simantics.diagram.adapter.FlagWriter" />\r            <resource uri="http://www.simantics.org/Diagram-0.0/TextElement"\r                       class="org.simantics.diagram.adapter.TextElementWriter" />\r     </target>\r\r     <target interface="org.simantics.diagram.symbolcontribution.SymbolContribution">\r               <type uri="http://www.simantics.org/Diagram-0.0/BasicSymbolContribution"\r                       class="org.simantics.diagram.symbolcontribution.BasicSymbolContribution">\r                      <this />\r               </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/IndexRootSymbolContribution"\r                   class="org.simantics.diagram.symbolcontribution.IndexRootSymbolContribution">\r          </type>\r        </target>\r\r     <target interface="org.simantics.diagram.symbolcontribution.SymbolContributionFilter">\r         <resource uri="http://www.simantics.org/Diagram-0.0/DenyFilter"\r                        class="org.simantics.diagram.symbolcontribution.DenyFilter"\r                    constructor="get">\r             </resource>\r            <type uri="http://www.simantics.org/Diagram-0.0/SCLFilter"\r                     class="org.simantics.diagram.symbolcontribution.SCLFilter">\r                    <this />\r               </type>\r        </target>\r\r\r    <target interface="org.simantics.g2d.routing.IRouter2">\r                <resource uri="http://www.simantics.org/Diagram-0.0/LinearRouting"\r                     class="org.simantics.g2d.routing.TrivialRouter2" />\r            <resource uri="http://www.simantics.org/Diagram-0.0/RightAngledRouting"\r                        class="org.simantics.g2d.routing.algorithm2.Router4" />\r        </target>\r\r     <target interface="org.simantics.ui.icons.ImageDescriptorProvider">\r            <type uri="http://www.simantics.org/Diagram-0.0/Diagram"\r                       class="org.simantics.ui.icons.BundleImageDescriptorProvider">\r                  <bundle />\r                     <string>icons/diagram.png</string>\r             </type>\r                <resource uri="http://www.simantics.org/Diagram-0.0/Diagram"\r                   class="org.simantics.ui.icons.BundleImageDescriptorProvider">\r                  <bundle />\r                     <string>icons/diagram.png</string>\r             </resource>\r    </target>\r\r     <target interface="org.simantics.db.layer0.adapter.StringModifierFactory">\r             <type uri="http://www.simantics.org/Diagram-0.0/Flag" class="org.simantics.diagram.flag.FlagStringModifierFactory">\r                    <graph />\r                      <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.diagram.flag.FlagLabelingScheme">\r             <baseType uri="http://www.simantics.org/Diagram-0.0/FlagLabelingScheme" />\r             <resource\r                      uri="http://www.simantics.org/Diagram-0.0/FlagLabelingScheme/Alphabetical"\r                     class="org.simantics.diagram.flag.PermutativeFlagLabelingScheme">\r                      <string>A</string>\r                     <string>A</string>\r                     <string>Z</string>\r             </resource>\r            <resource\r                      uri="http://www.simantics.org/Diagram-0.0/FlagLabelingScheme/Numeric"\r                  class="org.simantics.diagram.flag.PermutativeFlagLabelingScheme">\r                      <string>1</string>\r                     <string>1</string>\r                     <string>9</string>\r             </resource>\r    </target>\r\r     <target interface="org.simantics.scenegraph.loader.ScenegraphLoader">\r          <type uri="http://www.simantics.org/Diagram-0.0/Scenegraph/AbstractText" class="org.simantics.scenegraph.loader.StandardScenegraphLoader">\r                     <this/>\r                        <bundle />\r                     <string>org.simantics.diagram.elements.TextNode</string>\r               </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Scenegraph/SVGImage" class="org.simantics.scenegraph.loader.StandardScenegraphLoader">\r                 <this/>\r                        <bundle />\r                     <string>org.simantics.scenegraph.g2d.nodes.SVGNode</string>\r            </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Scenegraph/Composite" class="org.simantics.scenegraph.loader.StandardScenegraphLoader">\r                        <this/>\r                        <bundle />\r                     <string>org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode</string>\r          </type>\r        </target>\r      <target\r                interface="org.simantics.db.layer0.adapter.PasteHandler">\r              <type\r                  uri="http://www.simantics.org/Diagram-0.0/Scenegraph/Composite"\r                        class="org.simantics.diagram.adapter.ScenegraphCompositePasteHandler">\r                 <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil">\r         <resource uri="http://www.simantics.org/Diagram-0.0/Layer"\r                     class="org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil">\r                      <this />\r               </resource>\r    </target>\r</adapters>\r
\ No newline at end of file
index 87746246d87b86632beaf48d55f5a7e38d7c28e9..33df689be4014e48665683f1f59209cc22c1b011 100644 (file)
  *******************************************************************************/
 package org.simantics.diagram.synchronization.graph.layer;
 
+import java.util.Collection;
+import java.util.Map;
+
 import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.function.DbConsumer;
+import org.simantics.g2d.layers.ILayer;
+import org.simantics.g2d.layers.SimpleLayer;
 
 /**
  * @author Tuukka Lehtonen
  */
 public class GraphLayer {
 
+    public static final String PROP_VISIBLE = "PROP_VISIBLE";
+    public static final String PROP_FOCUSABLE = "PROP_FOCUSABLE";
+
     private final String   name;
 
     private final Resource layer;
+    
+    private final Map<String, Resource> tags;
 
-    private final Resource visible;
-
-    private final Resource focusable;
-
-    public GraphLayer(String name, Resource layer, Resource visible, Resource focusable) {
+    public GraphLayer(String name, Resource layer, Map<String, Resource> tags) {
         this.name = name;
         this.layer = layer;
-        this.visible = visible;
-        this.focusable = focusable;
+        this.tags = tags;
     }
 
     public GraphLayer withName(String name) {
-        return new GraphLayer(name, layer, visible, focusable);
+        return new GraphLayer(name, layer, tags);
     }
 
     public String getName() {
@@ -46,11 +53,24 @@ public class GraphLayer {
     }
 
     public Resource getVisible() {
-        return visible;
+        return tags.get(PROP_VISIBLE);
     }
 
     public Resource getFocusable() {
-        return focusable;
+        return tags.get(PROP_FOCUSABLE);
+    }
+
+    public ILayer getILayer() {
+        return new SimpleLayer(name);
+    }
+
+    public Collection<Resource> getTags() {
+        return tags.values();
+    }
+
+    public void forEachTag(DbConsumer<Resource> consumer) throws DatabaseException {
+        for (Resource r : tags.values())
+            consumer.accept(r);
     }
 
 }
\ No newline at end of file
index 5b6e0f63a3d2b12925ca2e1b2d0e590b3883c5ab..41947ef993c49bc937b39eedddb0a0cbf3d25460 100644 (file)
@@ -45,7 +45,6 @@ import org.simantics.g2d.layers.ILayer;
 import org.simantics.g2d.layers.ILayers;
 import org.simantics.g2d.layers.ILayersEditor;
 import org.simantics.g2d.layers.ILayersEditor.ILayersEditorListener;
-import org.simantics.g2d.layers.SimpleLayer;
 import org.simantics.g2d.layers.SimpleLayers;
 import org.simantics.layer0.Layer0;
 
@@ -175,15 +174,17 @@ public class GraphLayerManager {
         @Override
         public void perform(WriteGraph g) throws Exception {
             String newName = layer.getName();
-            for (Resource l : g.getObjects(diagram, dia.HasLayer)) {
-                String name = g.getRelatedValue(l, l0.HasName);
+            for (Resource layer : g.getObjects(diagram, dia.HasLayer)) {
+                String name = g.getRelatedValue(layer, l0.HasName);
                 if (newName.equals(name)) {
                     return;
                 }
             }
-            GraphLayer l = new GraphLayerUtil(g).createLayer(newName, false);
-            g.claim(diagram, dia.HasLayer, l.getLayer());
-            layers.put(newName, l);
+            
+            IGraphLayerUtil util = g.adapt(DiagramResource.getInstance(g).Layer, IGraphLayerUtil.class);
+            GraphLayer layer = util.createLayer(g, newName, false);
+            g.claim(diagram, dia.HasLayer, layer.getLayer());
+            layers.put(newName, layer);
         }
     }
 
@@ -292,14 +293,8 @@ public class GraphLayerManager {
         }
     }
 
-    GraphLayer loadLayer(ReadGraph g, Resource layer) throws DatabaseException {
-        String name = g.getRelatedValue(layer, l0.HasName);
-        Resource visible = g.getSingleObject(layer, dia.HasVisibleTag);
-        Resource focusable = g.getSingleObject(layer, dia.HasFocusableTag);
-        return new GraphLayer(name, layer, visible, focusable);
-    }
-
     public ILayersEditor loadLayers(IDiagram diagram, ReadGraph g, Resource diagramResource) throws DatabaseException {
+        
         SimpleLayers result = new SimpleLayers();
         ConcurrentMap<String, GraphLayer> newLayers = new ConcurrentHashMap<String, GraphLayer>();
 
@@ -314,10 +309,12 @@ public class GraphLayerManager {
 
             // We need to put GraphLayer to newLayers so...
             for (Resource layer : g.getObjects(diagramResource, dia.HasLayer)) {
-                GraphLayer gl = loadLayer(g, layer);
+                IGraphLayerUtil layerUtil = g.adapt(g.getSingleObject(layer, Layer0.getInstance(g).InstanceOf), IGraphLayerUtil.class);
+                
+                GraphLayer gl = layerUtil.loadLayer(g, layer);
                 for (String name : fixed) {
                     if (name.equals(gl.getName())) {
-                        SimpleLayer l = new SimpleLayer(gl.getName());
+                        ILayer l = gl.getILayer();
                         newLayers.put(gl.getName(), gl);
                         result.addLayer(l);
                         result.activate(l);
@@ -331,8 +328,9 @@ public class GraphLayerManager {
                 System.out.println("Loading layers");
 
             for (Resource layer : g.getObjects(diagramResource, dia.HasLayer)) {
-                GraphLayer gl = loadLayer(g, layer);
-                SimpleLayer l = new SimpleLayer(gl.getName());
+                IGraphLayerUtil layerUtil = g.adapt(g.getSingleObject(layer, Layer0.getInstance(g).InstanceOf), IGraphLayerUtil.class);
+                GraphLayer gl = layerUtil.loadLayer(g, layer);
+                ILayer l = gl.getILayer();
 
                 newLayers.put(gl.getName(), gl);
                 result.addLayer(l);
@@ -344,7 +342,8 @@ public class GraphLayerManager {
                 if (DEBUG_LAYERS)
                     System.out.println("    Loaded " + (active ? "active" : "inactive") + " layer '" + gl.getName() + "'");
 
-                l.addLayerListener(layerListener);
+                if (l instanceof IEditableLayer)
+                    ((IEditableLayer) l).addLayerListener(layerListener);
                 if (active)
                     result.activate(l);
             }
@@ -517,8 +516,7 @@ public class GraphLayerManager {
             for (ILayer layer : visibleLayers) {
                 GraphLayer gl = layers.get(layer.getName());
                 if (gl != null) {
-                    DiagramGraphUtil.tag(g, element, gl.getVisible(), true);
-                    DiagramGraphUtil.tag(g, element, gl.getFocusable(), true);
+                    gl.forEachTag(tag -> DiagramGraphUtil.tag(g, element, tag, true));
                 }
             }
         }
index 198452ed1a2fe7886e480f6facbaa584092bcbcd..6a4ecd667bc1190f7576d64b3c340da3fe86f18b 100644 (file)
  *******************************************************************************/
 package org.simantics.diagram.synchronization.graph.layer;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
@@ -24,51 +28,67 @@ import org.simantics.layer0.Layer0;
  * 
  * @author Tuukka Lehtonen
  */
-public final class GraphLayerUtil {
-
-    WriteGraph      graph;
-    Layer0          l0;
-    DiagramResource dia;
+public final class GraphLayerUtil implements IGraphLayerUtil {
 
-    public GraphLayerUtil(WriteGraph graph) {
-        this.graph = graph;
-        this.l0 = Layer0.getInstance(graph);
-        this.dia = DiagramResource.getInstance(graph);
+    public GraphLayerUtil(Resource layer) {
     }
 
-    public GraphLayer createLayer(String layerName, boolean active) throws DatabaseException {
+    @Override
+    public GraphLayer createLayer(WriteGraph graph, String layerName, boolean active) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+        
         Resource layer = graph.newResource();
-        graph.claim(layer, l0.InstanceOf, null, dia.Layer);
+        graph.claim(layer, L0.InstanceOf, null, DIA.Layer);
 
         // Assign tagging relations
-        Resource visibleTag = newTag(dia.IsVisible);
-        Resource focusableTag = newTag(dia.IsFocusable);
-        graph.claim(layer, dia.HasVisibleTag, visibleTag);
-        graph.claim(layer, dia.HasFocusableTag, focusableTag);
+        Resource visibleTag = newTag(graph, L0, DIA.IsVisible);
+        Resource focusableTag = newTag(graph, L0, DIA.IsFocusable);
+        graph.claim(layer, DIA.HasVisibleTag, visibleTag);
+        graph.claim(layer, DIA.HasFocusableTag, focusableTag);
 
         // Assign shared name property for all, the layer and the tags
         Resource name = graph.newResource();
-        graph.claim(name, l0.InstanceOf, null, l0.String);
+        graph.claim(name, L0.InstanceOf, null, L0.String);
         graph.claimValue(name, layerName);
 
-        graph.claim(layer, l0.HasName, name);
-        graph.claim(visibleTag, l0.HasName, name);
-        graph.claim(focusableTag, l0.HasName, name);
+        graph.claim(layer, L0.HasName, name);
+        graph.claim(visibleTag, L0.HasName, name);
+        graph.claim(focusableTag, L0.HasName, name);
 
-        setLayerActive(layer, active);
+        setLayerActive(graph, DIA, layer, active);
 
-        return new GraphLayer(layerName, layer, visibleTag, focusableTag);
+        Map<String, Resource> properties = new HashMap<>();
+        properties.put(GraphLayer.PROP_FOCUSABLE, focusableTag);
+        properties.put(GraphLayer.PROP_VISIBLE, visibleTag);
+        
+        return new GraphLayer(layerName, layer, properties);
     }
 
-    public Resource newTag(Resource baseTag) throws DatabaseException {
+    public static Resource newTag(WriteGraph graph, Layer0 L0, Resource baseTag) throws DatabaseException {
         Resource tag = graph.newResource();
-        graph.claim(tag, l0.SubrelationOf, baseTag);
-        graph.claim(tag, l0.InverseOf, tag);
+        graph.claim(tag, L0.SubrelationOf, baseTag);
+        graph.claim(tag, L0.InverseOf, tag);
         return tag;
     }
 
-    public void setLayerActive(Resource layer, boolean active) throws ManyObjectsForFunctionalRelationException, ServiceException {
-        graph.claimLiteral(layer, dia.IsActive, Boolean.valueOf(active));
+    public static void setLayerActive(WriteGraph graph, DiagramResource DIA, Resource layer, boolean active) throws ManyObjectsForFunctionalRelationException, ServiceException {
+        graph.claimLiteral(layer, DIA.IsActive, Boolean.valueOf(active));
+    }
+
+    @Override
+    public GraphLayer loadLayer(ReadGraph graph, Resource layer) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+        String name = graph.getRelatedValue(layer, L0.HasName);
+        Resource visible = graph.getSingleObject(layer, DIA.HasVisibleTag);
+        Resource focusable = graph.getSingleObject(layer, DIA.HasFocusableTag);
+        
+        Map<String, Resource> properties = new HashMap<>();
+        properties.put(GraphLayer.PROP_FOCUSABLE, focusable);
+        properties.put(GraphLayer.PROP_VISIBLE, visible);
+
+        return new GraphLayer(name, layer, properties);
     }
 
 }
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/IGraphLayerUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/IGraphLayerUtil.java
new file mode 100644 (file)
index 0000000..9b0f8fb
--- /dev/null
@@ -0,0 +1,14 @@
+package org.simantics.diagram.synchronization.graph.layer;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+
+public interface IGraphLayerUtil {
+
+    GraphLayer loadLayer(ReadGraph graph, Resource layer) throws DatabaseException;
+
+    GraphLayer createLayer(WriteGraph graph, String newName, boolean b) throws DatabaseException;
+
+}