use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class FileWidgetRendererUtil method renderFileElement.
/**
* @param widget the multi file widget
* @param xml the xml string builder
* @param file the file to render
* @param idx the index of the file
*/
public static void renderFileElement(final WMultiFileWidget widget, final XmlStringBuilder xml, final FileWidgetUpload file, final int idx) {
xml.appendTagOpen("ui:file");
xml.appendAttribute("id", file.getFileId());
xml.appendAttribute("name", file.getFile().getName());
xml.appendAttribute("type", file.getFile().getMimeType());
xml.appendAttribute("size", String.valueOf(file.getFile().getSize()));
xml.appendClose();
// Link to file
xml.appendTagOpen("ui:link");
xml.appendAttribute("id", widget.getId() + "-" + idx);
xml.appendUrlAttribute("url", widget.getFileUrl(file.getFileId()));
// Thumb nail (if used)
if (widget.isUseThumbnails()) {
xml.appendUrlAttribute("imageUrl", widget.getFileThumbnailUrl(file.getFileId()));
// Position (if provided)
ImagePosition thumbnailPosition = widget.getThumbnailPosition();
if (thumbnailPosition != null) {
switch(thumbnailPosition) {
case NORTH:
xml.appendAttribute("imagePosition", "n");
break;
case EAST:
xml.appendAttribute("imagePosition", "e");
break;
case SOUTH:
xml.appendAttribute("imagePosition", "s");
break;
case WEST:
xml.appendAttribute("imagePosition", "w");
break;
default:
throw new SystemException("Unknown image position: " + thumbnailPosition);
}
}
}
xml.appendClose();
if (widget.getFileAjaxAction() == null) {
xml.appendTagOpen("ui:windowAttributes");
xml.appendAttribute("name", "uploadfile");
xml.appendEnd();
}
xml.appendEscaped(file.getFile().getName());
xml.appendEndTag("ui:link");
xml.appendEndTag("ui:file");
}
use of com.github.bordertech.wcomponents.util.SystemException 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);
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WCheckBoxSelectRenderer method doRender.
/**
* Paints the given WCheckBoxSelect.
*
* @param component the WCheckBoxSelect to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WCheckBoxSelect select = (WCheckBoxSelect) component;
XmlStringBuilder xml = renderContext.getWriter();
int cols = select.getButtonColumns();
boolean readOnly = select.isReadOnly();
xml.appendTagOpen("ui:checkboxselect");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", select.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
int min = select.getMinSelect();
int max = select.getMaxSelect();
xml.appendOptionalAttribute("disabled", select.isDisabled(), "true");
xml.appendOptionalAttribute("required", select.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", select.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", component.getToolTip());
xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
xml.appendOptionalAttribute("min", min > 0, min);
xml.appendOptionalAttribute("max", max > 0, max);
}
xml.appendOptionalAttribute("frameless", select.isFrameless(), "true");
switch(select.getButtonLayout()) {
case COLUMNS:
xml.appendAttribute("layout", "column");
xml.appendOptionalAttribute("layoutColumnCount", cols > 0, cols);
break;
case FLAT:
xml.appendAttribute("layout", "flat");
break;
case STACKED:
xml.appendAttribute("layout", "stacked");
break;
default:
throw new SystemException("Unknown layout type: " + select.getButtonLayout());
}
xml.appendClose();
// Options
List<?> options = select.getOptions();
boolean renderSelectionsOnly = readOnly;
if (options != null) {
int optionIndex = 0;
List<?> selections = select.getSelected();
for (Object option : options) {
if (option instanceof OptionGroup) {
throw new SystemException("Option groups not supported in WCheckBoxSelect.");
} else {
renderOption(select, option, optionIndex++, xml, selections, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(select, renderContext);
}
xml.appendEndTag("ui:checkboxselect");
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WDataTableRenderer method doRender.
/**
* Paints the given WDataTable.
*
* @param component the WDataTable to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WDataTable table = (WDataTable) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:table");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", table.isHidden(), "true");
xml.appendOptionalAttribute("caption", table.getCaption());
switch(table.getType()) {
case TABLE:
xml.appendAttribute("type", "table");
break;
case HIERARCHIC:
xml.appendAttribute("type", "hierarchic");
break;
default:
throw new SystemException("Unknown table type: " + table.getType());
}
switch(table.getStripingType()) {
case ROWS:
xml.appendAttribute("striping", "rows");
break;
case COLUMNS:
xml.appendAttribute("striping", "cols");
break;
case NONE:
break;
default:
throw new SystemException("Unknown striping type: " + table.getStripingType());
}
switch(table.getSeparatorType()) {
case HORIZONTAL:
xml.appendAttribute("separators", "horizontal");
break;
case VERTICAL:
xml.appendAttribute("separators", "vertical");
break;
case BOTH:
xml.appendAttribute("separators", "both");
break;
case NONE:
break;
default:
throw new SystemException("Unknown separator type: " + table.getSeparatorType());
}
xml.appendClose();
if (table.getPaginationMode() != PaginationMode.NONE) {
paintPaginationElement(table, xml);
}
if (table.getSelectMode() != SelectMode.NONE) {
paintRowSelectionElement(table, xml);
}
if (table.getExpandMode() != ExpandMode.NONE) {
paintRowExpansionElement(table, xml);
}
if (table.isSortable()) {
paintSortElement(table, xml);
}
paintColumnHeadings(table, renderContext);
paintRows(table, renderContext);
paintTableActions(table, renderContext);
xml.appendEndTag("ui:table");
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WRadioButtonSelectRenderer method doRender.
/**
* Paints the given WRadioButtonSelect.
*
* @param component the WRadioButtonSelect to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WRadioButtonSelect rbSelect = (WRadioButtonSelect) component;
XmlStringBuilder xml = renderContext.getWriter();
int cols = rbSelect.getButtonColumns();
boolean readOnly = rbSelect.isReadOnly();
xml.appendTagOpen("ui:radiobuttonselect");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", rbSelect.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
xml.appendOptionalAttribute("disabled", rbSelect.isDisabled(), "true");
xml.appendOptionalAttribute("required", rbSelect.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", rbSelect.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", component.getToolTip());
xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
}
xml.appendOptionalAttribute("frameless", rbSelect.isFrameless(), "true");
switch(rbSelect.getButtonLayout()) {
case COLUMNS:
xml.appendAttribute("layout", "column");
xml.appendOptionalAttribute("layoutColumnCount", cols > 0, String.valueOf(cols));
break;
case FLAT:
xml.appendAttribute("layout", "flat");
break;
case STACKED:
xml.appendAttribute("layout", "stacked");
break;
default:
throw new SystemException("Unknown radio button layout: " + rbSelect.getButtonLayout());
}
xml.appendClose();
// Options
List<?> options = rbSelect.getOptions();
boolean renderSelectionsOnly = readOnly;
if (options != null) {
int optionIndex = 0;
Object selectedOption = rbSelect.getSelected();
for (Object option : options) {
if (option instanceof OptionGroup) {
throw new SystemException("Option groups not supported in WRadioButtonSelect.");
} else {
renderOption(rbSelect, option, optionIndex++, xml, selectedOption, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(rbSelect, renderContext);
}
xml.appendEndTag("ui:radiobuttonselect");
if (rbSelect.isAjax()) {
paintAjax(rbSelect, xml);
}
}
Aggregations