Search in sources :

Example 51 with SystemException

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

the class SeleniumWMultiDropdownWebElement method deselect.

/**
 * Deselect the option with given text.
 *
 * @param optionText the text of the option to deselect
 */
public void deselect(final String optionText) {
    if (isReadOnly()) {
        throw new SystemException("Cannot deselect option from a read-only WMultiDropdown");
    }
    if (optionText == null) {
        throw new IllegalArgumentException("Cannot deselect option without the option text");
    }
    WebElement dropdown = getDropdown(optionText);
    WebElement removeButton = getRemoveButton(dropdown);
    clickButton(removeButton, false);
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) WebElement(org.openqa.selenium.WebElement)

Example 52 with SystemException

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

the class SeleniumWMultiDropdownWebElement method switchFirstOption.

/**
 * Set a new selection in the first dropdown in a WMultiDropdown using visible option text. Convenient for setting a single selection.
 * @param toText the visible text of the option to select
 */
public void switchFirstOption(final String toText) {
    if (isReadOnly()) {
        throw new SystemException("Cannot switch selection from a read-only WMultiDropdown");
    }
    WebElement dropdown = getFirstDropdown();
    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 53 with SystemException

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

the class SeleniumWMultiDropdownWebElement method deselectAll.

/**
 * Deselect "all" options. A slight misnomer as the first dropdown will end up with its the first option selected.
 */
public void deselectAll() {
    if (isReadOnly()) {
        throw new SystemException("Cannot deselect all from a read-only WMultiDropdown");
    }
    List<WebElement> dropdowns = getDropdowns();
    if (dropdowns.isEmpty()) {
        // really should not be here but tehre is nothing to do
        LOG.warn("Found an editable WMultiDropdown with no select elements");
        return;
    }
    WebElement dropdown = getFirstDropdown();
    Select se = new Select(dropdown);
    se.selectByIndex(0);
    if (dropdowns.size() == 1) {
        // finished
        return;
    }
    // to remove all the other options shift-click any delete button
    WebElement removeButton = getRemoveButton(dropdowns.get(1));
    WebDriver driver = getDriver();
    if (driver instanceof HasInputDevices) {
        Actions shiftClick = new Actions(driver);
        shiftClick.keyDown(Keys.SHIFT).click(removeButton).keyUp(Keys.SHIFT).perform();
    } else {
        removeButton.sendKeys(Keys.chord(Keys.SHIFT, Keys.SPACE));
    }
    SeleniumWComponentsUtil.waitForPageReady(getDriver());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) SystemException(com.github.bordertech.wcomponents.util.SystemException) HasInputDevices(org.openqa.selenium.interactions.HasInputDevices) Actions(org.openqa.selenium.interactions.Actions) Select(org.openqa.selenium.support.ui.Select) WebElement(org.openqa.selenium.WebElement)

Example 54 with SystemException

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

the class WComponentRenderPerfTest method runRenderTest.

/**
 * Runs the render test.
 */
private static void runRenderTest() {
    UIContextImpl uic = new UIContextImpl();
    PrintWriter printWriter = new PrintWriter(new NullWriter());
    RenderContext renderContext = new WebXmlRenderContext(printWriter);
    WComponent component = null;
    long baseLineMemory = getHeapUsed();
    try {
        component = (WComponent) Class.forName(CLASS_TO_TEST).newInstance();
    } catch (Exception e) {
        String msg = "Unable to instantiate test component: " + CLASS_TO_TEST;
        LOG.error(LINE_PREFIX + msg);
        throw new SystemException(msg, e);
    }
    long memBeforePaint = getHeapUsed() - baseLineMemory;
    // Set up velocity etc. to obtain a memory reading, and
    // so that the performance results aren't skewed too much
    UIContextHolder.pushContext(uic);
    try {
        component.paint(renderContext);
        long memAfterOnePaint = getHeapUsed() - baseLineMemory;
        long startTime = System.currentTimeMillis();
        // Figure out the loop overhead
        for (int i = 0; i < NUM_RENDERS; i++) {
        }
        long loopOverhead = System.currentTimeMillis() - startTime;
        startTime = System.currentTimeMillis();
        // Now run the render test
        for (int i = 0; i < NUM_RENDERS; i++) {
            component.paint(renderContext);
        }
        long elapsedTime = System.currentTimeMillis() - startTime - loopOverhead;
        long memAfterAllPaints = getHeapUsed() - baseLineMemory;
        LOG.info(LINE_PREFIX + "Memory use before paint: " + memBeforePaint);
        LOG.info(LINE_PREFIX + "Memory use after 1 paint: " + memAfterOnePaint);
        LOG.info(LINE_PREFIX + "Memory use after " + NUM_RENDERS + " paints: " + memAfterAllPaints);
        LOG.info(LINE_PREFIX + "Render time: " + (elapsedTime / (double) NUM_RENDERS) + "ms");
        Object[] treeAndSession = new Object[] { component, uic };
        ObjectGraphNode root = ObjectGraphDump.dump(treeAndSession);
        LOG.info(LINE_PREFIX + "Component mem use: " + ((ObjectGraphNode) root.getChildAt(0)).getSize());
        LOG.info(LINE_PREFIX + "UIC mem use: " + ((ObjectGraphNode) root.getChildAt(1)).getSize());
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) IOException(java.io.IOException) SystemException(com.github.bordertech.wcomponents.util.SystemException) WComponent(com.github.bordertech.wcomponents.WComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) ObjectGraphNode(com.github.bordertech.wcomponents.util.ObjectGraphNode) PrintWriter(java.io.PrintWriter)

Example 55 with SystemException

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

the class SafetyContainer method handleRequest.

/**
 * Override handleRequest in order to safely process the example component, which has been excluded from normal
 * WComponent processing.
 *
 * @param request the request being responded to.
 */
@Override
public void handleRequest(final Request request) {
    if (!isInitialised()) {
        getOrCreateComponentModel().delegate = new SafetyContainerDelegate(UIContextHolder.getCurrent());
        setInitialised(true);
    }
    try {
        UIContext delegate = getComponentModel().delegate;
        UIContextHolder.pushContext(delegate);
        try {
            for (int i = 0; i < shim.getChildCount(); i++) {
                shim.getChildAt(i).serviceRequest(request);
            }
            delegate.doInvokeLaters();
        } finally {
            UIContextHolder.popContext();
        }
    } catch (final ActionEscape e) {
        // We don't want to catch ActionEscapes (e.g. ForwardExceptions)
        throw e;
    } catch (final Exception e) {
        if (isAjaxOrTargetedRequest(request)) {
            throw new SystemException(e.getMessage(), e);
        } else {
            setAttribute(ERROR_KEY, e);
        }
    }
}
Also used : ActionEscape(com.github.bordertech.wcomponents.ActionEscape) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) SystemException(com.github.bordertech.wcomponents.util.SystemException)

Aggregations

SystemException (com.github.bordertech.wcomponents.util.SystemException)91 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)17 WComponent (com.github.bordertech.wcomponents.WComponent)15 UIContext (com.github.bordertech.wcomponents.UIContext)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 Test (org.junit.Test)9 WebElement (org.openqa.selenium.WebElement)8 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 IOException (java.io.IOException)5 Select (org.openqa.selenium.support.ui.Select)5 Environment (com.github.bordertech.wcomponents.Environment)4 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3 Date (java.util.Date)3 List (java.util.List)3 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)3 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)2 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)2 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)2