You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/05/16 22:34:17 UTC
svn commit: r1103875 [3/3] -
/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/
Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectSwitchOffClientBehaviorRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectSwitchOffClientBehaviorRenderer.java?rev=1103875&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectSwitchOffClientBehaviorRenderer.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectSwitchOffClientBehaviorRenderer.java Mon May 16 20:34:16 2011
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.effect;
+
+import javax.faces.FacesException;
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.render.ClientBehaviorRenderer;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFClientBehaviorRenderer;
+
+@JSFClientBehaviorRenderer(
+ renderKitId = "HTML_BASIC",
+ type = "org.apache.myfaces.custom.effect.EffectSwitchOffBehavior")
+@ResourceDependencies({
+ @ResourceDependency(library="oam.custom.prototype", name="prototype.js"),
+ @ResourceDependency(library="oam.custom.prototype", name="effects.js")
+})
+public class EffectSwitchOffClientBehaviorRenderer extends ClientBehaviorRenderer
+{
+
+ @Override
+ public String getScript(ClientBehaviorContext behaviorContext,
+ ClientBehavior behavior)
+ {
+ AbstractEffectSwitchOffClientBehavior effectBehavior = (AbstractEffectSwitchOffClientBehavior) behavior;
+
+ UIComponent target = ( effectBehavior.getForId() != null ) ?
+ behaviorContext.getComponent().findComponent(effectBehavior.getForId()) :
+ behaviorContext.getComponent();
+ if (target == null)
+ {
+ throw new FacesException("Cannot find component set with forId: "+effectBehavior.getForId());
+ }
+ String clientId = target.getClientId();
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("Effect.SwitchOff('");
+ sb.append(clientId);
+ sb.append("')");
+
+ if (effectBehavior.getAppendJs() != null && effectBehavior.getAppendJs().length() > 0)
+ {
+ sb.append(';');
+ sb.append(effectBehavior.getAppendJs());
+ }
+
+ return sb.toString();
+ }
+}
Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectToggleClientBehaviorRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectToggleClientBehaviorRenderer.java?rev=1103875&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectToggleClientBehaviorRenderer.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectToggleClientBehaviorRenderer.java Mon May 16 20:34:16 2011
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.effect;
+
+import javax.faces.FacesException;
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.render.ClientBehaviorRenderer;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFClientBehaviorRenderer;
+
+@JSFClientBehaviorRenderer(
+ renderKitId = "HTML_BASIC",
+ type = "org.apache.myfaces.custom.effect.EffectToggleBehavior")
+@ResourceDependencies({
+ @ResourceDependency(library="oam.custom.prototype", name="prototype.js"),
+ @ResourceDependency(library="oam.custom.prototype", name="effects.js")
+})
+public class EffectToggleClientBehaviorRenderer extends ClientBehaviorRenderer
+{
+ /**
+ * Effect.Fade('id_of_element', { duration: 3.0 });
+ */
+ @Override
+ public String getScript(ClientBehaviorContext behaviorContext,
+ ClientBehavior behavior)
+ {
+ AbstractEffectToggleClientBehavior effectBehavior = (AbstractEffectToggleClientBehavior) behavior;
+
+ UIComponent target = ( effectBehavior.getForId() != null ) ?
+ behaviorContext.getComponent().findComponent(effectBehavior.getForId()) :
+ behaviorContext.getComponent();
+ if (target == null)
+ {
+ throw new FacesException("Cannot find component set with forId: "+effectBehavior.getForId());
+ }
+ String clientId = target.getClientId();
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("new Effect.toggle('");
+ sb.append(clientId);
+ sb.append('\'');
+ sb.append(',');
+ sb.append('\'');
+ sb.append(effectBehavior.getMode());
+ sb.append('\'');
+
+ if (effectBehavior.getDelay() != null || effectBehavior.getDuration() != null)
+ {
+ sb.append(",{");
+ boolean addComma = false;
+ addComma = EffectUtils.addProperty(sb, "delay", effectBehavior.getDelay(), addComma);
+ addComma = EffectUtils.addProperty(sb, "duration", effectBehavior.getDuration(), addComma);
+ sb.append('}');
+ }
+ sb.append(')');
+
+ if (effectBehavior.getAppendJs() != null && effectBehavior.getAppendJs().length() > 0)
+ {
+ sb.append(';');
+ sb.append(effectBehavior.getAppendJs());
+ }
+
+ return sb.toString();
+ }
+
+}
Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectUtils.java?rev=1103875&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectUtils.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/effect/EffectUtils.java Mon May 16 20:34:16 2011
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.effect;
+
+public class EffectUtils
+{
+
+ public static boolean addProperty(StringBuilder sb, String name, Object value, boolean addComma)
+ {
+ if (value != null)
+ {
+ if (addComma)
+ {
+ sb.append(',');
+ }
+ sb.append(name);
+ sb.append(':');
+ sb.append(value);
+ return true;
+ }
+ else
+ {
+ return addComma;
+ }
+ }
+
+ public static boolean addStringProperty(StringBuilder sb, String name, Object value, boolean addComma)
+ {
+ if (value != null)
+ {
+ if (addComma)
+ {
+ sb.append(',');
+ }
+ sb.append(name);
+ sb.append(':');
+ sb.append('\'');
+ sb.append(value);
+ sb.append('\'');
+ return true;
+ }
+ else
+ {
+ return addComma;
+ }
+ }
+
+}