use of org.eclipse.scanning.api.scan.ScanningException 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;
}
Aggregations