Search in sources :

Example 31 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class AjaxTabbedPanel method findTabs.

/**
 * Looks through the child components to locate the AjaxTabbedPanelTabs that are controlled by this panel.
 * Tabs without an explicit id attributed are assigned a calculated one.
 *
 * @param template the graph of elements passed to the constructor.
 */
private void findTabs(WODynamicGroup template) {
    if (template == null || template.childrenElements() == null)
        return;
    NSArray children = template.childrenElements();
    for (int i = 0; i < children.count(); i++) {
        WOElement child = (WOElement) children.objectAtIndex(i);
        if (child instanceof AjaxTabbedPanelTab) {
            AjaxTabbedPanelTab childTab = (AjaxTabbedPanelTab) child;
            // The tabs need to have an id attribute so we assign one if needed
            if (childTab.id() == null) {
                childTab.setParentId(id);
                childTab.setTabNumber(new WOConstantValueAssociation("_pane_" + tabs.count()));
            }
            tabs.addObject(childTab);
        } else if (child instanceof WODynamicGroup) {
            findTabs((WODynamicGroup) child);
        }
    }
}
Also used : NSArray(com.webobjects.foundation.NSArray) WODynamicGroup(com.webobjects.appserver._private.WODynamicGroup) WOConstantValueAssociation(com.webobjects.appserver._private.WOConstantValueAssociation) WOElement(com.webobjects.appserver.WOElement)

Example 32 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class AjaxTree method _fillInOpenNodes.

protected void _fillInOpenNodes(Object node, NSMutableArray nodes, boolean showNode) {
    if (showNode) {
        nodes.addObject(node);
    }
    if (treeModel().isExpanded(node)) {
        NSArray childrenTreeNodes = treeModel().childrenTreeNodes(node);
        if (childrenTreeNodes != null) {
            int childTreeNodeCount = childrenTreeNodes.count();
            for (int childTreeNodeNum = 0; childTreeNodeNum < childTreeNodeCount; childTreeNodeNum++) {
                Object childNode = childrenTreeNodes.objectAtIndex(childTreeNodeNum);
                _fillInOpenNodes(childNode, nodes, true);
            }
        }
    }
}
Also used : NSArray(com.webobjects.foundation.NSArray)

Example 33 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class AjaxAutoComplete method listeJS.

protected String listeJS() {
    StringBuilder str = new StringBuilder();
    str.append("new Array(");
    NSArray list = (NSArray) valueForBinding("list");
    int max = list.count();
    boolean hasItem = hasBinding("item");
    for (int i = 0; i < max; i++) {
        Object ds = list.objectAtIndex(i);
        if (i > 0) {
            str.append(',');
        }
        str.append("\n\"");
        if (hasItem) {
            setValueForBinding(ds, "item");
        }
        Object displayValue = valueForBinding("displayString", valueForBinding("item", ds));
        String escapedValue = displayValue.toString();
        if (escapedValue.contains("\"")) {
            escapedValue = escapedValue.replaceAll("(?<!\\\\)\"", "\\\\\\\"");
        }
        str.append(escapedValue);
        str.append('"');
    }
    str.append(')');
    return str.toString();
}
Also used : NSArray(com.webobjects.foundation.NSArray)

Example 34 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class AjaxAutoComplete method setStringValue.

public void setStringValue(String strValue) {
    if (hasBinding("selection")) {
        Object selection = null;
        if (strValue != null) {
            NSArray values = (NSArray) valueForBinding("list");
            int maxItems = maxItems();
            int itemsCount = 0;
            for (Enumeration e = values.objectEnumerator(); e.hasMoreElements() && itemsCount++ < maxItems; ) {
                Object value = e.nextElement();
                setValueForBinding(value, "item");
                String displayString = displayStringForValue(value);
                if (Objects.equals(displayString, strValue)) {
                    selection = value;
                    break;
                }
            }
        }
        setValueForBinding(selection, "selection");
    }
    setValueForBinding(strValue, "value");
}
Also used : Enumeration(java.util.Enumeration) NSArray(com.webobjects.foundation.NSArray)

Example 35 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class AjaxAutoComplete method handleRequest.

/**
 * Handles the Ajax request. Checks for the form value in the edit field,
 * pushes it up to the parent and pulls the "list" binding. The parent is
 * responsible for returning a list with some items that match the current value.
 */
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    // String inputString = request.contentString();
    String fieldValue = context.request().stringFormValueForKey(fieldName);
    setValueForBinding(fieldValue, "value");
    WOResponse response = AjaxUtils.createResponse(request, context);
    response.appendContentString("<ul>");
    int maxItems = maxItems();
    int itemsCount = 0;
    Object values = valueForBinding("list");
    WOElement child = _childTemplate();
    boolean hasItem = hasBinding("item");
    if (values instanceof NSArray) {
        for (Enumeration valueEnum = ((NSArray) values).objectEnumerator(); valueEnum.hasMoreElements() && itemsCount++ < maxItems; ) {
            appendItemToResponse(valueEnum.nextElement(), child, hasItem, response, context);
        }
    } else if (values instanceof List) {
        for (Iterator iter = ((List) values).iterator(); iter.hasNext() && itemsCount++ < maxItems; ) {
            appendItemToResponse(iter.next(), child, hasItem, response, context);
        }
    } else if (values instanceof Object[]) {
        Object[] array = (Object[]) values;
        for (int i = 0; i < array.length && i < maxItems; i++) {
            appendItemToResponse(array[i], child, hasItem, response, context);
        }
    } else if (values != null) {
        log.warn("Unsupported class type for list: {}", values.getClass().getCanonicalName());
    }
    response.appendContentString("</ul>");
    return response;
}
Also used : Enumeration(java.util.Enumeration) NSArray(com.webobjects.foundation.NSArray) Iterator(java.util.Iterator) List(java.util.List) WOResponse(com.webobjects.appserver.WOResponse) WOElement(com.webobjects.appserver.WOElement)

Aggregations

NSArray (com.webobjects.foundation.NSArray)53 Enumeration (java.util.Enumeration)17 NSMutableArray (com.webobjects.foundation.NSMutableArray)13 NSBundle (com.webobjects.foundation.NSBundle)5 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)5 File (java.io.File)4 List (java.util.List)4 WOAssociation (com.webobjects.appserver.WOAssociation)3 WOComponent (com.webobjects.appserver.WOComponent)3 NSDictionary (com.webobjects.foundation.NSDictionary)3 IOException (java.io.IOException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 WOElement (com.webobjects.appserver.WOElement)2 WOResponse (com.webobjects.appserver.WOResponse)2 WOConstantValueAssociation (com.webobjects.appserver._private.WOConstantValueAssociation)2 EOEvent (com.webobjects.eocontrol.EOEvent)2 EOSortOrdering (com.webobjects.eocontrol.EOSortOrdering)2 NSForwardException (com.webobjects.foundation.NSForwardException)2 NSKeyValueCoding (com.webobjects.foundation.NSKeyValueCoding)2