Author: Alex.Kolonitsky
Date: 2010-07-07 07:32:06 -0400 (Wed, 07 Jul 2010)
New Revision: 17755
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/
root/ui-sandbox/panels/trunk/ui/src/main/java/org/
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractDivPanel.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/Method.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UIDivPanel.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanel.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanelItem.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/behavior/
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/behavior/ToggleControl.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlDivPanel.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlTogglePanel.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlTogglePanelItem.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/MethodExpressionSelectedItemChangeListener.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/SelectedItemChangeEvent.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/SelectedItemChangeListener.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/ToggleControlRenderer.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/taglib/
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/taglib/SelectedItemChangeListenerHandler.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/taglib/TogglePanelTagHandler.java
Log:
RF-8745 TogglePanel component
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractDivPanel.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractDivPanel.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractDivPanel.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+import javax.faces.component.UIOutput;
+
+/**
+ * @author akolonitsky
+ * @version 1.0
+ * @since -4712-01-01
+ *
+ */
+public abstract class AbstractDivPanel extends UIOutput {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.panels.DivPanel";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.panels.DivPanel";
+
+ protected AbstractDivPanel() {
+ setRendererType("org.richfaces.panels.DivPanelRenderer");
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+}
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,641 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+import org.richfaces.event.SelectedItemChangeEvent;
+import org.richfaces.event.SelectedItemChangeListener;
+
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
+//import javax.faces.component.MessageFactory;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UpdateModelException;
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+import javax.faces.event.ExceptionQueuedEvent;
+import javax.faces.event.ExceptionQueuedEventContext;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PostValidateEvent;
+import javax.faces.event.PreValidateEvent;
+import javax.faces.event.ValueChangeListener;
+import javax.faces.validator.Validator;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author akolonitsky
+ * @version 1.0
+ * @since -4712-01-01
+ */
+public abstract class AbstractTogglePanel extends AbstractDivPanel implements
EditableValueHolder {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.panels.TogglePanel";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.panels.TogglePanel";
+
+ public static final String UPDATE_MESSAGE_ID =
+ "javax.faces.component.UIInput.UPDATE";
+
+ private String submittedSelectedItem = null;
+
+ private enum PropertyKeys {
+ localValueSet,
+ required,
+ valid,
+ immediate
+ }
+
+ protected AbstractTogglePanel() {
+ setRendererType("org.richfaces.panels.TogglePanelRenderer");
+ }
+
+
+ // -------------------------------------------------- Editable Value Holder
+
+ public Object getSubmittedValue() {
+ return this.submittedSelectedItem;
+ }
+
+ public void resetValue() {
+ this.setValue(null);
+ this.setSubmittedValue(null);
+ this.setLocalValueSet(false);
+ this.setValid(true);
+ }
+
+ public void setSubmittedValue(Object submittedValue) {
+ this.submittedSelectedItem = String.valueOf(submittedValue);
+ }
+
+ /**
+ * Return the "local value set" state for this component.
+ * Calls to <code>setValue()</code> automatically reset
+ * this property to <code>true</code>.
+ */
+ public boolean isLocalValueSet() {
+ return (Boolean) getStateHelper().eval(PropertyKeys.localValueSet, false);
+ }
+
+ /**
+ * Sets the "local value set" state for this component.
+ */
+ public void setLocalValueSet(boolean localValueSet) {
+ getStateHelper().put(PropertyKeys.localValueSet, localValueSet);
+ }
+
+ public boolean isValid() {
+ return (Boolean) getStateHelper().eval(PropertyKeys.valid, true);
+ }
+
+
+ public void setValid(boolean valid) {
+ getStateHelper().put(PropertyKeys.valid, valid);
+ }
+
+ /**
+ * <p>Return the "required field" state for this
component.</p>
+ */
+ public boolean isRequired() {
+ return (Boolean) getStateHelper().eval(PropertyKeys.required, false);
+ }
+
+ /**
+ * <p>Set the "required field" state for this component.</p>
+ *
+ * @param required The new "required field" state
+ */
+ public void setRequired(boolean required) {
+ getStateHelper().put(PropertyKeys.required, required);
+ }
+
+
+ public boolean isImmediate() {
+ return (Boolean) getStateHelper().eval(PropertyKeys.immediate, false);
+ }
+
+
+ public void setImmediate(boolean immediate) {
+ getStateHelper().put(PropertyKeys.immediate, immediate);
+ }
+
+ public MethodBinding getValidator() {
+ throw new UnknownError();
+ }
+
+ public void setValidator(MethodBinding validatorBinding) {
+ throw new UnknownError();
+ }
+
+ public MethodBinding getValueChangeListener() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setValueChangeListener(MethodBinding valueChangeMethod) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addValidator(Validator validator) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Validator[] getValidators() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeValidator(Validator validator) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addValueChangeListener(ValueChangeListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ public ValueChangeListener[] getValueChangeListeners() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeValueChangeListener(ValueChangeListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ // ----------------------------------------------------- UIComponent Methods
+
+ /**
+ * <p>Specialized decode behavior on top of that provided by the
+ * superclass. In addition to the standard
+ * <code>processDecodes</code> behavior inherited from {@link
+ * javax.faces.component.UIComponentBase}, calls <code>validate()</code>
if the the
+ * <code>immediate</code> property is true; if the component is
+ * invalid afterwards or a <code>RuntimeException</code> is thrown,
+ * calls {@link FacesContext#renderResponse}. </p>
+ *
+ * @throws NullPointerException {@inheritDoc}
+ */
+ @Override
+ public void processDecodes(FacesContext context) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ // Skip processing if our rendered flag is false
+ if (!isRendered()) {
+ return;
+ }
+
+ pushComponentToEL(context, null);
+
+ // Process all facets and children of this component
+ Iterator<UIComponent> kids = getFacetsAndChildren();
+ while (kids.hasNext()) {
+ UIComponent kid = kids.next();
+ if (isSelectedItem(kid)) {
+ kid.processDecodes(context);
+ }
+ }
+
+ // Process this component itself
+ try {
+ decode(context);
+ } catch (RuntimeException e) {
+ context.renderResponse();
+ throw e;
+ } finally {
+ popComponentFromEL(context);
+ }
+
+ if (isImmediate()) {
+ executeValidate(context);
+ }
+ }
+
+ /**
+ * <p>In addition to the standard <code>processValidators</code>
behavior
+ * inherited from {@link javax.faces.component.UIComponentBase}, calls
<code>validate()</code>
+ * if the <code>immediate</code> property is false (which is the
+ * default); if the component is invalid afterwards, calls
+ * {@link FacesContext#renderResponse}.
+ * If a <code>RuntimeException</code> is thrown during
+ * validation processing, calls {@link FacesContext#renderResponse}
+ * and re-throw the exception.
+ * </p>
+ *
+ * @throws NullPointerException {@inheritDoc}
+ */
+ @Override
+ public void processValidators(FacesContext context) {
+
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ // Skip processing if our rendered flag is false
+ if (!isRendered()) {
+ return;
+ }
+
+ pushComponentToEL(context, null);
+
+ Application app = context.getApplication();
+ app.publishEvent(context, PreValidateEvent.class, this);
+ // Process all the facets and children of this component
+ Iterator<UIComponent> kids = getFacetsAndChildren();
+ while (kids.hasNext()) {
+ UIComponent kid = kids.next();
+ if (isSelectedItem(kid)) {
+ kid.processValidators(context);
+ }
+ }
+ app.publishEvent(context, PostValidateEvent.class, this);
+ popComponentFromEL(context);
+
+ if (!isImmediate()) {
+ executeValidate(context);
+ }
+ }
+
+ /**
+ * <p>In addition to the standard <code>processUpdates</code>
behavior
+ * inherited from {@link javax.faces.component.UIComponentBase}, calls
+ * <code>updateModel()</code>.
+ * If the component is invalid afterwards, calls
+ * {@link FacesContext#renderResponse}.
+ * If a <code>RuntimeException</code> is thrown during
+ * update processing, calls {@link FacesContext#renderResponse}
+ * and re-throw the exception.
+ * </p>
+ *
+ * @throws NullPointerException {@inheritDoc}
+ */
+ @Override
+ public void processUpdates(FacesContext context) {
+
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ // Skip processing if our rendered flag is false
+ if (!isRendered()) {
+ return;
+ }
+
+ pushComponentToEL(context, null);
+
+ // Process all facets and children of this component
+ Iterator<UIComponent> kids = getFacetsAndChildren();
+ while (kids.hasNext()) {
+ UIComponent kid = kids.next();
+ if (isSelectedItem(kid)) {
+ kid.processUpdates(context);
+ }
+ }
+
+ popComponentFromEL(context);
+
+ try {
+ updateModel(context);
+ } catch (RuntimeException e) {
+ context.renderResponse();
+ throw e;
+ }
+
+ if (!isValid()) {
+ context.renderResponse();
+ }
+ }
+
+ /**
+ * @throws NullPointerException {@inheritDoc}
+ */
+ @Override
+ public void decode(FacesContext context) {
+
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ // Force validity back to "true"
+ setValid(true);
+ super.decode(context);
+ }
+
+ /**
+ * <p><span class="changed_modified_2_0">Perform</span>
+ * the following algorithm to update the model data
+ * associated with this {@link javax.faces.component.UIInput}, if any, as
appropriate.</p>
+ * <ul>
+ * <li>If the <code>valid</code> property of this component is
+ * <code>false</code>, take no further action.</li>
+ * <li>If the <code>localValueSet</code> property of this component
is
+ * <code>false</code>, take no further action.</li>
+ * <li>If no {@link javax.el.ValueExpression} for
<code>value</code> exists,
+ * take no further action.</li>
+ * <li>Call <code>setValue()</code> method of the {@link
javax.el.ValueExpression}
+ * to update the value that the {@link javax.el.ValueExpression} points
at.</li>
+ * <li>If the <code>setValue()</code> method returns successfully:
+ * <ul>
+ * <li>Clear the local value of this {@link
javax.faces.component.UIInput}.</li>
+ * <li>Set the <code>localValueSet</code> property of this
+ * {@link javax.faces.component.UIInput} to false.</li>
+ * </ul></li>
+ * <li>If the <code>setValue()</code> method throws an Exception:
+ * <ul>
+ * <li class="changed_modified_2_0">Enqueue an error message. Create
a
+ * {@link javax.faces.application.FacesMessage} with the id {@link
#UPDATE_MESSAGE_ID}. Create a
+ * {@link javax.faces.component.UpdateModelException}, passing the
<code>FacesMessage</code> and
+ * the caught exception to the constructor. Create an
+ * {@link javax.faces.event.ExceptionQueuedEventContext}, passing the
<code>FacesContext</code>,
+ * the <code>UpdateModelException</code>, this component instance, and
+ * {@link javax.faces.event.PhaseId#UPDATE_MODEL_VALUES} to its constructor. Call
+ * {@link FacesContext#getExceptionHandler} and then call
+ * {@link javax.faces.context.ExceptionHandler#processEvent}, passing the
+ * <code>ExceptionQueuedEventContext</code>.
+ * </li>
+ * <li>Set the <code>valid</code> property of this {@link
javax.faces.component.UIInput}
+ * to <code>false</code>.</li>
+ * </ul></li>
+ * The exception must not be re-thrown. This enables tree traversal
+ * to continue for this lifecycle phase, as in all the other lifecycle
+ * phases.
+ * </ul>
+ *
+ * @param context {@link FacesContext} for the request we are processing
+ * @throws NullPointerException if <code>context</code>
+ * is <code>null</code>
+ */
+ public void updateModel(FacesContext context) {
+
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ if (!isValid() || !isLocalValueSet()) {
+ return;
+ }
+
+ ValueExpression ve = getValueExpression("value");
+ if (ve == null) {
+ return;
+ }
+
+ Throwable caught = null;
+ FacesMessage message = null;
+ try {
+ ve.setValue(context.getELContext(), getLocalValue());
+ setValue(null);
+ setLocalValueSet(false);
+ } catch (ELException e) {
+ caught = e;
+ String messageStr = e.getMessage();
+ Throwable result = e.getCause();
+ while (null != result &&
result.getClass().isAssignableFrom(ELException.class)) {
+ messageStr = result.getMessage();
+ result = result.getCause();
+ }
+
+ if (messageStr == null) {
+ // todo
+ //message = MessageFactory.getMessage(context, UPDATE_MESSAGE_ID,
+ // MessageFactory.getLabel(context, this));
+ } else {
+ //message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr,
messageStr);
+ }
+ setValid(false);
+ } catch (Exception e) {
+ caught = e;
+ //message = MessageFactory.getMessage(context, UPDATE_MESSAGE_ID,
+ // MessageFactory.getLabel(context, this));
+ setValid(false);
+ }
+
+ if (caught != null) {
+ assert message != null;
+
+ @SuppressWarnings({"ThrowableInstanceNeverThrown"})
+ UpdateModelException toQueue = new UpdateModelException(message, caught);
+ ExceptionQueuedEventContext eventContext = new
ExceptionQueuedEventContext(context,
+ toQueue, this, PhaseId.UPDATE_MODEL_VALUES);
+ context.getApplication().publishEvent(context, ExceptionQueuedEvent.class,
eventContext);
+ }
+ }
+
+ /**
+ * Executes validation logic.
+ */
+ private void executeValidate(FacesContext context) {
+ try {
+ validate(context);
+ } catch (RuntimeException e) {
+ context.renderResponse();
+ throw e;
+ }
+
+ if (!isValid()) {
+ context.validationFailed();
+ context.renderResponse();
+ }
+ }
+
+ public void validate(FacesContext context) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ // Submitted value == null means "the component was not submitted at
all".
+ String submittedValue = getSubmittedSelectedItem();
+ if (submittedValue == null) {
+ return;
+ }
+
+ String previous = (String) getValue();
+ setValue(submittedValue);
+ setSubmittedSelectedItem(null);
+ if (!previous.equalsIgnoreCase(submittedValue)) {
+ queueEvent(new SelectedItemChangeEvent(this, previous, submittedValue));
+ }
+ }
+
+
+
+ // -------------------------------------------------- Panel Items Managing
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ @Override
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ private boolean isSelectedItem(UIComponent kid) {
+ String value = getSelectedItem();
+ if (value == null) {
+ value = getSubmittedSelectedItem();
+ }
+ return getChildName(kid).equals(value);
+ }
+
+ public String getFirstItem() {
+ checkChildCount(getChildCount());
+
+ return getChildName(getChildren().get(0));
+ }
+
+ private static void checkChildCount(int childCount) {
+ if (childCount < 1) {
+ throw new IllegalStateException("TogglePanel must have at least one
TogglePanelItem.");
+ }
+ }
+
+ public AbstractTogglePanelItem getItem(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name is required parameter.");
+ }
+ checkChildCount(getChildCount());
+
+ List<UIComponent> children = getChildren();
+ int index = getChildIndex(name, children);
+ if (index == -1) {
+ return null;
+ }
+ return (AbstractTogglePanelItem) children.get(index);
+ }
+
+ public String getNext(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name is required parameter.");
+ }
+ checkChildCount(getChildCount());
+
+
+ List<UIComponent> children = getChildren();
+
+ int nextItem = getChildIndex(name, children) + 1;
+ if (nextItem < children.size()) {
+ return getFirstItem();
+ } else {
+ return getChildName(children.get(nextItem));
+ }
+ }
+
+ private static int getChildIndex(String name, List<UIComponent> children) {
+ int ind = 0;
+ while (ind < children.size()) {
+ UIComponent child = children.get(ind);
+ if (name.equals(getChildName(child))) {
+ return ind;
+ }
+ ind++;
+ }
+
+// throw new IllegalStateException("Can't find child panel item with
name: " + name);
+ return -1;
+ }
+
+ private static String getChildName(UIComponent item) {
+ if (!(item instanceof AbstractTogglePanelItem)) {
+ throw new IllegalStateException("TogglePanel can contain only
TogglePanelItem as child.");
+ }
+
+ return ((AbstractTogglePanelItem) item).getName();
+ }
+
+ // ------------------------------------------------
+
+ public String getSubmittedSelectedItem() {
+ return submittedSelectedItem;
+ }
+
+ public void setSubmittedSelectedItem(String submittedSelectedItem) {
+ this.submittedSelectedItem = submittedSelectedItem;
+ }
+
+
+ // ------------------------------------------------ Properties
+
+ public String getSelectedItem() {
+ return (String) getValue();
+ }
+
+ public void setSelectedItem(String value) {
+ setValue(value);
+ }
+
+ public abstract Method getSwitchType();
+
+ public abstract boolean getBypassUpdates();
+
+ public abstract boolean getLimitToList();
+
+ public abstract Object getData();
+
+ public abstract String getStatus();
+
+ public abstract Object getExecute();
+
+ public abstract Object getRender();
+
+ public abstract MethodExpression getSelectedItemChangeListener();
+
+
+
+ // ------------------------------------------------ Event Processing Methods
+
+ /**
+ * <p>Add a new {@link SelectedItemChangeListener} to the set of listeners
+ * interested in being notified when {@link
org.richfaces.event.SelectedItemChangeEvent}s occur.</p>
+ *
+ * @param listener The {@link SelectedItemChangeListener} to be added
+ * @throws NullPointerException if <code>listener</code>
+ * is <code>null</code>
+ */
+ public void addSelectedItemChangeListener(SelectedItemChangeListener listener) {
+ addFacesListener(listener);
+ }
+
+ /**
+ * <p>Return the set of registered {@link SelectedItemChangeListener}s for this
instance.
+ * If there are no registered listeners, a zero-length array is returned.</p>
+ */
+ public SelectedItemChangeListener[] getSelectedItemChangeListeners() {
+ return (SelectedItemChangeListener[])
getFacesListeners(SelectedItemChangeListener.class);
+ }
+
+ /**
+ * <p>Remove an existing {@link SelectedItemChangeListener} (if any) from the
+ * set of listeners interested in being notified when
+ * {@link org.richfaces.event.SelectedItemChangeEvent}s occur.</p>
+ *
+ * @param listener The {@link SelectedItemChangeListener} to be removed
+ * @throws NullPointerException if <code>listener</code>
+ * is <code>null</code>
+ */
+ public void removeSelectedItemChangeListener(SelectedItemChangeListener listener) {
+ removeFacesListener(listener);
+ }
+
+}
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+
+/**
+ * @author akolonitsky
+ * @version 1.0
+ * @since -4712-01-01
+ */
+public abstract class AbstractTogglePanelItem extends AbstractDivPanel {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.panels.TogglePanelItem";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.panels.TogglePanelItem";
+
+ protected AbstractTogglePanelItem() {
+ setRendererType("org.richfaces.panels.TogglePanelItemRenderer");
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ @Override
+ public void setParent(UIComponent parent) {
+ if (!(parent instanceof AbstractTogglePanel)) {
+ throw new IllegalArgumentException("Parent of TogglePanelItem can be
only TogglePanel.");
+ }
+ super.setParent(parent);
+ }
+
+ @Override
+ public AbstractTogglePanel getParent() {
+ return (AbstractTogglePanel) super.getParent();
+ }
+
+ @Override
+ public Renderer getRenderer(FacesContext context) {
+ return super.getRenderer(context);
+ }
+
+ public abstract String getName();
+
+ public abstract Method getSwitchType();
+
+ public String toString() {
+ return "TogglePanelItem {name: " + getName() + ", switchType:
" + getSwitchType() + '}';
+ }
+}
Added: root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/Method.java
===================================================================
--- root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/Method.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/Method.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,22 @@
+package org.richfaces.component;
+
+/**
+ * @author akolonitsky
+ * @since Jun 15, 2010
+ */
+public enum Method {
+ /**
+ * value for tab change method for - client-side tabs.
+ */
+ client,
+
+ /**
+ * value for tab change method - server-side tabs
+ */
+ server,
+
+ /**
+ * value for tab change method - ajax tabs
+ */
+ ajax
+}
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UIDivPanel.java
===================================================================
--- root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UIDivPanel.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UIDivPanel.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+
+
+/**
+ * @author akolonitsky
+ * @since -4712-01-01
+ */
+public class UIDivPanel extends AbstractDivPanel {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.panels.DivPanel";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.panels.DivPanel";
+
+
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+
+}
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanel.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanel.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanel.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+import javax.el.MethodExpression;
+
+/**
+ * @author akolonitsky
+ * @since -4712-01-01
+ */
+public class UITogglePanel extends AbstractTogglePanel {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.panels.TogglePanel";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.panels.TogglePanel";
+
+ private enum PropertyKeys {
+ switchType,
+ bypassUpdates,
+ limitToList,
+ data,
+ status,
+ execute,
+ render,
+ selectedItemChangeListener
+ }
+
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ public Method getSwitchType() {
+ return (Method) getStateHelper().eval(PropertyKeys.switchType, Method.ajax);
+ }
+
+ public void setSwitchType(Method switchType) {
+ getStateHelper().put(PropertyKeys.switchType, switchType);
+ }
+
+ public boolean getBypassUpdates() {
+ return
Boolean.valueOf(String.valueOf(getStateHelper().eval(PropertyKeys.bypassUpdates)));
+ }
+
+ public void setBypassUpdates(boolean bypassUpdates) {
+ getStateHelper().put(PropertyKeys.bypassUpdates, bypassUpdates);
+ }
+
+ public boolean getLimitToList() {
+ return
Boolean.valueOf(String.valueOf(getStateHelper().eval(PropertyKeys.limitToList)));
+ }
+
+ public void setLimitToList(boolean limitToList) {
+ getStateHelper().put(PropertyKeys.limitToList, limitToList);
+ }
+
+ public Object getData() {
+ return getStateHelper().eval(PropertyKeys.data);
+ }
+
+ public void setData(Object data) {
+ getStateHelper().put(PropertyKeys.data, data);
+ }
+
+ public String getStatus() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.status));
+ }
+
+ public void setStatus(String status) {
+ getStateHelper().put(PropertyKeys.status, status);
+ }
+
+ public Object getExecute() {
+ return getStateHelper().eval(PropertyKeys.execute);
+ }
+
+ public void setExecute(Object execute) {
+ getStateHelper().put(PropertyKeys.execute, execute);
+ }
+
+ public Object getRender() {
+ return getStateHelper().eval(PropertyKeys.render);
+ }
+
+ public void setRender(Object render) {
+ getStateHelper().put(PropertyKeys.render, render);
+ }
+
+ public MethodExpression getSelectedItemChangeListener() {
+ return (MethodExpression)
getStateHelper().eval(PropertyKeys.selectedItemChangeListener);
+ }
+
+ public void setSelectedItemChangeListener(MethodExpression
selectedItemChangeListener) {
+ getStateHelper().put(PropertyKeys.selectedItemChangeListener,
selectedItemChangeListener);
+ }
+
+
+}
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanelItem.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanelItem.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanelItem.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+/**
+ * @author akolonitsky
+ * @since -4712-01-01
+ */
+public class UITogglePanelItem extends AbstractTogglePanelItem {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.panels.TogglePanelItem";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.panels.TogglePanelItem";
+
+ private enum PropertyKeys {
+ name,
+ switchType
+ }
+
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ @Override
+ public String getName() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.name));
+ }
+
+ public void setName(String name) {
+ getStateHelper().put(PropertyKeys.name, name);
+ }
+
+ @Override
+ public Method getSwitchType() {
+ return (Method) getStateHelper().eval(PropertyKeys.switchType,
getParent().getSwitchType());
+ }
+
+ public void setSwitchType(Method switchType) {
+ getStateHelper().put(PropertyKeys.switchType, switchType);
+ }
+
+
+}
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/behavior/ToggleControl.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/behavior/ToggleControl.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/behavior/ToggleControl.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component.behavior;
+
+import org.ajax4jsf.component.behavior.ClientBehavior;
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.richfaces.component.AbstractTogglePanel;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+
+/**
+ * @author akolonitsky
+ *
+ */
+public class ToggleControl extends ClientBehavior {
+
+ public static final String BEHAVIOR_ID =
"org.richfaces.component.behavior.ToggleControl";
+
+ private enum PropertyKeys {
+ event,
+ targetItem,
+ forPanel,
+ }
+
+ public String getEvent() {
+ return (String) getStateHelper().eval(PropertyKeys.event);
+ }
+
+ public void setEvent(String eventName) {
+ getStateHelper().eval(PropertyKeys.event, eventName);
+ }
+
+ public String getTargetItem() {
+ return (String) getStateHelper().eval(PropertyKeys.targetItem);
+ }
+
+ public void setTargetItem(String target) {
+ getStateHelper().put(PropertyKeys.targetItem, target);
+ }
+
+ public String getForPanel() {
+ return (String) getStateHelper().eval(PropertyKeys.forPanel);
+ }
+
+ public void setForPanel(String selector) {
+ getStateHelper().put(PropertyKeys.forPanel, selector);
+ }
+
+ public AbstractTogglePanel getPanel(UIComponent comp) throws FacesException {
+ String target = this.getForPanel();
+
+ if (target != null) {
+
+ UIComponent targetComponent = RendererUtils.getInstance()
+ .findComponentFor(comp, target);
+
+ if (null != targetComponent) {
+ return (AbstractTogglePanel) targetComponent;
+ } else {
+ throw new FacesException("Parent panel for control (id="
+ + comp.getClientId(getFacesContext()) + ") has not been
found.");
+ }
+ } else {
+ UIComponent control = comp;
+ while (control != null) {
+ if (control instanceof AbstractTogglePanel) {
+ return (AbstractTogglePanel) control;
+ }
+
+ control = control.getParent();
+ }
+ throw new FacesException("Parent panel for control (id="
+ + comp.getClientId(getFacesContext()) + ") has not been
found.");
+ }
+ }
+
+ @Override
+ public String getRendererType() {
+ return BEHAVIOR_ID;
+ }
+
+ @Override
+ public void setLiteralAttribute(String name, Object value) {
+// if (compare(PropertyKeys.operation, name)) {
+// setOperation((String) value);
+// } else if (compare(PropertyKeys.target, name)) {
+// setTargetItem((String) value);
+// } else if (compare(PropertyKeys.selector, name)) {
+// setForPanel((String) value);
+// }
+ }
+}
\ No newline at end of file
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlDivPanel.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlDivPanel.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlDivPanel.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,156 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component.html;
+
+
+import org.richfaces.component.UIDivPanel;
+
+public class HtmlDivPanel extends UIDivPanel {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.panels.DivPanel";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.panels.DivPanel";
+
+ private enum PropertyKeys {
+ lang,
+ onclick,
+ ondblclick,
+ onmousedown,
+ onmousemove,
+ onmouseout,
+ onmouseover,
+ onmouseup,
+ title,
+ style,
+ styleClass,
+ dir
+ }
+
+ public HtmlDivPanel() {
+ setRendererType("org.richfaces.panels.DivPanelRenderer");
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ public String getLang() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.lang));
+ }
+
+ public void setLang(String lang) {
+ getStateHelper().put(PropertyKeys.lang, lang);
+ }
+
+ public String getOnclick() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onclick));
+ }
+
+ public void setOnclick(String onclick) {
+ getStateHelper().put(PropertyKeys.onclick, onclick);
+ }
+
+ public String getOndblclick() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.ondblclick));
+ }
+
+ public void setOndblclick(String ondblclick) {
+ getStateHelper().put(PropertyKeys.ondblclick, ondblclick);
+ }
+
+ public String getOnmousedown() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmousedown));
+ }
+
+ public void setOnmousedown(String onmousedown) {
+ getStateHelper().put(PropertyKeys.onmousedown, onmousedown);
+ }
+
+ public String getOnmousemove() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmousemove));
+ }
+
+ public void setOnmousemove(String onmousemove) {
+ getStateHelper().put(PropertyKeys.onmousemove, onmousemove);
+ }
+
+ public String getOnmouseout() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmouseout));
+ }
+
+ public void setOnmouseout(String onmouseout) {
+ getStateHelper().put(PropertyKeys.onmouseout, onmouseout);
+ }
+
+ public String getOnmouseover() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmouseover));
+ }
+
+ public void setOnmouseover(String onmouseover) {
+ getStateHelper().put(PropertyKeys.onmouseover, onmouseover);
+ }
+
+ public String getOnmouseup() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmouseup));
+ }
+
+ public void setOnmouseup(String onmouseup) {
+ getStateHelper().put(PropertyKeys.onmouseup, onmouseup);
+ }
+
+ public String getTitle() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.title));
+ }
+
+ public void setTitle(String title) {
+ getStateHelper().put(PropertyKeys.title, title);
+ }
+
+ public String getStyle() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.style));
+ }
+
+ public void setStyle(String style) {
+ getStateHelper().put(PropertyKeys.style, style);
+ }
+
+ public String getStyleClass() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.styleClass));
+ }
+
+ public void setStyleClass(String styleClass) {
+ getStateHelper().put(PropertyKeys.styleClass, styleClass);
+ }
+
+ public String getDir() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.dir));
+ }
+
+ public void setDir(String dir) {
+ getStateHelper().put(PropertyKeys.dir, dir);
+ }
+
+
+}
+
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlTogglePanel.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlTogglePanel.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlTogglePanel.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component.html;
+
+import org.richfaces.component.UITogglePanel;
+
+public class HtmlTogglePanel extends UITogglePanel {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.panels.TogglePanel";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.panels.TogglePanel";
+
+ private enum PropertyKeys {
+ lang,
+ onclick,
+ ondblclick,
+ onmousedown,
+ onmousemove,
+ onmouseout,
+ onmouseover,
+ onmouseup,
+ title,
+ style,
+ styleClass,
+ dir,
+ oncomplete,
+ onbeforedomupdate,
+ onitemchange,
+ onitemchanged
+ }
+
+ public HtmlTogglePanel() {
+ setRendererType("org.richfaces.panels.TogglePanelRenderer");
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ public String getLang() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.lang));
+ }
+
+ public void setLang(String lang) {
+ getStateHelper().put(PropertyKeys.lang, lang);
+ }
+
+ public String getOnclick() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onclick));
+ }
+
+ public void setOnclick(String onclick) {
+ getStateHelper().put(PropertyKeys.onclick, onclick);
+ }
+
+ public String getOndblclick() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.ondblclick));
+ }
+
+ public void setOndblclick(String ondblclick) {
+ getStateHelper().put(PropertyKeys.ondblclick, ondblclick);
+ }
+
+ public String getOnmousedown() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmousedown));
+ }
+
+ public void setOnmousedown(String onmousedown) {
+ getStateHelper().put(PropertyKeys.onmousedown, onmousedown);
+ }
+
+ public String getOnmousemove() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmousemove));
+ }
+
+ public void setOnmousemove(String onmousemove) {
+ getStateHelper().put(PropertyKeys.onmousemove, onmousemove);
+ }
+
+ public String getOnmouseout() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmouseout));
+ }
+
+ public void setOnmouseout(String onmouseout) {
+ getStateHelper().put(PropertyKeys.onmouseout, onmouseout);
+ }
+
+ public String getOnmouseover() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmouseover));
+ }
+
+ public void setOnmouseover(String onmouseover) {
+ getStateHelper().put(PropertyKeys.onmouseover, onmouseover);
+ }
+
+ public String getOnmouseup() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmouseup));
+ }
+
+ public void setOnmouseup(String onmouseup) {
+ getStateHelper().put(PropertyKeys.onmouseup, onmouseup);
+ }
+
+ public String getTitle() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.title));
+ }
+
+ public void setTitle(String title) {
+ getStateHelper().put(PropertyKeys.title, title);
+ }
+
+ public String getStyle() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.style));
+ }
+
+ public void setStyle(String style) {
+ getStateHelper().put(PropertyKeys.style, style);
+ }
+
+ public String getStyleClass() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.styleClass));
+ }
+
+ public void setStyleClass(String styleClass) {
+ getStateHelper().put(PropertyKeys.styleClass, styleClass);
+ }
+
+ public String getDir() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.dir));
+ }
+
+ public void setDir(String dir) {
+ getStateHelper().put(PropertyKeys.dir, dir);
+ }
+
+ public String getOncomplete() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.oncomplete));
+ }
+
+ public void setOncomplete(String oncomplete) {
+ getStateHelper().put(PropertyKeys.oncomplete, oncomplete);
+ }
+
+ public String getOnbeforedomupdate() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onbeforedomupdate));
+ }
+
+ public void setOnbeforedomupdate(String onbeforedomupdate) {
+ getStateHelper().put(PropertyKeys.onbeforedomupdate, onbeforedomupdate);
+ }
+
+ public String getOnitemchange() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onitemchange));
+ }
+
+ public void setOnitemchange(String onitemchange) {
+ getStateHelper().put(PropertyKeys.onitemchange, onitemchange);
+ }
+
+ public String getOnitemchanged() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onitemchanged));
+ }
+
+ public void setOnitemchanged(String onitemchanged) {
+ getStateHelper().put(PropertyKeys.onitemchanged, onitemchanged);
+ }
+
+
+}
+
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlTogglePanelItem.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlTogglePanelItem.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/html/HtmlTogglePanelItem.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,173 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component.html;
+
+import org.richfaces.component.UITogglePanelItem;
+
+public class HtmlTogglePanelItem extends UITogglePanelItem {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.panels.TogglePanelItem";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.panels.TogglePanelItem";
+
+ private enum PropertyKeys {
+ lang,
+ onclick,
+ ondblclick,
+ onmousedown,
+ onmousemove,
+ onmouseout,
+ onmouseover,
+ onmouseup,
+ title,
+ style,
+ styleClass,
+ dir,
+ onenter,
+ onleave
+ }
+
+ public HtmlTogglePanelItem() {
+ setRendererType("org.richfaces.panels.TogglePanelItemRenderer");
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ public String getLang() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.lang));
+ }
+
+ public void setLang(String lang) {
+ getStateHelper().put(PropertyKeys.lang, lang);
+ }
+
+ public String getOnclick() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onclick));
+ }
+
+ public void setOnclick(String onclick) {
+ getStateHelper().put(PropertyKeys.onclick, onclick);
+ }
+
+ public String getOndblclick() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.ondblclick));
+ }
+
+ public void setOndblclick(String ondblclick) {
+ getStateHelper().put(PropertyKeys.ondblclick, ondblclick);
+ }
+
+ public String getOnmousedown() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmousedown));
+ }
+
+ public void setOnmousedown(String onmousedown) {
+ getStateHelper().put(PropertyKeys.onmousedown, onmousedown);
+ }
+
+ public String getOnmousemove() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmousemove));
+ }
+
+ public void setOnmousemove(String onmousemove) {
+ getStateHelper().put(PropertyKeys.onmousemove, onmousemove);
+ }
+
+ public String getOnmouseout() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmouseout));
+ }
+
+ public void setOnmouseout(String onmouseout) {
+ getStateHelper().put(PropertyKeys.onmouseout, onmouseout);
+ }
+
+ public String getOnmouseover() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmouseover));
+ }
+
+ public void setOnmouseover(String onmouseover) {
+ getStateHelper().put(PropertyKeys.onmouseover, onmouseover);
+ }
+
+ public String getOnmouseup() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onmouseup));
+ }
+
+ public void setOnmouseup(String onmouseup) {
+ getStateHelper().put(PropertyKeys.onmouseup, onmouseup);
+ }
+
+ public String getTitle() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.title));
+ }
+
+ public void setTitle(String title) {
+ getStateHelper().put(PropertyKeys.title, title);
+ }
+
+ public String getStyle() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.style));
+ }
+
+ public void setStyle(String style) {
+ getStateHelper().put(PropertyKeys.style, style);
+ }
+
+ public String getStyleClass() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.styleClass));
+ }
+
+ public void setStyleClass(String styleClass) {
+ getStateHelper().put(PropertyKeys.styleClass, styleClass);
+ }
+
+ public String getDir() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.dir));
+ }
+
+ public void setDir(String dir) {
+ getStateHelper().put(PropertyKeys.dir, dir);
+ }
+
+ public String getOnenter() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onenter));
+ }
+
+ public void setOnenter(String onenter) {
+ getStateHelper().put(PropertyKeys.onenter, onenter);
+ }
+
+ public String getOnleave() {
+ return String.valueOf(getStateHelper().eval(PropertyKeys.onleave));
+ }
+
+ public void setOnleave(String onleave) {
+ getStateHelper().put(PropertyKeys.onleave, onleave);
+ }
+
+
+}
+
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/MethodExpressionSelectedItemChangeListener.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/MethodExpressionSelectedItemChangeListener.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/MethodExpressionSelectedItemChangeListener.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,189 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.event;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.el.MethodNotFoundException;
+import javax.faces.context.FacesContext;
+import javax.faces.component.StateHolder;
+import javax.faces.event.AbortProcessingException;
+
+/**
+ * <p><strong><span
+ *
class="changed_modified_2_0">MethodExpressionSelectedItemChangeListener</span></strong>
+ * is a {@link SelectedItemChangeListener} that wraps a {@link
+ * MethodExpression}. When it receives a {@link SelectedItemChangeEvent}, it
+ * executes a method on an object identified by the {@link
+ * MethodExpression}.</p>
+ *
+ * @author akolonitsky
+ * @version 1.0
+ * @since -4712-01-01
+ *
+ */
+public class MethodExpressionSelectedItemChangeListener implements
SelectedItemChangeListener, StateHolder {
+
+ private static final Class[] SELECTED_ITEM_CHANGE_LISTENER_ZERO_ARG_SIG = new Class[]
{};
+
+ // ------------------------------------------------------ Instance Variables
+
+ private MethodExpression methodExpressionOneArg = null;
+ private MethodExpression methodExpressionZeroArg = null;
+
+ private boolean isTransient;
+
+
+ public MethodExpressionSelectedItemChangeListener() { }
+
+ /**
+ * <p><span class="changed_modified_2_0">Construct</span>
a {@link
+ * SelectedItemChangeListener} that contains a {@link
+ * MethodExpression}.<span
+ * class="changed_added_2_0">To accomodate method expression targets
+ * that take no arguments instead of taking a {@link
+ * SelectedItemChangeEvent} argument</span>, the implementation of this
+ * class must take the argument <code>methodExpressionOneArg</code>,
+ * extract its expression string, and create another
+ * <code>MethodExpression</code> whose expected param types match
+ * those of a zero argument method. The usage requirements for both
+ * of these <code>MethodExpression</code> instances are described in
+ * {@link #processSelectedItemChange}.</span></p>
+ *
+ * @param methodExpressionOneArg a <code>MethodExpression</code>
+ * that points to a method that returns <code>void</code> and takes
+ * a single argument of type {@link SelectedItemChangeEvent}.
+ */
+ public MethodExpressionSelectedItemChangeListener(MethodExpression
methodExpressionOneArg) {
+
+ super();
+ this.methodExpressionOneArg = methodExpressionOneArg;
+ FacesContext context = FacesContext.getCurrentInstance();
+ ELContext elContext = context.getELContext();
+ this.methodExpressionZeroArg = context.getApplication().
+ getExpressionFactory().createMethodExpression(elContext,
+ methodExpressionOneArg.getExpressionString(), Void.class,
+ SELECTED_ITEM_CHANGE_LISTENER_ZERO_ARG_SIG);
+ }
+
+ /**
+ * <p>Construct a {@link SelectedItemChangeListener} that contains a {@link
MethodExpression}.</p>
+ */
+ public MethodExpressionSelectedItemChangeListener(MethodExpression
methodExpressionOneArg,
+ MethodExpression methodExpressionZeroArg) {
+
+ super();
+ this.methodExpressionOneArg = methodExpressionOneArg;
+ this.methodExpressionZeroArg = methodExpressionZeroArg;
+ }
+
+ // ------------------------------------------------------- Event Method
+
+ /**
+ * <p><span class="changed_modified_2_0">Call</span>
through to the
+ * {@link MethodExpression} passed in our constructor. <span
+ * class="changed_added_2_0">First, try to invoke the
+ * <code>MethodExpression</code> passed to the constructor of this
+ * instance, passing the argument {@link SelectedItemChangeEvent} as the
+ * argument. If a {@link MethodNotFoundException} is thrown, call
+ * to the zero argument <code>MethodExpression</code> derived from
+ * the <code>MethodExpression</code> passed to the constructor of
+ * this instance. If that fails for any reason, throw an {@link
+ * AbortProcessingException}, including the cause of the
+ * failure.</span></p>
+ *
+ * @throws NullPointerException {@inheritDoc}
+ * @throws AbortProcessingException {@inheritDoc}
+ */
+ public void processSelectedItemChange(SelectedItemChangeEvent
selectedItemChangeEvent) throws AbortProcessingException {
+
+ if (selectedItemChangeEvent == null) {
+ throw new NullPointerException();
+ }
+ FacesContext context = FacesContext.getCurrentInstance();
+ ELContext elContext = context.getELContext();
+ // PENDING: The corresponding code in MethodExpressionActionListener
+ // has an elaborate message capture, logging, and rethrowing block.
+ // Why not here?
+ try {
+ methodExpressionOneArg.invoke(elContext, new Object[]
{selectedItemChangeEvent});
+ } catch (MethodNotFoundException mnf) {
+ if (null != methodExpressionZeroArg) {
+
+ try {
+ // try to invoke a no-arg version
+ methodExpressionZeroArg.invoke(elContext, new Object[]{});
+ } catch (ELException ee) {
+ throw new AbortProcessingException(ee.getMessage(), ee.getCause());
+ }
+ }
+ } catch (ELException ee) {
+ throw new AbortProcessingException(ee.getMessage(), ee.getCause());
+ }
+ }
+
+
+ // ------------------------------------------------ Methods from StateHolder
+
+
+ /**
+ * <p class="changed_modified_2_0">Both {@link MethodExpression}
+ * instances described in the constructor must be saved.</p>
+ */
+ public Object saveState(FacesContext context) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ return new Object[] {methodExpressionOneArg, methodExpressionZeroArg };
+ }
+
+
+ /**
+ * <p class="changed_modified_2_0">Both {@link MethodExpression}
+ * instances described in the constructor must be restored.</p>
+ */
+ public void restoreState(FacesContext context, Object state) {
+
+ if (context == null) {
+ throw new NullPointerException();
+ }
+ if (state == null) {
+ return;
+ }
+
+ methodExpressionOneArg = (MethodExpression) ((Object[]) state)[0];
+ methodExpressionZeroArg = (MethodExpression) ((Object[]) state)[1];
+ }
+
+
+ public boolean isTransient() {
+ return isTransient;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ isTransient = newTransientValue;
+ }
+}
+
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/SelectedItemChangeEvent.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/SelectedItemChangeEvent.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/SelectedItemChangeEvent.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.event;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+
+/**
+ * <p>A {@link SelectedItemChangeEvent} is a ...</p>
+ *
+ * @author akolonitsky
+ * @version 1.0
+ * @since -4712-01-01
+ */
+public class SelectedItemChangeEvent extends FacesEvent {
+
+ private final String oldItem;
+ private final String newItem;
+
+ // ------------------------------------------------------------ Constructors
+
+ /**
+ * <p>Construct a new event object from the specified source component,
+ * old value, and new value.</p>
+ *
+ * <p>The default {@link javax.faces.event.PhaseId} for this event is {@link
+ * javax.faces.event.PhaseId#ANY_PHASE}.</p>
+ *
+ * @param component Source {@link UIComponent} for this event
+ *
+ * @param oldItem
+ * @param newItem
+ *
+ * @throws IllegalArgumentException if <code>component</code> is
+ * <code>null</code>
+ */
+ public SelectedItemChangeEvent(UIComponent component, String oldItem, String newItem)
{
+ super(component);
+ this.oldItem = oldItem;
+ this.newItem = newItem;
+ }
+
+
+ // -------------------------------------------------------------- Properties
+
+ public String getOldItem() {
+ return oldItem;
+ }
+
+ public String getNewItem() {
+ return newItem;
+ }
+
+ // ------------------------------------------------- Event Broadcast Methods
+
+
+ public boolean isAppropriateListener(FacesListener listener) {
+ return listener instanceof SelectedItemChangeListener;
+ }
+
+ /**
+ * @throws javax.faces.event.AbortProcessingException {@inheritDoc}
+ */
+ public void processListener(FacesListener listener) {
+ ((SelectedItemChangeListener) listener).processSelectedItemChange(this);
+ }
+}
+
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/SelectedItemChangeListener.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/SelectedItemChangeListener.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/event/SelectedItemChangeListener.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.event;
+
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesListener;
+
+/**
+ * <p>A listener interface for receiving {@link SelectedItemChangeEvent}s. A
class
+ * that is interested in receiving such events implements this interface, and
+ * then registers itself with the source {@link javax.faces.component.UIComponent} of
interest, by
+ * calling <code>addSelectedItemChangeListener()</code>.</p>
+ *
+ * @author akolonitsky
+ * @version 1.0
+ * @since -4712-01-01
+ *
+ */
+public interface SelectedItemChangeListener extends FacesListener {
+
+
+ /**
+ * <p>Invoked when {@link SelectedItemChangeEvent} occurs.</p>
+ *
+ * @param event The {@link SelectedItemChangeEvent} that has occurred
+ *
+ * @throws AbortProcessingException Signal the JavaServer Faces
+ * implementation that no further processing on the current event
+ * should be performed
+ */
+ void processSelectedItemChange(SelectedItemChangeEvent event) throws
AbortProcessingException;
+
+}
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.renderkit.html;
+
+import static org.ajax4jsf.renderkit.RendererUtils.*;
+import org.ajax4jsf.renderkit.RendererBase;
+import org.richfaces.component.AbstractDivPanel;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * @author akolonitsky
+ * @since -4712-01-01
+ */
+public class DivPanelRenderer extends RendererBase {
+
+ public static final String[] ATTRIBUTES = new String[] {
+ "lang",
+ "onclick",
+ "ondblclick",
+ "onmousedown",
+ "onmousemove",
+ "onmouseout",
+ "onmouseover",
+ "onmouseup",
+ "title",
+ "style",
+ "styleClass",
+ "dir",
+ };
+
+ @Override
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ super.doEncodeBegin(writer, context, component);
+
+ writer.startElement(HTML.DIV_ELEM, component);
+ writer.writeAttribute("id", component.getClientId(context),
"clientId");
+
+ writeAttributes(writer, component, ATTRIBUTES);
+ }
+
+ private void writeAttributes(ResponseWriter writer, UIComponent component, String[]
attributes) throws IOException {
+ Map<String, Object> componentAttributes = component.getAttributes();
+ for (String attrName : attributes) {
+ Object attrValue = componentAttributes.get(attrName);
+ if (!"null".equalsIgnoreCase(String.valueOf(attrValue))) {
+ writer.writeAttribute(attrName, attrValue, attrName); // TODO Use
RendererUtils
+ }
+ }
+ }
+
+ @Override
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ super.doEncodeEnd(writer, context, component);
+
+ writeJavaScript(writer, context, component);
+
+ writer.endElement(HTML.DIV_ELEM);
+ }
+
+ protected void writeJavaScript(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
+ Object script = getScriptObject(context, component);
+ if (script != null) {
+ writer.startElement(HTML.SCRIPT_ELEM, component);
+ writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript",
"type");
+ writer.writeText(script, null);
+ writer.endElement(HTML.SCRIPT_ELEM);
+ }
+ }
+
+ protected Object getScriptObject(FacesContext context, UIComponent component) {
+ return null;
+ }
+
+ protected Map<String, Object> getScriptObjectOptions(FacesContext context,
UIComponent component) {
+ return null;
+ }
+
+ @Override
+ protected Class<? extends UIComponent> getComponentClass() {
+ return AbstractDivPanel.class;
+ }
+}
+
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/ToggleControlRenderer.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/ToggleControlRenderer.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/ToggleControlRenderer.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.renderkit.html;
+
+import org.richfaces.component.AbstractTogglePanel;
+import org.richfaces.component.behavior.ToggleControl;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.render.ClientBehaviorRenderer;
+import javax.faces.render.FacesBehaviorRenderer;
+import javax.faces.render.RenderKitFactory;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+@FacesBehaviorRenderer(
+ rendererType = "org.richfaces.component.behavior.ToggleControl",
+ renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT)
+@ResourceDependencies({
+ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js") })
+public class ToggleControlRenderer extends ClientBehaviorRenderer {
+
+ @Override
+ public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior
behavior) {
+ ToggleControl control = (ToggleControl) behavior;
+
+ AbstractTogglePanel panel = control.getPanel(behaviorContext.getComponent());
+ return "RichFaces.$('" + panel.getClientId() +
"').switchToItem('" + control.getTargetItem() + "'); return
false;";
+ }
+}
\ No newline at end of file
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.renderkit.html;
+
+import org.ajax4jsf.javascript.JSObject;
+import org.richfaces.component.AbstractTogglePanelItem;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author akolonitsky
+ * @since -4712-01-01
+ */
+@ResourceDependencies({
+ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "richfaces-event.js"),
+ @ResourceDependency(name = "richfaces-base-component.js"),
+ @ResourceDependency(name = "script/TogglePanelItem.js") })
+public class TogglePanelItemRenderer extends DivPanelRenderer {
+
+ @Override
+ protected void writeJavaScript(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
+ // All script must be written by TogglePanel using method getScriptObject
+ }
+
+ @Override
+ protected JSObject getScriptObject(FacesContext context, UIComponent component) {
+ return new JSObject("RichFaces.ui.TogglePanelItem",
component.getClientId(), getScriptObjectOptions(context, component));
+ }
+
+ @Override
+ protected Map<String, Object> getScriptObjectOptions(FacesContext context,
UIComponent component) {
+ AbstractTogglePanelItem panelItem = (AbstractTogglePanelItem) component;
+
+ Map<String, Object> options = new HashMap<String, Object>(2);
+ options.put("name", panelItem.getName());
+ options.put("switchMode", panelItem.getSwitchType());
+
+ return options;
+ }
+
+ @Override
+ protected Class<? extends UIComponent> getComponentClass() {
+ return AbstractTogglePanelItem.class;
+ }
+}
+
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,228 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.renderkit.html;
+
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.JSObject;
+import org.ajax4jsf.renderkit.AjaxEventOptions;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.richfaces.component.AbstractTogglePanel;
+import org.richfaces.component.AbstractTogglePanelItem;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.ajax4jsf.renderkit.RendererUtils.HTML;
+
+/**
+ * @author akolonitsky
+ * @since -4712-01-01
+ */
+@ResourceDependencies({
+ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "richfaces-event.js"),
+ @ResourceDependency(name = "richfaces-base-component.js"),
+ @ResourceDependency(name = "script/TogglePanel.js") })
+public class TogglePanelRenderer extends DivPanelRenderer {
+
+ private static final String VALUE_POSTFIX = "-value";
+
+ @Override
+ protected void doDecode(FacesContext context, UIComponent component) {
+ Map<String, String> requestMap =
+ context.getExternalContext().getRequestParameterMap();
+
+ // Don't overwrite the value unless you have to!
+ String newValue = requestMap.get(getSelectedItemRequestParamName(context,
component));
+ if (newValue != null) {
+ setSubmittedValue(component, newValue);
+
+// if (logger.isLoggable(Level.FINE)) {
+// logger.log(Level.FINE, "new value after decoding {0}",
newValue);
+// }
+ }
+
+ String compClientId = component.getClientId(context);
+ String clientId = requestMap.get(compClientId);
+ if (clientId != null && clientId.equals(compClientId)) {
+ AbstractTogglePanel panel = (AbstractTogglePanel) component;
+ AbstractTogglePanelItem panelItem = panel.getItem(newValue);
+ if (panelItem != null) {
+
context.getPartialViewContext().getRenderIds().add(panelItem.getClientId(context));
+
+ addOnCompleteParam(newValue, panel);
+ }
+ }
+ }
+
+ private void addOnCompleteParam(String newValue, AbstractTogglePanel panel) {
+ StringBuilder onComplete = new StringBuilder();
+
onComplete.append("RichFaces.$('").append(panel.getClientId()).append("').onCompleteHandler('")
+
.append(panel.getSelectedItem()).append("','").append(newValue).append("');
return false;");
+
+ AjaxContext.getCurrentInstance().appendOncomplete(onComplete.toString());
+ }
+
+ private static String getSelectedItemRequestParamName(FacesContext context,
UIComponent component) {
+ return component.getClientId(context) + VALUE_POSTFIX;
+ }
+
+// @Override
+ public void setSubmittedValue(UIComponent component, Object value) {
+ if (component instanceof AbstractTogglePanel) {
+ ((AbstractTogglePanel) component).setSubmittedSelectedItem((String) value);
+
+// if (logger.isLoggable(Level.FINE)) {
+// logger.fine("Set submitted value " + value + " on
component ");
+// }
+ }
+
+ }
+
+
+// @Override
+// public boolean getRendersChildren() {
+// return true;
+// }
+
+ @Override
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
comp) throws IOException {
+ super.doEncodeBegin(writer, context, comp);
+ AbstractTogglePanel panel = (AbstractTogglePanel) comp;
+
+ writer.startElement(HTML.INPUT_ELEM, comp);
+ writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
+ writer.writeAttribute(HTML.VALUE_ATTRIBUTE, panel.getSelectedItem(),
"selectedItem");
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, getSelectedItemRequestParamName(context,
comp), null);
+ writer.writeAttribute(HTML.NAME_ATTRIBUTE,
getSelectedItemRequestParamName(context, comp), null);
+ writer.endElement(HTML.INPUT_ELEM);
+ }
+
+ @Override
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
+ if (component.getChildCount() <= 0) {
+ return;
+ }
+
+ for (UIComponent child : component.getChildren()) {
+ if (!(child instanceof AbstractTogglePanelItem)) {
+ throw new IllegalStateException("Child of TogglePanel can be only
TogglePanelItem");
+ }
+
+ doEncodeChild(context, (AbstractTogglePanel) component,
(AbstractTogglePanelItem) child);
+ }
+ }
+
+ private void doEncodeChild(FacesContext facesContext, AbstractTogglePanel panel,
AbstractTogglePanelItem item)
+ throws IOException {
+
+ boolean isSelected = panel.getSelectedItem().equals(item.getName());
+ if (isSelected) {
+ item.encodeAll(facesContext);
+
+ } else {
+
+ switch (item.getSwitchType()) {
+ case client:
+ hidePanelItem(item);
+
+ item.encodeAll(facesContext);
+ break;
+
+ case ajax:
+ if (!item.isRendered()) {
+ break;
+ }
+
+ hidePanelItem(item);
+ item.encodeBegin(facesContext);
+ item.encodeEnd(facesContext);
+ break;
+
+ case server:
+ break;
+
+ default:
+ throw new IllegalStateException("Unknown switch type : " +
item.getSwitchType());
+ }
+ }
+
+
+ }
+
+ private static void hidePanelItem(UIComponent item) {
+ item.getAttributes().put(HTML.STYLE_ATTRIBUTE, "display:none");
+ }
+
+ @Override
+ protected JSObject getScriptObject(FacesContext context, UIComponent component) {
+ return new JSObject("RichFaces.ui.TogglePanel",
component.getClientId(), getScriptObjectOptions(context, component));
+ }
+
+ @Override
+ protected Map<String, Object> getScriptObjectOptions(FacesContext context,
UIComponent component) {
+ AbstractTogglePanel panel = (AbstractTogglePanel) component;
+
+ Map<String, Object> options = new HashMap<String, Object>(3);
+ options.put("selectedItem", panel.getValue());
+ options.put("switchMode", panel.getSwitchType());
+ options.put("items", getChildrenScriptObjects(context, panel));
+
+ options.put("ajax", getAjaxOptions(context, panel));
+
+ return options;
+ }
+
+ private static AjaxEventOptions getAjaxOptions(FacesContext context, UIComponent
panel) {
+ return AjaxRendererUtils.buildEventOptions(context, panel);
+ }
+
+ private List<JSObject> getChildrenScriptObjects(FacesContext context,
UIComponent component) {
+ List<JSObject> res = new
ArrayList<JSObject>(component.getChildCount());
+ for (UIComponent child : component.getChildren()) {
+ res.add(getChildScriptObject(context, (AbstractTogglePanelItem) child));
+ }
+ return res;
+ }
+
+ private JSObject getChildScriptObject(FacesContext context, AbstractTogglePanelItem
child) {
+ return ((TogglePanelItemRenderer) child.getRenderer(context))
+ .getScriptObject(context, child);
+ }
+
+ @Override
+ protected Class<? extends UIComponent> getComponentClass() {
+ return AbstractTogglePanel.class;
+ }
+}
+
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/taglib/SelectedItemChangeListenerHandler.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/taglib/SelectedItemChangeListenerHandler.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/taglib/SelectedItemChangeListenerHandler.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,209 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.taglib;
+
+import javax.el.ValueExpression;
+import javax.faces.application.Resource;
+import org.richfaces.component.AbstractTogglePanel;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import org.richfaces.event.SelectedItemChangeEvent;
+import org.richfaces.event.SelectedItemChangeListener;
+
+import javax.faces.view.AttachedObjectHandler;
+import javax.faces.view.EditableValueHolderAttachedObjectHandler;
+import javax.faces.view.facelets.*;
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ * @author akolonitsky
+ * @version 1.0
+ * @since -4712-01-01
+ */
+public final class SelectedItemChangeListenerHandler extends TagHandler implements
EditableValueHolderAttachedObjectHandler {
+
+ private static final String[] PRIMITIVE_NAMES = new String[] {"boolean",
+ "byte", "char", "double", "float",
"int", "long", "short", "void" };
+
+ private static final Class[] PRIMITIVES = new Class[] {boolean.class,
+ byte.class, char.class, double.class, float.class, int.class, long.class,
short.class, Void.TYPE };
+
+ private static class LazySelectedItemChangeListener implements
SelectedItemChangeListener, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String type;
+
+ private final ValueExpression binding;
+
+ LazySelectedItemChangeListener(String type, ValueExpression binding) {
+ this.type = type;
+ this.binding = binding;
+ }
+
+ public void processSelectedItemChange(SelectedItemChangeEvent event)
+ throws AbortProcessingException {
+
+ FacesContext faces = FacesContext.getCurrentInstance();
+ if (faces == null) {
+ return;
+ }
+
+ SelectedItemChangeListener instance = null;
+ if (this.binding != null) {
+ instance = (SelectedItemChangeListener)
binding.getValue(faces.getELContext());
+ }
+ if (instance == null && this.type != null) {
+ try {
+ instance = (SelectedItemChangeListener)
forName(this.type).newInstance();
+ } catch (Exception e) {
+ throw new AbortProcessingException("Couldn't Lazily
instantiate SelectedItemChangeListener", e);
+ }
+ if (this.binding != null) {
+ binding.setValue(faces.getELContext(), instance);
+ }
+ }
+ if (instance != null) {
+ instance.processSelectedItemChange(event);
+ }
+ }
+ }
+
+ private final TagAttribute binding;
+
+ private final String listenerType;
+
+ public SelectedItemChangeListenerHandler(TagConfig config) {
+ super(config);
+ this.binding = this.getAttribute("binding");
+ TagAttribute type = this.getAttribute("type");
+ if (type != null) {
+ if (type.isLiteral()) {
+ try {
+ forName(type.getValue());
+ } catch (ClassNotFoundException e) {
+ throw new TagAttributeException(type, "Couldn't qualify
SelectedItemChangeListener", e);
+ }
+ } else {
+ throw new TagAttributeException(type, "Must be a literal class name
of type SelectedItemChangeListener");
+ }
+ this.listenerType = type.getValue();
+ } else {
+ this.listenerType = null;
+ }
+ }
+
+ public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
+
+ // only process if it's been created
+ if (parent == null || !ComponentHandler.isNew(parent)) {
+ return;
+ }
+
+ if (parent instanceof AbstractTogglePanel) {
+ applyAttachedObject(ctx.getFacesContext(), parent);
+ } else if (parent.getAttributes().containsKey(Resource.COMPONENT_RESOURCE_KEY))
{
+ // Allow the composite component to know about the target component.
+ getAttachedObjectHandlers(parent).add(this);
+ } else {
+ throw new TagException(this.tag, "Parent is not of type
EditableValueHolder, type is: " + parent);
+ }
+ }
+
+ public void applyAttachedObject(FacesContext context, UIComponent parent) {
+ ValueExpression b = null;
+ if (this.binding != null) {
+ FaceletContext ctx = (FaceletContext)
context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
+ b = this.binding.getValueExpression(ctx, SelectedItemChangeListener.class);
+ }
+
+ AbstractTogglePanel evh = (AbstractTogglePanel) parent;
+ evh.addSelectedItemChangeListener(new
LazySelectedItemChangeListener(this.listenerType, b));
+ }
+
+ public String getFor() {
+ TagAttribute attr = this.getAttribute("for");
+ return attr == null ? null : attr.getValue();
+ }
+
+ // TODO Move to utility class
+ public static List<AttachedObjectHandler> getAttachedObjectHandlers(UIComponent
component) {
+ return getAttachedObjectHandlers(component, true);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public static List<AttachedObjectHandler> getAttachedObjectHandlers(UIComponent
component,
+ boolean create)
{
+ Map<String, Object> attrs = component.getAttributes();
+ List<AttachedObjectHandler> result = (List<AttachedObjectHandler>)
+ attrs.get("javax.faces.RetargetableHandlers");
+
+ if (result == null) {
+ if (create) {
+ result = new ArrayList<AttachedObjectHandler>();
+ attrs.put("javax.faces.RetargetableHandlers", result);
+ } else {
+ result = Collections.EMPTY_LIST;
+ }
+ }
+ return result;
+
+ }
+
+ public static Class forName(String name) throws ClassNotFoundException {
+ if (null == name || "".equals(name)) {
+ return null;
+ }
+ Class c = forNamePrimitive(name);
+ if (c == null) {
+ if (name.endsWith("[]")) {
+ String nc = name.substring(0, name.length() - 2);
+ c = Class.forName(nc, false,
Thread.currentThread().getContextClassLoader());
+ c = Array.newInstance(c, 0).getClass();
+ } else {
+ c = Class.forName(name, false,
Thread.currentThread().getContextClassLoader());
+ }
+ }
+ return c;
+ }
+
+ protected static Class forNamePrimitive(String name) {
+ if (name.length() <= 8) {
+ int p = Arrays.binarySearch(PRIMITIVE_NAMES, name);
+ if (p >= 0) {
+ return PRIMITIVES[p];
+ }
+ }
+ return null;
+ }
+}
+
Added:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/taglib/TogglePanelTagHandler.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/taglib/TogglePanelTagHandler.java
(rev 0)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/taglib/TogglePanelTagHandler.java 2010-07-07
11:32:06 UTC (rev 17755)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.taglib;
+
+import org.richfaces.component.AbstractTogglePanel;
+
+import org.richfaces.event.MethodExpressionSelectedItemChangeListener;
+import org.richfaces.event.SelectedItemChangeEvent;
+
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ * @author akolonitsky
+ * @version 1.0
+ * @since -4712-01-01
+ */
+public class TogglePanelTagHandler extends ComponentHandler {
+
+ private static final MetaRule META_RULE = new TogglePanelMetaRule();
+
+
+ public TogglePanelTagHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset metaRuleset = super.createMetaRuleset(type);
+ metaRuleset.addRule(META_RULE);
+ return metaRuleset;
+ }
+
+ private static class TogglePanelMetaRule extends MetaRule{
+
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget
meta) {
+ if (meta.isTargetInstanceOf(AbstractTogglePanel.class)) {
+ if ("selectedItemChangeListener".equals(name)) {
+ return new SelectedItemChangeExpressionMetadata(attribute);
+ }
+
+ }
+ return null;
+ }
+ }
+
+ private static final class SelectedItemChangeExpressionMetadata extends Metadata {
+ private static final Class<?>[] SELECTED_ITEM_CHANGE_SIG = new Class[]
{SelectedItemChangeEvent.class };
+
+ private final TagAttribute attr;
+
+ SelectedItemChangeExpressionMetadata(TagAttribute attr) {
+ this.attr = attr;
+ }
+
+ @Override
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((AbstractTogglePanel) instance).addSelectedItemChangeListener(new
MethodExpressionSelectedItemChangeListener(
+ this.attr.getMethodExpression(ctx, null,
SELECTED_ITEM_CHANGE_SIG)));
+ }
+ }
+
+
+
+}
+