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