From: Jussi Koskela Date: Mon, 11 Mar 2019 06:29:29 +0000 (+0200) Subject: Provide classifications and datatype for Variable-based drag sources X-Git-Tag: v1.43.0~136^2~180 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F64%2F2764%2F2;p=simantics%2Fplatform.git Provide classifications and datatype for Variable-based drag sources gitlab #270 Change-Id: Idf4b2b82e56f4c20897e4d403d075dbfde9b57b1 --- 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 111ac8a3a..e3e6eeafe 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 @@ -11,6 +11,7 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.Simantics; +import org.simantics.databoard.type.Datatype; import org.simantics.db.ReadGraph; import org.simantics.db.RequestProcessor; import org.simantics.db.Resource; @@ -19,8 +20,8 @@ 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.PossibleVariableGUID; import org.simantics.db.layer0.request.PossibleVariableRepresents; import org.simantics.db.layer0.request.VariableRead; import org.simantics.db.layer0.request.VariableURI; @@ -108,12 +109,30 @@ public class WorkbenchSelectionUtils { if(var != null) { String uri = processor.syncRequest(new VariableURI(var)); String guid = processor.syncRequest(new PossibleVariableGUID(var)); + + Set classifications = processor.syncRequest(new VariableRead>(var) { + @Override + public Set perform(ReadGraph graph) throws DatabaseException { + return var.getClassifications(graph); + } + }); + String classificationsStr = toJSONStringArray(new ArrayList<>(classifications)); + + Datatype datatype = processor.syncRequest(new VariableRead(var) { + @Override + public Datatype perform(ReadGraph graph) throws DatabaseException { + return var.getPossibleDatatype(graph); + } + }); + return toJSONObjectString( "type", "\"Variable\"", "uri", safeQuotedString(uri), "guid", safeQuotedString(guid), "resourceId", res == null ? "" : Long.toString(res.getResourceId()), - "typeResources", typesStr); + "typeResources", typesStr, + "classifications", classificationsStr, + "datatype", safeQuotedString(datatype != null ? datatype.getClass().getName() : null)); } if(res != null) { String uri = processor.syncRequest(new PossibleURI(res));