Search in sources :

Example 56 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SubordinateControlOptionsExample method createCondition.

/**
 * @return the condition for the subordinate control.
 */
private Condition createCondition() {
    // Compare value
    Object value;
    switch((TriggerType) drpTriggerType.getSelected()) {
        case DateField:
            value = dateCompareValue.getValue();
            break;
        case NumberField:
            value = numberCompareValue.getValue();
            break;
        default:
            value = comboCompareValue.getValue();
            break;
    }
    // Create condition
    Condition condition;
    switch((CompareType) drpCompareType.getSelected()) {
        case EQUAL:
            condition = new Equal(trigger, value);
            break;
        case NOT_EQUAL:
            condition = new NotEqual(trigger, value);
            break;
        case LESS_THAN:
            condition = new LessThan(trigger, value);
            break;
        case LESS_THAN_OR_EQUAL:
            condition = new LessThanOrEqual(trigger, value);
            break;
        case GREATER_THAN:
            condition = new GreaterThan(trigger, value);
            break;
        case GREATER_THAN_OR_EQUAL:
            condition = new GreaterThanOrEqual(trigger, value);
            break;
        case MATCH:
            condition = new Match(trigger, (String) value);
            break;
        default:
            throw new SystemException("Compare type not valid");
    }
    return condition;
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) CompareType(com.github.bordertech.wcomponents.subordinate.AbstractCompare.CompareType) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) Match(com.github.bordertech.wcomponents.subordinate.Match) LessThan(com.github.bordertech.wcomponents.subordinate.LessThan) SystemException(com.github.bordertech.wcomponents.util.SystemException) Equal(com.github.bordertech.wcomponents.subordinate.Equal) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) GreaterThan(com.github.bordertech.wcomponents.subordinate.GreaterThan)

Example 57 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SubordinateControlOptionsExample method buildControl.

/**
 * Build the subordinate control.
 */
private void buildControl() {
    buildControlPanel.reset();
    buildTargetPanel.reset();
    // Setup Trigger
    setupTrigger();
    // Create target
    SubordinateTarget target = setupTarget();
    // Create Actions
    com.github.bordertech.wcomponents.subordinate.Action trueAction;
    com.github.bordertech.wcomponents.subordinate.Action falseAction;
    switch((ControlActionType) drpActionType.getSelected()) {
        case ENABLE_DISABLE:
            trueAction = new Enable(target);
            falseAction = new Disable(target);
            break;
        case SHOW_HIDE:
            trueAction = new Show(target);
            falseAction = new Hide(target);
            break;
        case MAN_OPT:
            trueAction = new Mandatory(target);
            falseAction = new Optional(target);
            break;
        case SHOWIN_HIDEIN:
            trueAction = new ShowInGroup(target, targetGroup);
            falseAction = new HideInGroup(target, targetGroup);
            break;
        case ENABLEIN_DISABLEIN:
            trueAction = new EnableInGroup(target, targetGroup);
            falseAction = new DisableInGroup(target, targetGroup);
            break;
        default:
            throw new SystemException("ControlAction type not valid");
    }
    // Create Condition
    Condition condition = createCondition();
    if (cbNot.isSelected()) {
        condition = new Not(condition);
    }
    // Create Rule
    Rule rule = new Rule(condition, trueAction, falseAction);
    // Create Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    buildControlPanel.add(control);
    if (targetCollapsible.getDecoratedLabel() != null) {
        targetCollapsible.getDecoratedLabel().setTail(new WText(control.toString()));
    }
    control = new WSubordinateControl();
    rule = new Rule(new Equal(cbClientDisableTrigger, true), new Disable((SubordinateTarget) trigger), new Enable((SubordinateTarget) trigger));
    control.addRule(rule);
    buildControlPanel.add(control);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) Condition(com.github.bordertech.wcomponents.subordinate.Condition) Optional(com.github.bordertech.wcomponents.subordinate.Optional) HideInGroup(com.github.bordertech.wcomponents.subordinate.HideInGroup) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) EnableInGroup(com.github.bordertech.wcomponents.subordinate.EnableInGroup) ShowInGroup(com.github.bordertech.wcomponents.subordinate.ShowInGroup) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Not(com.github.bordertech.wcomponents.subordinate.Not) SystemException(com.github.bordertech.wcomponents.util.SystemException) WText(com.github.bordertech.wcomponents.WText) Equal(com.github.bordertech.wcomponents.subordinate.Equal) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) Enable(com.github.bordertech.wcomponents.subordinate.Enable) Show(com.github.bordertech.wcomponents.subordinate.Show) DisableInGroup(com.github.bordertech.wcomponents.subordinate.DisableInGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule) Disable(com.github.bordertech.wcomponents.subordinate.Disable) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory)

