]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/flag/DiagramFlagPreferences.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / flag / DiagramFlagPreferences.java
index 9756606221504173214c986a7c8e05ea4c8270b3..b11d89151b0c0aada933c9a96fb52233dde92df7 100644 (file)
-package org.simantics.diagram.flag;\r
-\r
-import org.simantics.Simantics;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.primitiverequest.PossibleObject;\r
-import org.simantics.db.common.request.ResourceRead;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.utils.datastructures.Callback;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class DiagramFlagPreferences {\r
-\r
-    /**\r
-     * Return the resource describing the currently active flag labeling scheme\r
-     * from the specified resource. The default intended resource for checking\r
-     * the scheme from is the active project.\r
-     */\r
-    public static class ReadFlagLabelingSchemeResource extends ResourceRead<Resource> {\r
-\r
-        public ReadFlagLabelingSchemeResource(Resource resource) {\r
-            super(resource);\r
-        }\r
-\r
-        @Override\r
-        public Resource perform(ReadGraph graph) throws DatabaseException {\r
-            DiagramResource DIA = DiagramResource.getInstance(graph);\r
-            Resource scheme = graph.syncRequest(new PossibleObject(resource,\r
-                    DIA.UsesLocalFlagLabelingScheme));\r
-            return scheme;\r
-        }\r
-\r
-    }\r
-\r
-    /**\r
-     * Adapt {@link FlagLabelingScheme} instance from the resource describing\r
-     * the currently active flag labeling scheme according to\r
-     * {@link ReadFlagLabelingSchemeResource}.\r
-     */\r
-    public static class ReadFlagLabelingScheme extends ResourceRead<FlagLabelingScheme> {\r
-\r
-        public ReadFlagLabelingScheme(Resource resource) {\r
-            super(resource);\r
-        }\r
-\r
-        @Override\r
-        public FlagLabelingScheme perform(ReadGraph graph) throws DatabaseException {\r
-            DiagramResource DIA = DiagramResource.getInstance(graph);\r
-            Resource scheme = graph.syncRequest(new ReadFlagLabelingSchemeResource(resource));\r
-            if (scheme == null)\r
-                return graph.adapt(DIA.FlagLabelingScheme_Alphabetical, FlagLabelingScheme.class);\r
-            return graph.adapt(scheme, FlagLabelingScheme.class);\r
-        }\r
-\r
-    }\r
-\r
-    public static Resource getActiveFlagLabelingSchemeResource(RequestProcessor processor) throws DatabaseException {\r
-        Resource project = Simantics.getProjectResource();\r
-        if (project == null)\r
-            throw new IllegalStateException("no project is active");\r
-\r
-        return processor.syncRequest(new ReadFlagLabelingSchemeResource(project));\r
-    }\r
-\r
-    public static FlagLabelingScheme getActiveFlagLabelingScheme(RequestProcessor processor) throws DatabaseException {\r
-        Resource project = Simantics.getProjectResource();\r
-        if (project == null)\r
-            throw new IllegalStateException("no project is active");\r
-\r
-        return processor.syncRequest(new ReadFlagLabelingScheme(project));\r
-    }\r
-\r
-    public static void setProjectFlagLabelingScheme(Resource scheme) {\r
-        Resource project = Simantics.getProjectResource();\r
-        if (project == null)\r
-            throw new IllegalStateException("no project is active");\r
-        setFlagLabelingScheme(Simantics.getSession(), project, scheme);\r
-    }\r
-\r
-    public static void setFlagLabelingScheme(Session session, final Resource forTarget, final Resource scheme) {\r
-        session.asyncRequest(new WriteRequest() {\r
-            @Override\r
-            public void perform(WriteGraph graph) throws DatabaseException {\r
-                setFlagLabelingScheme(graph, forTarget, scheme);\r
-            }\r
-        }, new Callback<DatabaseException>() {\r
-            @Override\r
-            public void run(DatabaseException parameter) {\r
-                if (parameter != null)\r
-                    ErrorLogger.defaultLogError(parameter);\r
-            }\r
-        });\r
-    }\r
-\r
-    public static void setFlagLabelingScheme(WriteGraph graph, Resource forTarget, Resource scheme) throws DatabaseException {\r
-        DiagramResource DIA = DiagramResource.getInstance(graph);\r
-        graph.deny(forTarget, DIA.UsesLocalFlagLabelingScheme);\r
-        graph.claim(forTarget, DIA.UsesLocalFlagLabelingScheme, scheme);\r
-    }\r
-\r
-}\r
+package org.simantics.diagram.flag;
+
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.primitiverequest.PossibleObject;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.utils.datastructures.Callback;
+import org.simantics.utils.ui.ErrorLogger;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class DiagramFlagPreferences {
+
+    /**
+     * Return the resource describing the currently active flag labeling scheme
+     * from the specified resource. The default intended resource for checking
+     * the scheme from is the active project.
+     */
+    public static class ReadFlagLabelingSchemeResource extends ResourceRead<Resource> {
+
+        public ReadFlagLabelingSchemeResource(Resource resource) {
+            super(resource);
+        }
+
+        @Override
+        public Resource perform(ReadGraph graph) throws DatabaseException {
+            DiagramResource DIA = DiagramResource.getInstance(graph);
+            Resource scheme = graph.syncRequest(new PossibleObject(resource,
+                    DIA.UsesLocalFlagLabelingScheme));
+            return scheme;
+        }
+
+    }
+
+    /**
+     * Adapt {@link FlagLabelingScheme} instance from the resource describing
+     * the currently active flag labeling scheme according to
+     * {@link ReadFlagLabelingSchemeResource}.
+     */
+    public static class ReadFlagLabelingScheme extends ResourceRead<FlagLabelingScheme> {
+
+        public ReadFlagLabelingScheme(Resource resource) {
+            super(resource);
+        }
+
+        @Override
+        public FlagLabelingScheme perform(ReadGraph graph) throws DatabaseException {
+            DiagramResource DIA = DiagramResource.getInstance(graph);
+            Resource scheme = graph.syncRequest(new ReadFlagLabelingSchemeResource(resource));
+            if (scheme == null)
+                return graph.adapt(DIA.FlagLabelingScheme_Alphabetical, FlagLabelingScheme.class);
+            return graph.adapt(scheme, FlagLabelingScheme.class);
+        }
+
+    }
+
+    public static Resource getActiveFlagLabelingSchemeResource(RequestProcessor processor) throws DatabaseException {
+        Resource project = Simantics.getProjectResource();
+        if (project == null)
+            throw new IllegalStateException("no project is active");
+
+        return processor.syncRequest(new ReadFlagLabelingSchemeResource(project));
+    }
+
+    public static FlagLabelingScheme getActiveFlagLabelingScheme(RequestProcessor processor) throws DatabaseException {
+        Resource project = Simantics.getProjectResource();
+        if (project == null)
+            throw new IllegalStateException("no project is active");
+
+        return processor.syncRequest(new ReadFlagLabelingScheme(project));
+    }
+
+    public static void setProjectFlagLabelingScheme(Resource scheme) {
+        Resource project = Simantics.getProjectResource();
+        if (project == null)
+            throw new IllegalStateException("no project is active");
+        setFlagLabelingScheme(Simantics.getSession(), project, scheme);
+    }
+
+    public static void setFlagLabelingScheme(Session session, final Resource forTarget, final Resource scheme) {
+        session.asyncRequest(new WriteRequest() {
+            @Override
+            public void perform(WriteGraph graph) throws DatabaseException {
+                setFlagLabelingScheme(graph, forTarget, scheme);
+            }
+        }, new Callback<DatabaseException>() {
+            @Override
+            public void run(DatabaseException parameter) {
+                if (parameter != null)
+                    ErrorLogger.defaultLogError(parameter);
+            }
+        });
+    }
+
+    public static void setFlagLabelingScheme(WriteGraph graph, Resource forTarget, Resource scheme) throws DatabaseException {
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+        graph.deny(forTarget, DIA.UsesLocalFlagLabelingScheme);
+        graph.claim(forTarget, DIA.UsesLocalFlagLabelingScheme, scheme);
+    }
+
+}