From: lempinen Date: Thu, 24 Nov 2011 12:23:07 +0000 (+0000) Subject: DnD series X-Git-Tag: simantics-1.6~96 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=91b7cf6f9360fb6eb70ecd39a219e895b680d4f7;p=simantics%2Fsysdyn.git DnD series git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23338 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 2a414727..983ac388 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/ChartAxisAndVariablesViewpoint.pgraph b/org.simantics.sysdyn.ontology/graph/ChartAxisAndVariablesViewpoint.pgraph index d07ed227..a7359115 100644 --- a/org.simantics.sysdyn.ontology/graph/ChartAxisAndVariablesViewpoint.pgraph +++ b/org.simantics.sysdyn.ontology/graph/ChartAxisAndVariablesViewpoint.pgraph @@ -22,4 +22,11 @@ CBC CBC @VP.customLabelRule JFREE.Axis VP.ResourceLabelLabelRule - @VP.customLabelRule JFREE.Series VP.ResourceLabelLabelRule \ No newline at end of file + @VP.customLabelRule JFREE.Series VP.ResourceLabelLabelRule + +CBC + @VP.dropActionContribution JFREE.Axis ACTIONS.DropAction 1.0 + @VP.dropActionContribution JFREE.Series ACTIONS.DropAction 1.0 + +ACTIONS = CAC.Actions : L0.Library +ACTIONS.DropAction : ACT.DropAction \ No newline at end of file diff --git a/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java b/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java index d6ff18c9..05192d1f 100644 --- a/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java +++ b/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java @@ -47,6 +47,8 @@ public class SysdynResource { public final Resource Built$in_Functions_zidz; public final Resource Center; public final Resource ChartAxisAndVariablesActionContext; + public final Resource ChartAxisAndVariablesActionContext_Actions; + public final Resource ChartAxisAndVariablesActionContext_Actions_DropAction; public final Resource ChartAxisAndVariablesBrowseContext; public final Resource ChartAxisAndVariablesBrowseContext_AxisChildRule; public final Resource ChartAxisAndVariablesBrowseContext_VariableChildRule; @@ -290,6 +292,8 @@ public class SysdynResource { public static final String Built$in_Functions_zidz = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/zidz"; public static final String Center = "http://www.simantics.org/Sysdyn-1.1/Center"; public static final String ChartAxisAndVariablesActionContext = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesActionContext"; + public static final String ChartAxisAndVariablesActionContext_Actions = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesActionContext/Actions"; + public static final String ChartAxisAndVariablesActionContext_Actions_DropAction = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesActionContext/Actions/DropAction"; public static final String ChartAxisAndVariablesBrowseContext = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext"; public static final String ChartAxisAndVariablesBrowseContext_AxisChildRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/AxisChildRule"; public static final String ChartAxisAndVariablesBrowseContext_VariableChildRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/VariableChildRule"; @@ -543,6 +547,8 @@ public class SysdynResource { Built$in_Functions_zidz = getResourceOrNull(graph, URIs.Built$in_Functions_zidz); Center = getResourceOrNull(graph, URIs.Center); ChartAxisAndVariablesActionContext = getResourceOrNull(graph, URIs.ChartAxisAndVariablesActionContext); + ChartAxisAndVariablesActionContext_Actions = getResourceOrNull(graph, URIs.ChartAxisAndVariablesActionContext_Actions); + ChartAxisAndVariablesActionContext_Actions_DropAction = getResourceOrNull(graph, URIs.ChartAxisAndVariablesActionContext_Actions_DropAction); ChartAxisAndVariablesBrowseContext = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext); ChartAxisAndVariablesBrowseContext_AxisChildRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_AxisChildRule); ChartAxisAndVariablesBrowseContext_VariableChildRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_VariableChildRule); diff --git a/org.simantics.sysdyn.ui/adapters.xml b/org.simantics.sysdyn.ui/adapters.xml index 3a9a9e3c..cd26fb0a 100644 --- a/org.simantics.sysdyn.ui/adapters.xml +++ b/org.simantics.sysdyn.ui/adapters.xml @@ -10,5 +10,5 @@ VTT Technical Research Centre of Finland - initial API and implementation --> - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartNode.java index 8e40c28b..598124bf 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartNode.java @@ -19,7 +19,6 @@ import org.simantics.browsing.ui.common.node.AbstractNode; import org.simantics.browsing.ui.common.node.DeleteException; import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IDropTargetNode; -import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ObjectsWithType; @@ -85,14 +84,8 @@ public class ChartNode extends AbstractNode implements IDropTargetNode Resource dataset = graph.syncRequest(new ObjectsWithType(plot, l0.ConsistsOf, jfree.Dataset)).iterator().next(); String rvi = Variables.getRVI(graph, variable); - Resource type = l0.String; - Resource literal = graph.newResource(); - graph.claim(literal, l0.InstanceOf, null, type); - graph.claimValue(literal, rvi, Bindings.STRING); - GraphUtils.create2(graph, jfree.Series, - l0.HasLabel, rvi, - jfree.HasVariableRVI, literal, + jfree.HasVariableRVI, rvi, l0.PartOf, dataset); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/DropAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/DropAction.java new file mode 100644 index 00000000..85f77a5a --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/DropAction.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.sysdyn.ui.trend.chart.graphexplorer; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.DropActionFactory; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.trend.chart.properties.ChartAxisAndVariablesTab; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Drop action for explorer in {@link ChartAxisAndVariablesTab}. This action is used for dropping + * both series and axis on top of each others. + * + * @author Teemu Lempinen + * + */ +public class DropAction implements DropActionFactory { + + @Override + public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException { + // Make sure that both target and source are resources + Resource t = AdaptionUtils.adaptToSingle(target, Resource.class); + Resource s = AdaptionUtils.adaptToSingle(source, Resource.class); + if(t != null && s != null) + return getRunnable(t, s); + return null; + } + + /** + * Get the runnable for doing the drop action + * + * @param t target resource + * @param s source resource + * @return Runnable + */ + private Runnable getRunnable(final Resource t, final Resource s) { + Runnable runnable = new Runnable() { + + @Override + public void run() { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource target = t; + Resource source = s; + + // Dropped a series over a series -> get target dataset + if(graph.isInstanceOf(target, jfree.Series) && graph.isInstanceOf(source, jfree.Series)) { + Resource dataset = graph.getPossibleObject(target, l0.PartOf); + if(dataset != null) + target = dataset; + } + + // Dropped a series over an axis -> get target dataset + if(graph.isInstanceOf(target, jfree.Axis) && graph.isInstanceOf(source, jfree.Series)) { + Resource dataset = graph.syncRequest(new PossibleObjectWithType(target, jfree.MapToRangeAxis_Inverse, jfree.Dataset)); + if(dataset != null) + target = dataset; + } + + // Move series to a dataset + if(graph.isInstanceOf(target, jfree.Dataset) && graph.isInstanceOf(source, jfree.Series)) { + graph.deny(source, l0.PartOf); + graph.claim(target, l0.ConsistsOf, source); + } + + // TODO: Change the order of axis and series. Implement when they are in ordered sets + } + }); + } + }; + return runnable; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AxisAndVariablesExplorerComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AxisAndVariablesExplorerComposite.java new file mode 100644 index 00000000..f15c9f06 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AxisAndVariablesExplorerComposite.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.sysdyn.ui.trend.chart.properties; + +import java.util.ArrayList; +import java.util.Map; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.common.ErrorLogger; +import org.simantics.browsing.ui.model.InvalidContribution; +import org.simantics.browsing.ui.model.dnd.DndBrowseContext; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.Read; +import org.simantics.structural.ui.modelBrowser.ModelBrowser2; +import org.simantics.ui.SimanticsUI; + +/** + * ExplorerComposite allowing ontology-based DnD definitions. DnD Copied from {@link ModelBrowser2} + * + * @author Teemu Lempinen + * + */ +public class AxisAndVariablesExplorerComposite extends GraphExplorerComposite { + + volatile DndBrowseContext dndBrowseContext; + + public AxisAndVariablesExplorerComposite(Map args, IWorkbenchSite site, Composite parent, + WidgetSupport support, int style) { + super(args, site, parent, support, style); + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + ArrayList browseContexts = new ArrayList(); + for (String uri : getBrowseContexts()) { + Resource browseContext = graph.getPossibleResource(uri); + if (browseContext != null) + browseContexts.add(browseContext); + } + try { + dndBrowseContext = DndBrowseContext.create(graph, browseContexts); + } catch (InvalidContribution e) { + ErrorLogger.defaultLogError(e); + } + } + }); + } + + @Override + protected void handleDrop(final Object data, final NodeContext target) { + if (target == null) + return; + + SimanticsUI.getSession().asyncRequest(new Read() { + @Override + public Runnable perform(ReadGraph graph) throws DatabaseException { + if (dndBrowseContext == null) + return null; + return dndBrowseContext.getAction(graph, target, data); + } + }, new Procedure() { + @Override + public void execute(Runnable result) { + if (result != null) + result.run(); + } + + @Override + public void exception(Throwable t) { + ErrorLogger.defaultLogError(t); + } + }); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartAxisAndVariablesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartAxisAndVariablesTab.java index dec67114..1e818b6a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartAxisAndVariablesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartAxisAndVariablesTab.java @@ -74,7 +74,7 @@ public class ChartAxisAndVariablesTab extends LabelPropertyTabContributor { GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); // (Ontology-based) GraphExplorer displaying range axis and variables mapped to those axis - explorer = new GraphExplorerComposite(ArrayMap.keys( + explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys( "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); explorer.setBrowseContexts(SysdynResource.URIs.ChartAxisAndVariablesBrowseContext); explorer.setInputSource(new SingleSelectionInputSource(