Search in sources :

Example 1 with TOCItem

use of org.glassfish.admingui.connector.TOCItem in project Payara by payara.

the class HelpTreeAdaptor method getFactoryOptions.

/**
 *	<p> This method returns the "options" that should be supplied to the
 *	    factory that creates the <code>TreeNode</code> for the given tree
 *	    node model object.</p>
 *
 *	<p> Some useful options for the standard <code>TreeNode</code>
 *	    component include:<p>
 *
 *	<ul><li>text</li>
 *	    <li>url</li>
 *	    <li>imageURL</li>
 *	    <li>target</li>
 *	    <li>action<li>
 *	    <li>actionListener</li>
 *	    <li>expanded</li></ul>
 *
 *	<p> See Tree / TreeNode component documentation for more details.</p>
 */
public Map<String, Object> getFactoryOptions(Object nodeObject) {
    if (nodeObject == null) {
        return null;
    }
    Map<String, Object> props = new HashMap<String, Object>();
    if (nodeObject instanceof TOC) {
        // This case deals with the top node.
        // Do (almost) nothing so that the root node does not show up...
        props.put("clientSide", true);
        Object value = getLayoutComponent().getOption("style");
        if (value != null) {
            props.put("style", value);
        }
        return props;
    } else if (!(nodeObject instanceof TOCItem)) {
        throw new IllegalArgumentException("Invalid node type for TOC: " + nodeObject.getClass().getName());
    }
    TOCItem item = (TOCItem) nodeObject;
    // Setup the properties...
    // NOTE: All supported options must be handled here,
    // otherwise they'll be ignored.
    // NOTE: Options will be evaluated later, do not eval here.
    props.put("expanded", item.isExpand());
    props.put("text", item.getText());
    // Add leading "/resource/" to ensure it's treated as *context root* relative.
    props.put("url", "/resource/" + item.getTargetPath());
    // Return the options
    return props;
}
Also used : HashMap(java.util.HashMap) TOCItem(org.glassfish.admingui.connector.TOCItem) TOC(org.glassfish.admingui.connector.TOC)

Example 2 with TOCItem

use of org.glassfish.admingui.connector.TOCItem in project Payara by payara.

the class ConsolePluginService method getHelpTOC.

/**
 *	<p> This method returns a merged Table Of Contents for all found help
 *	    sets for the given locale.</p>
 */
public synchronized TOC getHelpTOC(String locale) {
    if (locale == null) {
        // Use this as the default...
        locale = "en";
    }
    TOC mergedTOC = helpSetMap.get(locale);
    if (mergedTOC != null) {
        // Already calculated...
        return mergedTOC;
    }
    // TOC
    Map<String, List<URL>> mapUrls = getResources(locale + "/help/toc.xml");
    // Get our parser...
    ConfigParser parser = new ConfigParser(habitat);
    // Setup a new "merged" TOC...
    mergedTOC = new TOC();
    mergedTOC.setTOCItems(new ArrayList<TOCItem>());
    mergedTOC.setVersion("2.0");
    // Loop through the urls and add them all
    // module id
    String id = null;
    // prefix (minus module id)
    String prefix = "/" + locale + "/help/";
    // URLs to TOC files w/i each plugin module
    List<URL> urls = null;
    for (Map.Entry<String, List<URL>> entry : mapUrls.entrySet()) {
        id = entry.getKey();
        urls = entry.getValue();
        for (URL url : urls) {
            DomDocument doc = parser.parse(url);
            // Merge all the TOC's...
            TOC toc = (TOC) doc.getRoot().get();
            for (TOCItem item : toc.getTOCItems()) {
                insertTOCItem(mergedTOC.getTOCItems(), item, id + prefix);
            }
        }
    }
    // FIXME: Sort?
    return mergedTOC;
}
Also used : TOCItem(org.glassfish.admingui.connector.TOCItem) TOC(org.glassfish.admingui.connector.TOC) ConfigParser(org.jvnet.hk2.config.ConfigParser) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) MultiMap(org.jvnet.hk2.component.MultiMap) URL(java.net.URL) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 3 with TOCItem

use of org.glassfish.admingui.connector.TOCItem in project Payara by payara.

the class ConsolePluginService method insertTOCItem.

/**
 *	<p> This method inserts the given <code>item</code> into the
 *	    <code>dest</code> list.</p>
 */
private void insertTOCItem(List<TOCItem> dest, TOCItem item, String prefix) {
    int idx = dest.indexOf(item);
    if (idx == -1) {
        // Fix target path...
        fixTargetPath(item, prefix);
        // Not there yet, just add it...
        dest.add(item);
    } else {
        // Already there, insert children of item...
        TOCItem parent = dest.get(idx);
        for (TOCItem child : item.getTOCItems()) {
            insertTOCItem(parent.getTOCItems(), child, prefix);
        }
    }
}
Also used : TOCItem(org.glassfish.admingui.connector.TOCItem) IntegrationPoint(org.glassfish.admingui.connector.IntegrationPoint)

Aggregations

TOCItem (org.glassfish.admingui.connector.TOCItem)3 HashMap (java.util.HashMap)2 TOC (org.glassfish.admingui.connector.TOC)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 IntegrationPoint (org.glassfish.admingui.connector.IntegrationPoint)1 MultiMap (org.jvnet.hk2.component.MultiMap)1 ConfigParser (org.jvnet.hk2.config.ConfigParser)1 DomDocument (org.jvnet.hk2.config.DomDocument)1