use of com.github.bordertech.wcomponents.Action in project wcomponents by BorderTech.
the class SubordinateControlInterceptor_Test method testServiceRequestApplyControls.
@Test
public void testServiceRequestApplyControls() {
// Create Target
WButton target = new WButton();
target.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
buttonClicked = true;
}
});
// Create Control - Enable/Disable Button
WCheckBox box = new WCheckBox();
Rule rule = new Rule();
rule.setCondition(new Equal(box, Boolean.TRUE));
rule.addActionOnTrue(new Enable(target));
rule.addActionOnFalse(new Disable(target));
WSubordinateControl control = new WSubordinateControl();
control.addRule(rule);
// Create component tree
WContainer root = new WContainer();
root.add(control);
root.add(box);
root.add(target);
// Setup Intercepter
SubordinateControlInterceptor interceptor = new SubordinateControlInterceptor();
interceptor.setBackingComponent(root);
UIContext uic = createUIContext();
uic.setUI(root);
setActiveContext(uic);
buttonClicked = false;
// Test Service Request - Empty Request and no control registered, so the control should not be applied
MockRequest request = new MockRequest();
interceptor.serviceRequest(request);
// Target should still be enabled (control not applied)
Assert.assertFalse("After service request target should be enabled", target.isDisabled());
// Button not clicked
Assert.assertFalse("Button should not have been clicked", buttonClicked);
// Test Service Request - Try to click button while it is disabled and should not be clicked
target.setDisabled(true);
request.setParameter(target.getId(), "x");
interceptor.serviceRequest(request);
// Target should still be disabled (control not applied, as still not registered)
Assert.assertTrue("After service request target should be disabled", target.isDisabled());
// Button not clicked
Assert.assertFalse("Button should not have been clicked while disabled", buttonClicked);
// Test Prepare Paint - Should register and apply the subordinate control
target.setDisabled(false);
request = new MockRequest();
interceptor.preparePaint(request);
// Target should be disabled (Disabled by control as box is not selected)
Assert.assertTrue("After service request target should be disabled", target.isDisabled());
// Test Service Request - Simulate button click as it was enabled on the client by the check box being selected.
// As the controls have been registered from the Prepare Paint, they will be applied in the Service Request and
// this will enable the button and allow it to be clicked.
buttonClicked = false;
request.setParameter(target.getId(), "x");
setupCheckBoxRequest(box, request, true);
interceptor.serviceRequest(request);
// Target should be enabled (enabled by control as box is selected)
Assert.assertFalse("After service request target should be enabled", target.isDisabled());
// Button should have been clicked
Assert.assertTrue("Button should have been clicked", buttonClicked);
// // Check Subordinate Controls have not been cleared from session
// Assert.assertNotNull("Registered Controls should not have been cleared on the session",
// request.getSessionAttribute(SubordinateControlHelper.SUBORDINATE_CONTROL_SESSION_KEY));
//
// interceptor.preparePaint(request);
//
// // Check Subordinate Controls have been cleared from session
// Assert.assertNull("Registered Controls should have been cleared on the session",
// request.getSessionAttribute(SubordinateControlHelper.SUBORDINATE_CONTROL_SESSION_KEY));
}
use of com.github.bordertech.wcomponents.Action in project wcomponents by BorderTech.
the class WSuggestionsRenderer_Test method testDoPaintLookupTableOptions.
@Test
public void testDoPaintLookupTableOptions() throws IOException, SAXException, XpathException {
WSuggestions field = new WSuggestions(TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE);
assertSchemaMatch(field);
assertXpathEvaluatesTo(field.getId(), "//ui:suggestions/@id", field);
assertXpathNotExists("//ui:suggestions/@ajax", field);
assertXpathNotExists("//ui:suggestions/@min", field);
assertXpathNotExists("//ui:suggestions/suggestion", field);
assertXpathEvaluatesTo(field.getListCacheKey(), "//ui:suggestions/@data", field);
// If action set with a lookup table, AJAX flag should still be not set
field.setRefreshAction(new Action() {
@Override
public void execute(final ActionEvent event) {
// Do nothing
}
});
assertSchemaMatch(field);
assertXpathNotExists("//ui:suggestions/@ajax", field);
}
use of com.github.bordertech.wcomponents.Action 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.Action 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);
}
use of com.github.bordertech.wcomponents.Action in project wcomponents by BorderTech.
the class WRadioButtonTriggerActionExample method setup.
/**
* Add controls to the UI.
*/
private void setup() {
setLayout(new FlowLayout(FlowLayout.VERTICAL));
WFieldSet fset = new WFieldSet("Select a meal");
add(fset);
fset.setMargin(new Margin(null, null, Size.LARGE, null));
WFieldLayout flay = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
fset.add(flay);
flay.setLabelWidth(0);
flay.addField("Breakfast", rb1);
flay.addField("Lunch", rb2);
flay.addField("Dinner", rb3);
/*
* NOTE: you should never use submitOnChange with a WRadioButton
*/
fset.add(new WAjaxControl(mealSelections, textBox));
mealSelections.setActionOnChange(new Action() {
@Override
public void execute(final ActionEvent event) {
String selection = null;
if (rb1.isSelected()) {
selection = "Breakfast selected";
}
if (rb2.isSelected()) {
selection = "Lunch selected";
}
if (rb3.isSelected()) {
selection = "Dinner selected";
}
text1.setText(selection + " : " + (new Date()).toString());
}
});
textBox.add(text1);
add(textBox);
add(mealSelections);
}
Aggregations