org.eclipse.e4.core.commands,
org.eclipse.e4.ui.bindings;bundle-version="0.11.0",
org.eclipse.e4.core.di.annotations,
- org.eclipse.e4.core.services
+ org.eclipse.e4.core.services,
+ com.fasterxml.jackson.core.jackson-core;bundle-version="2.8.2"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2016 Association for Decentralized Information Management in\r
* Industry THTH ry.\r
* All rights reserved. This program and the accompanying materials\r
* are made available under the terms of the Eclipse Public License v1.0\r
*\r
* Contributors:\r
* VTT Technical Research Centre of Finland - initial API and implementation\r
+ * Semantum Oy - JSON plain text input support\r
*******************************************************************************/\r
package org.simantics.charts.editor;\r
\r
+import java.awt.datatransfer.DataFlavor;\r
import java.awt.datatransfer.Transferable;\r
import java.awt.datatransfer.UnsupportedFlavorException;\r
import java.awt.dnd.DnDConstants;\r
import java.awt.dnd.DropTargetDropEvent;\r
import java.awt.dnd.DropTargetEvent;\r
import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.nio.charset.Charset;\r
import java.util.ArrayList;\r
import java.util.Collection;\r
import java.util.Collections;\r
import java.util.List;\r
+import java.util.Optional;\r
+import java.util.stream.Collectors;\r
\r
import org.eclipse.jface.viewers.ISelection;\r
import org.simantics.Simantics;\r
+import org.simantics.charts.internal.JsonUtils;\r
import org.simantics.charts.query.AddChartItem;\r
import org.simantics.charts.query.ChartItemDescriptor;\r
import org.simantics.charts.ui.AddVariableToChartAction;\r
import org.simantics.databoard.util.ObjectUtils;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
import org.simantics.db.common.request.UnaryRead;\r
+import org.simantics.db.common.request.UniqueRead;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.SelectionHints;\r
import org.simantics.db.layer0.request.PossibleModel;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.db.layer0.variable.VariableReference;\r
import org.simantics.db.layer0.variable.Variables;\r
-import org.simantics.db.request.Read;\r
import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant;\r
import org.simantics.g2d.dnd.DragItem;\r
import org.simantics.g2d.dnd.IDnDContext;\r
import org.simantics.ui.dnd.LocalObjectTransfer;\r
import org.simantics.ui.dnd.LocalObjectTransferable;\r
import org.simantics.ui.selection.WorkbenchSelectionElement;\r
+import org.simantics.utils.FileUtils;\r
import org.simantics.utils.ui.ErrorLogger;\r
import org.simantics.utils.ui.ISelectionUtils;\r
import org.simantics.utils.ui.dialogs.ShowMessage;\r
\r
@Override\r
public void dragEnter(DropTargetDragEvent dtde, IDnDContext dp) {\r
- // The transferable doesn't know LOT\r
- if (!dtde.isDataFlavorSupported(LocalObjectTransferable.FLAVOR)) {\r
- dtde.rejectDrag();\r
- return;\r
- }\r
-\r
// The source cannot link, too bad\r
if ((dtde.getSourceActions() & DnDConstants.ACTION_LINK) == 0) {\r
dtde.rejectDrag();\r
}\r
\r
// Ensure the content is usable\r
+ if (dtde.isDataFlavorSupported(LocalObjectTransferable.FLAVOR)) {\r
+ dragEnterLocalObject(dtde, dp);\r
+ } else if (dtde.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor())) {\r
+ dragEnterPlainText(dtde, dp);\r
+ } else {\r
+ dtde.rejectDrag();\r
+ }\r
+ }\r
+\r
+ private void dragEnterLocalObject(DropTargetDragEvent dtde, IDnDContext dp) {\r
try {\r
- Transferable t = dtde.getTransferable();\r
- Object data = t.getTransferData(LocalObjectTransferable.FLAVOR);\r
+ Object data = dtde.getTransferable().getTransferData(LocalObjectTransferable.FLAVOR);\r
data = LocalObjectTransfer.getTransfer().getObject();\r
\r
- List<IDragItem> items = new ArrayList<IDragItem>();\r
+ List<IDragItem> items = new ArrayList<>();\r
+ Session session = Simantics.getSession();\r
\r
final List<Resource> resources = ISelectionUtils.getPossibleKeys(data, SelectionHints.KEY_MAIN, Resource.class);\r
if (!resources.isEmpty()) {\r
// Support SubscriptionItem drags\r
- items.addAll( Simantics.getSession().syncRequest(new Read<List<IDragItem>>() {\r
+ items.addAll( session.syncRequest(new UniqueRead<List<IDragItem>>() {\r
@Override\r
public List<IDragItem> perform(ReadGraph graph) throws DatabaseException {\r
- List<IDragItem> result = new ArrayList<IDragItem>();\r
- //Layer0 L0 = Layer0.getInstance(graph);\r
+ List<IDragItem> result = new ArrayList<>();\r
ModelingResources MOD = ModelingResources.getInstance(graph);\r
Resource targetModel = graph.syncRequest(new PossibleModel(container));\r
if (targetModel != null) {\r
for (Resource r : resources) {\r
- //System.out.println( graph.getPossibleRelatedValue(r, L0.HasName) );\r
if (graph.isInstanceOf(r, MOD.Subscription_Item)) {\r
Resource model = graph.syncRequest(new PossibleModel(r));\r
if (ObjectUtils.objectEquals(targetModel, model))\r
\r
if(data instanceof RVI) {\r
\r
- VariableReferenceDragItem vrdi = new VariableReferenceDragItem(Simantics.getSession().sync(new UnaryRead<RVI, VariableReference>((RVI)data) {\r
+ VariableReferenceDragItem vrdi = new VariableReferenceDragItem(session.sync(new UnaryRead<RVI, VariableReference>((RVI)data) {\r
@Override\r
public VariableReference perform(ReadGraph graph) throws DatabaseException {\r
return new VariableReference(parameter, Variables.getDatatype(graph, model, parameter), null);\r
// 1st try Variable\r
final List<Variable> vars2 = ISelectionUtils.getPossibleKeys(data, SelectionHints.KEY_MAIN, Variable.class);\r
if (!vars2.isEmpty()) {\r
- varItems = Simantics.getSession().syncRequest( new Read<List<IDragItem>>() {\r
+ varItems = session.syncRequest( new UniqueRead<List<IDragItem>>() {\r
@Override\r
public List<IDragItem> perform(ReadGraph graph) throws DatabaseException {\r
return toDragItems( graph.syncRequest(VariableReferences.variablesToReferences(model, vars2)) );\r
// Try legacy PropertyVariables\r
final List<PropertyVariables> vars = ISelectionUtils.getPossibleKeys(data, SelectionHints.KEY_MAIN, PropertyVariables.class);\r
if (!vars.isEmpty()) {\r
- varItems = Simantics.getSession().syncRequest( new Read<List<IDragItem>>() {\r
+ varItems = session.syncRequest( new UniqueRead<List<IDragItem>>() {\r
@Override\r
public List<IDragItem> perform(ReadGraph graph) throws DatabaseException {\r
List<PropertyVariables> vars2 = PropertyVariablesImpl.resolve(graph, vars);\r
if (data instanceof ISelection) {\r
final List<WorkbenchSelectionElement> wses = ISelectionUtils.filterSelection((ISelection)data, WorkbenchSelectionElement.class);\r
if (!wses.isEmpty()) {\r
- items.addAll( Simantics.getSession().syncRequest( new Read<List<IDragItem>>() {\r
+ items.addAll( session.syncRequest( new UniqueRead<List<IDragItem>>() {\r
@Override\r
public List<IDragItem> perform(ReadGraph graph) throws DatabaseException {\r
- List<Variable> wsevars = new ArrayList<Variable>();\r
+ List<Variable> wsevars = new ArrayList<>();\r
ChartVariable av = new ChartVariable(graph);\r
for(WorkbenchSelectionElement wse : wses) {\r
Variable v = wse.getContent(av);\r
}\r
}\r
\r
+ private void dragEnterPlainText(DropTargetDragEvent dtde, IDnDContext dp) {\r
+ try {\r
+ DataFlavor flavor = DataFlavor.getTextPlainUnicodeFlavor();\r
+ String flavorCharset = flavor.getParameter("charset");\r
+ Transferable t = dtde.getTransferable();\r
+ InputStream in = (InputStream) t.getTransferData(flavor);\r
+ String data = FileUtils.getContents(in, Charset.forName(flavorCharset));\r
+\r
+ List<IDragItem> items = new ArrayList<>();\r
+ Session session = Simantics.getSession();\r
+ Optional<Variable> v = JsonUtils.tryParseJsonPropertyVariable(session, data);\r
+ if (v.isPresent()) {\r
+ items.addAll( toDragItems( session.syncRequest(VariableReferences.variablesToReferences(model, Collections.singletonList(v.get()))) ) );\r
+ }\r
+\r
+ if (items.isEmpty()) {\r
+ dtde.rejectDrag();\r
+ } else {\r
+ // Accept, make sure it is Link\r
+ for (IDragItem i : items)\r
+ dp.add(i);\r
+ dtde.acceptDrag( DnDConstants.ACTION_LINK );\r
+ }\r
+ } catch (UnsupportedFlavorException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IOException e) {\r
+ ErrorLogger.defaultLogError(e);\r
+ dtde.rejectDrag();\r
+ } catch (DatabaseException e) {\r
+ ErrorLogger.defaultLogError(e);\r
+ dtde.rejectDrag();\r
+ }\r
+ }\r
+\r
@Override\r
public void dragExit(DropTargetEvent dte, IDnDContext dp) {\r
for (IDragItem i : dp.getItemsByClass(SubscriptionItemDragItem.class))\r
\r
@Override\r
public void drop(DropTargetDropEvent dtde, IDnDContext dp) {\r
- // Subscription Item\r
+ // Subscription Item\r
Collection<SubscriptionItemDragItem> subs = dp.getItemsByClass(SubscriptionItemDragItem.class);\r
if (!subs.isEmpty()) {\r
- List<ChartItemDescriptor> cicr = new ArrayList<ChartItemDescriptor>();\r
- for (SubscriptionItemDragItem sidi : subs) {\r
- cicr.add(sidi.getObject());\r
- }\r
- ChartDropActionFactory.addPlots(container, cicr, Collections.<Resource>emptySet()).run();\r
+ ChartDropActionFactory.addPlots(container,\r
+ subs.stream().map(DragItem::getObject).collect(Collectors.toList()),\r
+ Collections.<Resource>emptySet()).run();\r
dtde.dropComplete(true);\r
return;\r
}\r
- \r
+\r
// Variable Reference\r
Collection<VariableReferenceDragItem> vrdis = dp.getItemsByClass(VariableReferenceDragItem.class);\r
if (!vrdis.isEmpty()) {\r
- List<VariableReference> refs = new ArrayList<VariableReference>();\r
- for (VariableReferenceDragItem vrdi : vrdis) {\r
- refs.add( vrdi.getObject() );\r
- }\r
- Resource chart = container;\r
try {\r
- AddVariableToChartAction a = new AddVariableToChartAction( chart, null, refs );\r
- a.init();\r
- a.run();\r
+ new AddVariableToChartAction( container, null,\r
+ vrdis.stream().map(DragItem::getObject).collect(Collectors.toList()) )\r
+ .init().run();\r
dtde.dropComplete(true);\r
} catch (DatabaseException e) {\r
ShowMessage.showError(e.getClass().getName(), e.getMessage());\r
}\r
return;\r
}\r
- \r
+\r
dtde.rejectDrop();\r
}\r
\r
}\r
\r
private static List<IDragItem> toDragItems(Collection<VariableReference> references) {\r
- List<IDragItem> result = new ArrayList<IDragItem>(references.size());\r
- for (VariableReference vr : references) {\r
- VariableReferenceDragItem di = new VariableReferenceDragItem( vr );\r
- result.add( di );\r
- }\r
- return result;\r
+ return references.stream().map(VariableReferenceDragItem::new).collect(Collectors.toList());\r
}\r
- \r
+\r
@Override\r
public double getPriority() {\r
return 10.0;\r
--- /dev/null
+package org.simantics.charts.internal;\r
+\r
+import java.io.IOException;\r
+import java.util.Optional;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.RequestProcessor;\r
+import org.simantics.db.common.request.UniqueRead;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+\r
+import com.fasterxml.jackson.core.JsonFactory;\r
+import com.fasterxml.jackson.core.JsonParser;\r
+import com.fasterxml.jackson.core.JsonToken;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ *\r
+ */\r
+public class JsonUtils {\r
+\r
+ public static Optional<Variable> tryParseJsonPropertyVariable(RequestProcessor processor, String json) throws DatabaseException {\r
+ return processor.syncRequest(new UniqueRead<Optional<Variable>>() {\r
+ @Override\r
+ public Optional<Variable> perform(ReadGraph graph) throws DatabaseException {\r
+ return tryParseJsonPropertyVariable(graph, json);\r
+ }\r
+ });\r
+ }\r
+\r
+ public static Optional<Variable> tryParseJsonPropertyVariable(ReadGraph graph, String json) throws DatabaseException {\r
+ try (JsonParser jp = new JsonFactory().createParser(json)) {\r
+ return JsonUtils.readPossibleVariable(graph, jp);\r
+ } catch (IOException e) {\r
+ throw new DatabaseException(e);\r
+ }\r
+ }\r
+\r
+ public static Optional<Variable> readPossibleVariable(ReadGraph graph, JsonParser jp) throws IOException, DatabaseException {\r
+ Optional<String> uri = readPossibleVariableUri(jp);\r
+ return uri.isPresent() ? Optional.ofNullable(Variables.getPossibleVariable(graph, uri.get())) : Optional.empty();\r
+ }\r
+\r
+ public static Optional<String> readPossibleVariableUri(JsonParser jp) throws IOException {\r
+ // Sanity check: verify that we got "Json Object":\r
+ if (jp.nextToken() != JsonToken.START_OBJECT)\r
+ throw new IOException("Expected data to start with an Object");\r
+\r
+ String uri = null;\r
+ String type = null;\r
+ String defaultPropertyUri = null;\r
+\r
+ while (jp.nextToken() != JsonToken.END_OBJECT) {\r
+ String fieldName = jp.getCurrentName();\r
+ jp.nextToken();\r
+ if (fieldName.equals("uri")) {\r
+ uri = jp.getValueAsString();\r
+ } else if (fieldName.equals("type")) {\r
+ type = jp.getValueAsString();\r
+ } else if (fieldName.equals("defaultPropertyUri")) {\r
+ defaultPropertyUri = jp.getValueAsString();\r
+ }\r
+ }\r
+\r
+ return Optional.ofNullable("Variable".equals(type) ?\r
+ defaultPropertyUri != null ? defaultPropertyUri : uri\r
+ : null);\r
+ }\r
+\r
+}\r
* \r
* @throws DatabaseException\r
*/\r
- public void init() throws DatabaseException \r
+ public AddVariableToChartAction init() throws DatabaseException \r
{\r
Simantics.getSession().sync( new ReadRequest() {\r
@Override\r
init(g);\r
}\r
} );\r
+ return this;\r
}\r
\r
/**\r
* \r
* @throws DatabaseException\r
*/\r
- public void init( ReadGraph g ) throws DatabaseException \r
+ public AddVariableToChartAction init( ReadGraph g ) throws DatabaseException \r
{\r
Layer0 L0 = Layer0.getInstance(g);\r
if(chart != null) {\r
variableReferences.add( var.getVariableId().toPossibleString(g, configuration) );\r
}\r
}\r
+\r
+ return this;\r
}\r
\r
/**\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.Collections;\r
import java.util.HashSet;\r
import java.util.List;\r
+import java.util.Optional;\r
import java.util.Set;\r
+import java.util.stream.Collectors;\r
\r
import org.eclipse.jface.viewers.ISelection;\r
import org.simantics.Simantics;\r
+import org.simantics.charts.internal.JsonUtils;\r
import org.simantics.charts.ontology.ChartResource;\r
import org.simantics.charts.query.AddChartItem;\r
import org.simantics.charts.query.ChartItemDescriptor;\r
import org.simantics.modeling.utils.VariableReferences;\r
import org.simantics.trend.configuration.TrendItem.Renderer;\r
import org.simantics.ui.selection.WorkbenchSelectionElement;\r
-import org.simantics.utils.datastructures.collections.CollectionUtils;\r
import org.simantics.utils.ui.ErrorLogger;\r
import org.simantics.utils.ui.ISelectionUtils;\r
\r
if (targetModel == null) return null;\r
\r
if(source instanceof RVI) {\r
-\r
- RVI rvi = (RVI)source;\r
- List<VariableReference> refs = CollectionUtils.toList(new VariableReference(rvi, SubscriptionDropActionFactory.getDatatype(g, targetModel, rvi), null));\r
- \r
- AddVariableToChartAction a = new AddVariableToChartAction(chart, null, refs);\r
- a.init(g);\r
- return a;\r
- \r
+ List<VariableReference> refs = Collections.singletonList(new VariableReference((RVI)source,\r
+ SubscriptionDropActionFactory.getDatatype(g, targetModel, (RVI) source), null));\r
+ return new AddVariableToChartAction(chart, null, refs).init(g);\r
}\r
- \r
+\r
List<PropertyVariables> vars = ISelectionUtils.getPossibleKeys(source, SelectionHints.KEY_MAIN, PropertyVariables.class);\r
if (!vars.isEmpty()) {\r
// FIXME: this is a hack for indexed value support\r
vars = PropertyVariablesImpl.resolve(g, vars);\r
- List<VariableReference> references2 = g.syncRequest(VariableReferences.toReferences(targetModel, vars));\r
- List<VariableReference> references = new ArrayList<VariableReference>();\r
- for (VariableReference ref : references2) {\r
- if (ref.datatype instanceof BooleanType || ref.datatype instanceof NumberType) {\r
- references.add(ref);\r
- }\r
- }\r
- \r
- AddVariableToChartAction a = new AddVariableToChartAction(chart, null, references);\r
- a.init(g);\r
- return a;\r
+ List<VariableReference> references = toPropertyReferences(g, targetModel, vars);\r
+ if (!references.isEmpty())\r
+ return new AddVariableToChartAction(chart, null, references).init(g);\r
}\r
- final List<Variable> vars2 = ISelectionUtils.getPossibleKeys(source, SelectionHints.KEY_MAIN, Variable.class);\r
+\r
+ List<Variable> vars2 = ISelectionUtils.getPossibleKeys(source, SelectionHints.KEY_MAIN, Variable.class);\r
if (!vars2.isEmpty()) {\r
- // FIXME: this is a hack for indexed value support\r
- List<VariableReference> references2 = g.syncRequest(VariableReferences.variablesToReferences(targetModel, vars2));\r
- List<VariableReference> references = new ArrayList<VariableReference>();\r
- for (VariableReference ref : references2) {\r
- if (ref.datatype instanceof BooleanType || ref.datatype instanceof NumberType) {\r
- references.add(ref);\r
- }\r
- }\r
- AddVariableToChartAction a = new AddVariableToChartAction(chart, null, references);\r
- a.init(g);\r
- return a;\r
+ List<VariableReference> references = toReferences(g, targetModel, vars2);\r
+ if (!references.isEmpty())\r
+ return new AddVariableToChartAction(chart, null, references).init(g);\r
}\r
\r
if(source instanceof ISelection) {\r
List<WorkbenchSelectionElement> wses = ISelectionUtils.filterSelection((ISelection)source, WorkbenchSelectionElement.class);\r
if (!wses.isEmpty()) {\r
- List<Variable> wsevars = new ArrayList<Variable>();\r
+ List<Variable> wsevars = new ArrayList<>();\r
ChartVariable av = new ChartVariable(g);\r
for(WorkbenchSelectionElement wse : wses) {\r
Variable v = wse.getContent(av);\r
- if(v != null) {\r
+ if(v != null)\r
wsevars.add(v);\r
- }\r
}\r
\r
+ List<VariableReference> references = toReferences(g, targetModel, wsevars);\r
if (!wsevars.isEmpty()) {\r
- // FIXME: this is a hack for indexed value support\r
- List<VariableReference> references2 = g.syncRequest(VariableReferences.variablesToReferences(targetModel, wsevars));\r
- List<VariableReference> references = new ArrayList<VariableReference>();\r
- for (VariableReference ref : references2) {\r
- if (ref.datatype instanceof BooleanType || ref.datatype instanceof NumberType) {\r
- references.add(ref);\r
- }\r
- }\r
- AddVariableToChartAction a = new AddVariableToChartAction(chart, null, references);\r
- a.init(g);\r
- return a;\r
+ return new AddVariableToChartAction(chart, null, references).init(g);\r
}\r
}\r
}\r
return addPlots(chart, newItems, movedPlots);\r
}\r
\r
+ if (source instanceof String) {\r
+ // JSON ?\r
+ Optional<Variable> v = JsonUtils.tryParseJsonPropertyVariable(g, (String) source);\r
+ if (v.isPresent()) {\r
+ List<VariableReference> references = toReferences(g, targetModel, Collections.singletonList(v.get()));\r
+ if (!references.isEmpty())\r
+ return new AddVariableToChartAction(chart, null, references).init(g);\r
+ }\r
+ }\r
+\r
return null;\r
}\r
\r
- public static Runnable addPlots(final Resource chart, final List<ChartItemDescriptor> references, final Set<Resource> movedPlots) {\r
- return new Runnable() {\r
- @Override\r
- public void run() {\r
- Simantics.getSession().asyncRequest(\r
- AddChartItem.addAndMoveChartItems(chart, references, movedPlots),\r
- new ProcedureAdapter<Collection<Resource>>() {\r
- @Override\r
- public void exception(Throwable e) {\r
+ private static List<VariableReference> toReferences(ReadGraph graph, Resource contextIndexRoot, List<Variable> variables) throws DatabaseException {\r
+ if (variables.isEmpty())\r
+ return Collections.emptyList();\r
+ return filterReferences( graph.syncRequest(VariableReferences.variablesToReferences(contextIndexRoot, variables)) );\r
+ }\r
+\r
+ private static List<VariableReference> toPropertyReferences(ReadGraph graph, Resource contextIndexRoot, List<PropertyVariables> variables) throws DatabaseException {\r
+ if (variables.isEmpty())\r
+ return Collections.emptyList();\r
+ return filterReferences( graph.syncRequest(VariableReferences.toReferences(contextIndexRoot, variables)) );\r
+ }\r
+\r
+ private static List<VariableReference> filterReferences(List<VariableReference> variables) throws DatabaseException {\r
+ return variables.stream()\r
+ .filter(ref -> ref.datatype instanceof BooleanType || ref.datatype instanceof NumberType)\r
+ .collect(Collectors.toList());\r
+ }\r
+\r
+ public static Runnable addPlots(Resource chart, List<ChartItemDescriptor> references, Set<Resource> movedPlots) {\r
+ return () -> {\r
+ Simantics.getSession().asyncRequest(\r
+ AddChartItem.addAndMoveChartItems(chart, references, movedPlots),\r
+ new ProcedureAdapter<Collection<Resource>>() {\r
+ @Override\r
+ public void exception(Throwable e) {\r
+ if (e != null)\r
ErrorLogger.defaultLogError(e);\r
- }\r
- });\r
- }\r
+ }\r
+ });\r
};\r
}\r
\r
import java.util.Collections;\r
import java.util.HashSet;\r
import java.util.List;\r
+import java.util.Optional;\r
import java.util.Set;\r
\r
import org.simantics.Simantics;\r
import org.simantics.browsing.ui.common.ErrorLogger;\r
+import org.simantics.charts.internal.JsonUtils;\r
import org.simantics.databoard.type.Datatype;\r
import org.simantics.databoard.util.ObjectUtils;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.modeling.PropertyVariables;\r
import org.simantics.modeling.PropertyVariablesImpl;\r
import org.simantics.modeling.utils.VariableReferences;\r
-import org.simantics.utils.datastructures.Callback;\r
-import org.simantics.utils.datastructures.collections.CollectionUtils;\r
import org.simantics.utils.ui.ISelectionUtils;\r
\r
/**\r
Resource targetModel = g.syncRequest(new PossibleModel(subscription));\r
\r
if(source instanceof RVI) {\r
+ RVI rvi = (RVI)source;\r
+ List<VariableReference> refs = Collections.singletonList(new VariableReference(rvi, getDatatype(g, targetModel, rvi), null));\r
+ return addSubscriptions(g, subscription, refs, Collections.<Resource>emptySet());\r
+ }\r
\r
- RVI rvi = (RVI)source;\r
- List<VariableReference> refs = CollectionUtils.toList(new VariableReference(rvi, getDatatype(g, targetModel, rvi), null));\r
- if (!refs.isEmpty())\r
- return addSubscriptions(g, subscription, refs, Collections.<Resource>emptySet());\r
- \r
+ List<PropertyVariables> vars = ISelectionUtils.getPossibleKeys(source, SelectionHints.KEY_MAIN, PropertyVariables.class);\r
+ if (!vars.isEmpty()) {\r
+ // FIXME: this is a hack for indexed value support\r
+ vars = PropertyVariablesImpl.resolve(g, vars);\r
+ List<VariableReference> references = g.syncRequest(VariableReferences.toReferences(targetModel, vars));\r
+ if (!references.isEmpty())\r
+ return addSubscriptions(g, subscription, references, Collections.<Resource>emptySet());\r
} else {\r
- \r
- List<PropertyVariables> vars = ISelectionUtils.getPossibleKeys(source, SelectionHints.KEY_MAIN, PropertyVariables.class);\r
- if (!vars.isEmpty()) {\r
- // FIXME: this is a hack for indexed value support\r
- vars = PropertyVariablesImpl.resolve(g, vars);\r
+ List<Resource> srcs = ISelectionUtils.getPossibleKeys(source, SelectionHints.KEY_MAIN, Resource.class);\r
+ ModelingResources MOD = ModelingResources.getInstance(g);\r
+ Set<Resource> movedItems = new HashSet<>();\r
+ for (Resource src : srcs) {\r
+ if (g.isInstanceOf(src, MOD.Subscription_Item)) {\r
+ Resource model = g.syncRequest(new PossibleModel(src));\r
+ if (ObjectUtils.objectEquals(targetModel, model))\r
+ movedItems.add(src);\r
+ }\r
+ }\r
+ if (!movedItems.isEmpty())\r
+ return addSubscriptions(g, subscription, Collections.emptyList(), movedItems);\r
+ }\r
\r
- List<VariableReference> references = g.syncRequest(VariableReferences.toReferences(targetModel, vars));\r
- if (!references.isEmpty())\r
- return addSubscriptions(g, subscription, references, Collections.<Resource>emptySet());\r
- } else {\r
- List<Resource> srcs = ISelectionUtils.getPossibleKeys(source, SelectionHints.KEY_MAIN, Resource.class);\r
- ModelingResources MOD = ModelingResources.getInstance(g);\r
- Set<Resource> movedItems = new HashSet<Resource>();\r
- for (Resource src : srcs) {\r
- if (g.isInstanceOf(src, MOD.Subscription_Item)) {\r
- Resource model = g.syncRequest(new PossibleModel(src));\r
- if (ObjectUtils.objectEquals(targetModel, model))\r
- movedItems.add(src);\r
- }\r
- }\r
- if (!movedItems.isEmpty())\r
- return addSubscriptions(g, subscription, Collections.<VariableReference>emptyList(), movedItems);\r
- }\r
- \r
+ if (source instanceof String) {\r
+ // JSON ?\r
+ Optional<Variable> v = JsonUtils.tryParseJsonPropertyVariable(g, (String) source);\r
+ if (v.isPresent()) {\r
+ List<VariableReference> references = g.syncRequest(VariableReferences.variablesToReferences(targetModel, Collections.singletonList(v.get())));\r
+ return addSubscriptions(g, subscription, references, Collections.emptySet());\r
+ }\r
}\r
\r
return null;\r
}\r
\r
- private Runnable addSubscriptions(ReadGraph graph, final Resource subscription, final List<VariableReference> references,\r
- final Set<Resource> movedSubscriptionItems) throws DatabaseException {\r
- final AddVariableToChartAction action = new AddVariableToChartAction(null, subscription, references);\r
- action.init(graph);\r
- return new Runnable() {\r
- @Override\r
- public void run() {\r
- action.run();\r
- if(!movedSubscriptionItems.isEmpty()) {\r
- Simantics.getSession().asyncRequest(new WriteRequest() {\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- for (Resource item : movedSubscriptionItems) {\r
- graph.deny(item, L0.PartOf);\r
- graph.claim(subscription, L0.ConsistsOf, item);\r
- }\r
- }\r
- }, new Callback<DatabaseException>() {\r
- @Override\r
- public void run(DatabaseException e) {\r
- if (e != null)\r
- ErrorLogger.defaultLogError(e);\r
+ private Runnable addSubscriptions(ReadGraph graph, Resource subscription, List<VariableReference> references,\r
+ Set<Resource> movedSubscriptionItems) throws DatabaseException {\r
+ AddVariableToChartAction action = new AddVariableToChartAction(null, subscription, references).init(graph);\r
+ return () -> {\r
+ action.run();\r
+ if(!movedSubscriptionItems.isEmpty()) {\r
+ Simantics.getSession().asyncRequest(new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ for (Resource item : movedSubscriptionItems) {\r
+ graph.deny(item, L0.PartOf);\r
+ graph.claim(subscription, L0.ConsistsOf, item);\r
}\r
- });\r
- }\r
+ }\r
+ }, e -> {\r
+ if (e != null)\r
+ ErrorLogger.defaultLogError(e);\r
+ });\r
}\r
};\r
}\r
\r
DiagramResource DIA = DiagramResource.getInstance(graph);\r
ModelingResources MOD = ModelingResources.getInstance(graph);\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
\r
String uri = graph.getPossibleRelatedValue(resource, DIA.RuntimeDiagram_HasVariable);\r
if (uri == null)\r
\r
Resource config = graph.getPossibleObject(resource2, MOD.ElementToComponent);\r
if (config == null) {\r
+ if (graph.isInstanceOf(resource2, DIA.Connection)) {\r
+ Variable v = FlagUtil.getPossibleConnectionSignal(graph, var, resource2, L0.Entity);\r
+ if (v != null)\r
+ return v;\r
+ }\r
// Apros #9646: if resource2 is the diagram\r
// itself, return the diagram composite variable\r
// since it is generally more useful than the\r
}\r
\r
if(graph.isInstanceOf(resource2, DIA.Flag)) {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
Variable signal = FlagUtil.getPossibleFlagSignal(graph, var, resource2, L0.Entity);\r
if(signal != null)\r
return signal;\r
version="0.0.0"\r
unpack="false"/>\r
\r
+ <plugin\r
+ id="com.fasterxml.jackson.core.jackson-core"\r
+ download-size="0"\r
+ install-size="0"\r
+ version="0.0.0"\r
+ unpack="false"/>\r
+\r
</feature>\r