Search in sources :

Example 1 with LayoutComponent

use of com.sun.jsftemplating.layout.descriptors.LayoutComponent in project Payara by payara.

the class ListTreeAdaptor method getChildTreeNodeObjects.

/**
 *	<p> Returns child <code>TreeNode</code>s for the given
 *	    <code>TreeNode</code> model Object.</p>
 */
public List getChildTreeNodeObjects(Object nodeObject) {
    if (nodeObject == null) {
        return null;
    }
    if ((nodeObject instanceof Integer) && nodeObject.equals(TOP_ID)) {
        // Find/Return children here
        if (_children != null) {
            return _children;
        }
        // Find the children...
        FacesContext ctx = FacesContext.getCurrentInstance();
        // This is the descriptor for this dynamic TreeNode, it contains all
        // information (options) necessary for this Adaptor
        LayoutComponent desc = getLayoutComponent();
        Object val = desc.getOption("children");
        if (val == null) {
            throw new IllegalArgumentException("'children' must be specified!");
        }
        val = desc.resolveValue(ctx, getParentUIComponent(), val.toString());
        if ((val != null) && (val instanceof Map)) {
            _childMap = (Map<String, Object>) val;
            val = new ArrayList<Object>(_childMap.keySet());
            Collections.sort((List) val);
        }
        _children = (List<Object>) val;
        // Ok, we got the result, provide an event in case we want to
        // do some filtering
        Object retVal = getLayoutComponent().dispatchHandlers(ctx, FilterTreeEvent.EVENT_TYPE, new FilterTreeEvent(getParentUIComponent(), _children));
        if ((retVal != null) && (retVal instanceof List)) {
            // We have a return value, use it instead of the original list
            _children = (List<Object>) retVal;
        }
    } else {
        // Currently multiple levels are not implemented
        return null;
    }
    return _children;
}
Also used : FacesContext(javax.faces.context.FacesContext) ArrayList(java.util.ArrayList) List(java.util.List) LayoutComponent(com.sun.jsftemplating.layout.descriptors.LayoutComponent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with LayoutComponent

use of com.sun.jsftemplating.layout.descriptors.LayoutComponent in project Payara by payara.

the class HelpTreeIndexAdaptor method init.

/**
 *	<p> This method is called shortly after
 *	    {@link #getInstance(FacesContext, LayoutComponent, UIComponent)}.
 *	    It provides a place for post-creation initialization to take
 *	    occur.</p>
 */
public void init() {
    // Get the FacesContext
    FacesContext ctx = FacesContext.getCurrentInstance();
    // This is the descriptor for this dynamic TreeNode, it contains all
    // information (options) necessary for this Adaptor
    LayoutComponent desc = getLayoutComponent();
    // The parent UIComponent
    UIComponent parent = getParentUIComponent();
    // Get the Index
    Index index = (Index) desc.getEvaluatedOption(ctx, "index", parent);
    // The following method should set the "key" to the node containing all
    // the children... the children will also have keys which must be
    // retrievable by the next method (getChildTreeNodeObjects)... these
    // "keys" will be used by the rest of the methods in this file for
    // getting information about the TreeNode that should be built.
    setTreeNodeObject(index);
}
Also used : FacesContext(javax.faces.context.FacesContext) UIComponent(javax.faces.component.UIComponent) Index(org.glassfish.admingui.connector.Index) LayoutComponent(com.sun.jsftemplating.layout.descriptors.LayoutComponent)

Example 3 with LayoutComponent

use of com.sun.jsftemplating.layout.descriptors.LayoutComponent in project Payara by payara.

the class ListTreeAdaptor 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;
    }
    LayoutComponent desc = getLayoutComponent();
    Map<String, Object> props = new HashMap<String, Object>();
    if ((nodeObject instanceof Integer) && nodeObject.equals(TOP_ID)) {
        // This case deals with the top node.
        // NOTE: All supported options must be handled here,
        // otherwise they'll be ignored.
        // NOTE: Options will be evaluated later, do not eval here.
        setProperty(props, "text", desc.getOption("text"));
        setProperty(props, "url", desc.getOption("url"));
        setProperty(props, "imageURL", desc.getOption("imageURL"));
        setProperty(props, "target", desc.getOption("target"));
        setProperty(props, "action", desc.getOption("action"));
        // NOTE: Although actionListener is supported, LH currently
        // implements this to be the ActionListener of the "turner"
        // which is inconsistent with "action".  We should make use
        // of the "Handler" feature which provides a "toggle"
        // CommandEvent.
        setProperty(props, "actionListener", desc.getOption("actionListener"));
        setProperty(props, "expanded", desc.getOption("expanded"));
        setProperty(props, "rendered", desc.getOption("rendered"));
    } else {
        // This case deals with the children
        if (nodeObject instanceof Map) {
            String key = (String) desc.getOption("childNameKey");
            if (key == null) {
                key = "name";
            }
            setProperty(props, "text", ((Map) nodeObject).get(key));
        } else {
            // Use the object itself...
            setProperty(props, "text", nodeObject);
        }
        // Finish setting the child properties
        setProperty(props, "url", desc.getOption("childURL"));
        setProperty(props, "imageURL", desc.getOption("childImageURL"));
        setProperty(props, "action", desc.getOption("childAction"));
        String tt = (String) desc.getOption("targetConfigName");
        if (!GuiUtil.isEmpty(tt)) {
            setProperty(props, "targetConfigName", tt);
        }
        /*
	    String check = (String) desc.getOption("checkAdminServer");
	    if (!GuiUtil.isEmpty(check)) {
		String serverName = (String) props.get("text");
		if (serverName.equals("server")) {
		    setProperty(props, "text", "server (Admin Server)");
		    setProperty(props, "serverName", "server");
		} else {
		    setProperty(props, "serverName", serverName);
		}
	    }
	*/
        setProperty(props, "encodedText", GuiUtil.encode((String) props.get("text"), null, null));
        // We are using "childActionListener" for the hyperlink, not the TreeNode
        // setProperty(props, "actionListener", desc.getOption("childActionListener"));
        setProperty(props, "expanded", desc.getOption("childExpanded"));
    }
    // Return the options
    return props;
}
Also used : HashMap(java.util.HashMap) LayoutComponent(com.sun.jsftemplating.layout.descriptors.LayoutComponent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with LayoutComponent

use of com.sun.jsftemplating.layout.descriptors.LayoutComponent in project Payara by payara.

the class ListTreeAdaptor method getFacets.

/**
 *	<p> This method returns any facets that should be applied to the
 *	    <code>TreeNode (comp)</code>.  Useful facets for the sun
 *	    <code>TreeNode</code> component are: "content" and "image".</p>
 *
 *	<p> Facets that already exist on <code>comp</code>, or facets that
 *	    are directly added to <code>comp</code> do not need to be returned
 *	    from this method.</p>
 *
 *	<p> This implementation directly adds a "content" and "image" facet and
 *	    returns <code>null</code> from this method.</p>
 *
 *	@param	comp	    The tree node <code>UIComponent</code>.
 *	@param	nodeObject  The (model) object representing the tree node.
 */
public Map<String, UIComponent> getFacets(UIComponent comp, Object nodeObject) {
    if (nodeObject == null) {
        return null;
    }
    if ((nodeObject instanceof Integer) && nodeObject.equals(TOP_ID)) {
        // Top-level facets can be added directly, not needed here
        return null;
    }
    Properties props = new Properties();
    LayoutComponent desc = this.getLayoutComponent();
    // Check to see if a childActionListener was added
    // NOTE: This is not needed when a "command" event is used.  In the
    // case of a CommandEvent an ActionListener will be
    // automatically registered by the ComponentFactoryBase class
    // during "setOptions()".  Also, setting a childActionListener
    // here should not stop "command" handlers from being invoked.
    setProperty(props, "actionListener", desc.getOption("childActionListener"));
    // Also se the target and text...
    setProperty(props, "target", desc.getOption("childTarget"));
    // FIXME: Add support for other hyperlink properties??
    // Create Hyperlink
    // NOTE: Last attribute "content" will be the facet named used.
    FacesContext ctx = FacesContext.getCurrentInstance();
    ComponentUtil compUtil = ComponentUtil.getInstance(ctx);
    UIComponent imageLink = compUtil.getChild(comp, "imagelink", "com.sun.jsftemplating.component.factory.sun.ImageHyperlinkFactory", props, "image");
    // Force HTML renderer so we can use dynafaces safely.
    imageLink.setRendererType("com.sun.webui.jsf.ImageHyperlink");
    // We don't want the imageHyperlink to have the following property, so
    // set it after creating it
    setProperty(props, "text", comp.getAttributes().get("text"));
    UIComponent link = compUtil.getChild(comp, "link", "com.sun.jsftemplating.component.factory.sun.HyperlinkFactory", props, "content");
    // Force HTML renderer so we can use dynafaces safely.
    link.setRendererType("com.sun.webui.jsf.Hyperlink");
    // Check to see if we have a childURL, evalute it here (after component
    // is created, before rendered) so we can use the link itself to define
    // the URL.  This has proven to be useful...
    Object val = desc.getOption("childURL");
    if (val != null) {
        val = desc.resolveValue(ctx, link, val);
        link.getAttributes().put("url", val);
        imageLink.getAttributes().put("url", val);
    }
    // Set the image URL
    val = desc.getOption("childImageURL");
    if (val != null) {
        imageLink.getAttributes().put("imageURL", desc.resolveValue(ctx, link, val));
    }
    // Set href's handlers...
    // We do it this way rather than earlier b/c the factory will not
    // recognize this as a property, it requires it to be defined in the
    // LayoutComponent as a handler.  So we must do this manually like
    // this.
    List handlers = desc.getHandlers("childCommand");
    if (handlers != null) {
        link.getAttributes().put("command", handlers);
        imageLink.getAttributes().put("command", handlers);
        // This adds the required action listener to proces the commands
        // This is needed here b/c the factory has already executed -- the
        // factory is normally the place where this is added (iff there is
        // at least one command handler).
        (ActionSource.class.cast(link)).addActionListener(CommandActionListener.getInstance());
        (ActionSource.class.cast(imageLink)).addActionListener(CommandActionListener.getInstance());
    }
    // We already added the facet, return null...
    return null;
}
Also used : FacesContext(javax.faces.context.FacesContext) UIComponent(javax.faces.component.UIComponent) ComponentUtil(com.sun.jsftemplating.component.ComponentUtil) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties) LayoutComponent(com.sun.jsftemplating.layout.descriptors.LayoutComponent)

