X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FChartDropActionFactory.java;fp=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FChartDropActionFactory.java;h=7d08d943035d773060678e17d34ce859f107ebf8;hp=6a3de89a90700a47ea86a298c911ddac66588396;hb=c97b685ff67f795fd8cd7b166ee740d234a577f4;hpb=de86e08dadfd2733d23b3fe2817b27ae835d9f3b diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartDropActionFactory.java b/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartDropActionFactory.java index 6a3de89a9..7d08d9430 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartDropActionFactory.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartDropActionFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2014 Association for Decentralized Information Management in + * Copyright (c) 2007, 2017 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 @@ -8,6 +8,7 @@ * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - #7313 *******************************************************************************/ package org.simantics.charts.ui; @@ -16,13 +17,15 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.ISelection; import org.simantics.Simantics; -import org.simantics.charts.internal.JsonUtils; +import org.simantics.charts.Activator; +import org.simantics.charts.internal.VariableUtils; import org.simantics.charts.ontology.ChartResource; import org.simantics.charts.query.AddChartItem; import org.simantics.charts.query.ChartItemDescriptor; @@ -57,7 +60,7 @@ public class ChartDropActionFactory implements DropActionFactory { @Override public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException { - //System.out.println("DROP: " + source + " -> " + target); + //System.out.println("CHART DROP: " + source + " -> " + target); final Resource chart = ISelectionUtils.getSinglePossibleKey(target, SelectionHints.KEY_MAIN, Resource.class); if (chart == null) return null; @@ -66,7 +69,7 @@ public class ChartDropActionFactory implements DropActionFactory { if(source instanceof RVI) { List refs = Collections.singletonList(new VariableReference((RVI)source, - SubscriptionDropActionFactory.getDatatype(g, targetModel, (RVI) source), null)); + VariableUtils.getDatatype(g, targetModel, (RVI) source), null)); return new AddVariableToChartAction(chart, null, refs).init(g); } @@ -132,19 +135,23 @@ public class ChartDropActionFactory implements DropActionFactory { } if (source instanceof String) { - // JSON ? - Optional v = JsonUtils.tryParseJsonPropertyVariable(g, (String) source); - if (v.isPresent()) { - List references = toReferences(g, targetModel, Collections.singletonList(v.get())); - if (!references.isEmpty()) - return new AddVariableToChartAction(chart, null, references).init(g); - } + return handleStringDrop(g, chart, targetModel, (String) source); } return null; } - private static List toReferences(ReadGraph graph, Resource contextIndexRoot, List variables) throws DatabaseException { + private Runnable handleStringDrop(ReadGraph graph, Resource chart, Resource targetModel, String source) { + try { + List refs = VariableUtils.getVariableReferencesFromString(graph, targetModel, source); + return new AddVariableToChartAction(chart, null, refs).init(graph); + } catch (DatabaseException e) { + Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, getClass().getSimpleName() + ": Unrecognized String input: " + source)); + return null; + } + } + + private static List toReferences(ReadGraph graph, Resource contextIndexRoot, List variables) throws DatabaseException { if (variables.isEmpty()) return Collections.emptyList(); return filterReferences( graph.syncRequest(VariableReferences.variablesToReferences(contextIndexRoot, variables)) );