private Text diameterText;
private Text thicknessText;
private Text turnRadiusText;
+
+ // Validation message label
+ private Label validationLabel;
// Position selection
private Button startButton;
label = new Label(composite, SWT.NONE);
label.setText("Turn radius");
turnRadiusText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+
+ validationLabel = new Label(composite, SWT.NONE);
+ validationLabel.setText("");
lengthText.setEnabled(false);
angleText.setEnabled(false);
horizFillData.applyTo(diameterText);
horizFillData.applyTo(thicknessText);
horizFillData.applyTo(turnRadiusText);
+
+ GridDataFactory.fillDefaults().span(2, 1).align(SWT.END, SWT.END).grab(true, false).applyTo(validationLabel);
if (!allowed.contains(PositionType.NEXT) && !allowed.contains(PositionType.PREVIOUS)) {
turnViewer.getList().setEnabled(false);
filterAllowed.clear();
Set<PositionType> filterAllowed = new HashSet<PositionType>();
boolean ok = true;
+ String msg = null;
+
+ if (name.isEmpty() || usedNames.contains(name)) {
+ ok = false;
+ if (msg == null) {
+ if (name.isEmpty())
+ msg = "Please provide a valid name";
+ else
+ msg = "Name \"" + name + "\" is already in use";
+ }
+ }
+
if (selected == null) {
ok = false;
} else if (selected.isCode()) {// TODO : instead of disabling the button, we should filter the content.
angleText.setEnabled(false);
rotationAngleText.setEnabled(selected.isRotated());
ok = false;
-
+ if (msg == null) msg = "Cannot split a straight pipe with a straight pipe";
} else {
lengthText.setEnabled(true);
angleText.setEnabled(false);
rotationAngleText.setEnabled(selected.isRotated());
- if (length == null)
+ if (length == null || length <= 0.0) {
ok = false;
+ if (msg == null) msg = "Please provide a valid length";
+ }
}
} else if (selected.getType() == Type.TURN) {
filterAllowed.add(PositionType.NEXT);
lengthText.setEnabled(false);
angleText.setEnabled(true);
rotationAngleText.setEnabled(true);
- if (angle == null)
+ if (angle == null) {
ok = false;
+ if (msg == null) msg = "Please provide a rotation angle";
+ }
} else {
// this should not happen, since end components should not have variable, or
// modifiable flag.
turnRadiusText.setEnabled(true);
diameterText.setEnabled(true);
thicknessText.setEnabled(true);
- if (diameter == null || turnRadius == null || thickness == null)
+ if (diameter == null || diameter <= 0.0) {
+ ok = false;
+ if (msg == null) msg = "Please provide a valid diameter";
+ }
+ if (turnRadius == null || diameter != null && turnRadius < diameter / 2) {
ok = false;
+ if (msg == null) msg = "Please provide a valid turn radius";
+ }
+ if (thickness == null || thickness < 0.0 || diameter != null && thickness >= diameter / 2) {
+ ok = false;
+ if (msg == null) msg = "Please provide a valid wall thickness";
+ }
} else {
turnRadiusText.setEnabled(false);
diameterText.setEnabled(false);
this.filterAllowed.add(t);
}
- if (name.isEmpty() || usedNames.contains(name))
- ok = false;
+ validationLabel.setText(msg != null ? msg : "");
+ validationLabel.requestLayout();
getButton(OK).setEnabled(ok);
}