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
}\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
* @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
});\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
});\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
});\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
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
\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
\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
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
\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
\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
@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
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
* @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