package org.simantics.jfreechart.chart.properties;\r
\r
+import java.util.Collection;\r
+\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.request.Read;\r
-import org.simantics.utils.datastructures.Pair;\r
\r
-public class AllVariablesOfModel implements Read<Pair<String[],String[]>> {\r
+public class AllVariablesOfModel implements Read<Collection<ChartVariable>> {\r
\r
public Resource res;\r
\r
}\r
\r
@Override\r
- public Pair<String[],String[]> perform(ReadGraph graph) throws DatabaseException {\r
+ public Collection<ChartVariable> perform(ReadGraph graph) throws DatabaseException {\r
IAllVariablesOfModel query = graph.adapt(res, IAllVariablesOfModel.class);\r
- String ids[] = graph.syncRequest(query.getVariablesIdsQuery());\r
- String labels[] = new String[ids.length];\r
- for (int i = 0; i < ids.length; i++) {\r
- labels[i] = query.getVariablesLabel(graph, ids[i]);\r
- }\r
- return new Pair<String[], String[]>(ids, labels);\r
+ return graph.syncRequest(query.getVariablesQuery());\r
+ \r
}\r
\r
}\r
--- /dev/null
+package org.simantics.jfreechart.chart.properties;\r
+\r
+public class ChartVariable {\r
+ \r
+ private String rvi;\r
+ private String label;\r
+ \r
+ public ChartVariable(String rvi) {\r
+ this.rvi = rvi;\r
+ }\r
+ \r
+ public ChartVariable(String rvi, String label) {\r
+ this.rvi = rvi;\r
+ this.label = label;\r
+ }\r
+ \r
+ public String getRvi() {\r
+ return rvi;\r
+ }\r
+ \r
+ public String getLabel() {\r
+ return label;\r
+ }\r
+ \r
+ @Override\r
+ public String toString() {\r
+ if (label != null)\r
+ return label;\r
+ return rvi;\r
+ }\r
+\r
+}\r
package org.simantics.jfreechart.chart.properties;\r
\r
+import java.util.Collection;\r
+\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.request.Read;\r
public interface IAllVariablesOfModel {\r
\r
\r
- public Read<String[]> getVariablesIdsQuery();\r
+ public Read<Collection<ChartVariable>> getVariablesQuery();\r
\r
- public String getVariablesLabel(ReadGraph graph, String variableId) throws DatabaseException;\r
+ public String getVariablesLabel(ReadGraph graph, String rvi) throws DatabaseException;\r
+\r
\r
}\r
package org.simantics.jfreechart.chart.properties;\r
\r
import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Iterator;\r
\r
import org.eclipse.jface.fieldassist.ContentProposal;\r
import org.eclipse.jface.fieldassist.IContentProposal;\r
/*\r
* The proposals provided.\r
*/\r
- private Pair<String[],String[]> proposals;\r
+ private Collection<ChartVariable> proposals;\r
\r
/*\r
* The proposals mapped to IContentProposal. Cached for speed in the case\r
* the array of Strings to be returned whenever proposals are\r
* requested.\r
*/\r
- public IdLabelProposalProvider(Pair<String[],String[]> proposals) {\r
+ public IdLabelProposalProvider(Collection<ChartVariable> proposals) {\r
super();\r
this.proposals = proposals;\r
}\r
* @return the array of Objects that represent valid proposals for the field\r
* given its current content.\r
*/\r
+ @SuppressWarnings("unchecked")\r
public IContentProposal[] getProposals(String contents, int position) {\r
if (filterProposals) {\r
ArrayList list = new ArrayList();\r
- for (int i = 0; i < proposals.first.length; i++) {\r
- if (proposals.first[i].length() >= contents.length() && proposals.first[i].substring(0, contents.length()).equalsIgnoreCase(contents)) {\r
- if (proposals.second != null)\r
- list.add(new ContentProposal(proposals.first[i],proposals.second[i], null));\r
+ for (ChartVariable proposal : proposals) {\r
+ if (proposal.getRvi().length() >= contents.length() && proposal.getRvi().substring(0, contents.length()).equalsIgnoreCase(contents)) {\r
+ if (proposal.getLabel() != null)\r
+ list.add(new ContentProposal(proposal.getRvi(),proposal.getLabel(), null));\r
else\r
- list.add(new ContentProposal(proposals.first[i]));\r
- }\r
- }\r
- if (proposals.second != null) {\r
- for (int i = 0; i < proposals.second.length; i++) {\r
- if (proposals.second[i].length() >= contents.length() && proposals.second[i].substring(0, contents.length()).equalsIgnoreCase(contents)) {\r
- list.add(new ContentProposal(proposals.first[i],proposals.second[i], null));\r
- }\r
+ list.add(new ContentProposal(proposal.getRvi()));\r
+ } else if (proposal.getLabel() != null && proposal.getLabel().length() >= contents.length() && proposal.getLabel().substring(0, contents.length()).equalsIgnoreCase(contents)) {\r
+ list.add(new ContentProposal(proposal.getRvi(),proposal.getLabel(), null));\r
}\r
}\r
+ \r
return (IContentProposal[]) list.toArray(new IContentProposal[list\r
.size()]);\r
}\r
if (contentProposals == null) {\r
- contentProposals = new IContentProposal[proposals.first.length];\r
- for (int i = 0; i < proposals.first.length; i++) {\r
- if (proposals.second != null)\r
- contentProposals[i] = new ContentProposal(proposals.first[i],proposals.second[i],null);\r
+ contentProposals = new IContentProposal[proposals.size()];\r
+ Iterator<ChartVariable> iter = proposals.iterator();\r
+ for (int i = 0; i < proposals.size(); i++) {\r
+ ChartVariable proposal = iter.next();\r
+ if (proposal.getLabel() != null)\r
+ contentProposals[i] = new ContentProposal(proposal.getRvi(),proposal.getLabel(),null);\r
else\r
- contentProposals[i] = new ContentProposal(proposals.first[i]);\r
+ contentProposals[i] = new ContentProposal(proposal.getRvi());\r
}\r
}\r
return contentProposals;\r
* @param items\r
* the array of Strings to be used as proposals.\r
*/\r
- public void setProposals(Pair<String[],String[]> items) {\r
+ public void setProposals(Collection<ChartVariable> items) {\r
this.proposals = items;\r
contentProposals = null;\r
}\r
package org.simantics.jfreechart.chart.properties;\r
\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
import org.eclipse.jface.dialogs.IInputValidator;\r
import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
*/\r
public class VariableExistsValidator implements IInputValidator, Widget {\r
\r
- private String[] names;\r
+ private Collection<ChartVariable> variables;\r
private TrackedText text;\r
private boolean allowEmpty;\r
private boolean useLabels = false;\r
*/\r
public VariableExistsValidator(WidgetSupport support, TrackedText text, boolean allowEmpty) {\r
support.register(this);\r
+ this.variables = new ArrayList<ChartVariable>();\r
this.text = text;\r
this.allowEmpty = allowEmpty;\r
}\r
*/\r
@Override\r
public String isValid(String newText) {\r
+ System.out.println(this + " validate " + newText);\r
if(newText == null || newText.isEmpty()) {\r
if(allowEmpty)\r
return null;\r
return "Empty name not allowed";\r
}\r
\r
- synchronized (names) {\r
- for(String s : names) {\r
- if(newText.equals(s))\r
+ synchronized (variables) {\r
+ for(ChartVariable variable : variables) {\r
+ if(newText.equals(variable.getLabel()))\r
+ return null;\r
+ if(newText.equals(variable.getRvi()))\r
return null;\r
}\r
}\r
final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class);\r
\r
if(resource == null) {\r
- names = new String[0];\r
+ variables = new ArrayList<ChartVariable>();\r
return;\r
}\r
\r
// Find all variables and set them as the reference for isValid(String)\r
SimanticsUI.getSession().asyncRequest(\r
new AllVariablesOfModel(model)\r
- , new Listener<Pair<String[],String[]>>() {\r
+ , new Listener<Collection<ChartVariable>>() {\r
\r
@Override\r
- public void execute(Pair<String[],String[]> result) {\r
- if (!useLabels)\r
- names = result.first;\r
- else\r
- names = result.second;\r
+ public void execute(Collection<ChartVariable> variables) {\r
+ VariableExistsValidator.this.variables = variables;\r
}\r
\r
@Override\r
@Override\r
public void proposalAccepted(IContentProposal proposal) {\r
if(VariableModifier.this.control != null && !VariableModifier.this.control.isDisposed())\r
- VariableModifier.this.modifyText(new TrackedModifyEvent(VariableModifier.this.control, proposal.getContent()));\r
+ VariableModifier.this.modifyText(new TrackedModifyEvent(VariableModifier.this.control, proposal.getLabel()));\r
}\r
});\r
\r
*******************************************************************************/\r
package org.simantics.jfreechart.chart.properties;\r
\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;\r
import org.eclipse.swt.widgets.Control;\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
* @param resource A resource that is part of a model\r
*/\r
public VariableProposalProvider(final Control control, WidgetSupport support) {\r
- super(new Pair<String[], String[]>(new String[0], null));// super(String [] {});\r
+ super(new ArrayList<ChartVariable>());// super(String [] {});\r
support.register(this);\r
this.control = control;\r
}\r
\r
SimanticsUI.getSession().asyncRequest(\r
new AllVariablesOfModel(resource)\r
- , new Listener<Pair<String[],String[]>>() {\r
+ , new Listener<Collection<ChartVariable>>() {\r
\r
@Override\r
- public void execute(Pair<String[],String[]> result) {\r
+ public void execute(Collection<ChartVariable> result) {\r
setProposals(result);\r
}\r
\r
*******************************************************************************/\r
package org.simantics.jfreechart.chart.properties.bar;\r
\r
+import java.util.Collection;\r
+\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.eclipse.swt.SWT;\r
import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
import org.simantics.db.management.ISessionContext;\r
+import org.simantics.jfreechart.chart.properties.ChartVariable;\r
import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;\r
import org.simantics.jfreechart.chart.properties.RVIFactory;\r
\r
private TrackedText variable, label, time;\r
\r
- public BarSeriesPropertyComposite2(Composite parent, final ISessionContext context, WidgetSupport support, Pair<String[],String[]> variables, int style) {\r
+ public BarSeriesPropertyComposite2(Composite parent, final ISessionContext context, WidgetSupport support, Collection<ChartVariable> variables, int style) {\r
super(parent, style);\r
\r
GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);\r
GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
\r
variable = new TrackedText(this, support, SWT.BORDER);\r
- if (variables.second == null) {\r
- variable.setTextFactory(new RVIFactory());\r
- variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
- variable.setInputValidator(new VariableExistsValidator(support, variable));\r
- } else {\r
- // FIXME: using bijectionmap and trackedText looses the variables that have the same label.\r
- BijectionMap<String , String> map = new BijectionMap<String, String>();\r
- for (int i = 0; i < variables.first.length; i++) {\r
- map.map(variables.first[i], variables.second[i]);\r
- }\r
- variable.setTextFactory(new VariableFactory(map));\r
- variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
- variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
- }\r
+ \r
+ // FIXME: using bijectionmap and trackedText looses the variables that have the same label.\r
+ BijectionMap<String , String> map = new BijectionMap<String, String>();\r
+ for (ChartVariable variable : variables) {\r
+ map.map(variable.getRvi(), variable.toString());\r
+ }\r
+ variable.setTextFactory(new VariableFactory(map));\r
+ variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
+ variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
+ \r
variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
\r
*******************************************************************************/\r
package org.simantics.jfreechart.chart.properties.bar;\r
\r
+import java.util.Collection;\r
+\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.eclipse.jface.viewers.ISelectionProvider;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.jfreechart.chart.ChartUtils;\r
import org.simantics.jfreechart.chart.properties.AllVariablesOfModel;\r
+import org.simantics.jfreechart.chart.properties.ChartVariable;\r
import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;\r
import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite;\r
import org.simantics.layer0.Layer0;\r
}\r
\r
try {\r
- Pair<String[],String[]> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
+ Collection<ChartVariable> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
\r
spc = new BarSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, SWT.NONE);\r
\r
*******************************************************************************/\r
package org.simantics.jfreechart.chart.properties.pie;\r
\r
+import java.util.Collection;\r
+\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.eclipse.swt.SWT;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.jfreechart.chart.properties.BooleanPropertyFactory;\r
import org.simantics.jfreechart.chart.properties.BooleanSelectionListener;\r
+import org.simantics.jfreechart.chart.properties.ChartVariable;\r
import org.simantics.jfreechart.chart.properties.ColorPicker;\r
import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;\r
\r
private TrackedText variable, label, time;\r
\r
- public PieSeriesPropertyComposite2(Composite parent, ISessionContext context, WidgetSupport support, Pair<String[],String[]> variables,int style) {\r
+ public PieSeriesPropertyComposite2(Composite parent, ISessionContext context, WidgetSupport support, Collection<ChartVariable> variables,int style) {\r
super(parent, style);\r
\r
GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);\r
GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
\r
variable = new TrackedText(this, support, SWT.BORDER);\r
- if (variables.second == null) {\r
- variable.setTextFactory(new RVIFactory());\r
- variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
- variable.setInputValidator(new VariableExistsValidator(support, variable));\r
- } else {\r
- // FIXME: using bijectionmap and trackedText looses the variables that have the same label.\r
- BijectionMap<String , String> map = new BijectionMap<String, String>();\r
- for (int i = 0; i < variables.first.length; i++) {\r
- map.map(variables.first[i], variables.second[i]);\r
- }\r
- variable.setTextFactory(new VariableFactory(map));\r
- variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
- variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
- }\r
+ BijectionMap<String , String> map = new BijectionMap<String, String>();\r
+ for (ChartVariable variable : variables) {\r
+ map.map(variable.getRvi(), variable.toString());\r
+ }\r
+ variable.setTextFactory(new VariableFactory(map));\r
+ variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
+ variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
+ \r
variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
\r
*******************************************************************************/\r
package org.simantics.jfreechart.chart.properties.pie;\r
\r
+import java.util.Collection;\r
+\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
import org.eclipse.jface.viewers.ISelectionProvider;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.jfreechart.chart.ChartUtils;\r
import org.simantics.jfreechart.chart.properties.AllVariablesOfModel;\r
+import org.simantics.jfreechart.chart.properties.ChartVariable;\r
import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;\r
import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite;\r
import org.simantics.layer0.Layer0;\r
}\r
\r
try {\r
- Pair<String[],String[]> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
+ Collection<ChartVariable> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
PieSeriesPropertyComposite2 spc = new PieSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, SWT.NONE);\r
propertyContainer.setContent(spc);\r
Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.request.Read;\r
+import org.simantics.jfreechart.chart.properties.ChartVariable;\r
import org.simantics.jfreechart.chart.properties.IAllVariablesOfModel;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.simulation.ontology.SimulationResource;\r
}\r
\r
@Override\r
- public Read<String[]> getVariablesIdsQuery() {\r
+ public Read<Collection<ChartVariable>> getVariablesQuery() {\r
return new VariableQuery();\r
} \r
\r
- @Override\r
+ \r
public String getVariablesLabel(ReadGraph graph, String variableId)\r
throws DatabaseException {\r
return variableId.substring(1).replace('/', '.');\r
}\r
\r
- private class VariableQuery implements Read<String[]> {\r
+ private class VariableQuery implements Read<Collection<ChartVariable>> {\r
@Override\r
- public String[] perform(ReadGraph graph) throws DatabaseException {\r
+ public Collection<ChartVariable> perform(ReadGraph graph) throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(graph);\r
SimulationResource simu = SimulationResource.getInstance(graph);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
\r
+ List<ChartVariable> result = new ArrayList<ChartVariable>();\r
// Find the model of this resource\r
Resource model = AllVariablesOfModel.this.model;\r
while(model != null && !graph.isInstanceOf(model, sr.SysdynModel))\r
model = graph.getPossibleObject(model, l0.PartOf);\r
\r
if(model == null)\r
- return new String[0];\r
+ return result;;\r
\r
// Find the models configuration\r
Resource conf = graph.getSingleObject(model, simu.HasConfiguration);\r
- List<String> items = new ArrayList<String>();\r
+ \r
\r
// Recursively read all configurations and add items\r
- ReadConfiguration(graph, conf, "", items);\r
+ ReadConfiguration(graph, conf, "", result);\r
\r
// Add time to the variable list\r
- items.add("time");\r
+ result.add(new ChartVariable("time"));\r
\r
// Finally sort the results\r
- Collections.sort(items, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
- return items.toArray(new String[items.size()]);\r
+ Collections.sort(result, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+ return result;\r
}\r
}\r
\r
* @param items Found variables\r
* @throws DatabaseException\r
*/\r
- private void ReadConfiguration(ReadGraph graph, Resource configuration, String path, Collection<String> items) throws DatabaseException {\r
+ private void ReadConfiguration(ReadGraph graph, Resource configuration, String path, Collection<ChartVariable> items) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
String name;\r
for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.IndependentVariable))) {\r
name = path + NameUtils.getSafeName(graph, resource);\r
- items.add(name);\r
+ items.add(new ChartVariable(name, name));\r
}\r
\r
for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Input))) {\r
name = path + NameUtils.getSafeName(graph, resource);\r
- items.add(name);\r
+ items.add(new ChartVariable(name, name));\r
}\r
\r
for(Resource module : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) {\r