Commit be2bb726 authored by Tuukka Lehtonen's avatar Tuukka Lehtonen
Browse files

Put showing of subscription item values behind a preference

The new preference is on the Subscriptions page with the label
Show subscription item values in Model Browser.

It is disabled by default since its use can make the model browser DB
queries very frequently updating and very heavy. All the user has to do
is expanding a subscription group with hundreds or thousands of items in
the model browser and the system will slow down to a crawl.

gitlab #855
parent fd6297e1
package org.simantics.db.layer0.request.external;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.simantics.db.ReadGraph;
import org.simantics.db.common.request.ParametrizedPrimitiveRead;
import org.simantics.db.procedure.Listener;
import org.simantics.utils.datastructures.Triple;
/**
* @author Tuukka Lehtonen
* @since 1.52.0
*/
public class EclipsePreferenceBooleanPrimitiveRead extends ParametrizedPrimitiveRead<Triple<String,String,Boolean>,Boolean> implements IPreferenceChangeListener {
private Listener<Boolean> listener;
public EclipsePreferenceBooleanPrimitiveRead(String plugin, String key, boolean def) {
super(Triple.make(plugin, key, def));
}
@Override
public void register(ReadGraph graph, Listener<Boolean> procedure) {
IEclipsePreferences preferenceNode = resolvePreferenceNode();
if (!procedure.isDisposed() && preferenceNode != null) {
preferenceNode.addPreferenceChangeListener(this);
}
listener = procedure;
Boolean value = preferenceNode != null ? preferenceNode.getBoolean(parameter.second, parameter.third) : parameter.third;
procedure.execute(value);
}
@Override
public void preferenceChange(PreferenceChangeEvent event) {
if (parameter.second.equals(event.getKey())) {
IEclipsePreferences preferenceNode = resolvePreferenceNode();
Boolean value = preferenceNode != null ? preferenceNode.getBoolean(parameter.second, parameter.third) : parameter.third;
listener.execute(value);
}
}
@Override
public void unregistered() {
IEclipsePreferences preferenceNode = resolvePreferenceNode();
if (preferenceNode != null) {
preferenceNode.removePreferenceChangeListener(this);
}
listener = null;
}
private IEclipsePreferences resolvePreferenceNode() {
IEclipsePreferences preferenceNode = InstanceScope.INSTANCE.getNode( parameter.first );
return preferenceNode;
}
}
......@@ -32,6 +32,7 @@ import org.simantics.db.layer0.variable.Variable;
import org.simantics.modeling.ModelingResources;
import org.simantics.modeling.subscription.ModelContexts;
import org.simantics.modeling.subscription.ModelContextsRequest;
import org.simantics.modeling.subscription.SubscriptionItemLabel;
/**
* @author Tuukka Lehtonen
......@@ -59,10 +60,6 @@ public class SubscriptionItemLabelDecorationRule implements LabelDecorationRule
};
static LabelDecorator UNRESOLVABLE = new LabelDecorator.Stub() {
@Override
public String decorateLabel(String label, String column, int itemIndex) {
return label + " (INVALID)";
}
@SuppressWarnings("unchecked")
public <C> C decorateForeground(C color, String column, int itemIndex) {
return (C) INVALID;
......@@ -80,6 +77,10 @@ public class SubscriptionItemLabelDecorationRule implements LabelDecorationRule
@Override
public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
if (!SubscriptionItemLabel.showValuesInLabel(graph))
// Keep subscription item labeling as light as possible unless otherwise desired
return null;
Resource item = (Resource) content;
ModelingResources MOD = ModelingResources.getInstance(graph);
......
......@@ -14,12 +14,17 @@ package org.simantics.modeling.ui.preferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
......@@ -32,7 +37,8 @@ public class SubscriptionPreferencePage extends FieldEditorPreferencePage implem
private NumberFieldEditor fSubscriptionIntervalEditor = null;
private NumberFieldEditor fSubscriptionGainEditor = null;
private NumberFieldEditor fSubscriptionBiasEditor = null;
private BooleanFieldEditor fSubscriptionShowValues = null;
/**
* Create the console page.
*/
......@@ -82,6 +88,23 @@ public class SubscriptionPreferencePage extends FieldEditorPreferencePage implem
fSubscriptionBiasEditor = new NumberFieldEditor(SubscriptionPreferences.P_SUBSCRIPTION_BIAS, "Bias", newItemSettings);
addField(fSubscriptionBiasEditor);
{
Group visualsGroup = new Group(getFieldEditorParent(), SWT.NONE);
visualsGroup.setText("Subscription related visualizations");
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(visualsGroup);
FillLayout vfl = new FillLayout();
vfl.marginWidth = 5;
vfl.marginHeight = 5;
visualsGroup.setLayout(vfl);
Composite visualSettings = new Composite(visualsGroup, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(visualSettings);
fSubscriptionShowValues = new BooleanFieldEditor(SubscriptionPreferences.P_SUBSCRIPTION_SHOW_VALUE_IN_MODEL_BROWSER, "Show subscription item values in Model Browser", visualSettings);
addField(fSubscriptionShowValues);
createNoteComposite(visualSettings, "Warning:", "Enabling this with lots of subscription items can slow the UI down heavily");
}
}
/**
......@@ -91,5 +114,23 @@ public class SubscriptionPreferencePage extends FieldEditorPreferencePage implem
public void init(IWorkbench workbench) {
}
protected Composite createNoteComposite(Composite composite, String title, String message) {
Composite messageComposite = new Composite(composite, SWT.NONE);
GridLayout messageLayout = new GridLayout();
messageLayout.numColumns = 2;
messageLayout.marginWidth = 0;
messageLayout.marginHeight = 0;
messageComposite.setLayout(messageLayout);
GridDataFactory.fillDefaults().span(2, 1).applyTo(messageComposite);
final Label noteLabel = new Label(messageComposite, SWT.BOLD);
noteLabel.setText(title);
noteLabel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
noteLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
Label messageLabel = new Label(messageComposite, SWT.WRAP);
messageLabel.setText(message);
return messageComposite;
}
}
......@@ -28,6 +28,7 @@ public class SubscriptionPreferenceInitializer extends AbstractPreferenceInitial
node.putDouble(SubscriptionPreferences.P_SUBSCRIPTION_DEADBAND, SubscriptionPreferences.DEFAULT_SUBSCRIPTION_DEADBAND);
node.putDouble(SubscriptionPreferences.P_SUBSCRIPTION_BIAS, SubscriptionPreferences.DEFAULT_SUBSCRIPTION_BIAS);
node.putDouble(SubscriptionPreferences.P_SUBSCRIPTION_GAIN, SubscriptionPreferences.DEFAULT_SUBSCRIPTION_GAIN);
node.putBoolean(SubscriptionPreferences.P_SUBSCRIPTION_SHOW_VALUE_IN_MODEL_BROWSER, SubscriptionPreferences.DEFAULT_SHOW_VALUE_IN_MODEL_BROWSER);
}
}
......@@ -23,10 +23,12 @@ public class SubscriptionPreferences {
public static final String P_SUBSCRIPTION_GAIN = "subscriptionitem.gain"; //$NON-NLS-1$
public static final String P_SUBSCRIPTION_BIAS = "subscriptionitem.bias"; //$NON-NLS-1$
public static final String P_SUBSCRIPTION_UNIT = "subscriptionitem.unit"; //$NON-NLS-1$
public static final String P_SUBSCRIPTION_SHOW_VALUE_IN_MODEL_BROWSER = "subscriptionitem.modelBrowser.showValue"; //$NON-NLS-1$
public static final double DEFAULT_SUBSCRIPTION_INTERVAL = 0.0;
public static final double DEFAULT_SUBSCRIPTION_DEADBAND = 0.;
public static final double DEFAULT_SUBSCRIPTION_BIAS = 0.0;
public static final double DEFAULT_SUBSCRIPTION_GAIN = 1.0;
public static final boolean DEFAULT_SHOW_VALUE_IN_MODEL_BROWSER = false;
}
......@@ -12,14 +12,17 @@ import org.simantics.db.GraphHints;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.common.procedure.adapter.TransientCacheListener;
import org.simantics.db.common.request.PossibleIndexRoot;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.exception.PendingVariableException;
import org.simantics.db.layer0.request.PossibleVariableValue;
import org.simantics.db.layer0.request.external.EclipsePreferenceBooleanPrimitiveRead;
import org.simantics.db.layer0.variable.RVI;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.layer0.Layer0;
import org.simantics.modeling.ModelingResources;
import org.simantics.modeling.preferences.SubscriptionPreferences;
import org.simantics.utils.datastructures.Pair;
import org.simantics.utils.format.FormattingUtils;
import org.simantics.utils.format.ValueFormat;
......@@ -28,6 +31,16 @@ public class SubscriptionItemLabel {
private static final String NO_VARIABLE_ID = "<no variable id>";
private static EclipsePreferenceBooleanPrimitiveRead showValuesInLabelsRequest =
new EclipsePreferenceBooleanPrimitiveRead(
SubscriptionPreferences.P_NODE,
SubscriptionPreferences.P_SUBSCRIPTION_SHOW_VALUE_IN_MODEL_BROWSER,
SubscriptionPreferences.DEFAULT_SHOW_VALUE_IN_MODEL_BROWSER);
public static boolean showValuesInLabel(ReadGraph graph) throws DatabaseException {
return graph.syncRequest(showValuesInLabelsRequest, TransientCacheListener.instance());
}
public static String resolveLabel(ReadGraph graph, Resource item, boolean synchronous) throws DatabaseException {
IEclipsePreferences chartPreferenceNode = InstanceScope.INSTANCE.getNode( "org.simantics.charts" );
String s = chartPreferenceNode.get("chart.valueformat", ValueFormat.Default.name());
......@@ -36,7 +49,8 @@ public class SubscriptionItemLabel {
}
public static String resolveLabel(ReadGraph graph, Resource item, ValueFormat valueFormat, boolean synchronous) throws DatabaseException {
return resolveLabel(graph, item, valueFormat, synchronous, true, true);
boolean showValue = showValuesInLabel(graph);
return resolveLabel(graph, item, valueFormat, synchronous, true, showValue);
}
public static String resolveLabel(ReadGraph graph, Resource item, ValueFormat valueFormat, boolean synchronous, boolean tryLabel, boolean showValue) throws DatabaseException {
......@@ -56,7 +70,7 @@ public class SubscriptionItemLabel {
return NO_VARIABLE_ID;
Resource model = graph.syncRequest(new PossibleIndexRoot(item));
if (model != null) {
if (model != null) {
ModelContexts contexts = graph.syncRequest(new ModelContextsRequest(model), TransientCacheAsyncListener.<ModelContexts>instance());
Variable configurationContext = contexts.getConfigurationContext();
Variable experimentContext = contexts.getExperimentContext();
......@@ -104,6 +118,11 @@ public class SubscriptionItemLabel {
label = sb.toString();
}
} else {
// Inform user that the subscription item can't be resolved to a value
// which means it is possibly referencing a component#property that no
// longer exists.
label = label + " (INVALID)";
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment