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);
}
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);
}
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());
}
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();
}
}
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);
}
}
}
Aggregations