Search in sources :

Example 1 with WStyledText

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

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

the class WStyledTextRenderer method doRender.

/**
 * Paints the given WStyledText.
 *
 * @param component the WStyledText to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WStyledText text = (WStyledText) component;
    XmlStringBuilder xml = renderContext.getWriter();
    String textString = text.getText();
    if (textString != null && textString.length() > 0) {
        xml.appendTagOpen("ui:text");
        xml.appendOptionalAttribute("class", component.getHtmlClass());
        switch(text.getType()) {
            case EMPHASISED:
                xml.appendAttribute("type", "emphasised");
                break;
            case HIGH_PRIORITY:
                xml.appendAttribute("type", "highPriority");
                break;
            case LOW_PRIORITY:
                xml.appendAttribute("type", "lowPriority");
                break;
            case MEDIUM_PRIORITY:
                xml.appendAttribute("type", "mediumPriority");
                break;
            case ACTIVE_INDICATOR:
                xml.appendAttribute("type", "activeIndicator");
                break;
            case MATCH_INDICATOR:
                xml.appendAttribute("type", "matchIndicator");
                break;
            case INSERT:
                xml.appendAttribute("type", "insert");
                break;
            case DELETE:
                xml.appendAttribute("type", "delete");
                break;
            case MANDATORY_INDICATOR:
                xml.appendAttribute("type", "mandatoryIndicator");
                break;
            case PLAIN:
            default:
                xml.appendAttribute("type", "plain");
                break;
        }
        switch(text.getWhitespaceMode()) {
            case PARAGRAPHS:
                xml.appendAttribute("space", "paragraphs");
                break;
            case PRESERVE:
                xml.appendAttribute("space", "preserve");
                break;
            case DEFAULT:
                break;
            default:
                throw new IllegalArgumentException("Unknown white space mode: " + text.getWhitespaceMode());
        }
        xml.appendClose();
        if (WStyledText.WhitespaceMode.PARAGRAPHS.equals(text.getWhitespaceMode())) {
            textString = text.isEncodeText() ? WebUtilities.encode(textString) : HtmlToXMLUtil.unescapeToXML(textString);
            writeParagraphs(textString, xml);
        } else {
            xml.append(textString, text.isEncodeText());
        }
        xml.appendEndTag("ui:text");
    }
}
Also used : WStyledText(com.github.bordertech.wcomponents.WStyledText) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 3 with WStyledText

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

the class WStyledTextRenderer_Test method testPaint.

@Test
public void testPaint() throws IOException, SAXException, XpathException {
    String text = "WStyledText_Test.testRenderedFormat.text";
    WStyledText styledText = new WStyledText(text);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='plain']", styledText);
    styledText = new WStyledText(text, WStyledText.Type.PLAIN);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='plain']", styledText);
    styledText = new WStyledText(text, WStyledText.Type.EMPHASISED);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='emphasised']", styledText);
    styledText = new WStyledText(text, WStyledText.Type.HIGH_PRIORITY);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='highPriority']", styledText);
    styledText = new WStyledText(text, WStyledText.Type.LOW_PRIORITY);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='lowPriority']", styledText);
    styledText = new WStyledText(text, WStyledText.Type.MEDIUM_PRIORITY);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='mediumPriority']", styledText);
    styledText = new WStyledText(text, WStyledText.Type.ACTIVE_INDICATOR);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='activeIndicator']", styledText);
    styledText = new WStyledText(text, WStyledText.Type.MATCH_INDICATOR);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='matchIndicator']", styledText);
    styledText = new WStyledText(text, WStyledText.Type.INSERT);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='insert']", styledText);
    styledText = new WStyledText(text, WStyledText.Type.DELETE);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='delete']", styledText);
    styledText = new WStyledText(text, WStyledText.Type.MANDATORY_INDICATOR);
    assertSchemaMatch(styledText);
    assertXpathEvaluatesTo(text, "//ui:text[@type='mandatoryIndicator']", styledText);
    // Check null / empty strings
    styledText = new WStyledText(null, WStyledText.Type.MATCH_INDICATOR);
    assertXpathNotExists("//ui:text", styledText);
    styledText = new WStyledText("", WStyledText.Type.MATCH_INDICATOR);
    assertXpathNotExists("//ui:text", styledText);
}
Also used : WStyledText(com.github.bordertech.wcomponents.WStyledText) Test(org.junit.Test)

Example 4 with WStyledText

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

the class WStyledTextRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WStyledText styledText = new WStyledText(getMaliciousContent());
    assertSafeContent(styledText);
    styledText.setToolTip(getMaliciousAttribute("ui:textfield"));
    assertSafeContent(styledText);
    styledText.setAccessibleText(getMaliciousAttribute("ui:textfield"));
    assertSafeContent(styledText);
    styledText.setWhitespaceMode(WStyledText.WhitespaceMode.PRESERVE);
    assertSafeContent(styledText);
    styledText.setWhitespaceMode(WStyledText.WhitespaceMode.PARAGRAPHS);
    assertSafeContent(styledText);
}
Also used : WStyledText(com.github.bordertech.wcomponents.WStyledText) Test(org.junit.Test)

Example 5 with WStyledText

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

the class WStyledTextRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WStyledText component = new WStyledText();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WStyledTextRenderer);
}
Also used : WStyledText(com.github.bordertech.wcomponents.WStyledText) Test(org.junit.Test)

Aggregations

WStyledText (com.github.bordertech.wcomponents.WStyledText)7 Test (org.junit.Test)4 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)2 Equal (com.github.bordertech.wcomponents.subordinate.Equal)2 Rule (com.github.bordertech.wcomponents.subordinate.Rule)2 Action (com.github.bordertech.wcomponents.Action)1 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)1 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)1 WButton (com.github.bordertech.wcomponents.WButton)1 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)1 WDropdown (com.github.bordertech.wcomponents.WDropdown)1 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)1 WPanel (com.github.bordertech.wcomponents.WPanel)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 Hide (com.github.bordertech.wcomponents.subordinate.Hide)1 ShowInGroup (com.github.bordertech.wcomponents.subordinate.ShowInGroup)1 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)1 ArrayList (java.util.ArrayList)1