Search in sources :

Example 1 with WComponentGroup

use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.

the class WDropdownOptionsExample method applySettings.

/**
 * Apply the settings from the control table to the drop down.
 */
private void applySettings() {
    container.reset();
    infoPanel.reset();
    // create the list of options.
    List<String> options = new ArrayList<>(Arrays.asList(OPTIONS_ARRAY));
    if (cbNullOption.isSelected()) {
        options.add(0, "");
    }
    // create the dropdown.
    final WDropdown dropdown = new WDropdown(options);
    // set the dropdown type.
    dropdown.setType((DropdownType) rbsDDType.getSelected());
    // set the selected option if applicable.
    String selected = (String) rgDefaultOption.getSelected();
    if (selected != null && !NONE.equals(selected)) {
        dropdown.setSelected(selected);
    }
    // set the width.
    if (nfWidth.getValue() != null) {
        dropdown.setOptionWidth(nfWidth.getValue().intValue());
    }
    // set the tool tip.
    if (tfToolTip.getText() != null && tfToolTip.getText().length() > 0) {
        dropdown.setToolTip(tfToolTip.getText());
    }
    // set misc options.
    dropdown.setVisible(cbVisible.isSelected());
    dropdown.setDisabled(cbDisabled.isSelected());
    // add the action for action on change, ajax and subordinate.
    if (cbActionOnChange.isSelected() || cbAjax.isSelected() || cbSubmitOnChange.isSelected()) {
        final WStyledText info = new WStyledText();
        info.setWhitespaceMode(WhitespaceMode.PRESERVE);
        infoPanel.add(info);
        dropdown.setActionOnChange(new Action() {

            @Override
            public void execute(final ActionEvent event) {
                String selectedOption = (String) dropdown.getSelected();
                info.setText(selectedOption);
            }
        });
    }
    // this has to be below the set action on change so it is
    // not over written.
    dropdown.setSubmitOnChange(cbSubmitOnChange.isSelected());
    // add the ajax target.
    if (cbAjax.isSelected()) {
        WAjaxControl update = new WAjaxControl(dropdown);
        update.addTarget(infoPanel);
        container.add(update);
    }
    // add the subordinate stuff.
    if (rbsDDType.getValue() == WDropdown.DropdownType.COMBO) {
        // This is to work around a WComponent Subordinate logic flaw.
        cbSubordinate.setSelected(false);
    }
    if (cbSubordinate.isSelected()) {
        WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
        container.add(group);
        WSubordinateControl control = new WSubordinateControl();
        container.add(control);
        for (String option : OPTIONS_ARRAY) {
            buildSubordinatePanel(dropdown, option, group, control);
        }
        // add a rule for none selected.
        Rule rule = new Rule();
        control.addRule(rule);
        rule.setCondition(new Equal(dropdown, ""));
        rule.addActionOnTrue(new Hide(group));
    }
    WFieldLayout flay = new WFieldLayout();
    flay.setLabelWidth(25);
    container.add(flay);
    flay.addField("Configured dropdown", dropdown);
    flay.addField((WLabel) null, new WButton("Submit"));
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) ArrayList(java.util.ArrayList) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WStyledText(com.github.bordertech.wcomponents.WStyledText) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WButton(com.github.bordertech.wcomponents.WButton) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WDropdown(com.github.bordertech.wcomponents.WDropdown) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule)

Example 2 with WComponentGroup

use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.

the class DisableInGroup_Test method testActionType.

@Test
public void testActionType() {
    SubordinateTarget target = new WTextField();
    WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
    group.addToGroup(target);
    DisableInGroup action = new DisableInGroup(target, group);
    Assert.assertEquals("Incorrect Action Type", action.getActionType(), AbstractAction.ActionType.DISABLEIN);
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 3 with WComponentGroup

use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.

the class EnableInGroup_Test method testConstructor.

@Test
public void testConstructor() {
    SubordinateTarget target = new MyTarget();
    WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
    EnableInGroup action = new EnableInGroup(target, group);
    Assert.assertEquals("Value for EnableIn should be false", Boolean.FALSE, action.getValue());
    Assert.assertEquals("Target for EnableIn should be the group", group, action.getTarget());
    Assert.assertEquals("TargetInGroup for EnableIn should be the target", target, action.getTargetInGroup());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Test(org.junit.Test)

Example 4 with WComponentGroup

use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.

the class EnableInGroup_Test method testToString.

@Test
public void testToString() {
    SubordinateTarget target1 = new MyTarget();
    SubordinateTarget target2 = new MyTarget();
    SubordinateTarget target3 = new MyTarget();
    WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
    group.addToGroup(target1);
    group.addToGroup(target2);
    group.addToGroup(target3);
    EnableInGroup action = new EnableInGroup(target2, group);
    Assert.assertEquals("Incorrect toString for action", "enable MyTarget in WComponentGroup([MyTarget, MyTarget, MyTarget])", action.toString());
    new WLabel("test label", target2);
    Assert.assertEquals("Incorrect toString for action with a label", "enable test label in WComponentGroup([MyTarget, MyTarget, MyTarget])", action.toString());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 5 with WComponentGroup

use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.

the class HideInGroup_Test method testConstructor.

@Test
public void testConstructor() {
    SubordinateTarget target = new MyTarget();
    WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
    HideInGroup action = new HideInGroup(target, group);
    Assert.assertEquals("Value for HideIn should be true", Boolean.TRUE, action.getValue());
    Assert.assertEquals("Target for HideIn should be the group", group, action.getTarget());
    Assert.assertEquals("TargetInGroup for HideIn should be the target", target, action.getTargetInGroup());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Test(org.junit.Test)

Aggregations

WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)34 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)30 Test (org.junit.Test)30 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)12 WTextField (com.github.bordertech.wcomponents.WTextField)12 WContainer (com.github.bordertech.wcomponents.WContainer)10 Equal (com.github.bordertech.wcomponents.subordinate.Equal)9 Rule (com.github.bordertech.wcomponents.subordinate.Rule)9 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)9 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)7 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)7 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)7 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)6 WLabel (com.github.bordertech.wcomponents.WLabel)5 Hide (com.github.bordertech.wcomponents.subordinate.Hide)4 WButton (com.github.bordertech.wcomponents.WButton)3 Show (com.github.bordertech.wcomponents.subordinate.Show)3 WComponent (com.github.bordertech.wcomponents.WComponent)2 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)2 Disable (com.github.bordertech.wcomponents.subordinate.Disable)2