use of net.sourceforge.usbdm.packageParser.ApplyWhenCondition in project usbdm-eclipse-plugins by podonoghue.
the class UsbdmOptionsPanel method validate.
/**
* Validates control & returns error message
*
* @return
*
* @return Error message (null if none)
*
* @throws Exception
*/
public String validate() {
if (fButtonMap == null) {
// Button not yet created
return null;
}
// Propagate dependencies between buttons
// Bit of a hack - do the page multiple times to propagate dependency changes
Set<Entry<String, Button>> buttonSet = fButtonMap.entrySet();
for (int i = 0; i < 5; i++) {
// Check and update all buttons and record if any changed
boolean noChanges = true;
for (Entry<String, Button> entry : buttonSet) {
Button button = entry.getValue();
ProjectVariable projectVariable = fVariableMap.get(entry.getKey());
boolean enabled = true;
try {
ApplyWhenCondition applyWhenCondition = projectVariable.getRequirement();
// if (projectVariable.getId().equals("projectOptionValue.KSDK-usb-audio-generator")) {
// applyWhenCondition.setVerbose(true);
// }
enabled = applyWhenCondition.enabled(fDevice, fOptionMap, fButtonMap);
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
if (button.isEnabled() != enabled) {
button.setEnabled(enabled);
noChanges = false;
}
if (!button.isEnabled()) {
button.setSelection(false);
}
}
if (noChanges) {
break;
}
}
// Check for at least one radio button selected in each group
for (Group group : fGroupList) {
boolean radioButtonSelected = false;
boolean radioButtonPresent = false;
for (Control child : group.getChildren()) {
if (child instanceof Button) {
Button button = (Button) child;
if (button.isEnabled() && (button.getStyle() & SWT.RADIO) != 0) {
radioButtonPresent = true;
if (radioButtonSelected) {
// Clear multiple button selection
button.setSelection(false);
}
radioButtonSelected = radioButtonSelected || button.getSelection();
}
}
}
if (radioButtonPresent && !radioButtonSelected) {
// Prompt to select a radio button
return "Select " + group.getText();
}
}
return null;
}
Aggregations