]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added resourceId and GUID to diagram DnD content 28/2328/4
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 18 Oct 2018 07:56:20 +0000 (10:56 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 18 Oct 2018 10:34:29 +0000 (10:34 +0000)
gitlab #150

Change-Id: I2a012199f5d7e11991b640d7187132e7b5f0d2f3

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleGUID.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleVariableGUID.java [new file with mode: 0644]
bundles/org.simantics.ui/src/org/simantics/ui/selection/WorkbenchSelectionUtils.java

diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleGUID.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleGUID.java
new file mode 100644 (file)
index 0000000..c06f719
--- /dev/null
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2018 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.request;
+
+import org.simantics.datatypes.literal.GUID;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+
+public class PossibleGUID extends ResourceRead<String> {
+
+    public PossibleGUID(Resource resource) {
+        super(resource);
+    }
+
+    @Override
+    public String perform(ReadGraph graph) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        GUID guid = graph.getPossibleRelatedValue(resource, L0.identifier, GUID.BINDING);
+        return guid != null ? guid.indexString() : null;
+    }
+
+}
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleVariableGUID.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleVariableGUID.java
new file mode 100644 (file)
index 0000000..ffd06e9
--- /dev/null
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2018 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.request;
+
+import org.simantics.datatypes.literal.GUID;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+
+public class PossibleVariableGUID extends VariableRead<String> {
+
+    public PossibleVariableGUID(Variable variable) {
+        super(variable);
+    }
+
+    @Override
+    public String perform(ReadGraph graph) throws DatabaseException {
+        GUID guid = variable.getPossiblePropertyValue(graph, "identifier", GUID.BINDING);
+        return guid != null ? guid.indexString() : null;
+    }
+
+}
index 47e866d0f61a651d7df83d53c93e6041740cdd09..111ac8a3a2722b89b7945343830d059e2c3d82f5 100644 (file)
@@ -18,6 +18,8 @@ import org.simantics.db.common.primitiverequest.IsInstanceOf;
 import org.simantics.db.common.primitiverequest.Supertypes;
 import org.simantics.db.common.primitiverequest.Types;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.PossibleGUID;
+import org.simantics.db.layer0.request.PossibleVariableGUID;
 import org.simantics.db.layer0.request.PossibleURI;
 import org.simantics.db.layer0.request.PossibleVariableRepresents;
 import org.simantics.db.layer0.request.VariableRead;
@@ -105,16 +107,22 @@ public class WorkbenchSelectionUtils {
                String typesStr = getTypeResourceString(processor, res, var);
                if(var != null) {
                        String uri = processor.syncRequest(new VariableURI(var));
+                       String guid = processor.syncRequest(new PossibleVariableGUID(var));
                        return toJSONObjectString(
                                        "type", "\"Variable\"",
                                        "uri", safeQuotedString(uri),
+                                       "guid", safeQuotedString(guid),
+                                       "resourceId", res == null ? "" : Long.toString(res.getResourceId()),
                                        "typeResources", typesStr);
                }
                if(res != null) {
-                       String uri = processor.syncRequest(new PossibleURI(res));
+                   String uri = processor.syncRequest(new PossibleURI(res));
+                   String guid = processor.syncRequest(new PossibleGUID(res));
                        return toJSONObjectString(
                                        "type", "\"Resource\"",
                                        "uri", safeQuotedString(uri),
+                                       "guid", safeQuotedString(guid),
+                                       "resourceId", Long.toString(res.getResourceId()),
                                        "typeResources", typesStr);
                }
                return "{ \"type\": \"Unknown\" }";