]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/AnnotationUtils.java
Sync git svn branch with SVN repository r33382.
[simantics/platform.git] / bundles / org.simantics.annotation.ui / src / org / simantics / annotation / ui / AnnotationUtils.java
index 3bc50dae9b5fed14f871136a05f4f425d34e7fb9..2abd2d6706d90d28e3f97ff49053197312dd16c7 100644 (file)
@@ -101,9 +101,9 @@ public class AnnotationUtils {
                return Pair.make(property, type);\r
        }\r
 \r
-       public static void newAnnotation(ReadGraph graph, final Resource parent, Resource model) throws DatabaseException {\r
+       public static void newAnnotation(ReadGraph graph, Resource parent, Resource model) throws DatabaseException {\r
 \r
-        final Map<Resource, Pair<String, ImageDescriptor>> map = new HashMap<Resource, Pair<String,ImageDescriptor>>();\r
+        Map<Resource, Pair<String, ImageDescriptor>> map = new HashMap<>();\r
         findAnnotationTypes(graph, model, map);\r
         findAnnotations(graph, model, map);\r
         queryUserSelectedAnnotationType(map, selected -> {\r
@@ -130,9 +130,9 @@ public class AnnotationUtils {
        }\r
        }\r
        \r
-       public static void newAnnotation(ReadGraph graph, final Variable position, Resource model) throws DatabaseException {\r
+       public static void newAnnotation(ReadGraph graph, Variable position, Resource model) throws DatabaseException {\r
 \r
-        final Map<Resource, Pair<String, ImageDescriptor>> map = new HashMap<Resource, Pair<String,ImageDescriptor>>();\r
+        Map<Resource, Pair<String, ImageDescriptor>> map = new HashMap<>();\r
         findAnnotationTypes(graph, model, map);\r
         findAnnotations(graph, model, map);\r
         queryUserSelectedAnnotationType(map, selected -> {\r
@@ -163,7 +163,7 @@ public class AnnotationUtils {
         * @param model\r
         * @throws DatabaseException\r
         */\r
-       public static void newAnnotation(final Resource parent, final Resource model) throws DatabaseException {\r
+       public static void newAnnotation(Resource parent, Resource model) throws DatabaseException {\r
                if (model == null)\r
                        return;\r
                Simantics.getSession().syncRequest(new ReadRequest() {\r
@@ -174,7 +174,7 @@ public class AnnotationUtils {
                });\r
        }\r
 \r
-       public static void newAnnotation(final Resource parent) throws DatabaseException {\r
+       public static void newAnnotation(Resource parent) throws DatabaseException {\r
         Simantics.getSession().syncRequest(new ReadRequest() {\r
             @Override\r
             public void run(ReadGraph graph) throws DatabaseException {\r
@@ -185,7 +185,7 @@ public class AnnotationUtils {
         });\r
        }\r
 \r
-       public static void newAnnotation(final Variable position) throws DatabaseException {\r
+       public static void newAnnotation(Variable position) throws DatabaseException {\r
         Simantics.getSession().syncRequest(new ReadRequest() {\r
             @Override\r
             public void run(ReadGraph graph) throws DatabaseException {\r
@@ -196,14 +196,13 @@ public class AnnotationUtils {
         });\r
        }\r
 \r
-       public static void newAnnotationInstance(final Resource parent, final Resource model) throws DatabaseException {\r
+       public static void newAnnotationInstance(Resource parent, Resource model) throws DatabaseException {\r
         if (model == null)\r
             return;\r
         Simantics.getSession().syncRequest(new ReadRequest() {\r
             @Override\r
             public void run(ReadGraph graph) throws DatabaseException {\r
-                \r
-                final Map<Resource, Pair<String, ImageDescriptor>> map = new HashMap<Resource, Pair<String,ImageDescriptor>>();\r
+                Map<Resource, Pair<String, ImageDescriptor>> map = new HashMap<>();\r
                 findAnnotationTypes(graph, model, map);\r
                 queryUserSelectedAnnotationType(map, selected -> {\r
                     Simantics.getSession().async(new WriteRequest() {\r
@@ -240,6 +239,11 @@ public class AnnotationUtils {
                        if (graph.hasStatement(_res, L0.Abstract))\r
                                continue;\r
 \r
+                       // Don't allow instantiation of non-user-selectable annotation types\r
+                       Boolean userSelectable = graph.getPossibleRelatedValue2(_res, ANNO.AnnotationType_systemAnnotation, Bindings.BOOLEAN);\r
+                       if (Boolean.TRUE.equals(userSelectable))\r
+                               continue;\r
+\r
                        Resource res = graph.getPossibleObject(_res, L0.HasRange_Inverse);\r
                        if(res == null) {\r
                                \r
@@ -265,7 +269,7 @@ public class AnnotationUtils {
 \r
                                name = name + " - " + URIStringUtils.unescape(parentURI);\r
 \r
-                               map.put(_res, new Pair<String, ImageDescriptor>(name, descriptor));\r
+                               map.put(_res, Pair.make(name, descriptor));\r
                                \r
                        } else {\r
                                \r
@@ -291,7 +295,7 @@ public class AnnotationUtils {
 \r
                                name = name + " - " + URIStringUtils.unescape(parentURI);\r
 \r
-                               map.put(_res, new Pair<String, ImageDescriptor>(name, descriptor));\r
+                               map.put(_res, Pair.make(name, descriptor));\r
                        \r
                        }\r
                        \r
@@ -311,8 +315,6 @@ public class AnnotationUtils {
         ImageDescriptor descriptor = graph.adapt(ANNO.Images_Annotation, ImageDescriptor.class);\r
 \r
         for(Resource _res : query.find(graph, model)) {\r
-            // Don't allow instantiation of abstract annotation types.\r
-\r
             String name = graph.getPossibleRelatedValue(_res, L0.HasName, Bindings.STRING);\r
             if (name == null)\r
                 continue;\r
@@ -334,8 +336,13 @@ public class AnnotationUtils {
 \r
             Resource type = graph.getPossibleType(_res, ANNO.Annotation);\r
             if(type != null) {\r
-               Resource relation = graph.getPossibleObject(type, L0.HasRange_Inverse);\r
-               if(relation != null) {\r
+                // Don't list instances of non-user-selectable annotation types\r
+                Boolean userSelectable = graph.getPossibleRelatedValue2(type, ANNO.AnnotationType_systemAnnotation, Bindings.BOOLEAN);\r
+                if (Boolean.TRUE.equals(userSelectable))\r
+                    continue;\r
+\r
+                Resource relation = graph.getPossibleObject(type, L0.HasRange_Inverse);\r
+                if(relation != null) {\r
                     String rName = graph.getPossibleRelatedValue(relation, L0.HasName, Bindings.STRING);\r
                     if(rName != null) {\r
                        name = name + " - " + rName;\r
@@ -345,7 +352,7 @@ public class AnnotationUtils {
             \r
             name = name + " - " + URIStringUtils.unescape(parentURI);\r
             \r
-            map.put(_res, new Pair<String, ImageDescriptor>(name, descriptor));\r
+            map.put(_res, Pair.make(name, descriptor));\r
             \r
         }\r
 \r
@@ -380,7 +387,7 @@ public class AnnotationUtils {
                        @Override\r
                        public Map<Resource, Pair<String, ImageDescriptor>> perform(ReadGraph graph) throws DatabaseException {\r
 \r
-                               Map<Resource, Pair<String, ImageDescriptor>> result = new HashMap<Resource, Pair<String,ImageDescriptor>>();\r
+                               Map<Resource, Pair<String, ImageDescriptor>> result = new HashMap<>();\r
 \r
                                Layer0 L0 = Layer0.getInstance(graph);\r
                                AnnotationResource ANNO = AnnotationResource.getInstance(graph);\r
@@ -399,7 +406,7 @@ public class AnnotationUtils {
                                        if(!path.startsWith(modelURI)) continue;\r
                                        String suffix = URIStringUtils.unescape(path.substring(modelPos));\r
                                        if(suffix.startsWith("/")) suffix = suffix.substring(1);\r
-                                       result.put(lib, new Pair<String, ImageDescriptor>(suffix, descriptor));\r
+                                       result.put(lib, Pair.make(suffix, descriptor));\r
 \r
                                }\r
 \r
@@ -532,48 +539,40 @@ public class AnnotationUtils {
         * @param selectionCallback\r
         */\r
        public static void queryUserSelectedAnnotationType(\r
-                       final Map<Resource, Pair<String, ImageDescriptor>> map,\r
-                       final Consumer<Resource> selectionCallback)\r
+                       Map<Resource, Pair<String, ImageDescriptor>> map,\r
+                       Consumer<Resource> selectionCallback)\r
        {\r
-               Display.getDefault().asyncExec(new Runnable() {\r
-                       @Override\r
-                       public void run() {\r
-                               Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();\r
-                               ResourceSelectionDialog3<Resource> dialog = new ResourceSelectionDialog3<Resource>(shell, map, "Select annotation type from list") {\r
-                                       @Override\r
-                                       protected IDialogSettings getBaseDialogSettings() {\r
-                                               return Activator.getDefault().getDialogSettings();\r
-                                       }\r
-                               };\r
-                               if (dialog.open() == Window.OK) {\r
-                                       Object[] result = dialog.getResult();\r
-                                       if (result != null && result.length == 1) {\r
-                                               final Resource res = (Resource)result[0];\r
-                                               selectionCallback.accept(res);\r
-                                       }\r
+               Display.getDefault().asyncExec(() -> {\r
+                       Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();\r
+                       ResourceSelectionDialog3<Resource> dialog = new ResourceSelectionDialog3<Resource>(shell, map, "Select annotation type from list") {\r
+                               @Override\r
+                               protected IDialogSettings getBaseDialogSettings() {\r
+                                       return Activator.getDefault().getDialogSettings();\r
+                               }\r
+                       };\r
+                       if (dialog.open() == Window.OK) {\r
+                               Object[] result = dialog.getResult();\r
+                               if (result != null && result.length == 1) {\r
+                                       selectionCallback.accept((Resource) result[0]);\r
                                }\r
                        }\r
                });\r
        }\r
 \r
        public static void queryLibrary(\r
-                       final Map<Resource, Pair<String, ImageDescriptor>> map,\r
-                       final Consumer<Pair<Resource,String>> selectionCallback)\r
+                       Map<Resource, Pair<String, ImageDescriptor>> map,\r
+                       Consumer<Pair<Resource,String>> selectionCallback)\r
        {\r
-               Display.getDefault().asyncExec(new Runnable() {\r
-                       @Override\r
-                       public void run() {\r
-                               Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();\r
-                               SaveAnnotationDialog page = new SaveAnnotationDialog(shell, map, "Select library");\r
-                               if (page.open() == Window.OK) {\r
-                                       Object[] result = page.getResult();\r
-                                       if (result != null && result.length == 1) {\r
-                                               final Resource res = (Resource)result[0];\r
-                                               selectionCallback.accept(Pair.make(res, page.getName()));\r
-                                       }\r
+               Display.getDefault().asyncExec(() -> {\r
+                       Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();\r
+                       SaveAnnotationDialog page = new SaveAnnotationDialog(shell, map, "Select library");\r
+                       if (page.open() == Window.OK) {\r
+                               Object[] result = page.getResult();\r
+                               if (result != null && result.length == 1) {\r
+                                       selectionCallback.accept(Pair.make((Resource)result[0], page.getName()));\r
                                }\r
                        }\r
                });\r
        }\r
        \r
-}
\ No newline at end of file
+}\r