001: /*
002: ItsNat Java Web Application Framework
003: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004: Author: Jose Maria Arranz Santamaria
005:
006: This program is free software: you can redistribute it and/or modify
007: it under the terms of the GNU Affero General Public License as published by
008: the Free Software Foundation, either version 3 of the License, or
009: (at your option) any later version. See the GNU Affero General Public
010: License for more details. See the copy of the GNU Affero General Public License
011: included in this program. If not, see <http://www.gnu.org/licenses/>.
012: */
013:
014: package org.itsnat.impl.comp.html;
015:
016: import org.itsnat.comp.ItsNatListCellEditor;
017: import org.itsnat.comp.ItsNatListCellRenderer;
018: import org.itsnat.comp.html.ItsNatHTMLSelect;
019: import org.itsnat.comp.ui.ItsNatListUI;
020: import org.itsnat.core.ItsNatException;
021: import org.itsnat.impl.comp.ItsNatListInternal;
022: import javax.swing.event.ListDataEvent;
023: import org.itsnat.comp.ItsNatListStructure;
024: import org.itsnat.comp.html.ui.ItsNatHTMLSelectUI;
025: import org.itsnat.core.NameValue;
026: import org.itsnat.impl.comp.ItsNatListSharedImpl;
027: import org.w3c.dom.Document;
028: import org.w3c.dom.Node;
029: import org.w3c.dom.html.HTMLFormElement;
030: import org.w3c.dom.html.HTMLSelectElement;
031:
032: /**
033: *
034: * @author jmarranz
035: */
036: public abstract class ItsNatHTMLSelectImpl extends
037: ItsNatHTMLFormComponentImpl implements ItsNatHTMLSelect,
038: ItsNatListInternal {
039: protected ItsNatListCellRenderer renderer;
040:
041: /**
042: * Creates a new instance of ItsNatHTMLSelectImpl
043: */
044: public ItsNatHTMLSelectImpl(HTMLSelectElement selectElem,
045: NameValue[] artifacts,
046: ItsNatHTMLComponentManagerImpl componentMgr) {
047: super (selectElem, artifacts, componentMgr);
048:
049: setItsNatListCellRenderer(componentMgr
050: .createDefaultItsNatListCellRenderer());
051: }
052:
053: public static ItsNatHTMLSelect newItsNatHTMLSelect(
054: HTMLSelectElement element, NameValue[] artifacts,
055: ItsNatHTMLComponentManagerImpl componentMgr) {
056: if (element.getMultiple())
057: return componentMgr.createItsNatHTMLSelectMult(element,
058: artifacts);
059: else
060: return componentMgr.createItsNatHTMLSelectComboBox(element,
061: artifacts);
062: }
063:
064: public boolean hasDefaultBehaviorChangeEvent() {
065: return true;
066: }
067:
068: public ItsNatListStructure getItsNatListStructure() {
069: // La estructura es fija, no puede tener algo a medida
070: return null;
071: }
072:
073: public HTMLSelectElement getHTMLSelectElement() {
074: return (HTMLSelectElement) getHTMLElement();
075: }
076:
077: public HTMLFormElement getHTMLFormElement() {
078: return getHTMLSelectElement().getForm();
079: }
080:
081: public ItsNatListUI getItsNatListUI() {
082: return (ItsNatListUI) compUI;
083: }
084:
085: public ItsNatHTMLSelectUI getItsNatHTMLSelectUI() {
086: return (ItsNatHTMLSelectUI) compUI;
087: }
088:
089: public void bindDataModel() {
090: ItsNatListSharedImpl.bindDataModel(this );
091: }
092:
093: public void unbindDataModel() {
094: ItsNatListSharedImpl.unbindDataModel(this );
095: }
096:
097: public void syncUIWithDataModel() {
098: ItsNatListSharedImpl.syncUIWithDataModel(this );
099: }
100:
101: public int indexOf(Object obj) {
102: return ItsNatListSharedImpl.indexOf(obj, getListModel());
103: }
104:
105: public void intervalAdded(ListDataEvent e) {
106: ItsNatListSharedImpl.intervalAdded(this , e);
107: }
108:
109: public void intervalRemoved(ListDataEvent e) {
110: ItsNatListSharedImpl.intervalRemoved(this , e);
111: }
112:
113: public void contentsChanged(ListDataEvent e) {
114: ItsNatListSharedImpl.contentsChanged(this , e);
115: }
116:
117: public void insertElementAtInternal(int i, Object item) {
118: ItsNatListUI compUI = getItsNatListUI();
119: compUI.insertElementAt(i, item);
120: }
121:
122: public void removeAllElementsInternal() {
123: ItsNatListUI compUI = getItsNatListUI();
124: compUI.removeAllElements();
125: }
126:
127: public void removeElementRangeInternal(int fromIndex, int toIndex) {
128: ItsNatListUI compUI = getItsNatListUI();
129: compUI.removeElementRange(fromIndex, toIndex);
130: }
131:
132: public void blur() {
133: getItsNatHTMLDocumentImpl().getJSScriptUtilImpl()
134: .callNodeMethod(getHTMLElement(), "blur",
135: new Object[0], true);
136: }
137:
138: public void focus() {
139: getItsNatHTMLDocumentImpl().getJSScriptUtilImpl()
140: .callNodeMethod(getHTMLElement(), "focus",
141: new Object[0], true);
142: }
143:
144: public ItsNatListCellRenderer getItsNatListCellRenderer() {
145: return renderer;
146: }
147:
148: public void setItsNatListCellRenderer(
149: ItsNatListCellRenderer renderer) {
150: this .renderer = renderer;
151: }
152:
153: public ItsNatListCellEditor getItsNatListCellEditor() {
154: return null;
155: }
156:
157: public void setItsNatListCellEditor(ItsNatListCellEditor cellEditor) {
158: throw new ItsNatException(
159: "<select> options can not be graphically edited");
160: }
161:
162: public void startEditingAt(int index) {
163: throw new ItsNatException(
164: "<select> options can not be graphically edited");
165: }
166:
167: public boolean isEditing() {
168: return false;
169: }
170:
171: public int getEditingIndex() {
172: return -1;
173: }
174:
175: public String getEditorActivatorEvent() {
176: throw new ItsNatException(
177: "<select> options can not be graphically edited");
178: }
179:
180: public void setEditorActivatorEvent(String event) {
181: throw new ItsNatException(
182: "<select> options can not be graphically edited");
183: }
184:
185: public Node createDefaultNode() {
186: Document doc = getItsNatDocument().getDocument();
187: HTMLSelectElement elem = (HTMLSelectElement) doc
188: .createElement("select");
189: if (isCombo())
190: elem.setMultiple(false);
191: else
192: elem.setMultiple(true);
193: return elem;
194: }
195:
196: public abstract boolean isCombo();
197: }
|