Search in sources :

Example 16 with Equal

use of com.github.bordertech.wcomponents.subordinate.Equal in project wcomponents by BorderTech.

the class WDropdownOptionsExample method buildSubordinatePanel.

/**
 * Builds a panel for the subordinate control, including the rule for that particular option.
 *
 * @param dropdown the subordinate trigger.
 * @param value the dropdown option to be added
 * @param group the group
 * @param control the subordinate control
 */
private void buildSubordinatePanel(final WDropdown dropdown, final String value, final WComponentGroup<SubordinateTarget> group, final WSubordinateControl control) {
    // create the panel.
    WPanel panel = new WPanel();
    WStyledText subordinateInfo = new WStyledText();
    subordinateInfo.setWhitespaceMode(WhitespaceMode.PRESERVE);
    subordinateInfo.setText(value + " - Subordinate");
    panel.add(subordinateInfo);
    // add the panel to the screen and group.
    infoPanel.add(panel);
    group.addToGroup(panel);
    // create the rule
    Rule rule = new Rule();
    control.addRule(rule);
    rule.setCondition(new Equal(dropdown, value));
    rule.addActionOnTrue(new ShowInGroup(panel, group));
}
Also used : ShowInGroup(com.github.bordertech.wcomponents.subordinate.ShowInGroup) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WPanel(com.github.bordertech.wcomponents.WPanel) WStyledText(com.github.bordertech.wcomponents.WStyledText) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule)

Example 17 with Equal

use of com.github.bordertech.wcomponents.subordinate.Equal in project wcomponents by BorderTech.

the class SubordinateControlMandatoryExample method build.

/**
 * Creates the component to be added to the validation container. This is doen in a static method because the
 * component is passed into the superclass constructor.
 *
 * @return the component to be added to the validation container.
 */
private static WComponent build() {
    WContainer root = new WContainer();
    WSubordinateControl control = new WSubordinateControl();
    root.add(control);
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    layout.setMargin(new com.github.bordertech.wcomponents.Margin(0, 0, 12, 0));
    WCheckBox checkBox = new WCheckBox();
    layout.addField("Set Mandatory", checkBox);
    WTextField text = new WTextField();
    layout.addField("Might need this field", text);
    WTextField mandatoryField = new WTextField();
    layout.addField("Another field always mandatory", mandatoryField);
    mandatoryField.setMandatory(true);
    final WRadioButtonSelect rbSelect = new WRadioButtonSelect("australian_state");
    layout.addField("Select a state", rbSelect);
    root.add(layout);
    Rule rule = new Rule();
    rule.setCondition(new Equal(checkBox, Boolean.TRUE.toString()));
    rule.addActionOnTrue(new Mandatory(text));
    rule.addActionOnFalse(new Optional(text));
    rule.addActionOnTrue(new Mandatory(rbSelect));
    rule.addActionOnFalse(new Optional(rbSelect));
    control.addRule(rule);
    return root;
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) Optional(com.github.bordertech.wcomponents.subordinate.Optional) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WTextField(com.github.bordertech.wcomponents.WTextField) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory)

Example 18 with Equal

use of com.github.bordertech.wcomponents.subordinate.Equal in project wcomponents by BorderTech.

the class SubordinateControlOptionsExample method createCondition.

/**
 * @return the condition for the subordinate control.
 */
private Condition createCondition() {
    // Compare value
    Object value;
    switch((TriggerType) drpTriggerType.getSelected()) {
        case DateField:
            value = dateCompareValue.getValue();
            break;
        case NumberField:
            value = numberCompareValue.getValue();
            break;
        default:
            value = comboCompareValue.getValue();
            break;
    }
    // Create condition
    Condition condition;
    switch((CompareType) drpCompareType.getSelected()) {
        case EQUAL:
            condition = new Equal(trigger, value);
            break;
        case NOT_EQUAL:
            condition = new NotEqual(trigger, value);
            break;
        case LESS_THAN:
            condition = new LessThan(trigger, value);
            break;
        case LESS_THAN_OR_EQUAL:
            condition = new LessThanOrEqual(trigger, value);
            break;
        case GREATER_THAN:
            condition = new GreaterThan(trigger, value);
            break;
        case GREATER_THAN_OR_EQUAL:
            condition = new GreaterThanOrEqual(trigger, value);
            break;
        case MATCH:
            condition = new Match(trigger, (String) value);
            break;
        default:
            throw new SystemException("Compare type not valid");
    }
    return condition;
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) CompareType(com.github.bordertech.wcomponents.subordinate.AbstractCompare.CompareType) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) Match(com.github.bordertech.wcomponents.subordinate.Match) LessThan(com.github.bordertech.wcomponents.subordinate.LessThan) SystemException(com.github.bordertech.wcomponents.util.SystemException) Equal(com.github.bordertech.wcomponents.subordinate.Equal) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) GreaterThan(com.github.bordertech.wcomponents.subordinate.GreaterThan)

Example 19 with Equal

use of com.github.bordertech.wcomponents.subordinate.Equal in project wcomponents by BorderTech.

the class SubordinateControlOptionsExample method buildControl.

/**
 * Build the subordinate control.
 */
