Author: nbelaevski
Date: 2010-07-06 13:03:33 -0400 (Tue, 06 Jul 2010)
New Revision: 17746
Added:
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/AbstractComboBox.java
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/ComboBoxRendererBase.java
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/view/
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/view/facelets/
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/view/facelets/ComboBoxHandler.java
root/ui-sandbox/inputs/trunk/combobox/src/main/templates/
root/ui-sandbox/inputs/trunk/combobox/src/main/templates/comboBox.template.xml
Removed:
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/AutocompleteRenderer.java
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/script/ComboBox.js
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/script/SelectBase.js
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/script/images/
Modified:
root/ui-sandbox/inputs/trunk/combobox/pom.xml
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/ComboBox.js
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/SelectBase.js
Log:
Latest comboBox changes check-in
Modified: root/ui-sandbox/inputs/trunk/combobox/pom.xml
===================================================================
--- root/ui-sandbox/inputs/trunk/combobox/pom.xml 2010-07-06 17:01:55 UTC (rev 17745)
+++ root/ui-sandbox/inputs/trunk/combobox/pom.xml 2010-07-06 17:03:33 UTC (rev 17746)
@@ -51,6 +51,10 @@
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
<dependency>
<groupId>org.richfaces.cdk</groupId>
Added:
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/AbstractComboBox.java
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/AbstractComboBox.java
(rev 0)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/AbstractComboBox.java 2010-07-06
17:03:33 UTC (rev 17746)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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 java.util.List;
+
+import javax.el.MethodExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.Signature;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@JsfComponent(tag = @Tag(type = TagType.Facelets, handler =
"org.richfaces.view.facelets.ComboBoxHandler"))
+public abstract class AbstractComboBox extends UIInput {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.ComboBox";
+
+ public static final String COMPONENT_FAMILY = UIInput.COMPONENT_FAMILY;
+
+ //TODO nick - change to Object -
https://jira.jboss.org/browse/RF-8897
+ public abstract List<?> getAutocompleteList();
+
+ @Attribute(signature = @Signature(returnType = Object.class, parameters = {
FacesContext.class, UIComponent.class,
+ String.class }))
+ public abstract MethodExpression getAutocompleteMethod();
+ public abstract void setAutocompleteMethod(MethodExpression expression);
+
+ @Attribute(literal = true)
+ public abstract String getVar();
+}
Deleted:
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/AutocompleteRenderer.java
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/AutocompleteRenderer.java 2010-07-06
17:01:55 UTC (rev 17745)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/AutocompleteRenderer.java 2010-07-06
17:03:33 UTC (rev 17746)
@@ -1,5 +0,0 @@
-package org.richfaces.renderkit;
-
-class AutocompleteRenderer {
-
-}
\ No newline at end of file
Added:
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/ComboBoxRendererBase.java
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/ComboBoxRendererBase.java
(rev 0)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/ComboBoxRendererBase.java 2010-07-06
17:03:33 UTC (rev 17746)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.el.ELException;
+import javax.el.MethodExpression;
+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 org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.AbstractComboBox;
+
+import com.google.common.collect.Iterators;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@ResourceDependencies({
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "richfaces-event.js"),
+ @ResourceDependency(name = "richfaces-base-component.js"),
+ @ResourceDependency(library = "org.richfaces", name =
"richfaces-selection.js"),
+ @ResourceDependency(library = "org.richfaces", name =
"SelectBase.js"),
+ @ResourceDependency(library = "org.richfaces", name =
"ComboBox.js"),
+ @ResourceDependency(library = "org.richfaces", name =
"ComboBox.ecss")
+
+})
+public class ComboBoxRendererBase extends RendererBase {
+
+ //TODO nick - handle parameter
+ private Iterator<Object> getItems(FacesContext facesContext, AbstractComboBox
component) {
+ Object itemsObject = null;
+
+ MethodExpression autocompleteMethod = component.getAutocompleteMethod();
+ if (autocompleteMethod != null) {
+ try {
+ itemsObject = autocompleteMethod.invoke(facesContext.getELContext(),
+ new Object[] {facesContext, component, null});
+ } catch (ELException e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ } else {
+ itemsObject = component.getAutocompleteList();
+ }
+
+ Iterator<Object> result;
+
+ //TODO nick - primitive arrays support
+ if (itemsObject instanceof Object[]) {
+ result = Iterators.forArray((Object[]) itemsObject);
+ } else if (itemsObject != null) {
+ result = ((Iterable<Object>) itemsObject).iterator();
+ } else {
+ result = Iterators.emptyIterator();
+ }
+
+ return result;
+ }
+
+ private Object saveVar(FacesContext context, String var) {
+ if (var != null) {
+ Map<String, Object> requestMap =
context.getExternalContext().getRequestMap();
+ return requestMap.get(var);
+ }
+
+ return null;
+ }
+
+ private void setVar(FacesContext context, String var, Object varObject) {
+ if (var != null) {
+ Map<String, Object> requestMap =
context.getExternalContext().getRequestMap();
+ requestMap.put(var, varObject);
+ }
+ }
+
+ protected void encodeItem(FacesContext facesContext, AbstractComboBox comboBox,
Object item) throws IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.startElement(HTML.LI_ELEMENT, comboBox);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_option cb_font",
null);
+
+ if (comboBox.getChildCount() > 0) {
+ for (UIComponent child: comboBox.getChildren()) {
+ child.encodeAll(facesContext);
+ }
+ } else {
+ if (item != null) {
+ //TODO nick - use converter
+ writer.writeText(item, null);
+ }
+ }
+
+ writer.endElement(HTML.LI_ELEMENT);
+ }
+
+ protected void encodeItems(FacesContext facesContext, UIComponent component) throws
IOException {
+ AbstractComboBox comboBox = (AbstractComboBox) component;
+
+ ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.startElement(HTML.UL_ELEMENT, component);
+ responseWriter.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_list_ul",
null);
+
+ boolean hasEncodedElements = false;
+
+ Object savedVar = saveVar(facesContext, comboBox.getVar());
+
+ for (Iterator<Object> items = getItems(facesContext, comboBox);
items.hasNext(); ) {
+ hasEncodedElements = true;
+
+ Object nextItem = items.next();
+ setVar(facesContext, comboBox.getVar(), nextItem);
+
+ encodeItem(facesContext, comboBox, nextItem);
+ }
+
+ setVar(facesContext, comboBox.getVar(), savedVar);
+
+ if (!hasEncodedElements) {
+ responseWriter.startElement(HTML.LI_ELEMENT, component);
+ responseWriter.writeAttribute(HTML.STYLE_ATTRIBUTE, "display:none",
null);
+ responseWriter.endElement(HTML.LI_ELEMENT);
+ }
+
+ responseWriter.endElement(HTML.UL_ELEMENT);
+ }
+
+}
Added:
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/view/facelets/ComboBoxHandler.java
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/view/facelets/ComboBoxHandler.java
(rev 0)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/view/facelets/ComboBoxHandler.java 2010-07-06
17:03:33 UTC (rev 17746)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.view.facelets;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+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;
+
+import org.richfaces.MethodMetadata;
+import org.richfaces.component.AbstractComboBox;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+//TODO nick - this should be generated by CDK
+public class ComboBoxHandler extends ComponentHandler {
+
+ private static final MetaRule AUTOCOMPLETE_METHOD_META_RULE = new MetaRule() {
+
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget
meta) {
+ if (meta.isTargetInstanceOf(AbstractComboBox.class)) {
+ if ("autocompleteMethod".equals(name)) {
+ return new MethodMetadata(attribute, FacesContext.class,
UIComponent.class, String.class) {
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((AbstractComboBox)
instance).setAutocompleteMethod(getMethodExpression(ctx));
+ }
+ };
+ }
+ }
+
+ return null;
+ }
+ };
+
+ public ComboBoxHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset metaRuleset = super.createMetaRuleset(type);
+ metaRuleset.addRule(AUTOCOMPLETE_METHOD_META_RULE);
+ return metaRuleset;
+ }
+
+}
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/ComboBox.js
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/ComboBox.js 2010-07-06
17:01:55 UTC (rev 17745)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/ComboBox.js 2010-07-06
17:03:33 UTC (rev 17746)
@@ -52,7 +52,7 @@
this.options = {};
// call constructor of parent class
$super.constructor.call(this, componentId+ID.SELECT, fieldId, options);
- $p.attachToDom(componentId);
+ $p.attachToDom.call(this, componentId);
this.componentId = componentId;
this.options = $.extend(this.options, defaultOptions, options);
//this.currentValue = rf.getDomElement(this.fieldId).value;
@@ -84,7 +84,7 @@
};
var onMouseOver = function(event) {
- console && console.log && console.log("mouseOver");
+ //console && console.log && console.log("mouseOver");
var element = event.target;
while (element.parentNode && element.parentNode!=event.currentTarget) {
element = element.parentNode;
@@ -138,7 +138,7 @@
};
// Add new properties and methods
- $.extend(rf.ui.SelectBase.prototype, (function () {
+ $.extend(rf.ui.ComboBox.prototype, (function () {
return {
name:"CompoBox",
destroy: function () {
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/SelectBase.js
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/SelectBase.js 2010-07-06
17:01:55 UTC (rev 17745)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/SelectBase.js 2010-07-06
17:03:33 UTC (rev 17746)
@@ -88,17 +88,17 @@
};
var onSelectMouseDown = function () {
this.isMouseDown = true;
- console && console.log && console.log("onMouseDown");
+ //console && console.log && console.log("onMouseDown");
};
var onSelectMouseUp = function () {
//this.isMouseDown = false;
rf.getDomElement(this.fieldId).focus();
- console && console.log && console.log("onMouseUp");
+ //console && console.log && console.log("onMouseUp");
};
var onButtonShow = function (event) {
this.isMouseDown = true;
- console && console.log && console.log("onButtonShow -
"+this.timeoutId);
+ //console && console.log && console.log("onButtonShow -
"+this.timeoutId);
if (this.timeoutId) {
window.clearTimeout(this.timeoutId);
this.timeoutId = null;
@@ -114,15 +114,15 @@
};
var onFocus = function (event) {
- console && console.log && console.log("onFocus");
+ //console && console.log && console.log("onFocus");
};
var onBlur = function (event) {
- console && console.log && console.log("onBlur");
+ //console && console.log && console.log("onBlur");
if (this.isMouseDown) {
rf.getDomElement(this.fieldId).focus();
this.isMouseDown = false;
- console && console.log && console.log("---------> and
focus");
+ //console && console.log && console.log("---------> and
focus");
} else if (this.isVisible && !this.isMouseDown/*&&
checkOnBlur.call(this, event)*/) {
var _this = this;
this.timeoutId = window.setTimeout(function(){_this.hide();}, 200);
@@ -210,7 +210,7 @@
name:"SelectBase",
show: function (event) {
if (this.onBeforeShow(event)!=false) {
- $(rf.getDomElement(this.selectId)).show();
+ $(rf.getDomElement(this.selectId)).setPosition({id: this.fieldId},
{type:"DROPDOWN", offset:[0,20]}).show();
this.isVisible = true;
this.scrollElements = rf.Event.bindScrollEventHandlers(this.selectId, this.hide,
this, this.namespace);
if (this.onShow) {
Deleted:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/script/ComboBox.js
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/script/ComboBox.js 2010-07-06
17:01:55 UTC (rev 17745)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/script/ComboBox.js 2010-07-06
17:03:33 UTC (rev 17746)
@@ -1,225 +0,0 @@
-(function ($, rf) {
- rf.utils = rf.utils || {};
-
- rf.utils.Cache = function (data, options) {
- this.key = options.key;
- this.cache = {}
- this.cache[this.key] = data || [];
- this.values = options.parse && options.parse(data) || this.cache[this.key];
- };
-
- var getItems = function (key) {
- var newCache = [];
-
- if (this.cache[key]) {
- newCache = this.cache[key];
- } else {
- var itemsCache = this.cache[this.key];
- for (var i = 0; i<this.values.length; i++) {
- var value = this.values[i].toLowerCase();
- var p = value.indexOf(key.toLowerCase());
- if (p == 0) {
- newCache.push(itemsCache[i]);
- }
- }
-
- if ((!this.lastKey || key.indexOf(this.lastKey)!=0) && newCache.length > 0)
{
- //console && console.log && console.log("added
key:"+key+" length:" + newCache.length)
- this.cache[key] = newCache;
- if (newCache.length==1) {
- this.lastKey = key;
- }
- }
- }
-
- return newCache;
- };
-
- $.extend(rf.utils.Cache.prototype, (function () {
- return {
- getItems: getItems
- };
- })());
-
-})(jQuery, RichFaces);
-
-(function ($, rf) {
-
- rf.ui = rf.ui || {};
- // Constructor definition
- rf.ui.ComboBox = function(componentId, fieldId, options) {
- this.namespace = "."+rf.Event.createNamespace(this.name, this.componentId);
- this.options = {};
- // call constructor of parent class
- $super.constructor.call(this, componentId+ID.SELECT, fieldId, options);
- $p.attachToDom.call(this, componentId);
- this.componentId = componentId;
- this.options = $.extend(this.options, defaultOptions, options);
- //this.currentValue = rf.getDomElement(this.fieldId).value;
- this.index = -1;
- bindEventHandlers.call(this);
- updateItemsList.call(this, "");
- };
-
- var $p ={};
-
- // Extend component class and add protected methods from parent class to our container
- $p = rf.ui.SelectBase.extend(rf.ui.SelectBase, rf.ui.ComboBox, $p);
-
- // define super class link
- var $super = rf.ui.ComboBox.$super;
-
- var defaultOptions = {
- selectedItemClass:'cb_select',
- autoFill:true
- };
-
- var ID = {
- SELECT:'List',
- ITEMS:'Items'
- };
-
- var bindEventHandlers = function () {
- rf.Event.bindById(this.componentId+ID.ITEMS, "mouseover"+this.namespace,
onMouseOver, this);
- };
-
- var onMouseOver = function(event) {
- //console && console.log && console.log("mouseOver");
- var element = event.target;
- while (element.parentNode && element.parentNode!=event.currentTarget) {
- element = element.parentNode;
- };
- if (element.parentNode) {
- var index = this.items.index(element);
- if (index!=this.index) {
- this.selectItem(index);
- }
- }
- };
-
- var updateItemsList = function (value) {
- this.items = $(rf.getDomElement(this.componentId+ID.ITEMS)).children();
- this.cache = new rf.utils.Cache(this.items, {
- parse: getData,
- key: value
- });
- };
-
- var getData = function (nodeList) {
- var data = [];
- nodeList.each(function () {
- data.push($(this).text());
- });
- return data;
- };
-
- var scrollToSelectedItem = function() {
- var offset = 0;
- this.items.slice(0, this.index).each(function() {
- offset += this.offsetHeight;
- });
- var itemsContainer = this.items.first().parent();
- if(offset < itemsContainer.scrollTop()) {
- itemsContainer.scrollTop(offset);
- } else {
- offset+=this.items.get(this.index).offsetHeight;
- if(offset - itemsContainer.scrollTop() > itemsContainer.get(0).clientHeight)
{
- itemsContainer.scrollTop(offset - itemsContainer.innerHeight());
- }
- }
- };
-
- var autoFill = function (inputValue, value) {
- if( this.options.autoFill) {
- var field = rf.getDomElement(this.fieldId);
- field.value = inputValue + value.substring(inputValue.length);
- rf.Selection.set(field, inputValue.length, field.value.length);
- }
- };
-
- // Add new properties and methods
- $.extend(rf.ui.ComboBox.prototype, (function () {
- return {
- name:"CompoBox",
- destroy: function () {
- //TODO: add all unbind
- $super.destroy.call(this);
- },
- getNamespace: function () {
- return this.namespace;
- },
-
- selectItem: function(index, isOffset, noAutoFill) {
- if (this.items.length==0) return;
-
- if (this.index!=-1) {
- this.items.eq(this.index).removeClass(this.options.selectedItemClass);
- }
-
- if (index==undefined) {
- this.index = -1;
- return;
- }
-
- if (isOffset) {
- this.index += index;
- if ( this.index<0 ) {
- this.index = this.items.length - 1;
- } else if (this.index >= this.items.length) {
- this.index = 0;
- }
- } else {
- if (index<0) {
- index = 0;
- } else if (index>=this.items.length) {
- index = this.items.length - 1;
- }
- this.index = index;
- }
- var item = this.items.eq(this.index);
- item.addClass(this.options.selectedItemClass);
-
- scrollToSelectedItem.call(this);
- !noAutoFill && autoFill.call(this, this.newValue, item.text());
- },
-
- selectPrevItem: function () {
- this.selectItem(-1, true);
- },
- selectNextItem: function () {
- this.selectItem(1, true);
- },
- selectPageUp: function () {
-
- },
- selectPageDown: function () {
-
- },
- onBeforeShow: function (event) {
- },
-
- changeValue: function (event, value) {
- // TODO: ajax call here if needed
-
- this.selectItem();
- var newItems = this.cache.getItems(value);
- this.items = $(newItems);
- $(rf.getDomElement(this.componentId+ID.ITEMS)).empty().append(newItems);
- this.index = -1;
- this.newValue = value;
- this.selectItem(0, false, event.which == rf.KEYS.BACKSPACE);
- },
-
- onShow: function (event) {
- if (this.items && this.items.length>0) {
- //??TODO it's nessesary only if not changed value
- this.selectItem(0);
- }
- },
-
- onHide: function () {
- this.selectItem();
- }
- };
- })());
-})(jQuery, RichFaces);
\ No newline at end of file
Deleted:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/script/SelectBase.js
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/script/SelectBase.js 2010-07-06
17:01:55 UTC (rev 17745)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/script/SelectBase.js 2010-07-06
17:03:33 UTC (rev 17746)
@@ -1,256 +0,0 @@
-// TODO: move this extend to RichFaces.Event for exapmle
-$.extend(RichFaces.Event, {
- bindScrollEventHandlers: function(element, handler, component) {
- var elements = [];
- element = RichFaces.getDomElement(element).parentNode;
- while (element && element!=window.document.body)
- {
- if (element.offsetWidth!=element.scrollWidth ||
element.offsetHeight!=element.scrollHeight)
- {
- elements.push(element);
- RichFaces.Event.bind(element, "scroll"+component.getNamespace(), handler,
component);
- }
- element = element.parentNode;
- }
- return elements;
- },
- unbindScrollEventHandlers: function(elements, component) {
- RichFaces.Event.unbind(elements, component.getNamespace());
- elements = null;
- }
-});
-
-(function (rf) {
- rf.KEYS = {
- BACKSPACE: 8,
- TAB: 9,
- RETURN: 13,
- ESC: 27,
- PAGEUP: 33,
- PAGEDOWN: 34,
- LEFT: 37,
- UP: 38,
- RIGHT: 39,
- DOWN: 40,
- DEL: 46,
- }
-})(RichFaces);
-
-(function ($, rf) {
-
- rf.ui = rf.ui || {};
-
- // Constructor definition
- rf.ui.SelectBase = function(selectId, fieldId, options) {
- // call constructor of parent class
- $super.constructor.call(this, selectId);
- this.selectId = selectId;
- this.fieldId = fieldId;
- this.options = $.extend({}, defaultOptions, options);
- this.namespace = this.namespace || "."+rf.Event.createNamespace(this.name,
this.selectId);
- this.currentValue = this.getInputValue();
- bindEventHandlers.call(this);
- };
-
- var $p ={};
-
- // Extend component class and add protected methods from parent class to our container
- $p = rf.BaseComponent.extend(rf.BaseComponent, rf.ui.SelectBase, $p);
-
- // define super class link
- var $super = rf.ui.SelectBase.$super;
-
- var defaultOptions = {
- changeDelay:8
- };
-
- var bindEventHandlers = function() {
- if (this.options.buttonId) {
- rf.Event.bindById(this.options.buttonId, "mousedown"+this.namespace,
onButtonShow, this);
- rf.Event.bindById(this.options.buttonId, "mouseup"+this.namespace,
onSelectMouseUp, this);
- }
-
- var inputEventHandlers = {};
- inputEventHandlers["focus"+this.namespace] = onFocus;
- inputEventHandlers["blur"+this.namespace] = onBlur;
- inputEventHandlers["click"+this.namespace] = onClick;
- inputEventHandlers[($.browser.opera ? "keypress" :
"keydown")+this.namespace] = onKeyDown;
- rf.Event.bindById(this.fieldId, inputEventHandlers, this);
-
- inputEventHandlers = {};
- inputEventHandlers["click"+this.namespace] = onSelectClick;
- inputEventHandlers["mousedown"+this.namespace] = onSelectMouseDown;
- inputEventHandlers["mouseup"+this.namespace] = onSelectMouseUp;
- rf.Event.bindById(this.selectId, inputEventHandlers, this);
- }
-
- var onSelectClick = function () {
- };
- var onSelectMouseDown = function () {
- this.isMouseDown = true;
- //console && console.log && console.log("onMouseDown");
- };
- var onSelectMouseUp = function () {
- //this.isMouseDown = false;
- rf.getDomElement(this.fieldId).focus();
- //console && console.log && console.log("onMouseUp");
- };
-
- var onButtonShow = function (event) {
- this.isMouseDown = true;
- //console && console.log && console.log("onButtonShow -
"+this.timeoutId);
- if (this.timeoutId) {
- window.clearTimeout(this.timeoutId);
- this.timeoutId = null;
- rf.getDomElement(this.fieldId).focus();
- }
-
- if (this.isVisible) {
- this.hide(event);
- } else {
- this.show(event);
- //rf.getDomElement(this.fieldId).focus();
- }
- };
-
- var onFocus = function (event) {
- //console && console.log && console.log("onFocus");
- };
-
- var onBlur = function (event) {
- //console && console.log && console.log("onBlur");
- if (this.isMouseDown) {
- rf.getDomElement(this.fieldId).focus();
- this.isMouseDown = false;
- //console && console.log && console.log("---------> and
focus");
- } else if (this.isVisible && !this.isMouseDown/*&&
checkOnBlur.call(this, event)*/) {
- var _this = this;
- this.timeoutId = window.setTimeout(function(){_this.hide();}, 200);
- }
- };
-
- var onClick = function (event) {
- };
-
- var onChange = function (event) {
- var value = this.getInputValue();
- var flag = value != this.currentValue;
- if (event.which == rf.KEYS.LEFT || event.which == rf.KEYS.RIGHT || flag) {
- if (flag) {
- this.changeValue(event, value);
- this.currentValue = value;
- if (!this.isVisible) {
- this.show();
- }
- }
- }
- }
-
-
- /*var checkOnBlur = function (event) {
- var e = $(rf.getDomElement(this.options.buttonId));
- return (e == event.target) || $(event.target).closest(e);
- };*/
-
- var onKeyDown = function (event) {
- switch(event.which) {
- case rf.KEYS.UP:
- event.preventDefault();
- if (this.isVisible) {
- this.selectPrevItem();
- }
- break;
- case rf.KEYS.DOWN:
- event.preventDefault();
- if (this.isVisible) {
- this.selectNextItem();
- } else {
- this.show();
- }
- break;
- case rf.KEYS.PAGEUP:
- event.preventDefault();
- if (this.isVisible) {
- this.selectPageUp();
- }
- break;
- case rf.KEYS.PAGEDOWN:
- event.preventDefault();
- if (this.isVisible) {
- this.selectPageDown();
- }
- break;
- case rf.KEYS.TAB:
- case rf.KEYS.RETURN:
- event.preventDefault();
- /*if( selectCurrentItem() ) {
- event.preventDefault();
- //TODO: bind form submit event handler to cancel form submit under the opera
- //cancelSubmit = true;
- return false;
- }*/
- this.hide();
- break;
- case rf.KEYS.ESC:
- this.hide();
- break;
- default:
- if (!this.options.selectOnly) {
- var _this = this;
- window.clearTimeout(this.changeTimerId);
- this.changeTimerId = window.setTimeout(function(){onChange.call(_this, event);},
this.options.changeDelay)
- }
- break;
- }
- }
-
- // Add new properties and methods
- $.extend(rf.ui.SelectBase.prototype, (function () {
- return {
- name:"SelectBase",
- show: function (event) {
- if (this.onBeforeShow(event)!=false) {
- $(rf.getDomElement(this.selectId)).setPosition({id: this.fieldId},
{type:"DROPDOWN", offset:[0,20]}).show();
- this.isVisible = true;
- this.scrollElements = rf.Event.bindScrollEventHandlers(this.selectId, this.hide,
this, this.namespace);
- if (this.onShow) {
- this.onShow(event);
- }
- }
- },
- hide: function (event) {
- rf.Event.unbindScrollEventHandlers(this.scrollElements, this);
- $(rf.getDomElement(this.selectId)).hide();
- this.isVisible = false;
- if (this.onHide) {
- this.onHide(event);
- }
- },
- destroy: function () {
- //TODO: add all unbind
- rf.Event.unbindById(this.options.buttonId, this.namespace);
- rf.Event.unbindById(this.fieldId, this.namespace);
- $super.destroy.call(this);
- },
- getNamespace: function () {
- return this.namespace;
- },
-
- selectPrevItem: function () {
- },
- selectNextItem: function () {
- },
- selectPageUp: function () {
- },
- selectPageDown: function () {
- },
- onBeforeShow: function () {
- },
- getInputValue: function () {
- var value = this.fieldId ? rf.getDomElement(this.fieldId).value : undefined;
- return value;
- }
-
- };
- })());
-})(jQuery, RichFaces);
\ No newline at end of file
Added: root/ui-sandbox/inputs/trunk/combobox/src/main/templates/comboBox.template.xml
===================================================================
--- root/ui-sandbox/inputs/trunk/combobox/src/main/templates/comboBox.template.xml
(rev 0)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/templates/comboBox.template.xml 2010-07-06
17:03:33 UTC (rev 17746)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://richfaces.org/cdk/xhtml-el"
xmlns:cdk="http://richfaces.org/cdk/core"
+
xmlns:c="http://richfaces.org/cdk/jstl/core"
xmlns:cc="http://richfaces.org/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.renderkit.html.ComboBoxRenderer</cdk:class>
+
<cdk:superclass>org.richfaces.renderkit.ComboBoxRendererBase</cdk:superclass>
+ <cdk:component-family>javax.faces.Input</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.ComboBoxRenderer
+ </cdk:renderer-type>
+ <cdk:renders-children>true</cdk:renders-children>
+ </cc:interface>
+
+ <cc:implementation>
+ <div id="#{clientId}" class="cb_field_width cb_field">
+ <div style="position : relative; overflow : hidden; text-align :
left; padding-right : 21px;">
+ <input id="#{clientId}Input" type="text"
class="cb_font cb_input" />
+ <div id="#{clientId}Button" class="cb_button">
+ <div class="cb_button_arrow"></div>
+ </div>
+ </div>
+
+ <div id="#{clientId}List" class="cb_list_cord">
+
+ <div class="cb_shadow">
+ <div class="cb_shadow_t"></div>
+ <div class="cb_shadow_l"></div>
+ <div class="cb_shadow_r"></div>
+ <div class="cb_shadow_b"></div>
+
+ <div class="cb_list_decoration">
+ <div class="cb_list_scroll cb_list_width
cb_list_height">
+ <cdk:body>
+ <cdk:call expression="encodeItems(facesContext,
component)"/>
+ </cdk:body>
+ </div>
+ </div>
+ </div>
+ </div>
+ <script type="text/javascript">
+ new RichFaces.ui.ComboBox("#{clientId}",
+ "#{clientId}Input", {buttonId:"#{clientId}Button",
+ selectedItemClass:'cb_select'});
+ </script>
+ </div>
+ </cc:implementation>
+
+</cdk:root>