Example 5 with LayoutComponent

use of com.sun.jsftemplating.layout.descriptors.LayoutComponent in project Payara by payara.

the class PluginHandlers method includeFirstIntegrationPoint.

/**
 *	Includes the first IP based on priority for the given type.  It adds
 *	the content to the given UIComponent root.  If the IP content looks
 *	like a URL (contains ://), a StaticText component will be added with
 *	the value of the content from the URL.
 */
@Handler(id = "includeFirstIntegrationPoint", input = { @HandlerInput(name = "type", type = String.class, required = true), @HandlerInput(name = "root", type = UIComponent.class, required = false) })
public static void includeFirstIntegrationPoint(HandlerContext handlerCtx) throws java.io.IOException {
    // Get the input
    String type = (String) handlerCtx.getInputValue("type");
    UIComponent root = (UIComponent) handlerCtx.getInputValue("root");
    // Get the IntegrationPoints
    FacesContext ctx = handlerCtx.getFacesContext();
    Set<IntegrationPoint> points = getSortedIntegrationPoints(getIntegrationPoints(ctx, type));
    if (points != null) {
        Iterator<IntegrationPoint> it = points.iterator();
        if (it.hasNext()) {
            // Get the first one...
            IntegrationPoint point = it.next();
            root = getIntegrationPointParent(ctx, root, point);
            // Check to see if IP points to an external URL...
            if (point.getContent().lastIndexOf("://", 15) != -1) {
                // Treat content as a url...
                URL contentURL = FileUtil.searchForFile(point.getContent(), null);
                if (contentURL == null) {
                    throw new IOException("Unable to locate file: " + point.getContent());
                }
                // Read the content...
                String content = new String(FileUtil.readFromURL(contentURL));
                // Create a StaticText component and add it under the
                // "root" component.
                LayoutComponent stDesc = new LayoutComponent(null, "externalContent", new ComponentType("tmpTextCT", "com.sun.jsftemplating.component.factory.basic.StaticTextFactory"));
                stDesc.addOption("value", content);
                ComponentUtil.getInstance(ctx).createChildComponent(ctx, stDesc, root);
            } else {
                // Include the first one...
                includeIntegrationPoint(ctx, root, point);
            }
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ComponentType(com.sun.jsftemplating.layout.descriptors.ComponentType) UIComponent(javax.faces.component.UIComponent) IntegrationPoint(org.glassfish.admingui.connector.IntegrationPoint) IOException(java.io.IOException) LayoutComponent(com.sun.jsftemplating.layout.descriptors.LayoutComponent) URL(java.net.URL) Handler(com.sun.jsftemplating.annotation.Handler) LayoutViewHandler(com.sun.jsftemplating.layout.LayoutViewHandler)

Aggregations

LayoutComponent (com.sun.jsftemplating.layout.descriptors.LayoutComponent)6 FacesContext (javax.faces.context.FacesContext)5 UIComponent (javax.faces.component.UIComponent)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Handler (com.sun.jsftemplating.annotation.Handler)1 ComponentUtil (com.sun.jsftemplating.component.ComponentUtil)1 LayoutViewHandler (com.sun.jsftemplating.layout.LayoutViewHandler)1 ComponentType (com.sun.jsftemplating.layout.descriptors.ComponentType)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Properties (java.util.Properties)1 Index (org.glassfish.admingui.connector.Index)1 IntegrationPoint (org.glassfish.admingui.connector.IntegrationPoint)1 TOC (org.glassfish.admingui.connector.TOC)1