use of com.github.bordertech.wcomponents.ActionEvent in project wcomponents by BorderTech.
the class WSuggestionsRenderer_Test method testDoPaintAjaxOptions.
@Test
public void testDoPaintAjaxOptions() throws IOException, SAXException, XpathException {
List<String> options = Arrays.asList("A", "B", "C");
WSuggestions field = new WSuggestions(options);
// Set action for AJAX refresh
field.setRefreshAction(new Action() {
@Override
public void execute(final ActionEvent event) {
// Do nothing
}
});
assertSchemaMatch(field);
assertXpathEvaluatesTo(field.getId(), "//ui:suggestions/@id", field);
assertXpathNotExists("//ui:suggestions/@min", field);
assertXpathNotExists("//ui:suggestions/@data", field);
// AJAX flag should be true
assertXpathEvaluatesTo("true", "//ui:suggestions/@ajax", field);
// Suggestions should only be rendered when refreshed via AJAX
assertXpathNotExists("//ui:suggestions/ui:suggestion", field);
// Setup suggestions as the current AJAX trigger
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
try {
AjaxOperation operation = new AjaxOperation(field.getId(), field.getId());
AjaxHelper.setCurrentOperationDetails(operation, null);
assertSchemaMatch(field);
assertXpathExists("//ui:suggestions/ui:suggestion", field);
assertXpathEvaluatesTo(options.get(0), "//ui:suggestions/ui:suggestion[1]/@value", field);
assertXpathEvaluatesTo(options.get(1), "//ui:suggestions/ui:suggestion[2]/@value", field);
assertXpathEvaluatesTo(options.get(2), "//ui:suggestions/ui:suggestion[3]/@value", field);
} finally {
AjaxHelper.clearCurrentOperationDetails();
}
}
use of com.github.bordertech.wcomponents.ActionEvent in project wcomponents by BorderTech.
the class WButtonRenderer_Test method testAllOptions.
@Test
public void testAllOptions() throws IOException, SAXException, XpathException {
WButton button = new WButton("All");
button.setDisabled(true);
setFlag(button, ComponentModel.HIDE_FLAG, true);
button.setToolTip("Title");
button.setAccessKey('T');
button.setImageUrl("http://localhost/image.png");
button.setImagePosition(ImagePosition.EAST);
button.setRenderAsLink(true);
button.setAjaxTarget(new WTextField());
button.setPopupTrigger(true);
setActiveContext(createUIContext());
WPanel validationComponent = new WPanel();
button.setAction(new ValidatingAction(new WValidationErrors(), validationComponent) {
@Override
public void executeOnValid(final ActionEvent event) {
// Do nothing
}
});
WContainer root = new WContainer();
root.add(button);
root.add(validationComponent);
assertXpathExists("//html:button[@id]", button);
assertXpathExists("//html:button[contains(@class, 'wc-linkbutton')]", button);
assertXpathEvaluatesTo(button.getText(), "//html:button", button);
assertXpathEvaluatesTo("disabled", "//html:button/@disabled", button);
assertXpathEvaluatesTo("hidden", "//html:button/@hidden", button);
assertXpathEvaluatesTo(button.getToolTip(), "//html:button/@title", button);
assertXpathUrlEvaluatesTo(button.getImageUrl(), "//html:button//html:img/@src", button);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imge')]", button);
assertXpathEvaluatesTo(button.getAccessKeyAsString(), "//html:button/@accesskey", button);
assertXpathEvaluatesTo("true", "//html:button/@aria-haspopup", button);
assertXpathEvaluatesTo(validationComponent.getId(), "//html:button/@data-wc-validate", button);
assertXpathEvaluatesTo(button.getId(), "//ui:ajaxtrigger/@triggerId", button);
button.setImagePosition(ImagePosition.NORTH);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgn')]", button);
button.setImagePosition(ImagePosition.SOUTH);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgs')]", button);
button.setImagePosition(ImagePosition.WEST);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgw')]", button);
button.setClientCommandOnly(true);
assertXpathEvaluatesTo("button", "//html:button/@type", button);
}
use of com.github.bordertech.wcomponents.ActionEvent in project wcomponents by BorderTech.
the class ValidatingAction_Test method testExecuteOnError.
@Test
public void testExecuteOnError() {
componentToValidate.setErrorLevel(Diagnostic.ERROR);
Assert.assertEquals("Incorrect validation component returned.", componentToValidate, validatingAction.getComponentToValidate());
validatingAction.execute(new ActionEvent("source", "command"));
Assert.assertTrue("Should have called executeOnError", validatingAction.executeOnErrorExecuted);
Assert.assertFalse("Should not have called executeOnValid", validatingAction.executeOnValidExecuted);
}
use of com.github.bordertech.wcomponents.ActionEvent in project wcomponents by BorderTech.
the class LinkOptionsExample method getButtonControls.
/**
* build the button controls field set.
*
* @param errors the error pane from the page.
* @return a field set for the controls.
*/
private WFieldSet getButtonControls(final WValidationErrors errors) {
// Options Layout
WFieldSet fieldSet = new WFieldSet("Link configuration");
WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(30);
layout.addField("Link text", tfLinkLabel);
layout.addField("Link address", tfUrlField);
layout.addField("Link AccessKey", tfAccesskey).getLabel().setHint("A single upper case letter or digit.");
layout.addField("Render as button", cbRenderAsButton);
layout.addField("Disabled", cbDisabled);
layout.addField("Open in a new window", cbOpenNew);
layout.addField("setImage ('/image/attachment.png')", cbSetImage);
layout.addField("Image Position", ddImagePosition);
layout.setMargin(new com.github.bordertech.wcomponents.Margin(0, 0, 6, 0));
// Apply Button
WButton apply = new WButton("Apply");
apply.setAction(new ValidatingAction(errors, fieldSet) {
@Override
public void executeOnValid(final ActionEvent event) {
applySettings();
}
});
fieldSet.add(layout);
fieldSet.add(apply);
return fieldSet;
}
use of com.github.bordertech.wcomponents.ActionEvent in project wcomponents by BorderTech.
the class SimpleTabs method addTab.
/**
* Adds a tab.
*
* @param card the tab content.
* @param name the tab name.
*/
public void addTab(final WComponent card, final String name) {
WContainer titledCard = new WContainer();
WText title = new WText("<b>[" + name + "]:</b><br/>");
title.setEncodeText(false);
titledCard.add(title);
titledCard.add(card);
deck.add(titledCard);
final TabButton button = new TabButton(name, titledCard);
button.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
deck.makeVisible(button.getAssociatedCard());
}
});
btnPanel.add(button);
}
Aggregations