/** * Returns the id of the related field ({@link #relatedField}). * * @return The id of the field that is related to this indicator. */ public String getRelatedFieldId() { return relatedField.getId(); }
/** * Retrieves the user interface that was registered with the given key. If the UI has not been registered, this * attempts to load the UI using the key as a class name. * * @param key the registration key * @return the UI for the given key. The UI may be newly created. */ @Override public synchronized WComponent getUI(final String key) { Object obj = registry.get(key); if (obj == null) { // Looks like we haven't tried loading this UI yet, so do it now. obj = loadUI(key); // Cache the result. // Note that the result could be a flag indicating that no UI could be load for the given key. registry.put(key, obj); if (obj instanceof WComponent) { ((WComponent) obj).setLocked(true); } } if (obj instanceof WComponent) { LOG.debug("Returning cached WComponent. Key=" + key); return (WComponent) obj; } else { return null; } }
/** * Retrieves the top-level WComponent in the tree. * * @param comp the component branch to start from. * @return the top-level WComponent in the tree. */ public static WComponent getTop(final WComponent comp) { WComponent top = comp; for (WComponent parent = top.getParent(); parent != null; parent = parent.getParent()) { top = parent; } return top; }
/** * Renders the given WComponent to a String outside of the context of a Servlet. This is good for getting hold of * the XML for debugging, unit testing etc. Also it is good for using the WComponent framework as a more generic * templating framework. * * @param request the request being responded to. * @param component the root WComponent to render. * @return the rendered output as a String. */ public static String render(final Request request, final WComponent component) { boolean needsContext = UIContextHolder.getCurrent() == null; if (needsContext) { UIContextHolder.pushContext(new UIContextImpl()); } try { StringWriter buffer = new StringWriter(); component.preparePaint(request); try (PrintWriter writer = new PrintWriter(buffer)) { component.paint(new WebXmlRenderContext(writer)); } return buffer.toString(); } finally { if (needsContext) { UIContextHolder.popContext(); } } }
xml.appendAttribute("id", component.getId()); xml.appendOptionalAttribute("class", component.getHtmlClass()); xml.appendOptionalAttribute("track", component.isTracking(), "true"); xml.appendOptionalAttribute("hidden", label.isHidden(), "true"); xml.appendClose(); if (head != null && head.isVisible()) { xml.appendTagOpen("ui:labelhead"); xml.appendAttribute("id", label.getId() + "-head"); xml.appendClose(); head.paint(renderContext); xml.appendEndTag("ui:labelhead"); xml.appendAttribute("id", label.getId() + "-body"); xml.appendClose(); body.paint(renderContext); xml.appendEndTag("ui:labelbody"); if (tail != null && tail.isVisible()) { xml.appendTagOpen("ui:labeltail"); xml.appendAttribute("id", label.getId() + "-tail"); xml.appendClose(); tail.paint(renderContext); xml.appendEndTag("ui:labeltail");
case EAGER: { content.setVisible(true); AjaxHelper.registerContainer(getId(), getId() + "-content", content.getId()); break; content.setVisible(isOpen()); if (!isOpen()) { AjaxHelper.registerContainer(getId(), getId() + "-content", content.getId()); content.setVisible(isOpen()); AjaxHelper.registerContainer(getId(), getId() + "-content", content.getId()); break; content.setVisible(isOpen()); break; content.setVisible(true); break;
if (component != null && (component.isVisible() || component instanceof WInvisibleContainer)) { xml.appendTagOpen("ui:debugInfo"); xml.appendAttribute("for", component.getId()); xml.appendAttribute("class", component.getClass().getName()); xml.appendOptionalAttribute("type", getType(component)); xml.appendAttribute("value", component.isDefaultState()); xml.appendEnd();
/** * {@inheritDoc} */ @Override protected void paintComponent(final RenderContext renderContext) { long start = new Date().getTime(); content.paint(renderContext); long finish = new Date().getTime(); long elapse = finish - start; getOrCreateComponentModel().setAttribute("elapse_paint", elapse); }
@Override public VisitorResult visit(final WComponent comp) { // In traversing the tree, special components like WInvisbleContainer, WRepeatRoot are still traversed // (so ignore them) if (comp.isVisible()) { list.add(new ComponentWithContext(comp, UIContextHolder.getCurrent())); } return VisitorResult.CONTINUE; } };
/** * Removes the given component from this component's list of children. * * @param aChild child component */ void remove(final WComponent aChild) { ComponentModel model = getOrCreateComponentModel(); if (model.getChildren() == null) { model.setChildren(copyChildren(getComponentModel().getChildren())); } if (model.getChildren().remove(aChild)) { // Deallocate children list if possible, to reduce session size. if (model.getChildren().isEmpty()) { model.setChildren(null); } // The child component has been successfully removed so clean up the context. aChild.reset(); // If the parent has been set in the shared model, we must override // it in the session model for the component to be considered removed. // This unfortunately means that the model will remain in the user's session. if (aChild.getParent() != null && aChild instanceof AbstractWComponent) { ((AbstractWComponent) aChild).getOrCreateComponentModel().setParent(null); ((AbstractWComponent) aChild).removeNotify(); } } }
/** * Prepares a single row for painting. * * @param request the request being responded to. * @param rowIndex the row index. */ protected void prepareRow(final Request request, final int rowIndex) { WComponent row = getRepeatedComponent(); row.preparePaint(request); }
@Override protected void preparePaintComponent(final Request request) { if (isLazy()) { if (AjaxHelper.getCurrentOperation() == null) { setRendered(null); } super.preparePaintComponent(request); if (isOpen()) { setRendered(Boolean.TRUE); } // Keep Lazy tabs that are open as visible during AJAX operations. getContent().setVisible(isOpen() || isRendered()); } else { super.preparePaintComponent(request); } }
@Override public VisitorResult visit(final WComponent comp) { VisitorResult result = super.visit(comp); // If hidden then abort branch if (result == VisitorResult.CONTINUE && comp.isHidden()) { return VisitorResult.ABORT_BRANCH; } return result; } };
/** * Retrieves the components for the given term. * * @param term the term of the children to be retrieved. * @return the child components for the given term, may be empty. */ private List<WComponent> getComponentsForTerm(final String term) { List<WComponent> childList = content.getComponentModel().getChildren(); List<WComponent> result = new ArrayList<>(); if (childList != null) { for (int i = 0; i < childList.size(); i++) { WComponent child = childList.get(i); if (term.equals(child.getTag())) { result.add(child); } } } return result; }
Environment environment = uiComponent.getEnvironment(); getInterceptor().preparePaint(getRequest()); String contentType = getUI().getHeaders().getContentType(); Response response = getResponse(); response.setContentType(contentType);