private void buildControl() {
    buildControlPanel.reset();
    buildTargetPanel.reset();
    // Setup Trigger
    setupTrigger();
    // Create target
    SubordinateTarget target = setupTarget();
    // Create Actions
    com.github.bordertech.wcomponents.subordinate.Action trueAction;
    com.github.bordertech.wcomponents.subordinate.Action falseAction;
    switch((ControlActionType) drpActionType.getSelected()) {
        case ENABLE_DISABLE:
            trueAction = new Enable(target);
            falseAction = new Disable(target);
            break;
        case SHOW_HIDE:
            trueAction = new Show(target);
            falseAction = new Hide(target);
            break;
        case MAN_OPT:
            trueAction = new Mandatory(target);
            falseAction = new Optional(target);
            break;
        case SHOWIN_HIDEIN:
            trueAction = new ShowInGroup(target, targetGroup);
            falseAction = new HideInGroup(target, targetGroup);
            break;
        case ENABLEIN_DISABLEIN:
            trueAction = new EnableInGroup(target, targetGroup);
            falseAction = new DisableInGroup(target, targetGroup);
            break;
        default:
            throw new SystemException("ControlAction type not valid");
    }
    // Create Condition
    Condition condition = createCondition();
    if (cbNot.isSelected()) {
        condition = new Not(condition);
    }
    // Create Rule
    Rule rule = new Rule(condition, trueAction, falseAction);
    // Create Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    buildControlPanel.add(control);
    if (targetCollapsible.getDecoratedLabel() != null) {
        targetCollapsible.getDecoratedLabel().setTail(new WText(control.toString()));
    }
    control = new WSubordinateControl();
    rule = new Rule(new Equal(cbClientDisableTrigger, true), new Disable((SubordinateTarget) trigger), new Enable((SubordinateTarget) trigger));
    control.addRule(rule);
    buildControlPanel.add(control);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) Condition(com.github.bordertech.wcomponents.subordinate.Condition) Optional(com.github.bordertech.wcomponents.subordinate.Optional) HideInGroup(com.github.bordertech.wcomponents.subordinate.HideInGroup) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) EnableInGroup(com.github.bordertech.wcomponents.subordinate.EnableInGroup) ShowInGroup(com.github.bordertech.wcomponents.subordinate.ShowInGroup) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Not(com.github.bordertech.wcomponents.subordinate.Not) SystemException(com.github.bordertech.wcomponents.util.SystemException) WText(com.github.bordertech.wcomponents.WText) Equal(com.github.bordertech.wcomponents.subordinate.Equal) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) Enable(com.github.bordertech.wcomponents.subordinate.Enable) Show(com.github.bordertech.wcomponents.subordinate.Show) DisableInGroup(com.github.bordertech.wcomponents.subordinate.DisableInGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule) Disable(com.github.bordertech.wcomponents.subordinate.Disable) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory)

Example 20 with Equal

use of com.github.bordertech.wcomponents.subordinate.Equal in project wcomponents by BorderTech.

the class WDateFieldExample method addDateRangeExample.

/**
 * Add date range example.
 */
private void addDateRangeExample() {
    add(new WHeading(WHeading.MAJOR, "Example of a date range component"));
    WFieldSet dateRange = new WFieldSet("Enter the expected arrival and departure dates.");
    add(dateRange);
    WPanel dateRangePanel = new WPanel();
    dateRangePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0));
    dateRange.add(dateRangePanel);
    final WDateField arrivalDate = new WDateField();
    final WDateField departureDate = new WDateField();
    // One could add some validation rules around this so that "arrival" was always earlier than or equal to "departure"
    WLabel arrivalLabel = new WLabel("Arrival", arrivalDate);
    arrivalLabel.setHint("dd MMM yyyy");
    WLabel departureLabel = new WLabel("Departure", departureDate);
    departureLabel.setHint("dd MMM yyyy");
    dateRangePanel.add(arrivalLabel);
    dateRangePanel.add(arrivalDate);
    dateRangePanel.add(departureLabel);
    dateRangePanel.add(departureDate);
    // subordinate control to ensure that the departure date is only enabled if the arrival date is populated
    WSubordinateControl control = new WSubordinateControl();
    add(control);
    Rule rule = new Rule(new Equal(arrivalDate, null));
    control.addRule(rule);
    rule.addActionOnTrue(new Disable(departureDate));
    rule.addActionOnFalse(new Enable(departureDate));
    control.addRule(rule);
}
Also used : WFieldSet(com.github.bordertech.wcomponents.WFieldSet) FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WPanel(com.github.bordertech.wcomponents.WPanel) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WDateField(com.github.bordertech.wcomponents.WDateField) Enable(com.github.bordertech.wcomponents.subordinate.Enable) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHeading(com.github.bordertech.wcomponents.WHeading) Disable(com.github.bordertech.wcomponents.subordinate.Disable) WLabel(com.github.bordertech.wcomponents.WLabel)

Aggregations

Equal (com.github.bordertech.wcomponents.subordinate.Equal)27 Rule (com.github.bordertech.wcomponents.subordinate.Rule)25 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)24 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)17 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)17 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)17 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)17 WContainer (com.github.bordertech.wcomponents.WContainer)16 WTextField (com.github.bordertech.wcomponents.WTextField)16 Test (org.junit.Test)16 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)13 Hide (com.github.bordertech.wcomponents.subordinate.Hide)13 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)12 Show (com.github.bordertech.wcomponents.subordinate.Show)12 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)9 Disable (com.github.bordertech.wcomponents.subordinate.Disable)8 Enable (com.github.bordertech.wcomponents.subordinate.Enable)8 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)6 Condition (com.github.bordertech.wcomponents.subordinate.Condition)6 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5