use of com.github.bordertech.wcomponents.WApplication 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.WApplication in project wcomponents by BorderTech.
the class ServerCache method setUI.
/**
* Set the UI for the launcher.
*
* @param key the UI key
* @param ui the UI component
* @return the registered UI instance
*/
public static WComponent setUI(final String key, final WComponent ui) {
if (!(LAUNCHER instanceof DynamicLauncher)) {
return ui;
}
// If a DynamicLauncher is being used, set the UI to match this component.
synchronized (LAUNCHER) {
DynamicLauncher dynamic = (DynamicLauncher) LAUNCHER;
// Set the current key
dynamic.setCurrentKey(key);
// Check if already registered
WApplication egUI = dynamic.getRegisteredComponent(key);
if (egUI != null) {
// Already registered, check if wrapped
return (ui instanceof WApplication) ? egUI : egUI.getChildAt(0);
}
// Register UI - Check if needs to be wrapped
dynamic.registerComponent(key, wrapUI(ui));
// This is the registered instance
return ui;
}
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class DefaultPageShell method getApplicationTitle.
/**
* Retrieves the application title for the given context. This mess is required due to WWindow essentially existing
* as a separate UI root. If WWindow is eventually removed, then we can just retrieve the title from the root
* WApplication.
*
* @param uic the context to check.
* @return the current application title.
*/
private String getApplicationTitle(final UIContext uic) {
WComponent root = uic.getUI();
String title = root instanceof WApplication ? ((WApplication) root).getTitle() : null;
Map<String, String> params = uic.getEnvironment().getHiddenParameters();
String target = params.get(WWindow.WWINDOW_REQUEST_PARAM_KEY);
if (target != null) {
ComponentWithContext targetComp = WebUtilities.getComponentById(target, true);
if (targetComp != null && targetComp.getComponent() instanceof WWindow) {
try {
UIContextHolder.pushContext(targetComp.getContext());
title = ((WWindow) targetComp.getComponent()).getTitle();
} finally {
UIContextHolder.popContext();
}
}
}
return title == null ? "" : title;
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class WrongStepAjaxInterceptor method handleWarpToTheFuture.
/**
* Warp the user to the future by replacing the entire page.
*
* @param uic the current user context
*/
private void handleWarpToTheFuture(final UIContext uic) {
// Increment the step counter
StepCountUtil.incrementSessionStep(uic);
// Get component at end of chain
WComponent application = getUI();
// Call handle step error on WApplication
if (application instanceof WApplication) {
LOG.warn("The handleStepError method will be called on WApplication.");
((WApplication) application).handleStepError();
}
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class WrongStepServerInterceptor method serviceRequest.
/**
* Override to check whether the step variable in the incoming request matches what we expect.
*
* @param request the request being serviced.
*/
@Override
public void serviceRequest(final Request request) {
// Get expected step count
UIContext uic = UIContextHolder.getCurrent();
int expected = uic.getEnvironment().getStep();
// Get step count from the request
int got = StepCountUtil.getRequestStep(request);
// or no Step count and processing a GET
if (expected == got || (!StepCountUtil.isStepOnRequest(request) && "GET".equals(request.getMethod()))) {
// Process Service Request
getBackingComponent().serviceRequest(request);
} else {
// Invalid step
LOG.warn("SERVER: Wrong step detected. Expected step " + expected + " but got step " + got);
// Redirect to error page
if (StepCountUtil.isErrorRedirect()) {
String url = StepCountUtil.getErrorUrl();
LOG.warn("User will be redirected to an error page. URL: " + url);
try {
getResponse().sendRedirect(url);
} catch (IOException e) {
LOG.warn("Error trying to redirect for wrong step indicator.");
}
// Make sure the render phase is not processed
throw new ActionEscape();
} else {
// Warp to the future
// Call handle step error
WComponent application = getUI();
if (application instanceof WApplication) {
LOG.warn("The handleStepError method will be called on WApplication.");
((WApplication) application).handleStepError();
}
LOG.warn("The render phase will warp the user back to the future.");
}
}
}
Aggregations