Search in sources :

Example 26 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SeleniumWMultiDropdownWebElement method switchOption.

/**
 * Change a selected option from one value to another.
 * @param fromText the current selected text
 * @param toText the text to select
 */
public void switchOption(final String fromText, final String toText) {
    if (isReadOnly()) {
        throw new SystemException("Cannot switch selection from a read-only WMultiDropdown");
    }
    WebElement dropdown = getDropdown(fromText);
    Select se = new Select(dropdown);
    se.selectByVisibleText(toText);
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) Select(org.openqa.selenium.support.ui.Select) WebElement(org.openqa.selenium.WebElement)

Example 27 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SeleniumWMultiDropdownWebElement method getRemoveButton.

/**
 * @param dropdown the WebElement representing the dropdown which will be removed if the remove button is invoked
 * @return the remove button for the dropdown
 */
public WebElement getRemoveButton(final WebElement dropdown) {
    if (isReadOnly()) {
        throw new SystemException("Cannot get remove button from a read-only WMultiDropdown");
    }
    if (dropdown == null) {
        throw new IllegalArgumentException("Cannot get remove button without a reference dropdown");
    }
    String id = dropdown.getAttribute("id");
    WebElement firstOption = getFirstDropdown();
    if (id.equals(firstOption.getAttribute("id"))) {
        throw new SystemException("Cannot get remove button for the first option");
    }
    String cssSelector = "button[aria-controls='" + id + "']";
    return findElementImmediate(By.cssSelector(cssSelector));
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) WebElement(org.openqa.selenium.WebElement)

Example 28 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SeleniumWMultiDropdownWebElement method select.

/**
 * Select an option using its visible text.
 * @param optionText the text of the option to select
 */
public void select(final String optionText) {
    if (isReadOnly()) {
        throw new SystemException("Cannot select from a read-only WMultiDropdown");
    }
    clickButton(getAddButton(), true);
    Select se = new Select(getFirstDropdown());
    se.selectByVisibleText(optionText);
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) Select(org.openqa.selenium.support.ui.Select)

Example 29 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class WSubordinateControlRenderer method paintCondition.

/**
 * Paints a condition.
 *
 * @param condition the condition to paint.
 * @param xml the writer to send the output to
 */
private void paintCondition(final Condition condition, final XmlStringBuilder xml) {
    if (condition instanceof And) {
        xml.appendTag("ui:and");
        for (Condition operand : ((And) condition).getConditions()) {
            paintCondition(operand, xml);
        }
        xml.appendEndTag("ui:and");
    } else if (condition instanceof Or) {
        xml.appendTag("ui:or");
        for (Condition operand : ((Or) condition).getConditions()) {
            paintCondition(operand, xml);
        }
        xml.appendEndTag("ui:or");
    } else if (condition instanceof Not) {
        xml.appendTag("ui:not");
        paintCondition(((Not) condition).getCondition(), xml);
        xml.appendEndTag("ui:not");
    } else if (condition instanceof AbstractCompare) {
        AbstractCompare compare = (AbstractCompare) condition;
        xml.appendTagOpen("ui:condition");
        xml.appendAttribute("controller", compare.getTrigger().getId());
        xml.appendAttribute("value", compare.getComparePaintValue());
        xml.appendOptionalAttribute("operator", getCompareTypeName(compare.getCompareType()));
        xml.appendEnd();
    } else {
        throw new SystemException("Unknown condition: " + condition);
    }
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) AbstractCompare(com.github.bordertech.wcomponents.subordinate.AbstractCompare) Not(com.github.bordertech.wcomponents.subordinate.Not) Or(com.github.bordertech.wcomponents.subordinate.Or) SystemException(com.github.bordertech.wcomponents.util.SystemException) And(com.github.bordertech.wcomponents.subordinate.And)

Example 30 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class WDataTableRenderer method paintPaginationElement.

/**
 * Paint the pagination aspects of the WDataTable.
 * @param table the WDataTable being rendered
 * @param xml the string builder in use
 */
private void paintPaginationElement(final WDataTable table, final XmlStringBuilder xml) {
    TableDataModel model = table.getDataModel();
    xml.appendTagOpen("ui:pagination");
    if (model instanceof TreeTableDataModel) {
        // For tree tables, we only include top-level nodes for pagination.
        TreeNode firstNode = ((TreeTableDataModel) model).getNodeAtLine(0);
        xml.appendAttribute("rows", firstNode == null ? 0 : firstNode.getParent().getChildCount());
    } else {
        xml.appendAttribute("rows", model.getRowCount());
    }
    xml.appendAttribute("rowsPerPage", table.getRowsPerPage());
    xml.appendAttribute("currentPage", table.getCurrentPage());
    switch(table.getPaginationMode()) {
        case CLIENT:
            xml.appendAttribute("mode", "client");
            break;
        case DYNAMIC:
        case SERVER:
            xml.appendAttribute("mode", "dynamic");
            break;
        case NONE:
            break;
        default:
            throw new SystemException("Unknown pagination mode: " + table.getPaginationMode());
    }
    xml.appendEnd();
}
Also used : TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) SystemException(com.github.bordertech.wcomponents.util.SystemException) TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeNode(com.github.bordertech.wcomponents.util.TreeNode) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel)

Aggregations

SystemException (com.github.bordertech.wcomponents.util.SystemException)94 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)17 WComponent (com.github.bordertech.wcomponents.WComponent)15 UIContext (com.github.bordertech.wcomponents.UIContext)13 Test (org.junit.Test)12 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 WebElement (org.openqa.selenium.WebElement)9 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 IOException (java.io.IOException)5 Select (org.openqa.selenium.support.ui.Select)5 ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)4 Request (com.github.bordertech.wcomponents.Request)4 InputStream (java.io.InputStream)4 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 Environment (com.github.bordertech.wcomponents.Environment)3 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Date (java.util.Date)3 List (java.util.List)3