From 522b8362e7db64811fb614126f69c1024571e1f0 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 24 Nov 2011 09:17:24 +0000 Subject: [PATCH] RVIModifier with proposal support. XYDataset support for parameter domain axis git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23337 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/trend/chart/XYDataset.java | 22 +++++- .../properties/GeneralChartPropertiesTab.java | 4 +- .../trend/chart/properties/RVIModifier.java | 72 ++++++++++++++++++- .../properties/SeriesPropertyComposite.java | 58 ++------------- .../properties/VariableProposalProvider.java | 15 +++- 5 files changed, 110 insertions(+), 61 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java index 45efcd2c..9d70bea0 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java @@ -112,10 +112,28 @@ public class XYDataset implements IDataset { double[] va = v.getPossiblePropertyValue(graph, SysdynVariableProperties.VALUES , Bindings.DOUBLE_ARRAY); // Get domain axis values (time OR other variable) double[] ta; - if(domainValues != null) + if(domainValues != null) { ta = domainValues; - else + + // If domainAxis is other than time, parameter values size is different. + if(domainValues.length > va.length) { + double value = va[0]; + va = new double[domainValues.length]; + for(int i = 0; i < domainValues.length; i++) + va[i] = value; + } + + // If domainAxis is a parameter, the domainValues array is too short + if(domainValues.length < va.length && domainValues.length == 2 && domainValues[0] == domainValues[1]) { + double value = domainValues[0]; + ta = new double[va.length]; + for(int i = 0; i < va.length; i++) + ta[i] = value; + } + + } else { ta = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIMES , Bindings.DOUBLE_ARRAY); + } if(ta!=null && va!=null && (va.length == ta.length)) // Add series if everything OK diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/GeneralChartPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/GeneralChartPropertiesTab.java index a354c134..095e0b85 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/GeneralChartPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/GeneralChartPropertiesTab.java @@ -151,8 +151,8 @@ public class GeneralChartPropertiesTab extends LabelPropertyTabContributor imple label.setText("Variable:"); xvariable = new TrackedText(xgroup, domainAxisSupport, SWT.BORDER); - xvariable.setTextFactory(new StringPropertyFactory(JFreeChartResource.URIs.HasVariableRVI, "")); - xvariable.addModifyListener(new StringPropertyModifier(context, JFreeChartResource.URIs.HasVariableRVI)); + xvariable.setTextFactory(new RVIFactory()); + xvariable.addModifyListener(new RVIModifier(xvariable.getWidget(), domainAxisSupport)); xvariable.setColorProvider(new JFreeChartPropertyColorProvider(xvariable.getResourceManager())); GridDataFactory.fillDefaults().grab(true, false).applyTo(xvariable.getWidget()); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java index e8f28709..7061001a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java @@ -11,7 +11,18 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart.properties; +import org.eclipse.jface.bindings.keys.KeyStroke; +import org.eclipse.jface.bindings.keys.ParseException; +import org.eclipse.jface.fieldassist.ContentProposalAdapter; +import org.eclipse.jface.fieldassist.IContentProposal; +import org.eclipse.jface.fieldassist.IContentProposalListener; +import org.eclipse.jface.fieldassist.IContentProposalListener2; +import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; +import org.eclipse.jface.fieldassist.TextContentAdapter; +import org.eclipse.swt.widgets.Control; import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -19,13 +30,72 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.sysdyn.JFreeChartResource; /** - * Class for modifying variable name to rvi and saving it to database + * Class for modifying variable name to rvi and saving it to database. + * + * Modifier also adds content proposal support to the control it is added to. * @author Teemu Lempinen * */ public class RVIModifier extends TextModifyListenerImpl { private boolean active; + private Control control; + + private char[] alphaNumericCharacters = { + 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','å','ä','ö', + 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Å','Ä','Ö', + '1','2','3','4','5','6','7','8','9','0','.'}; + + /** + * Create a new RVIModifier and attach a content proposal support to control + * @param control + * @param support + */ + public RVIModifier(Control control, WidgetSupport support) { + this.control = control; + this.active = true; + + KeyStroke keyStroke = null; + try { + keyStroke = KeyStroke.getInstance("Ctrl+Space"); + } catch (ParseException e1) { + e1.printStackTrace(); + } + + SimpleContentProposalProvider scpp = new VariableProposalProvider(control, support); + scpp.setFiltering(true); + + ContentProposalAdapter adapter = new ContentProposalAdapter( + control, new TextContentAdapter(), scpp, keyStroke, alphaNumericCharacters); + adapter.setAutoActivationDelay(0); + adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); + adapter.addContentProposalListener(new IContentProposalListener2() { + + @Override + public void proposalPopupOpened(ContentProposalAdapter adapter) { + if(RVIModifier.this != null) + RVIModifier.this.deactivate(); + } + + @Override + public void proposalPopupClosed(ContentProposalAdapter adapter) { + if(RVIModifier.this != null) + RVIModifier.this.activate(); + } + }); + + adapter.addContentProposalListener(new IContentProposalListener() { + + @Override + public void proposalAccepted(IContentProposal proposal) { + if(RVIModifier.this.control != null && !RVIModifier.this.control.isDisposed()) + RVIModifier.this.modifyText(new TrackedModifyEvent(RVIModifier.this.control, proposal.getContent())); + } + }); + + + } + @Override public void applyText(WriteGraph graph, Resource issue, String text) throws DatabaseException { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/SeriesPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/SeriesPropertyComposite.java index 212e563f..1276908c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/SeriesPropertyComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/SeriesPropertyComposite.java @@ -11,14 +11,6 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart.properties; -import org.eclipse.jface.bindings.keys.KeyStroke; -import org.eclipse.jface.bindings.keys.ParseException; -import org.eclipse.jface.fieldassist.ContentProposalAdapter; -import org.eclipse.jface.fieldassist.IContentProposal; -import org.eclipse.jface.fieldassist.IContentProposalListener; -import org.eclipse.jface.fieldassist.IContentProposalListener2; -import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; -import org.eclipse.jface.fieldassist.TextContentAdapter; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; @@ -54,7 +46,6 @@ public class SeriesPropertyComposite extends Composite { private TrackedText variable, label; private TrackedSpinner width; - private RVIModifier variableRVIModifier; public SeriesPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { super(parent, style); @@ -66,53 +57,12 @@ public class SeriesPropertyComposite extends Composite { label.setText("Variable:"); GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - this.variable = new TrackedText(this, support, SWT.BORDER); - this.variable.setTextFactory(new RVIFactory()); - variableRVIModifier = new RVIModifier(); - this.variable.addModifyListener(variableRVIModifier); - this.variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager())); + variable = new TrackedText(this, support, SWT.BORDER); + variable.setTextFactory(new RVIFactory()); + variable.addModifyListener(new RVIModifier(variable.getWidget(), support)); + variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager())); GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget()); - // KeyStroke for content assistant - KeyStroke keyStroke = null; - try { - keyStroke = KeyStroke.getInstance("Ctrl+Space"); - } catch (ParseException e1) { - e1.printStackTrace(); - } - - - SimpleContentProposalProvider scpp = new VariableProposalProvider(this.variable.getWidget(), support); - scpp.setFiltering(true); - - ContentProposalAdapter adapter = new ContentProposalAdapter( - this.variable.getWidget(), new TextContentAdapter(), scpp, keyStroke, null); - adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); - - adapter.addContentProposalListener(new IContentProposalListener2() { - - @Override - public void proposalPopupOpened(ContentProposalAdapter adapter) { - if(variableRVIModifier != null) - variableRVIModifier.deactivate(); - } - - @Override - public void proposalPopupClosed(ContentProposalAdapter adapter) { - if(variableRVIModifier != null) - variableRVIModifier.activate(); - } - }); - - adapter.addContentProposalListener(new IContentProposalListener() { - - @Override - public void proposalAccepted(IContentProposal proposal) { - if(variable != null && !variable.getWidget().isDisposed()) - variableRVIModifier.modifyText(new TrackedModifyEvent(variable.getWidget(), proposal.getContent())); - } - }); - // Label to be displayed in chart for this series (usually same as the variable label = new Label(this, SWT.NONE); label.setText("Label:"); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java index cd453d84..45c88218 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java @@ -13,6 +13,8 @@ package org.simantics.sysdyn.ui.trend.chart.properties; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.List; import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; import org.eclipse.swt.widgets.Control; @@ -23,15 +25,16 @@ import org.simantics.db.Resource; import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.request.Read; import org.simantics.db.management.ISessionContext; import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.strings.AlphanumComparator; /** * Provides all variables a model contains @@ -72,6 +75,8 @@ public class VariableProposalProvider extends SimpleContentProposalProvider impl Layer0 l0 = Layer0.getInstance(graph); SimulationResource simu = SimulationResource.getInstance(graph); SysdynResource sr = SysdynResource.getInstance(graph); + + // Find the model of this resource Resource model = resource; while(!graph.isInstanceOf(model, sr.SysdynModel) && model != null) model = graph.getPossibleObject(model, l0.PartOf); @@ -79,9 +84,15 @@ public class VariableProposalProvider extends SimpleContentProposalProvider impl if(model == null) return new String[0]; + // Find the models configuration Resource conf = graph.getSingleObject(model, simu.HasConfiguration); - Collection items = new ArrayList(); + List items = new ArrayList(); + + // Recursively read all configurations and add items ReadConfiguration(graph, conf, "", items); + + // Finally sort the results + Collections.sort(items, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR); return items.toArray(new String[items.size()]); } -- 2.47.1