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;
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;
private Button removeVisualisationTemplateButton;
- private Button applyButton;
-
public DynamicVisualisationsUI(Composite parent, int style) {
super(parent, style);
// ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.V_SCROLL);
}
});
- 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);
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);
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
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);
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
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");
if (colorLocationItems.length > 0) {
colorLocationCombo.select(0);
}
+ addSelectionListener(colorLocationCombo);
label = new Label(parent, SWT.NONE);
label.setText("Size");
if (colorSizeItems.length > 0) {
colorSizeCombo.select(0);
}
+ addSelectionListener(colorSizeCombo);
}
private void initializeObjectSizes(Composite parent) {
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");
if (sizeLocationItems.length > 0) {
sizeLocationCombo.select(0);
}
+ addSelectionListener(sizeLocationCombo);
label = new Label(parent, SWT.NONE);
label.setText("Size");
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) {
if (getParent().isDisposed())
return;
- applyButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null);
removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null);
if (visualisation != null) {