@Override public boolean setFocus(boolean inputOnly) { if (!isRelevant()) return false; final XFormsCaseControl selectedCase = getSelectedCase(); return selectedCase != null && selectedCase.setFocus(inputOnly); }
/** * Set the currently selected case. * * @param caseControlToSelect case control to select */ public void setSelectedCase(XFormsCaseControl caseControlToSelect) { if (caseControlToSelect.parent() != this) throw new OXFException("xf:case is not child of current xf:switch."); final XFormsSwitchControlLocal localForUpdate = (XFormsSwitchControlLocal) getLocalForUpdate(); final XFormsCaseControl previouslySelectedCaseControl = getSelectedCase(); final boolean isChanging = previouslySelectedCaseControl.getId() != caseControlToSelect.getId(); localForUpdate.selectedCaseControlId = caseControlToSelect.getId(); if (isChanging) { // "This action adjusts all selected attributes on the affected cases to reflect the new // state, and then // performs the following:" // "1. Dispatching an xforms-deselect event to the currently selected case." Dispatch.dispatchEvent(new XFormsDeselectEvent(previouslySelectedCaseControl)); if (isXForms11Switch()) { // Partial refresh on the case that is being deselected // Do this after xforms-deselect is dispatched containingDocument().getControls().doPartialRefresh(previouslySelectedCaseControl); // Partial refresh on the case that is being selected // Do this before xforms-select is dispatched containingDocument().getControls().doPartialRefresh(caseControlToSelect); } // "2. Dispatching an xforms-select event to the case to be selected." Dispatch.dispatchEvent(new XFormsSelectEvent(caseControlToSelect)); } }
private String findDefaultSelectedCaseId() { // TODO: Use ElementAnalysis instead final List<Element> caseElements = Dom4jUtils.elements(element(), XFormsConstants.XFORMS_CASE_QNAME); for (final Element caseElement : caseElements) { if (XFormsCaseControl.isDefaultSelected(caseElement)) { // Found first case with selected="true" return XFormsUtils.getElementId(caseElement); } } // Didn't find a case with selected="true" so return first case return XFormsUtils.getElementId(caseElements.get(0)); }
@Override public void outputAjaxDiff( ContentHandlerHelper ch, XFormsControl other, AttributesImpl attributesImpl, boolean isNewlyVisibleSubtree) { // Output regular diff super.outputAjaxDiff(ch, other, attributesImpl, isNewlyVisibleSubtree); // Output switch-specific diff if needed only final XFormsSwitchControl otherSwitchControl = (XFormsSwitchControl) other; if (!compareSelectedCase(otherSwitchControl)) { if (isRelevant()) { // Output newly selected case id final String selectedCaseEffectiveId = getSelectedCaseEffectiveId(); assert selectedCaseEffectiveId != null; ch.element( "xxf", XFormsConstants.XXFORMS_NAMESPACE_URI, "div", new String[] { "id", XFormsUtils.namespaceId(containingDocument(), selectedCaseEffectiveId), "visibility", "visible" }); if (otherSwitchControl != null && otherSwitchControl.isRelevant()) { // Used to be relevant, simply output deselected case ids final String previousSelectedCaseId = getOtherSelectedCaseEffectiveId(otherSwitchControl); assert previousSelectedCaseId != null; ch.element( "xxf", XFormsConstants.XXFORMS_NAMESPACE_URI, "div", new String[] { "id", XFormsUtils.namespaceId(containingDocument(), previousSelectedCaseId), "visibility", "hidden" }); } else { // Control was not relevant, send all deselected to be sure // TODO: This should not be needed because the repeat template should have a reasonable // default. final List<XFormsCaseControl> children = getChildrenCases(); if (children != null && children.size() > 0) { for (final XFormsCaseControl caseControl : children) { if (!caseControl.getEffectiveId().equals(selectedCaseEffectiveId)) { ch.element( "xxf", XFormsConstants.XXFORMS_NAMESPACE_URI, "div", new String[] { "id", XFormsUtils.namespaceId(containingDocument(), caseControl.getEffectiveId()), "visibility", "hidden" }); } } } } } } }