import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
\r
public class AllVariablesOfModel implements Read<Collection<ChartVariable>> {\r
\r
- public Resource res;\r
+ public Resource model;\r
\r
+ /**\r
+ * Queries all variables of a model \r
+ * @param res the model.\r
+ */\r
public AllVariablesOfModel(Resource res) {\r
- this.res = res;\r
+ this.model = res;\r
+ }\r
+ \r
+ public Resource getModel() {\r
+ return model;\r
}\r
\r
@Override\r
public Collection<ChartVariable> perform(ReadGraph graph) throws DatabaseException {\r
- if(!graph.hasStatement(res))\r
+ if(!graph.hasStatement(model))\r
return Collections.emptyList();\r
- IAllVariablesOfModel query = graph.adapt(res, IAllVariablesOfModel.class);\r
+ IAllVariablesOfModel query = graph.adapt(model, IAllVariablesOfModel.class);\r
return graph.syncRequest(query.getVariablesQuery());\r
}\r
+ \r
+ public static AllVariablesOfModel withRandomResource(ISessionContext context, final Resource resource) throws DatabaseException {\r
+ Resource model = context.getSession().syncRequest(new Read<Resource>() {\r
+\r
+ @Override\r
+ public Resource perform(ReadGraph graph) throws DatabaseException {\r
+ Resource r = resource;\r
+ while((r = graph.getPossibleObject(r, Layer0.getInstance(graph).PartOf)) != null) {\r
+ if(graph.isInstanceOf(r, SimulationResource.getInstance(graph).Model))\r
+ return r;\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ });\r
+ if (model == null)\r
+ return null;\r
+ return new AllVariablesOfModel(model);\r
+ }\r
\r
}\r
\r
import org.eclipse.core.runtime.Assert;\r
import org.eclipse.core.runtime.ListenerList;\r
-import org.eclipse.jface.dialogs.IInputValidator;\r
import org.eclipse.jface.resource.JFaceResources;\r
import org.eclipse.jface.resource.LocalResourceManager;\r
import org.eclipse.jface.resource.ResourceManager;\r
import org.eclipse.swt.widgets.Text;\r
import org.simantics.browsing.ui.swt.widgets.DefaultColorProvider;\r
import org.simantics.browsing.ui.swt.widgets.impl.ITrackedColorProvider;\r
-\r
import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory;\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
state |= EDITING | MOUSE_DOWN_FIRST_TIME;\r
}\r
\r
- private void applyEdit() {\r
+ @SuppressWarnings("unchecked")\r
+ private void applyEdit() {\r
try {\r
if (isTextValid() != null) {\r
text.setText(textBeforeEdit);\r
setSelected(text.getText());\r
//System.out.println("apply");\r
if (modifyListeners != null) {\r
- StringChooserModifyEvent event = new StringChooserModifyEvent(text, selected, text.getText());\r
+ StringChooserModifyEvent<T> event = new StringChooserModifyEvent<T>(text, selected, text.getText());\r
for (Object o : modifyListeners.getListeners()) {\r
- ((StringChooserModifyListener) o).modifySelection(event);\r
+ ((StringChooserModifyListener<T>) o).modifySelection(event);\r
}\r
}\r
}\r
return text;\r
}\r
\r
- public synchronized void addModifyListener(StringChooserModifyListener listener) {\r
+ public synchronized void addModifyListener(StringChooserModifyListener<T> listener) {\r
if (modifyListeners == null) {\r
modifyListeners = new ListenerList(ListenerList.IDENTITY);\r
}\r
modifyListeners.add(listener);\r
}\r
\r
- public synchronized void removeModifyListener(StringChooserModifyListener listener) {\r
+ public synchronized void removeModifyListener(StringChooserModifyListener<T> listener) {\r
if (modifyListeners == null)\r
return;\r
modifyListeners.remove(listener);\r
}\r
}\r
}\r
+ \r
+ public void dispose() {\r
+ allowedLabels.clear();\r
+ allowedLabels = null;\r
+ objectFactory = null;\r
+ objectToLabel.clear();\r
+ objectToLabel = null;\r
+ \r
+ }\r
+ \r
+ \r
}\r
import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.db.procedure.Listener;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.ui.AdaptionUtils;\r
\r
return;\r
}\r
\r
- Resource model = null;\r
+ \r
try {\r
/* Find the model resource. It can be found with PartOf \r
relations from series resource in a chart */\r
- model = context.getSession().syncRequest(new Read<Resource>() {\r
-\r
- @Override\r
- public Resource perform(ReadGraph graph) throws DatabaseException {\r
- Resource r = resource;\r
- while((r = graph.getPossibleObject(r, Layer0.getInstance(graph).PartOf)) != null) {\r
- if(graph.isInstanceOf(r, SimulationResource.getInstance(graph).Model))\r
- return r;\r
- }\r
- return null;\r
- }\r
- \r
- });\r
+ AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource);\r
\r
- if(model != null) {\r
+ if(query != null) {\r
// Find all variables and set them as the reference for isValid(String)\r
- SimanticsUI.getSession().asyncRequest(\r
- new AllVariablesOfModel(model)\r
+ SimanticsUI.getSession().asyncRequest(query\r
, new Listener<Collection<ChartVariable>>() {\r
\r
@Override\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.db.procedure.Listener;\r
import org.simantics.ui.SimanticsUI;\r
if(resource == null)\r
return;\r
this.resource = resource;\r
+ /* Find the model resource. It can be found with PartOf \r
+ relations from series resource in a chart */\r
+ try {\r
+ AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource);\r
+ SimanticsUI.getSession().asyncRequest(query\r
+ , new Listener<Collection<ChartVariable>>() {\r
+\r
+ @Override\r
+ public void execute(Collection<ChartVariable> result) {\r
+ setProposals(result);\r
+ }\r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return control == null || \r
+ control.isDisposed() || \r
+ !resource.equals(VariableProposalProvider.this.resource);\r
+ }\r
+\r
+ }); \r
+ } catch (DatabaseException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
\r
- SimanticsUI.getSession().asyncRequest(\r
- new AllVariablesOfModel(resource)\r
- , new Listener<Collection<ChartVariable>>() {\r
-\r
- @Override\r
- public void execute(Collection<ChartVariable> result) {\r
- setProposals(result);\r
- }\r
-\r
- @Override\r
- public void exception(Throwable t) {\r
- t.printStackTrace();\r
- }\r
-\r
- @Override\r
- public boolean isDisposed() {\r
- return control == null || \r
- control.isDisposed() || \r
- !resource.equals(VariableProposalProvider.this.resource);\r
- }\r
-\r
- }); \r
+ \r
\r
}\r
\r
GridDataFactory.fillDefaults().applyTo(time.getWidget());\r
}\r
}\r
+ \r
+ @Override\r
+ public void dispose() {\r
+ variable.dispose();\r
+ variable = null;\r
+ super.dispose();\r
+ }\r
}\r
}\r
\r
try {\r
- Collection<ChartVariable> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
+ AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource);\r
+ Collection<ChartVariable> variables = context.getSession().syncRequest(query);\r
\r
spc = new BarSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, options, SWT.NONE);\r
\r
exploded.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Series_exploded));\r
GridDataFactory.fillDefaults().applyTo(exploded.getWidget());\r
}\r
+ \r
+ @Override\r
+ public void dispose() {\r
+ variable.dispose();\r
+ variable = null;\r
+ super.dispose();\r
+ }\r
\r
}\r
}\r
\r
try {\r
- Collection<ChartVariable> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
+ AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource);\r
+ Collection<ChartVariable> variables = context.getSession().syncRequest(query);\r
PieSeriesPropertyComposite2 spc = new PieSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, options, SWT.NONE);\r
propertyContainer.setContent(spc);\r
Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r