Search in sources :

Example 1 with SubordinateTarget

use of com.github.bordertech.wcomponents.SubordinateTarget 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 SubordinateTarget

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

the class AbstractAction_Test method testConstructor.

@Test
public void testConstructor() {
    SubordinateTarget target = new MyTarget();
    Object value = new Object();
    AbstractAction action = new MyAction(target, value);
    Assert.assertEquals("Incorrect Target returned", target, action.getTarget());
    Assert.assertEquals("Incorrect Value returned", value, action.getValue());
    // Null target
    try {
        action = new MyAction(null, new MyTarget());
        Assert.fail("Null target should have thrown an exception");
    } catch (IllegalArgumentException e) {
        Assert.assertNotNull("Exception should have a message", e.getMessage());
    }
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Test(org.junit.Test)

Example 3 with SubordinateTarget

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

the class AbstractSetMandatory_Test method testExecute.

@Test
public void testExecute() {
    // ---------------------
    // Valid Target (WInput) and TRUE Boolean Value
    SubordinateTarget target1 = new MyTarget();
    AbstractSetMandatory mandatory = new MyMandatory(target1, Boolean.TRUE);
    // Should be mandatory
    mandatory.execute();
    Assert.assertTrue("Target (Mandatable) should be mandatory", ((Mandatable) target1).isMandatory());
    // FALSE Boolean Value
    mandatory = new MyMandatory(target1, Boolean.FALSE);
    // Should not be mandatory
    mandatory.execute();
    Assert.assertFalse("Target (Mandatable) should not be mandatory", ((Mandatable) target1).isMandatory());
    // ---------------------
    // Valid Target (WField) and TRUE Boolean Value
    Input textArea = new WTextArea();
    WField target2 = new WFieldLayout().addField("test", textArea);
    mandatory = new MyMandatory(target2, Boolean.TRUE);
    // Should be mandatory
    mandatory.execute();
    Assert.assertTrue("Target (WField) should be mandatory", textArea.isMandatory());
    // FALSE Boolean Value
    mandatory = new MyMandatory(target2, Boolean.FALSE);
    // Should not be mandatory
    mandatory.execute();
    Assert.assertFalse("Target (WField) should not be mandatory", textArea.isMandatory());
    // ---------------------
    // Valid Target (WFieldSet) and TRUE Boolean Value
    WFieldSet target3 = new WFieldSet("Test");
    mandatory = new MyMandatory(target3, Boolean.TRUE);
    // Should be mandatory
    mandatory.execute();
    Assert.assertTrue("Target (WFieldSet) should be mandatory", target3.isMandatory());
    // FALSE Boolean Value
    mandatory = new MyMandatory(target3, Boolean.FALSE);
    // Should not be mandatory
    mandatory.execute();
    Assert.assertFalse("Target (WFieldSet) should not be mandatory", target3.isMandatory());
    // ---------------------
    // Invalid Target (Cannot be set Mandatory) and Boolean Value
    MyInvalidTarget target4 = new MyInvalidTarget();
    mandatory = new MyMandatory(target4, Boolean.TRUE);
    // Should do nothing
    mandatory.execute();
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Input(com.github.bordertech.wcomponents.Input) WField(com.github.bordertech.wcomponents.WField) WFieldSet(com.github.bordertech.wcomponents.WFieldSet) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Test(org.junit.Test)

Example 4 with SubordinateTarget

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

the class AbstractSetVisible_Test method testExecute.

@Test
public void testExecute() {
    // ----------------------
    // Valid Target and FALSE Boolean Value
    SubordinateTarget target = new MyTarget();
    AbstractSetVisible visible = new MyVisible(target, Boolean.FALSE);
    // Execute Action
    visible.execute();
    // Should be hidden
    Assert.assertTrue("Target should be hidden", target.isHidden());
    // Should be visible
    Assert.assertTrue("Target should be visible", target.isVisible());
    // Should be not validate
    Assert.assertFalse("Target should not be validate", target.isValidate());
    // ----------------------
    // Valid Target and TRUE Boolean Value
    target = new MyTarget();
    visible = new MyVisible(target, Boolean.TRUE);
    setFlag((MyTarget) target, ComponentModel.HIDE_FLAG, true);
    // Execute Action
    visible.execute();
    // Should be not hidden
    Assert.assertFalse("Target should not be hidden", target.isHidden());
    // Should be visible
    Assert.assertTrue("Target should be visible", target.isVisible());
    // Should be validate
    Assert.assertTrue("Target should not be validate", target.isValidate());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Test(org.junit.Test)

Example 5 with SubordinateTarget

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

the class AbstractSetVisible_Test method testConstructor.

@Test
public void testConstructor() {
    SubordinateTarget target = new MyTarget();
    Boolean value = Boolean.TRUE;
    // Constructor - 1
    AbstractSetVisible visible = new MyVisible(target, value);
    Assert.assertEquals("Incorrect target returned", target, visible.getTarget());
    Assert.assertEquals("Incorrect value returned", value, visible.getValue());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Test(org.junit.Test)

Aggregations

SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)57 Test (org.junit.Test)53 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)30 WTextField (com.github.bordertech.wcomponents.WTextField)21 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)18 Equal (com.github.bordertech.wcomponents.subordinate.Equal)17 Rule (com.github.bordertech.wcomponents.subordinate.Rule)17 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)17 WContainer (com.github.bordertech.wcomponents.WContainer)15 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)15 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)15 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)15 Hide (com.github.bordertech.wcomponents.subordinate.Hide)12 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)11 Show (com.github.bordertech.wcomponents.subordinate.Show)11 WLabel (com.github.bordertech.wcomponents.WLabel)5 Condition (com.github.bordertech.wcomponents.subordinate.Condition)5 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)3 And (com.github.bordertech.wcomponents.subordinate.And)3 Disable (com.github.bordertech.wcomponents.subordinate.Disable)3