@Override public void processChildren(SourcePrinter out, StackMenuContext context) throws CruxGeneratorException { String item = getWidgetCreator().createVariableName("item"); String className = StackMenuItem.class.getCanonicalName(); String label = context.getChildElement().optString("label"); label = getWidgetCreator().resolveI18NString(label); String key = context.getChildElement().optString("key"); key = EscapeUtils.quote(key); out.println(className + " " + item + " = new " + className + "(" + key + ", " + label + ");"); setItemAttributes(out, context, item); String parentWidget = context.itemStack.getFirst(); out.println(parentWidget + ".add(" + item + ");"); context.itemStack.addFirst(item); }
/** * Sets the item attributes before adding it to the parent. * * @param out * @param context * @param item */ private void setItemAttributes(SourcePrinter out, StackMenuContext context, String item) { String open = context.readChildProperty("open"); if (!StringUtils.isEmpty(open)) { out.println(item + ".setOpen(" + Boolean.parseBoolean(open) + ");"); } String style = context.readChildProperty("style"); if (!StringUtils.isEmpty(style)) { if (styleProcessor == null) { styleProcessor = new StyleProcessor(getWidgetCreator()); } styleProcessor.processAttribute(out, context, style); } String styleName = context.readChildProperty("styleName"); if (!StringUtils.isEmpty(styleName)) { out.println(item + ".setStyleName(" + EscapeUtils.quote(styleName) + ");"); } String tooltip = context.readChildProperty("tooltip"); if (!StringUtils.isEmpty(tooltip)) { out.println(item + ".setTitle(" + EscapeUtils.quote(tooltip) + ");"); } }
@Override public void processChildren(SourcePrinter out, StackMenuContext context) throws CruxGeneratorException { context.itemStack.add(context.getWidget()); }