Search in sources :

Example 16 with WApplication

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);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WText(com.github.bordertech.wcomponents.WText) WApplication(com.github.bordertech.wcomponents.WApplication) WDefinitionList(com.github.bordertech.wcomponents.WDefinitionList) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule)

Example 17 with WApplication

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;
    }
}
Also used : WApplication(com.github.bordertech.wcomponents.WApplication) DynamicLauncher(com.github.bordertech.wcomponents.test.selenium.DynamicLauncher)

Example 18 with WApplication

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;
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WApplication(com.github.bordertech.wcomponents.WApplication) WWindow(com.github.bordertech.wcomponents.WWindow) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 19 with WApplication

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();
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WApplication(com.github.bordertech.wcomponents.WApplication)

Example 20 with WApplication

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.");
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) ActionEscape(com.github.bordertech.wcomponents.ActionEscape) UIContext(com.github.bordertech.wcomponents.UIContext) WApplication(com.github.bordertech.wcomponents.WApplication) IOException(java.io.IOException)

Aggregations

WApplication (com.github.bordertech.wcomponents.WApplication)28 Test (org.junit.Test)14 UIContext (com.github.bordertech.wcomponents.UIContext)13 WComponent (com.github.bordertech.wcomponents.WComponent)8 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 WButton (com.github.bordertech.wcomponents.WButton)4 WLabel (com.github.bordertech.wcomponents.WLabel)4 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)3 WText (com.github.bordertech.wcomponents.WText)3 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)3 PrintWriter (java.io.PrintWriter)3 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 WWindow (com.github.bordertech.wcomponents.WWindow)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 Map (java.util.Map)2 Before (org.junit.Before)2 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)1 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)1 Environment (com.github.bordertech.wcomponents.Environment)1