01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.comp.html.ui;
15:
16: import org.itsnat.comp.ItsNatComboBox;
17: import org.itsnat.comp.html.ItsNatHTMLSelectComboBox;
18: import org.itsnat.comp.ui.ItsNatComboBoxUI;
19: import org.itsnat.impl.comp.html.ItsNatHTMLSelectComboBoxImpl;
20: import org.itsnat.impl.core.domutil.ItsNatDOMUtilInternal;
21: import org.w3c.dom.html.HTMLOptionElement;
22: import org.w3c.dom.html.HTMLSelectElement;
23:
24: /**
25: *
26: * @author jmarranz
27: */
28: public class ItsNatHTMLSelectComboBoxUIImpl extends
29: ItsNatHTMLSelectUIImpl implements ItsNatComboBoxUI {
30:
31: /**
32: * Creates a new instance of ItsNatHTMLSelectComboBoxUIImpl
33: */
34: public ItsNatHTMLSelectComboBoxUIImpl(
35: ItsNatHTMLSelectComboBoxImpl parentComp) {
36: super (parentComp);
37:
38: HTMLSelectElement selectElem = getHTMLSelectElement();
39: selectElem.setMultiple(false); // Se impone
40: }
41:
42: public ItsNatHTMLSelectComboBox getItsNatHTMLSelectComboBox() {
43: return (ItsNatHTMLSelectComboBox) parentComp;
44: }
45:
46: public ItsNatHTMLSelectComboBoxImpl getItsNatHTMLSelectComboBoxImpl() {
47: return (ItsNatHTMLSelectComboBoxImpl) parentComp;
48: }
49:
50: /*
51: public int getSelectedIndex()
52: {
53: HTMLSelectElement selectElem = getHTMLSelectElement();
54: return selectElem.getSelectedIndex();
55: }
56: */
57:
58: public void setSelectedIndex(int index) {
59: int len = getLength();
60: for (int i = 0; i < len; i++) {
61: HTMLOptionElement option = getHTMLOptionElementAt(i);
62: boolean oldState = option.getSelected();
63: boolean newState = (index == i);
64: if (oldState != newState) {
65: ItsNatDOMUtilInternal.setAttribute(option, "selected",
66: newState);
67: // option.setSelected(newState); no está definida en versiones de Xerces antiguas (ej. 2.6.2)
68: }
69: }
70:
71: /* Podríamos usar:
72: HTMLSelectElement selectElem = getHTMLSelectElement();
73: selectElem.setSelectedIndex(index);
74:
75: pero Xerces no usa la propiedad selectedIndex realmente, cambia el selected de los OPTION adecuadamente
76: es decir hace algo parecido a lo que hacemos antes, pero nos interesa tener
77: un total control y evitar al máximo enviar código inútil.
78:
79: Podríamos usar también la propiedad selectedIndex pero tiene el problema de que no tiene
80: atributo asociado importante por ejemplo para que el control remoto se entere del estado actual.
81: */
82: }
83:
84: public ItsNatComboBox getItsNatComboBox() {
85: return (ItsNatComboBox) parentComp;
86: }
87: }
|