Search in sources :

Example 1 with AbstractOverlapModel

use of org.eclipse.scanning.api.points.models.AbstractOverlapModel in project gda-core by openGDA.

the class PtychographyGridPathEditor method createEditorPart.

@Override
public Composite createEditorPart(Composite parent) {
    final Composite composite = super.createEditorPart(parent);
    new Label(composite, SWT.NONE).setText("Beam overlap");
    Composite overlapControls = new Composite(composite, SWT.NONE);
    GridDataFactory.fillDefaults().applyTo(overlapControls);
    GridLayoutFactory.fillDefaults().spacing(0, 1).applyTo(overlapControls);
    Text overlapText = new Text(overlapControls, SWT.BORDER);
    grabHorizontalSpace.applyTo(overlapText);
    binder.bind(overlapText, "overlap", getModel());
    Slider overlapSlider = new Slider(overlapControls, SWT.HORIZONTAL);
    // not inclusive
    overlapSlider.setMaximum(100);
    overlapSlider.setMinimum(0);
    overlapSlider.setIncrement(5);
    overlapSlider.setSelection(50);
    overlapSlider.addListener(SWT.Selection, event -> overlapText.setText(Double.toString(overlapSlider.getSelection() / 100.0)));
    overlapText.addListener(SWT.Modify, event -> overlapSlider.setSelection((int) (Double.parseDouble(overlapText.getText()) * 100)));
    grabHorizontalSpace.applyTo(overlapSlider);
    try {
        Object[] beamDimensions = getBeamDimensions();
        AbstractOverlapModel overlapModel = (AbstractOverlapModel) getModel();
        overlapModel.setBeamSize(beamDimensions);
        overlapText.setText(String.valueOf(overlapModel.getOverlap()));
        String beamDimensionsHint = "Beam dimensions = " + beamDimensions[0] + " x " + beamDimensions[1];
        composite.setToolTipText(beamDimensionsHint);
        // Show 'invalid' icon on text if overlap is outside valid range
        ControlDecorationSupport.create(new MultiValidator() {

            IObservableValue observable = binder.getObservableValue(overlapText);

            @Override
            protected IStatus validate() {
                double range = Double.parseDouble((String) observable.getValue());
                return range >= 0 && range < 1 ? ValidationStatus.ok() : ValidationStatus.error("0 <= overlap < 1");
            }
        }, SWT.LEFT);
    } catch (ScanningException e) {
        logger.error("Error getting beam dimensions", e);
        overlapText.setEnabled(false);
        overlapSlider.setEnabled(false);
        skipACell(composite);
        Label errorLabel = new Label(composite, SWT.NONE);
        errorLabel.setText("Beam dimensions not set!");
        errorLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
        showErrorDialog(composite.getShell());
    }
    new Label(composite, SWT.NONE).setText("Random offset");
    Text offsetText = new Text(composite, SWT.BORDER);
    offsetText.setToolTipText("% of step size");
    grabHorizontalSpace.applyTo(offsetText);
    binder.bind(offsetText, "randomOffset", getModel());
    makeCommonOptionsControls(composite);
    return composite;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) Slider(org.eclipse.swt.widgets.Slider) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) AbstractOverlapModel(org.eclipse.scanning.api.points.models.AbstractOverlapModel) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Aggregations

IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)1 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)1 IStatus (org.eclipse.core.runtime.IStatus)1 AbstractOverlapModel (org.eclipse.scanning.api.points.models.AbstractOverlapModel)1 ScanningException (org.eclipse.scanning.api.scan.ScanningException)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Slider (org.eclipse.swt.widgets.Slider)1 Text (org.eclipse.swt.widgets.Text)1