]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/SCLAnnotation.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.annotation.ui / src / org / simantics / annotation / ui / SCLAnnotation.java
index bfd96391a2d170390b587b6f854e4fd5b6ffe49e..ae4a72f439251ef74d52420ed2ac4a74cf2cba19 100644 (file)
-package org.simantics.annotation.ui;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.util.Map;\r
-\r
-import org.eclipse.core.runtime.NullProgressMonitor;\r
-import org.simantics.Simantics;\r
-import org.simantics.annotation.ui.wizard.AnnotationTypeExporter;\r
-import org.simantics.annotation.ui.wizard.AnnotationTypeImportWizard;\r
-import org.simantics.databoard.serialization.SerializationException;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.Statement;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.request.PropertyInfo;\r
-import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;\r
-import org.simantics.db.layer0.util.Layer0Utils;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.userComponent.ComponentTypeCommands;\r
-import org.simantics.scl.runtime.tuple.Tuple2;\r
-import org.simantics.utils.datastructures.Pair;\r
-\r
-public class SCLAnnotation {\r
-       \r
-\r
-       public static Resource newAnnotationType(WriteGraph graph, Resource parent) throws DatabaseException {\r
-               \r
-               Pair<Resource, Resource> annotation = AnnotationUtils.newAnnotationType(graph, parent);\r
-               Resource type = annotation.second;\r
-               \r
-               return type;\r
-       }\r
-       \r
-       public static Tuple2 newAnnotationType1(WriteGraph graph, Resource parent) throws DatabaseException {\r
-               \r
-               Pair<Resource, Resource> annotation = AnnotationUtils.newAnnotationType(graph, parent);\r
-               Tuple2 tuple = new Tuple2(annotation.first, annotation.second);\r
-               \r
-               return tuple;\r
-       }\r
-       \r
-       public static Resource newAnnotationValue(WriteGraph graph, Resource parent, Resource property) throws DatabaseException {\r
-               graph.markUndoPoint();\r
-               Resource annotationValue = AnnotationUtils.newAnnotationInstance(graph, parent, property);\r
-               return annotationValue;\r
-       }\r
-\r
-       public static Resource newAnnotationValueWithName(WriteGraph graph, Resource parent, String name, Resource property) throws DatabaseException {\r
-               Resource existing = Layer0Utils.getPossibleChild(graph, parent, name);\r
-               if(existing != null) return existing;\r
-               Resource annotationValue = AnnotationUtils.newAnnotationInstance(graph, parent, name, property);\r
-               return annotationValue;\r
-       }\r
-\r
-       public static Resource newAnnotationProperty(WriteGraph graph, Resource annotationType) throws DatabaseException {\r
-               \r
-               Resource annotationProperty = ComponentTypeCommands.createPropertyWithDefaults(graph, annotationType);\r
-               \r
-               return annotationProperty;\r
-       }\r
-       \r
-       public static Resource advancedAnnotationProperty(WriteGraph graph, Resource annotationType, String name, String value, String unit, String range, String label, String description) throws DatabaseException {\r
-               \r
-               Resource property = ComponentTypeCommands.createProperty(graph, annotationType, name, value, unit, range, label, description);\r
-               \r
-               return property;\r
-       }\r
-       \r
-       public static void removeAnnotationProperty(WriteGraph graph, Resource property) throws DatabaseException {\r
-               \r
-               Resource annotationType = getAnnotationType(graph, property);\r
-               ComponentTypeCommands.removeProperty(graph, annotationType, property);\r
-       }\r
-       \r
-       public static void setPropertyType(WriteGraph graph, Resource property, String type) throws DatabaseException {\r
-               \r
-               Resource annotationType = getAnnotationType(graph, property);\r
-               ComponentTypeCommands.setRequiredType(graph, property, type);\r
-               ComponentTypeCommands.convertDefaultValue(graph, annotationType, property, type);\r
-               \r
-       }\r
-       \r
-       public static void setPropertyUnit(WriteGraph graph, Resource property, String unit) throws DatabaseException {\r
-               \r
-               Resource annotationType = getAnnotationType(graph, property);\r
-               ComponentTypeCommands.setUnit(graph, property, annotationType, unit);\r
-               \r
-       }\r
-       \r
-       public static void setPropertyLabel(WriteGraph graph, Resource property, String label) throws DatabaseException {\r
-               \r
-               ComponentTypeCommands.setLabel(graph, property, label);\r
-       }\r
-       \r
-       public static void setPropertyRange(WriteGraph graph, Resource property, String range) throws DatabaseException {\r
-               \r
-               Resource annotationType = getAnnotationType(graph, property);\r
-               ComponentTypeCommands.setRange(graph, property, annotationType, range);\r
-       }\r
-       \r
-       public static void setPropertyDescription(WriteGraph graph, Resource property, String description) throws DatabaseException {\r
-               \r
-               ComponentTypeCommands.setDescription(graph, property, description);\r
-       }\r
-       \r
-       public static void setDefaultValue(WriteGraph graph, Resource property, String value) throws DatabaseException {\r
-               \r
-               Resource annotationType = getAnnotationType(graph, property);\r
-               ComponentTypeCommands.setDefaultValue(graph, annotationType, property, value);\r
-       }\r
-       \r
-       public static Resource attachAnnotation(WriteGraph graph, Resource parent, Resource annotationType) throws DatabaseException {\r
-\r
-               Resource annotation = AnnotationUtils.newAnnotation(graph, parent, annotationType);\r
-               \r
-               return annotation;\r
-       }\r
-       \r
-       public static Resource getAnnotationType(ReadGraph graph, Resource property) throws DatabaseException {\r
-               \r
-               Layer0 L0 = Layer0.getInstance(graph);\r
-               Resource annotationType = graph.getPossibleObject(property, L0.PartOf);\r
-               return annotationType;\r
-               \r
-       }\r
-       \r
-       public static Resource saveAnnotation(WriteGraph graph, Resource annotation, Resource library, String name) throws DatabaseException {\r
-               return SCL.SaveModifier.saveAnnotation(graph, annotation, library, name);\r
-       }\r
-       \r
-       public static void importAnnotationFromFile(File importLocation, Resource target) throws SerializationException, IOException, DatabaseException {\r
-               Session session = Simantics.getSession();\r
-               AnnotationTypeImportWizard.doImport(new NullProgressMonitor(), importLocation, session, target);\r
-       }\r
-       \r
-       public static void exportAnnotationToFile(File location, Resource annotationType) throws DatabaseException, IOException {\r
-               AnnotationTypeExporter.doExport(location, annotationType);\r
-       }\r
-       \r
-       public static void rename(WriteGraph graph, Resource resource, String newName) throws DatabaseException {\r
-               ComponentTypeCommands.rename(graph, resource, newName);\r
-       }\r
-\r
-    public static void copyAnnotationData(WriteGraph graph, Resource source, Resource target) throws DatabaseException {\r
-        // source and target are expected to be of the same type\r
-        Map<String, PropertyInfo> sps = graph.syncRequest(new UnescapedPropertyMapOfResource(source));\r
-        Map<String, PropertyInfo> tps = graph.syncRequest(new UnescapedPropertyMapOfResource(target));\r
-\r
-        for (PropertyInfo sp : sps.values()) {\r
-            PropertyInfo tp = tps.get(sp.name);\r
-            if (tp != null) {\r
-                for (Statement srcstm : graph.getStatements(source, sp.predicate)) {\r
-                    if (srcstm.isAsserted(source)) {\r
-                        // Make sure the target value is asserted as well.\r
-                        graph.deny(target, sp.predicate);\r
-                    } else {\r
-                        Resource property = srcstm.getObject();\r
-                        // Remove existing property from source and link the target property\r
-                        for (Statement tgtstm : graph.getStatements(target, tp.predicate)) {\r
-                            if (!tgtstm.isAsserted(target))\r
-                                graph.deny(tgtstm);\r
-                        }\r
-                        // Re-link the source property to the target entity.\r
-                        graph.deny(source, sp.predicate, property);\r
-                        graph.claim(target, tp.predicate, property);\r
-                    }\r
-                }\r
-            }\r
-        }\r
-    }\r
-\r
+package org.simantics.annotation.ui;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.simantics.Simantics;
+import org.simantics.annotation.ui.wizard.AnnotationTypeExporter;
+import org.simantics.annotation.ui.wizard.AnnotationTypeImportWizard;
+import org.simantics.databoard.serialization.SerializationException;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.Statement;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.PropertyInfo;
+import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.userComponent.ComponentTypeCommands;
+import org.simantics.scl.runtime.tuple.Tuple2;
+import org.simantics.utils.datastructures.Pair;
+
+public class SCLAnnotation {
+       
+
+       public static Resource newAnnotationType(WriteGraph graph, Resource parent) throws DatabaseException {
+               
+               Pair<Resource, Resource> annotation = AnnotationUtils.newAnnotationType(graph, parent);
+               Resource type = annotation.second;
+               
+               return type;
+       }
+       
+       public static Tuple2 newAnnotationType1(WriteGraph graph, Resource parent) throws DatabaseException {
+               
+               Pair<Resource, Resource> annotation = AnnotationUtils.newAnnotationType(graph, parent);
+               Tuple2 tuple = new Tuple2(annotation.first, annotation.second);
+               
+               return tuple;
+       }
+       
+       public static Resource newAnnotationValue(WriteGraph graph, Resource parent, Resource property) throws DatabaseException {
+               graph.markUndoPoint();
+               Resource annotationValue = AnnotationUtils.newAnnotationInstance(graph, parent, property);
+               return annotationValue;
+       }
+
+       public static Resource newAnnotationValueWithName(WriteGraph graph, Resource parent, String name, Resource property) throws DatabaseException {
+               Resource existing = Layer0Utils.getPossibleChild(graph, parent, name);
+               if(existing != null) return existing;
+               Resource annotationValue = AnnotationUtils.newAnnotationInstance(graph, parent, name, property);
+               return annotationValue;
+       }
+
+       public static Resource newAnnotationProperty(WriteGraph graph, Resource annotationType) throws DatabaseException {
+               
+               Resource annotationProperty = ComponentTypeCommands.createPropertyWithDefaults(graph, annotationType);
+               
+               return annotationProperty;
+       }
+       
+       public static Resource advancedAnnotationProperty(WriteGraph graph, Resource annotationType, String name, String value, String unit, String range, String label, String description) throws DatabaseException {
+               
+               Resource property = ComponentTypeCommands.createProperty(graph, annotationType, name, value, unit, range, label, description);
+               
+               return property;
+       }
+       
+       public static void removeAnnotationProperty(WriteGraph graph, Resource property) throws DatabaseException {
+               
+               Resource annotationType = getAnnotationType(graph, property);
+               ComponentTypeCommands.removeProperty(graph, annotationType, property);
+       }
+       
+       public static void setPropertyType(WriteGraph graph, Resource property, String type) throws DatabaseException {
+               
+               Resource annotationType = getAnnotationType(graph, property);
+               ComponentTypeCommands.setRequiredType(graph, property, type);
+               ComponentTypeCommands.convertDefaultValue(graph, annotationType, property, type);
+               
+       }
+       
+       public static void setPropertyUnit(WriteGraph graph, Resource property, String unit) throws DatabaseException {
+               
+               Resource annotationType = getAnnotationType(graph, property);
+               ComponentTypeCommands.setUnit(graph, property, annotationType, unit);
+               
+       }
+       
+       public static void setPropertyLabel(WriteGraph graph, Resource property, String label) throws DatabaseException {
+               
+               ComponentTypeCommands.setLabel(graph, property, label);
+       }
+       
+       public static void setPropertyRange(WriteGraph graph, Resource property, String range) throws DatabaseException {
+               
+               Resource annotationType = getAnnotationType(graph, property);
+               ComponentTypeCommands.setRange(graph, property, annotationType, range);
+       }
+       
+       public static void setPropertyDescription(WriteGraph graph, Resource property, String description) throws DatabaseException {
+               
+               ComponentTypeCommands.setDescription(graph, property, description);
+       }
+       
+       public static void setDefaultValue(WriteGraph graph, Resource property, String value) throws DatabaseException {
+               
+               Resource annotationType = getAnnotationType(graph, property);
+               ComponentTypeCommands.setDefaultValue(graph, annotationType, property, value);
+       }
+       
+       public static Resource attachAnnotation(WriteGraph graph, Resource parent, Resource annotationType) throws DatabaseException {
+
+               Resource annotation = AnnotationUtils.newAnnotation(graph, parent, annotationType);
+               
+               return annotation;
+       }
+       
+       public static Resource getAnnotationType(ReadGraph graph, Resource property) throws DatabaseException {
+               
+               Layer0 L0 = Layer0.getInstance(graph);
+               Resource annotationType = graph.getPossibleObject(property, L0.PartOf);
+               return annotationType;
+               
+       }
+       
+       public static Resource saveAnnotation(WriteGraph graph, Resource annotation, Resource library, String name) throws DatabaseException {
+               return SCL.SaveModifier.saveAnnotation(graph, annotation, library, name);
+       }
+       
+       public static void importAnnotationFromFile(File importLocation, Resource target) throws SerializationException, IOException, DatabaseException {
+               Session session = Simantics.getSession();
+               AnnotationTypeImportWizard.doImport(new NullProgressMonitor(), importLocation, session, target);
+       }
+       
+       public static void exportAnnotationToFile(File location, Resource annotationType) throws DatabaseException, IOException {
+               AnnotationTypeExporter.doExport(location, annotationType);
+       }
+       
+       public static void rename(WriteGraph graph, Resource resource, String newName) throws DatabaseException {
+               ComponentTypeCommands.rename(graph, resource, newName);
+       }
+
+    public static void copyAnnotationData(WriteGraph graph, Resource source, Resource target) throws DatabaseException {
+        // source and target are expected to be of the same type
+        Map<String, PropertyInfo> sps = graph.syncRequest(new UnescapedPropertyMapOfResource(source));
+        Map<String, PropertyInfo> tps = graph.syncRequest(new UnescapedPropertyMapOfResource(target));
+
+        for (PropertyInfo sp : sps.values()) {
+            PropertyInfo tp = tps.get(sp.name);
+            if (tp != null) {
+                for (Statement srcstm : graph.getStatements(source, sp.predicate)) {
+                    if (srcstm.isAsserted(source)) {
+                        // Make sure the target value is asserted as well.
+                        graph.deny(target, sp.predicate);
+                    } else {
+                        Resource property = srcstm.getObject();
+                        // Remove existing property from source and link the target property
+                        for (Statement tgtstm : graph.getStatements(target, tp.predicate)) {
+                            if (!tgtstm.isAsserted(target))
+                                graph.deny(tgtstm);
+                        }
+                        // Re-link the source property to the target entity.
+                        graph.deny(source, sp.predicate, property);
+                        graph.claim(target, tp.predicate, property);
+                    }
+                }
+            }
+        }
+    }
+
 }
\ No newline at end of file