001    /*
002     * Apache License
003     * Version 2.0, January 2004
004     * http://www.apache.org/licenses/
005     *
006     * Copyright 2008-2010 by chenillekit.org
007     *
008     * Licensed under the Apache License, Version 2.0 (the "License");
009     * you may not use this file except in compliance with the License.
010     * You may obtain a copy of the License at
011     *
012     * http://www.apache.org/licenses/LICENSE-2.0
013     */
014    
015    package org.chenillekit.tapestry.core.mixins.yui;
016    
017    import org.apache.tapestry5.BindingConstants;
018    import org.apache.tapestry5.ClientElement;
019    import org.apache.tapestry5.MarkupWriter;
020    import org.apache.tapestry5.annotations.Environmental;
021    import org.apache.tapestry5.annotations.Import;
022    import org.apache.tapestry5.annotations.InjectContainer;
023    import org.apache.tapestry5.annotations.Parameter;
024    import org.apache.tapestry5.corelib.base.AbstractField;
025    import org.apache.tapestry5.json.JSONObject;
026    import org.apache.tapestry5.services.javascript.JavaScriptSupport;
027    import org.chenillekit.tapestry.core.base.AbstractYahooComponent;
028    
029    /**
030     * @author <a href="mailto:homburgs@googlemail.com">sven</a>
031     * @version $Id: SplitButton.java 675 2010-07-30 14:49:17Z homburgs $
032     */
033    @Import(stack = {"yahoo"}, stylesheet = {"${yahoo.yui}/button/assets/skins/sam/button.css"},
034                    library = {"${yahoo.yui}/button/button${yahoo.yui.mode}.js"})
035    public class SplitButton extends AbstractYahooComponent
036    {
037            @Parameter(required = false, defaultPrefix = BindingConstants.LITERAL)
038            private String label;
039    
040            /**
041             * RenderSupport to get unique client side id.
042             */
043            @Environmental
044            private JavaScriptSupport javascriptSupport;
045    
046            @InjectContainer
047            private ClientElement clientElement;
048    
049            /**
050             * Tapestry render phase method.
051             * Start a tag here, end it in afterRender
052             *
053             * @param writer the markup writer
054             */
055            void beginRender(MarkupWriter writer)
056            {
057    
058            }
059    
060    
061            /**
062             * Tapestry render phase method. End a tag here.
063             *
064             * @param writer the markup writer
065             */
066            void afterRender(MarkupWriter writer)
067            {
068                    JSONObject options = new JSONObject();
069    
070                    options.put("label", label);
071    
072                    if (clientElement instanceof AbstractField)
073                            options.put("disabled", ((AbstractField) clientElement).isDisabled());
074                    else
075                            options.put("disabled", isDisabled());
076    
077                    configure(options);
078    
079                    javascriptSupport.addScript("new YAHOO.widget.Button('%s', %s)", clientElement.getClientId(), options);
080            }
081    
082            /**
083             * Invoked to allow subclasses to further configure the parameters passed to this mixin's javascript
084             * options. Subclasses may override this method to configure additional features of this mixin.
085             * <p/>
086             * This implementation does nothing.
087             *
088             * @param options option object
089             */
090            protected void configure(JSONObject options)
091            {
092            }
093    }