use of com.github.bordertech.wcomponents.validation.ValidatingAction in project wcomponents by BorderTech.
the class GridLayoutOptionsExample method getLayoutControls.
/**
* build the list controls field set.
*
* @param errors the error box to be linked to the apply button.
* @return a field set for the controls.
*/
private WFieldSet getLayoutControls(final WValidationErrors errors) {
// Options Layout
WFieldSet fieldSet = new WFieldSet("List configuration");
WFieldLayout layout = new ControlFieldLayout();
fieldSet.add(layout);
// options.
columnCount.setDecimalPlaces(0);
columnCount.setMinValue(0);
columnCount.setNumber(DEFAULT_COLUMN_COUNT);
columnCount.setMandatory(true);
layout.addField("Number of Columns", columnCount);
rowCount.setDecimalPlaces(0);
rowCount.setMinValue(0);
rowCount.setNumber(DEFAULT_ROW_COUNT);
rowCount.setMandatory(true);
layout.addField("Number of Rows", rowCount);
hGap.setDecimalPlaces(0);
hGap.setMinValue(0);
hGap.setNumber(0);
hGap.setMandatory(true);
layout.addField("Horizontal Gap", hGap);
vGap.setDecimalPlaces(0);
vGap.setMinValue(0);
vGap.setNumber(0);
vGap.setMandatory(true);
layout.addField("Vertical Gap", vGap);
boxCount.setDecimalPlaces(0);
boxCount.setMinValue(0);
boxCount.setNumber(DEFAULT_BOX_COUNT);
boxCount.setMandatory(true);
layout.addField("Number of Boxes", boxCount);
layout.addField("Visible", cbVisible);
layout.addField("Allow responsive design", cbResponsive);
// Apply Button
WButton apply = new WButton("Apply");
apply.setAction(new ValidatingAction(errors, this) {
@Override
public void executeOnValid(final ActionEvent event) {
applySettings();
}
});
layout.addField(apply);
fieldSet.add(new WAjaxControl(apply, container));
fieldSet.setMargin(new Margin(null, null, Size.LARGE, null));
return fieldSet;
}
use of com.github.bordertech.wcomponents.validation.ValidatingAction in project wcomponents by BorderTech.
the class ExampleSection method buildUI.
/**
* Add the controls to the section in the right order.
*/
private void buildUI() {
add(messages);
add(tabset);
// add(new AccessibilityWarningContainer());
container.add(new WText("Select an example from the menu"));
// Set a static ID on container and it becomes a de-facto naming context.
container.setIdName("eg");
tabset.addTab(container, "(no selection)", WTabSet.TAB_MODE_CLIENT);
WImage srcImage = new WImage(new ImageResource("/image/text-x-source.png", "View Source"));
srcImage.setCacheKey("srcTabImage");
tabset.addTab(source, new WDecoratedLabel(srcImage), WTabSet.TAB_MODE_LAZY).setToolTip("View Source");
// The refresh current view button.
WButton refreshButton = new WButton("\u200b");
refreshButton.setToolTip("Refresh");
refreshButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-refresh"));
// refreshButton.setImage("/image/refresh-w.png");
refreshButton.setRenderAsLink(true);
refreshButton.setAction(new ValidatingAction(messages.getValidationErrors(), refreshButton) {
@Override
public void executeOnValid(final ActionEvent event) {
// Do Nothing
}
});
// The reset example button.
final WButton resetButton = new WButton("\u200b");
resetButton.setToolTip("Reset");
resetButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-times-circle"));
// resetButton.setImage("/image/cancel-w.png");
resetButton.setRenderAsLink(true);
resetButton.setAction(new ValidatingAction(messages.getValidationErrors(), resetButton) {
@Override
public void executeOnValid(final ActionEvent event) {
resetExample();
}
});
addToTail(refreshButton);
addToTail(new WText("\u2002"));
addToTail(resetButton);
}
use of com.github.bordertech.wcomponents.validation.ValidatingAction in project wcomponents by BorderTech.
the class WButtonRenderer method doRender.
/**
* Paints the given WButton.
*
* @param component the WButton to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
XmlStringBuilder xml = renderContext.getWriter();
WButton button = (WButton) component;
String text = button.getText();
String imageUrl = button.getImageUrl();
String accessibleText = button.getAccessibleText();
String toolTip = button.getToolTip();
if (Util.empty(text) && imageUrl == null && Util.empty(accessibleText) && Util.empty(toolTip)) {
throw new SystemException("WButton text or imageUrl must be specified");
}
xml.appendTagOpen(getTagName(button));
String buttonId = button.getId();
ImagePosition pos = button.getImagePosition();
if (Util.empty(text) && Util.empty(toolTip) && Util.empty(accessibleText)) {
// If the button has an imageUrl but no text equivalent get the text equivalent off of the image
WImage imgHolder = button.getImageHolder();
if (null != imgHolder) {
toolTip = imgHolder.getAlternativeText();
}
}
xml.appendAttribute("id", buttonId);
xml.appendAttribute("name", buttonId);
xml.appendAttribute("value", "x");
xml.appendAttribute("type", getButtonType(button));
xml.appendAttribute("class", geHtmlClassName(button));
xml.appendOptionalAttribute("disabled", button.isDisabled(), "disabled");
xml.appendOptionalAttribute("hidden", button.isHidden(), "hidden");
xml.appendOptionalAttribute("title", toolTip);
xml.appendOptionalAttribute("aria-label", accessibleText);
xml.appendOptionalAttribute("aria-haspopup", button.isPopupTrigger(), "true");
xml.appendOptionalAttribute("accesskey", Util.upperCase(button.getAccessKeyAsString()));
xml.appendOptionalAttribute("data-wc-btnmsg", button.getMessage());
if (button.isCancel()) {
xml.appendAttribute("formnovalidate", "formnovalidate");
} else {
Action action = button.getAction();
if (action instanceof ValidatingAction) {
WComponent validationTarget = ((ValidatingAction) action).getComponentToValidate();
xml.appendAttribute("data-wc-validate", validationTarget.getId());
}
}
xml.appendClose();
if (imageUrl != null) {
xml.appendTagOpen("span");
String imageHolderClass = "wc_nti";
if (pos != null) {
StringBuffer imageHolderClassBuffer = new StringBuffer("wc_btn_img wc_btn_img");
switch(pos) {
case NORTH:
imageHolderClassBuffer.append("n");
break;
case EAST:
imageHolderClassBuffer.append("e");
break;
case SOUTH:
imageHolderClassBuffer.append("s");
break;
case WEST:
imageHolderClassBuffer.append("w");
break;
default:
throw new SystemException("Unknown image position: " + pos);
}
imageHolderClass = imageHolderClassBuffer.toString();
}
xml.appendAttribute("class", imageHolderClass);
xml.appendClose();
if (pos != null && text != null) {
xml.appendTag("span");
xml.appendEscaped(text);
xml.appendEndTag("span");
}
xml.appendTagOpen("img");
xml.appendUrlAttribute("src", imageUrl);
String alternateText = pos == null ? text : "";
xml.appendAttribute("alt", alternateText);
xml.appendEnd();
xml.appendEndTag("span");
} else if (text != null) {
xml.appendEscaped(text);
}
xml.appendEndTag(getTagName(button));
if (button.isAjax()) {
paintAjax(button, xml);
}
}
Aggregations