/** * Retrieves the root component of a WComponent hierarchy. * * @param uic the context to retrieve the root component for. * @param comp a component in the tree. * @return the root of the tree. */ public static WComponent getRoot(final UIContext uic, final WComponent comp) { UIContextHolder.pushContext(uic); try { return WebUtilities.getTop(comp); } finally { UIContextHolder.popContext(); } }
/** * Override WComponent internal id to include a row index. * * @return the internal id for this WComponent in the given context. */ @Override public String getInternalId() { UIContext uic = UIContextHolder.getCurrent(); String repeaterId; String suffix; if (uic instanceof SubUIContext) { SubUIContext subContext = (SubUIContext) uic; UIContextHolder.pushContext(subContext.getParentContext()); try { repeaterId = repeater.getInternalId(); suffix = String.valueOf(subContext.getContextId()); } finally { UIContextHolder.popContext(); } } else { repeaterId = repeater.getInternalId(); suffix = ""; } StringBuffer iidBuf = new StringBuffer(); iidBuf.append(repeaterId); iidBuf.append("r"); iidBuf.append(suffix); return iidBuf.toString(); }
/** * @return the registered subordinate controls or null */ public static Set<String> getRegisteredSubordinateControls() { UIContext uic = UIContextHolder.getCurrentPrimaryUIContext(); return uic == null ? null : (Set<String>) uic.getFwkAttribute(SUBORDINATE_CONTROL_SESSION_KEY); }
/** * @return the primary context for the current context */ public static UIContext getCurrentPrimaryUIContext() { return getPrimaryUIContext(getCurrent()); }
/** * Setup the user contest for this row. * * @return true if row context setup successfully */ protected boolean setupRowUic() { UIContext uic = UIContextHolder.getCurrent(); UIContext ruic = getRowUic(); if (ruic == null || uic == ruic) { return false; } UIContextHolder.pushContext(ruic); return true; }
/** * Pushes a context onto the top of stack. This method is called by internal WComponent containers (e.g. WServlet) * at the start of processing a request. and by components which repeat content. * * @param uic the UIContext to push. */ public static void pushContext(final UIContext uic) { if (DebugUtil.isDebugFeaturesEnabled()) { ALL_ACTIVE_CONTEXTS.put(getPrimaryUIContext(uic), null); } getStack().push(uic); }
/** * Creates a LinkDiagnosticImpl. * * @param sourceField the field that is the source of the diagnostic, or null if there is no appropriate field * @param description the description (message) of the diagnostic * @param severity one of Diagnostic.INFO, Diagnostic.WARNING or Diagnostic.ERROR */ private LinkDiagnosticImpl(final WComponent sourceField, final String description, final int severity) { super(severity, UIContextHolder.getCurrent(), sourceField, description); }
/** * Temporarily replaces the environment while the UI prepares to render. * * @param request the request being responded to. */ @Override public void preparePaint(final Request request) { if (windowId == null) { super.preparePaint(request); } else { // Get the window component ComponentWithContext target = WebUtilities.getComponentById(windowId, true); if (target == null) { throw new SystemException("No window component for id " + windowId); } UIContext uic = UIContextHolder.getCurrentPrimaryUIContext(); Environment originalEnvironment = uic.getEnvironment(); uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target)); UIContextHolder.pushContext(target.getContext()); try { super.preparePaint(request); } finally { uic.setEnvironment(originalEnvironment); UIContextHolder.popContext(); } } }
UIContextHolder.pushContext(uic); UIContextHolder.reset();
/** * Renders the given component to xml. * * @param component the component to render. * @return the rendered format of the component. */ public String render(final WebComponent component) { boolean needsContext = UIContextHolder.getCurrent() == null; if (needsContext) { setActiveContext(createUIContext()); } try { StringWriter buffer = new StringWriter(); component.preparePaint(new MockRequest()); PrintWriter writer = new PrintWriter(buffer); component.paint(new WebXmlRenderContext(writer)); writer.close(); return buffer.toString(); } finally { if (needsContext) { UIContextHolder.popContext(); } } }
/** * Sets the given context to be the active one. * * @param uic the context to set as active. */ private void setActiveContext(final UIContext uic) { resetContext(); UIContextHolder.pushContext(uic); }
/** * Clear the row context. * * @param pop true if pop context */ protected void clearRowUic(final boolean pop) { if (pop) { UIContextHolder.popContext(); } }
/** * Resets the UIContext stack after each test method. */ @After public void resetContext() { UIContextHolder.reset(); } }
/** * A utility function to iterate to the primary (top most) context and return it. * * @param uic the UIContext to retrieve the primary context for. * @return the primary context for the given context. * @deprecated Use {@link UIContextHolder#getPrimaryUIContext(com.github.bordertech.wcomponents.UIContext)} instead. */ @Deprecated public static UIContext getPrimaryUIContext(final UIContext uic) { return UIContextHolder.getPrimaryUIContext(uic); } }
/** * This can be used by column components on a {@link WTable} to determine the current row key. * * @return the row key for the current row, or null if no row details */ public static Object getCurrentRowKey() { UIContext uic = UIContextHolder.getCurrent(); if (uic instanceof SubUIContext) { return ((SubUIContext) uic).getRowId(); } return null; }
/** * Temporarily replaces the environment while the UI is being rendered. * * @param renderContext the context to render to. */ @Override public void paint(final RenderContext renderContext) { if (windowId == null) { super.paint(renderContext); } else { // Get the window component ComponentWithContext target = WebUtilities.getComponentById(windowId, true); if (target == null) { throw new SystemException("No window component for id " + windowId); } UIContext uic = UIContextHolder.getCurrentPrimaryUIContext(); Environment originalEnvironment = uic.getEnvironment(); uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target)); UIContextHolder.pushContext(target.getContext()); try { super.paint(renderContext); } finally { uic.setEnvironment(originalEnvironment); UIContextHolder.popContext(); } } }
UIContextHolder.pushContext(uic); prepareRequest(); handleError(t); } finally { UIContextHolder.reset(); dispose();
/** * Sets the given context to be the active one. * * @param uic the context to set as active. */ protected void setActiveContext(final UIContext uic) { resetContext(); UIContextHolder.pushContext(uic); }
/** * Resets the UIContext stack after each test method. */ @After public void resetContext() { UIContextHolder.reset(); }
/** * Finds all instances that make up the tree (static and dynamic) and gathers stats. * * @param root the root component to start from. * @return the statistics for components in the given subtree. */ private Map<WComponent, Stat> createWCTreeStats(final WComponent root) { Map<WComponent, Stat> statsMap = new HashMap<>(); UIContextHolder.pushContext(uic); try { addStats(statsMap, root); } finally { UIContextHolder.popContext(); } return statsMap; }