X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fvisualisations%2FDynamicVisualisationsUI.java;h=c5be0451242f8fafccbe0fd3f4cdf1eb4626c997;hb=ae5159794b57b980f6f2d5e509e6a47843be8ca0;hp=14a8f00fa61c0646d84e60107674f78dd1a0cb26;hpb=a2c485af95024784aa9de3378759ee94b8caea2e;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java index 14a8f00f..c5be0451 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java @@ -18,6 +18,12 @@ import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Button; @@ -28,6 +34,7 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Widget; import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -85,8 +92,6 @@ public class DynamicVisualisationsUI extends Composite { private Button removeVisualisationTemplateButton; - private Button applyButton; - public DynamicVisualisationsUI(Composite parent, int style) { super(parent, style); // ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.V_SCROLL); @@ -174,22 +179,6 @@ public class DynamicVisualisationsUI extends Composite { } }); - applyButton = new Button(buttonBarsComposite, SWT.NONE); - applyButton.setText("Apply"); - applyButton.setEnabled(visualisation != null); - applyButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - try { - persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); - } catch (Exception e1) { - LOGGER.error("Could not persist visualisation template", e1); - ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); - } - } - }); - removeVisualisationTemplateButton = new Button(buttonBarsComposite, SWT.NONE); removeVisualisationTemplateButton.setText("Remove"); removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null); @@ -474,17 +463,21 @@ public class DynamicVisualisationsUI extends Composite { Button usedButton = new Button(parent, SWT.CHECK); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(usedButton); + addSelectionListener(usedButton); Combo variableCombo = new Combo(parent, SWT.READ_ONLY); variableCombo.setItems(colorContributions.keySet().toArray(new String[colorContributions.size()])); + addSelectionListener(variableCombo); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo); Text minText = new Text(parent, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(minText); + addSelectionListener(minText); Text maxText = new Text(parent, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(maxText); + addSelectionListener(maxText); Text unit = new Text(parent, SWT.READ_ONLY); GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit); @@ -492,9 +485,11 @@ public class DynamicVisualisationsUI extends Composite { Combo colorMapCombo = new Combo(parent, SWT.READ_ONLY); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(colorMapCombo); colorMapCombo.setItems(colorMaps.keySet().toArray(new String[colorMaps.keySet().size()])); + addSelectionListener(colorMapCombo); Button defaultButton = new Button(parent, SWT.CHECK); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton); + addSelectionListener(defaultButton); defaultButton.addSelectionListener(new SelectionAdapter() { @Override @@ -637,17 +632,21 @@ public class DynamicVisualisationsUI extends Composite { Button usedButton = new Button(parent, SWT.CHECK); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(usedButton); + addSelectionListener(usedButton); Combo variableCombo = new Combo(parent, SWT.READ_ONLY); variableCombo.setItems(sizeContributions.keySet().toArray(new String[sizeContributions.size()])); + addSelectionListener(variableCombo); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo); Text minText = new Text(parent, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(minText); + addSelectionListener(minText); Text maxText = new Text(parent, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(maxText); + addSelectionListener(maxText); Label unit = new Label(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit); @@ -655,9 +654,11 @@ public class DynamicVisualisationsUI extends Composite { Combo sizeMapCombo = new Combo(parent, SWT.READ_ONLY); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(sizeMapCombo); sizeMapCombo.setItems(sizeMaps.keySet().toArray(new String[sizeMaps.keySet().size()])); + addSelectionListener(sizeMapCombo); Button defaultButton = new Button(parent, SWT.CHECK); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton); + addSelectionListener(defaultButton); defaultButton.addSelectionListener(new SelectionAdapter() { @Override @@ -766,12 +767,15 @@ public class DynamicVisualisationsUI extends Composite { showColorButton = new Button(parent, SWT.CHECK); showColorButton.setText("Show"); + addSelectionListener(showColorButton); colorTicksButton = new Button(parent, SWT.CHECK); colorTicksButton.setText("Ticks"); + addSelectionListener(colorTicksButton); colorGradientButton = new Button(parent, SWT.CHECK); colorGradientButton.setText("Gradients"); + addSelectionListener(colorGradientButton); Label label = new Label(parent, SWT.NONE); label.setText("Location"); @@ -781,6 +785,7 @@ public class DynamicVisualisationsUI extends Composite { if (colorLocationItems.length > 0) { colorLocationCombo.select(0); } + addSelectionListener(colorLocationCombo); label = new Label(parent, SWT.NONE); label.setText("Size"); @@ -790,6 +795,7 @@ public class DynamicVisualisationsUI extends Composite { if (colorSizeItems.length > 0) { colorSizeCombo.select(0); } + addSelectionListener(colorSizeCombo); } private void initializeObjectSizes(Composite parent) { @@ -837,12 +843,15 @@ public class DynamicVisualisationsUI extends Composite { private void createSizeBars(Composite parent) { showSizeButton = new Button(parent, SWT.CHECK); showSizeButton.setText("Show"); + addSelectionListener(showSizeButton); sizeTicksButton = new Button(parent, SWT.CHECK); sizeTicksButton.setText("Ticks"); + addSelectionListener(sizeTicksButton); sizeGradientButton = new Button(parent, SWT.CHECK); sizeGradientButton.setText("Gradient"); + addSelectionListener(sizeGradientButton); Label label = new Label(parent, SWT.NONE); label.setText("Location"); @@ -852,6 +861,7 @@ public class DynamicVisualisationsUI extends Composite { if (sizeLocationItems.length > 0) { sizeLocationCombo.select(0); } + addSelectionListener(sizeLocationCombo); label = new Label(parent, SWT.NONE); label.setText("Size"); @@ -861,6 +871,64 @@ public class DynamicVisualisationsUI extends Composite { if (sizeSizeItems.length > 0) { sizeSizeCombo.select(0); } + addSelectionListener(sizeSizeCombo); + } + + private void addSelectionListener(Widget widget) { + if (widget instanceof Button) { + ((Button) widget).addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + try { + persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); + } catch (Exception e1) { + LOGGER.error("Could not persist visualisation template", e1); + ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); + } + } + }); + } else if (widget instanceof Combo) { + ((Combo) widget).addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + try { + persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); + } catch (Exception e1) { + LOGGER.error("Could not persist visualisation template", e1); + ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); + } + } + }); + } else if (widget instanceof Text) { + ((Text) widget).addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + try { + persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); + } catch (Exception e1) { + LOGGER.error("Could not persist visualisation template", e1); + ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); + } + } + }); + ((Text) widget).addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + if(e.keyCode == SWT.CR || e.keyCode == SWT.LF) { + try { + persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); + } catch (Exception e1) { + LOGGER.error("Could not persist visualisation template", e1); + ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); + } + } + } + }); + } } public void setParentResource(Resource parentResource) { @@ -950,7 +1018,6 @@ public class DynamicVisualisationsUI extends Composite { if (getParent().isDisposed()) return; - applyButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null); removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null); if (visualisation != null) {