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.AfterRender;
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.ioc.annotations.Inject;
026 import org.apache.tapestry5.json.JSONObject;
027 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
028 import org.chenillekit.tapestry.core.base.AbstractYahooComponent;
029
030 /**
031 * @author <a href="mailto:homburgs@googlemail.com">sven</a>
032 * @version $Id: Button.java 697 2010-09-06 12:09:50Z homburgs $
033 */
034 @Import(stack = {"yahoo"}, stylesheet = {"${yahoo.yui}/button/assets/skins/sam/button.css"},
035 library = {"${yahoo.yui}/button/button${yahoo.yui.mode}.js", "Button.js"})
036 //@MixinAfter
037 public class Button extends AbstractYahooComponent
038 {
039 @Parameter(required = false, defaultPrefix = BindingConstants.LITERAL)
040 private String label;
041
042 @Parameter(required = false, defaultPrefix = BindingConstants.LITERAL)
043 private String type;
044
045 /**
046 * RenderSupport to get unique client side id.
047 */
048 @Inject
049 private JavaScriptSupport javascriptSupport;
050
051 @InjectContainer
052 private ClientElement clientElement;
053
054 /**
055 * Tapestry render phase method. End a tag here.
056 *
057 * @param writer the markup writer
058 */
059 @AfterRender
060 void afterRender(MarkupWriter writer)
061 {
062 JSONObject options = new JSONObject();
063
064 options.put("label", label);
065
066 if (clientElement instanceof AbstractField)
067 options.put("disabled", ((AbstractField) clientElement).isDisabled());
068 else
069 options.put("disabled", isDisabled());
070
071 configure(options);
072
073 javascriptSupport.addScript("new Button('%s', %s);", clientElement.getClientId(), options);
074 }
075
076 /**
077 * Invoked to allow subclasses to further configure the parameters passed to this mixin's javascript
078 * options. Subclasses may override this method to configure additional features of this mixin.
079 * <p/>
080 * This implementation does nothing.
081 *
082 * @param options option object
083 */
084 protected void configure(JSONObject options)
085 {
086 }
087 }