Example 58 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SeleniumWRadioButtonSelectWebElement method getRadioButton.

/**
 * Get the radio button at a given option index. Only applies to WRadioButtonSelect in an interactive state.
 *
 * @param idx the option's index
 * @return a HTML input element in the radio button state.
 */
public WebElement getRadioButton(final int idx) {
    if (isReadOnly()) {
        throw new SystemException("WRadioButtonSelect in a read-only state has no radio buttons.");
    }
    WebElement option = getOption(idx);
    By by = By.tagName(getOptionTag());
    return SeleniumWComponentsUtil.findElementImmediateForElement(option, by);
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) By(org.openqa.selenium.By) WebElement(org.openqa.selenium.WebElement)

Example 59 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class AjaxInterceptor method paintContainerResponse.

/**
 * Paint the ajax container response.
 *
 * @param renderContext the render context
 * @param operation the ajax operation
 */
private void paintContainerResponse(final RenderContext renderContext, final AjaxOperation operation) {
    WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
    XmlStringBuilder xml = webRenderContext.getWriter();
    // Get trigger's context
    ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext();
    if (trigger == null) {
        throw new SystemException("No context available for trigger " + operation.getTriggerId());
    }
    xml.appendTagOpen("ui:ajaxtarget");
    xml.appendAttribute("id", operation.getTargetContainerId());
    xml.appendAttribute("action", AjaxOperation.AjaxAction.REPLACE_CONTENT.getDesc());
    xml.appendClose();
    // Paint targets - Assume targets are in the same context as the trigger
    UIContextHolder.pushContext(trigger.getContext());
    try {
        for (String targetId : operation.getTargets()) {
            ComponentWithContext target;
            if (targetId.equals(operation.getTriggerId())) {
                target = trigger;
            } else {
                target = WebUtilities.getComponentById(targetId, true);
                if (target == null) {
                    LOG.warn("Could not find ajax target to render [" + targetId + "]");
                    continue;
                }
            }
            target.getComponent().paint(renderContext);
        }
    } finally {
        UIContextHolder.popContext();
    }
    xml.appendEndTag("ui:ajaxtarget");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) SystemException(com.github.bordertech.wcomponents.util.SystemException) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 60 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class AjaxPageShellInterceptor method paint.

/**
 * Paints the targeted ajax regions. The format of the response is an agreement between the server and the client
 * side handling our AJAX response.
 *
 * @param renderContext the renderContext to send the output to.
 */
@Override
public void paint(final RenderContext renderContext) {
    WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
    XmlStringBuilder xml = webRenderContext.getWriter();
    AjaxOperation operation = AjaxHelper.getCurrentOperation();
    if (operation == null) {
        // the request attribute that we place in the ui contenxt in the action phase can't be null
        throw new SystemException("Can't paint AJAX response. Couldn't find the expected reference to the AjaxOperation.");
    }
    UIContext uic = UIContextHolder.getCurrent();
    String focusId = uic.getFocussedId();
    xml.append(XMLUtil.getXMLDeclarationWithThemeXslt(uic));
    xml.appendTagOpen("ui:ajaxresponse");
    xml.append(XMLUtil.STANDARD_NAMESPACES);
    xml.appendOptionalAttribute("defaultFocusId", uic.isFocusRequired() && !Util.empty(focusId), focusId);
    xml.appendClose();
    getBackingComponent().paint(renderContext);
    xml.appendEndTag("ui:ajaxresponse");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Aggregations

SystemException (com.github.bordertech.wcomponents.util.SystemException)91 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)17 WComponent (com.github.bordertech.wcomponents.WComponent)15 UIContext (com.github.bordertech.wcomponents.UIContext)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 Test (org.junit.Test)9 WebElement (org.openqa.selenium.WebElement)8 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 IOException (java.io.IOException)5 Select (org.openqa.selenium.support.ui.Select)5 Environment (com.github.bordertech.wcomponents.Environment)4 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3 Date (java.util.Date)3 List (java.util.List)3 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)3 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)2 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)2 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)2