use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class AbstractContainerHelper method createUIContext.
/**
* Creates and initialises a new UIContext.
*
* @return a new UIContext.
*/
protected UIContext createUIContext() {
// Create UIC
UIContext uic = new UIContextImpl();
uic.setUI(getUI());
return uic;
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class AbstractContainerHelper method prepareUserContext.
/**
* Prepare the user context for this request.
* <p>
* This must be called before processAction and render.
* </p>
*
* @return the user context
*/
public UIContext prepareUserContext() {
UIContext uic = getUIContext();
if (requestImpliesNew() || uic == null) {
LOG.debug("Preparing a new session");
setNewConversation(Boolean.TRUE);
uic = createUIContext();
setUIContext(uic);
} else {
setNewConversation(Boolean.FALSE);
// In Development mode, simulate running in a cluster
cycleUIContext();
}
return uic;
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class AjaxInterceptor method serviceRequest.
/**
* {@inheritDoc}
*/
@Override
public void serviceRequest(final Request request) {
String triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
AjaxOperation ajaxOperation = AjaxHelper.getCurrentOperation();
if (ajaxOperation == null) {
throw new IllegalStateException("No AJAX operation available for trigger " + triggerId + ".");
}
ComponentWithContext triggerWithContext = AjaxHelper.getCurrentTriggerAndContext();
if (triggerWithContext == null) {
throw new IllegalStateException("No component/context available for AJAX trigger " + triggerId + ".");
}
UIContext uic = UIContextHolder.getCurrent();
// Reset the focus for this new request.
uic.setFocussed(null, null);
// We've hit the action phase, so we do want focus on this app.
uic.setFocusRequired(true);
// Process trigger only
if (isProcessTriggerOnly(triggerWithContext, ajaxOperation)) {
// Get user context
UIContext tuic = triggerWithContext.getContext();
UIContextHolder.pushContext(tuic);
try {
WComponent trigger = triggerWithContext.getComponent();
trigger.serviceRequest(request);
// Manually invoke laters as the InvokeLaters in the service request is not run due to the trigger
// having a "parent"
tuic.doInvokeLaters();
} finally {
UIContextHolder.popContext();
}
} else if ("GET".equals(request.getMethod())) {
// GET only supports the above scenarios
throw new IllegalStateException("GET is not supported for the AJAX trigger " + triggerId + ".");
} else {
// service the request
super.serviceRequest(request);
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class DevToolkit method getTree.
/**
* Retrieves a tree representation of the WComponent UI being served by the LDE, in a format suitable for rendering
* to the UI.
*
* @return a tree representation of the WComponent UI.
*/
public TreeNode getTree() {
UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
String[] debugTree = uic.getUI().toString().split("\n");
TreeNode root = new UITreeNode(debugTree[0]);
TreeNode parent = root;
TreeNode last = root;
for (int i = 1; i < debugTree.length; i++) {
String line = debugTree[i].trim();
if (line.charAt(0) == '[') {
parent = last;
TreeNode child = new UITreeNode(debugTree[++i]);
parent.add(child);
last = child;
} else if (line.charAt(0) == ']') {
parent = parent.getParent();
} else {
TreeNode child = new UITreeNode(debugTree[i]);
parent.add(child);
last = child;
}
}
return root;
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class ByWComponentPath method findElements.
/**
* {@inheritDoc}
*/
@Override
public List<WebElement> findElements(final SearchContext searchContext) {
List<WebElement> result = new ArrayList<>();
ComponentWithContext[] components = null;
UIContextHolder.pushContext(getContext());
try {
components = TreeUtil.findWComponents(getComponent(), path, visibleOnly);
} finally {
UIContextHolder.popContext();
}
if (components.length != 0) {
componentClass = components[0].getComponent().getClass();
}
for (ComponentWithContext comp : components) {
WComponent cmp = comp.getComponent();
UIContext cmpUic = comp.getContext();
UIContextHolder.pushContext(cmpUic);
try {
List<WebElement> resultForComp = findElement(searchContext, cmpUic, cmp, getValue());
result.addAll(resultForComp);
} finally {
UIContextHolder.popContext();
}
}
return result;
}
Aggregations