use of com.github.bordertech.wcomponents.WDefinitionList in project wcomponents by BorderTech.
the class WDefinitionListRenderer method doRender.
/**
* Paints the given definition list.
*
* @param component the list to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WDefinitionList list = (WDefinitionList) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:definitionlist");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
switch(list.getType()) {
case FLAT:
xml.appendAttribute("type", "flat");
break;
case COLUMN:
xml.appendAttribute("type", "column");
break;
case STACKED:
xml.appendAttribute("type", "stacked");
break;
case NORMAL:
break;
default:
throw new SystemException("Unknown layout type: " + list.getType());
}
xml.appendClose();
// Render margin
MarginRendererUtil.renderMargin(list, renderContext);
for (Duplet<String, ArrayList<WComponent>> term : list.getTerms()) {
xml.appendTagOpen("ui:term");
xml.appendAttribute("text", I18nUtilities.format(null, term.getFirst()));
xml.appendClose();
for (WComponent data : term.getSecond()) {
xml.appendTag("ui:data");
data.paint(renderContext);
xml.appendEndTag("ui:data");
}
xml.appendEndTag("ui:term");
}
xml.appendEndTag("ui:definitionlist");
}
use of com.github.bordertech.wcomponents.WDefinitionList in project wcomponents by BorderTech.
the class ExampleSection method selectExample.
/**
* Selects an example.
*
* @param example the example to select.
* @param exampleName the name of the example being selected.
*/
public void selectExample(final WComponent example, final String exampleName) {
WComponent currentExample = container.getChildAt(0).getParent();
if (currentExample != null && currentExample.getClass().equals(example.getClass())) {
// Same example selected, do nothing
return;
}
resetExample();
container.removeAll();
this.getDecoratedLabel().setBody(new WText(exampleName));
WApplication app = WebUtilities.getAncestorOfClass(WApplication.class, this);
if (app != null) {
app.setTitle(exampleName);
}
if (example instanceof ErrorComponent) {
tabset.getTab(0).setText("Error");
source.setSource(null);
} else {
String className = example.getClass().getName();
WDefinitionList list = new WDefinitionList(WDefinitionList.Type.COLUMN);
container.add(list);
list.addTerm("Example path", new WText(className.replaceAll("\\.", " / ")));
list.addTerm("Example JavaDoc", new JavaDocText(getSource(className)));
container.add(new WHorizontalRule());
tabset.getTab(0).setText(example.getClass().getSimpleName());
source.setSource(getSource(className));
}
container.add(example);
example.setLocked(true);
}
use of com.github.bordertech.wcomponents.WDefinitionList in project wcomponents by BorderTech.
the class WDefinitionListRenderer_Test method testRenderedFormat.
@Test
public void testRenderedFormat() throws IOException, SAXException, XpathException {
final String term1 = "WDefinitionListRenderer_Test.testRenderedFormat.term1";
final String term2 = "WDefinitionListRenderer_Test.testRenderedFormat.term2";
final String term3 = "WDefinitionListRenderer_Test.testRenderedFormat.term3";
final String text1 = "WDefinitionListRenderer_Test.testRenderedFormat.text1";
final String text2 = "WDefinitionListRenderer_Test.testRenderedFormat.text2";
final String text3 = "WDefinitionListRenderer_Test.testRenderedFormat.text3";
final String text4 = "WDefinitionListRenderer_Test.testRenderedFormat.text3";
WDefinitionList list = new WDefinitionList();
assertSchemaMatch(list);
assertXpathNotExists("//ui:definitionlist/ui:term", list);
assertXpathNotExists("//ui:definitionlist/@type", list);
list.setType(WDefinitionList.Type.STACKED);
list.addTerm(term1, new WText(text1));
assertSchemaMatch(list);
assertXpathEvaluatesTo("stacked", "//ui:definitionlist/@type", list);
assertXpathEvaluatesTo("1", "count(//ui:definitionlist/ui:term)", list);
assertXpathEvaluatesTo(term1, "//ui:definitionlist/ui:term/@text", list);
assertXpathEvaluatesTo("1", "count(//ui:definitionlist/ui:term/ui:data)", list);
assertXpathEvaluatesTo(text1, "normalize-space(//ui:definitionlist/ui:term/ui:data)", list);
list.addTerm(term1, new WText(text2));
list.setType(WDefinitionList.Type.COLUMN);
assertSchemaMatch(list);
assertXpathEvaluatesTo("column", "//ui:definitionlist/@type", list);
assertXpathEvaluatesTo("1", "count(//ui:definitionlist/ui:term)", list);
assertXpathEvaluatesTo(term1, "//ui:definitionlist/ui:term/@text", list);
assertXpathEvaluatesTo("2", "count(//ui:definitionlist/ui:term/ui:data)", list);
assertXpathEvaluatesTo(text1, "normalize-space(//ui:definitionlist/ui:term/ui:data[1])", list);
assertXpathEvaluatesTo(text2, "normalize-space(//ui:definitionlist/ui:term/ui:data[2])", list);
list.addTerm(term2, new WText(text3));
list.setType(WDefinitionList.Type.FLAT);
assertSchemaMatch(list);
assertXpathEvaluatesTo("flat", "//ui:definitionlist/@type", list);
assertXpathEvaluatesTo("2", "count(//ui:definitionlist/ui:term)", list);
assertXpathEvaluatesTo(term1, "//ui:definitionlist/ui:term[1]/@text", list);
assertXpathEvaluatesTo("2", "count(//ui:definitionlist/ui:term[1]/ui:data)", list);
assertXpathEvaluatesTo(text1, "normalize-space(//ui:definitionlist/ui:term[1]/ui:data[1])", list);
assertXpathEvaluatesTo(text2, "normalize-space(//ui:definitionlist/ui:term[1]/ui:data[2])", list);
assertXpathEvaluatesTo(term2, "//ui:definitionlist/ui:term[2]/@text", list);
assertXpathEvaluatesTo("1", "count(//ui:definitionlist/ui:term[2]/ui:data)", list);
assertXpathEvaluatesTo(text3, "normalize-space(//ui:definitionlist/ui:term[2]/ui:data[1])", list);
list.addTerm(term3, new WText(text4));
assertSchemaMatch(list);
assertXpathEvaluatesTo("3", "count(//ui:definitionlist/ui:term)", list);
assertXpathEvaluatesTo(term1, "//ui:definitionlist/ui:term[1]/@text", list);
assertXpathEvaluatesTo("2", "count(//ui:definitionlist/ui:term[1]/ui:data)", list);
assertXpathEvaluatesTo(text1, "normalize-space(//ui:definitionlist/ui:term[1]/ui:data[1])", list);
assertXpathEvaluatesTo(text2, "normalize-space(//ui:definitionlist/ui:term[1]/ui:data[2])", list);
assertXpathEvaluatesTo(term2, "//ui:definitionlist/ui:term[2]/@text", list);
assertXpathEvaluatesTo("1", "count(//ui:definitionlist/ui:term[2]/ui:data)", list);
assertXpathEvaluatesTo(text3, "normalize-space(//ui:definitionlist/ui:term[2]/ui:data[1])", list);
assertXpathEvaluatesTo("1", "count(//ui:definitionlist/ui:term[3]/ui:data)", list);
assertXpathEvaluatesTo(text4, "normalize-space(//ui:definitionlist/ui:term[3]/ui:data[1])", list);
}
use of com.github.bordertech.wcomponents.WDefinitionList in project wcomponents by BorderTech.
the class WDefinitionListRenderer_Test method testRendererCorrectlyConfigured.
@Test
public void testRendererCorrectlyConfigured() {
WDefinitionList list = new WDefinitionList();
Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(list) instanceof WDefinitionListRenderer);
}
use of com.github.bordertech.wcomponents.WDefinitionList in project wcomponents by BorderTech.
the class WDefinitionListRenderer_Test method testRenderedWithMargins.
@Test
public void testRenderedWithMargins() throws IOException, SAXException, XpathException {
WDefinitionList section = new WDefinitionList();
assertXpathNotExists("//ui:definitionlist/ui:margin", section);
Margin margin = new Margin(0);
section.setMargin(margin);
assertXpathNotExists("//ui:definitionlist/ui:margin", section);
margin = new Margin(Size.SMALL);
section.setMargin(margin);
assertSchemaMatch(section);
assertXpathEvaluatesTo("sm", "//ui:definitionlist/ui:margin/@all", section);
assertXpathEvaluatesTo("", "//ui:definitionlist/ui:margin/@north", section);
assertXpathEvaluatesTo("", "//ui:definitionlist/ui:margin/@east", section);
assertXpathEvaluatesTo("", "//ui:definitionlist/ui:margin/@south", section);
assertXpathEvaluatesTo("", "//ui:definitionlist/ui:margin/@west", section);
margin = new Margin(Size.SMALL, Size.MEDIUM, Size.LARGE, Size.XL);
section.setMargin(margin);
assertSchemaMatch(section);
assertXpathEvaluatesTo("", "//ui:definitionlist/ui:margin/@all", section);
assertXpathEvaluatesTo("sm", "//ui:definitionlist/ui:margin/@north", section);
assertXpathEvaluatesTo("med", "//ui:definitionlist/ui:margin/@east", section);
assertXpathEvaluatesTo("lg", "//ui:definitionlist/ui:margin/@south", section);
assertXpathEvaluatesTo("xl", "//ui:definitionlist/ui:margin/@west", section);
}
Aggregations