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.5.0"
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
String name = getConfigurationComponentNameForElement(graph, element);\r
if (name == null)\r
return null;\r
- AffineTransform transform = DiagramGraphUtil.getAffineTransform(graph, element);\r
+ AffineTransform transform = DiagramGraphUtil.getDynamicAffineTransform(graph, runtimeDiagram, element);\r
Vec2d offset = DiagramGraphUtil.getOffset(graph, element);\r
boolean enabled = !DiagramGraphUtil.getProfileMonitorsHidden(graph, element);\r
boolean up = DiagramGraphUtil.getProfileMonitorsUp(graph, element);\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<projectDescription>\r
- <name>org.simantics.help.feature</name>\r
- <comment></comment>\r
- <projects>\r
- </projects>\r
- <buildSpec>\r
- <buildCommand>\r
- <name>org.eclipse.pde.FeatureBuilder</name>\r
- <arguments>\r
- </arguments>\r
- </buildCommand>\r
- </buildSpec>\r
- <natures>\r
- <nature>org.eclipse.pde.FeatureNature</nature>\r
- </natures>\r
-</projectDescription>\r
+++ /dev/null
-###############################################################################\r
-# Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
-# in 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
-# which accompanies this distribution, and is available at\r
-# http://www.eclipse.org/legal/epl-v10.html\r
-#\r
-# Contributors:\r
-# VTT Technical Research Centre of Finland - initial API and implementation\r
-###############################################################################\r
-bin.includes = feature.xml\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<!--
- Copyright (c) 2007, 2010 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
- -->\r
-<feature\r
- id="org.simantics.help"\r
- label="Simantics Help"\r
- version="1.1.1.qualifier"\r
- provider-name="VTT Technical Research Centre of Finland">\r
-\r
- <description>\r
- This feature gather together the parts of Eclipse SDK that are needed to use the Eclipse help system and cheat sheets.\r
- </description>\r
-\r
- <license url="http://www.eclipse.org/legal/epl-v10.html">\r
- Licensed under Eclipse Public License (EPL) 1.0.\r
- </license>\r
-\r
- <plugin\r
- id="org.eclipse.help"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.help.base"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.help.ui"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.apache.lucene.analysis"\r
- download-size="887"\r
- install-size="1772"\r
- version="3.5.0.v20120725-1805"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.apache.lucene.core"\r
- download-size="1513"\r
- install-size="3048"\r
- version="3.5.0.v20120725-1805"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.help.webapp"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.equinox.http.registry"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="javax.servlet"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="javax.servlet.jsp"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.equinox.jsp.jasper"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.equinox.jsp.jasper.registry"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.equinox.http.jetty"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.equinox.http.servlet"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.ui.cheatsheets"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="javax.el"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="com.sun.el"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.apache.commons.logging"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.apache.jasper.glassfish"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.jetty.continuation"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.jetty.http"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.jetty.io"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.jetty.security"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.jetty.server"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.jetty.servlet"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="org.eclipse.jetty.util"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
- <plugin\r
- id="winterwell.markdown"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
-</feature>\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
if(node instanceof ConnectionNode) {\r
return getLocalBounds(node);\r
} else if(node instanceof SingleElementNode) {\r
+ // For normal symbols\r
INode image = NodeUtil.findChildByPrefix((SingleElementNode)node, "composite_image");\r
if (image == null)\r
+ // For generic text nodes\r
image = NodeUtil.findChildByPrefix((SingleElementNode) node, "text");\r
+ if (image == null)\r
+ // For I/O table diagram flags (value of org.simantics.diagram.flag.FlagSceneGraph.VISUAL_ROOT)\r
+ image = NodeUtil.findChildByPrefix((SingleElementNode) node, "visual");\r
if (image == null)\r
image = NodeUtil.getNearestChildByClass((SingleElementNode) node, FlagNode.class);\r
if (image != null)\r
\r
import gnu.trove.map.TObjectIntMap;\r
import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.procedure.TIntProcedure;\r
import gnu.trove.procedure.TObjectProcedure;\r
\r
public class TrendNode extends G2DParentNode implements TrendLayout {\r
\r
TObjectIntMap<String> newItemMap = itemIndexMap(newSpec.items);\r
TObjectIntMap<String> currentItemMap = itemIndexMap(spec.items);\r
- TObjectIntMap<String> addedItemMap = subtract(newItemMap, currentItemMap);\r
TObjectIntMap<String> removedItemMap = subtract(currentItemMap, newItemMap);\r
Map<String, VertRuler> existingRulers = new HashMap<>();\r
if (this.spec.axisMode == YAxisMode.MultiAxis) {\r
for (int i=0; i<analogItems.size(); i++)\r
vertRulers.add( addNode(VertRuler.class) );\r
} else {\r
+ // Remove rulers of the items that were removed\r
+ // and add new rulers to have enough of them for\r
+ // each separate analog signal.\r
removedItemMap.forEachKey(new TObjectProcedure<String>() {\r
@Override\r
public boolean execute(String id) {\r
return true;\r
}\r
});\r
- addedItemMap.forEachValue(new TIntProcedure() {\r
- @Override\r
- public boolean execute(int index) {\r
- vertRulers.add( index, addNode(VertRuler.class) );\r
- return true;\r
- }\r
- });\r
+ for (int i = vertRulers.size(); i < analogItems.size(); ++i) {\r
+ VertRuler ruler = addNode(VertRuler.class);\r
+ vertRulers.add(ruler);\r
+ }\r
}\r
\r
for (int i = 0; i < analogItems.size(); i++) {\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
# VTT Technical Research Centre of Finland - initial API and implementation\r
###############################################################################\r
bin.includes = feature.xml\r
-root=root\r
+++ /dev/null
-== Known Issues ==\r
-\r
-=== Unexpected JVM crashes related to diagrams (AWT) ===\r
-Ticket [https://www.simulationsite.net/trac/simantics/ticket/626 #626]\r
-\r
-There's currently no resolution or workaround for this issue.\r
-Mostly these seem to be related to graphics card drivers and possible bugs therein.\r
- \r
-The only advice we currently have to give is to:\r
-* Update to the latest JRE/JDK\r
-* Update your graphics card drivers if possible\r
-* Try changing between D3D, OpenGL and software rendering\r
-** TODO: howto!\r