From: Hannu Niemistö Date: Thu, 18 Oct 2018 07:56:20 +0000 (+0300) Subject: Added resourceId and GUID to diagram DnD content X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=7bb7b8f82ffc6bae57bac36505705b0c7722263e;p=simantics%2Fplatform.git Added resourceId and GUID to diagram DnD content gitlab #150 Change-Id: I2a012199f5d7e11991b640d7187132e7b5f0d2f3 --- 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 index 000000000..c06f719fb --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleGUID.java @@ -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 { + + 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 index 000000000..ffd06e924 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleVariableGUID.java @@ -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 { + + 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; + } + +} diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/selection/WorkbenchSelectionUtils.java b/bundles/org.simantics.ui/src/org/simantics/ui/selection/WorkbenchSelectionUtils.java index 47e866d0f..111ac8a3a 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/selection/WorkbenchSelectionUtils.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/selection/WorkbenchSelectionUtils.java @@ -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\" }";