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;
15:
16: import org.itsnat.comp.ItsNatButtonToggle;
17: import org.itsnat.comp.html.ItsNatHTMLInputButtonToggle;
18: import org.itsnat.comp.ui.ItsNatButtonToggleUI;
19: import javax.swing.ButtonModel;
20: import javax.swing.JToggleButton.ToggleButtonModel;
21: import org.itsnat.core.NameValue;
22: import org.itsnat.impl.comp.ItsNatButtonToggleBasedSharedImpl;
23: import org.itsnat.impl.comp.ItsNatButtonToggleInternal;
24: import org.w3c.dom.html.HTMLInputElement;
25:
26: /**
27: *
28: * @author jmarranz
29: */
30: public abstract class ItsNatHTMLInputButtonToggleImpl extends
31: ItsNatHTMLInputButtonBaseImpl implements
32: ItsNatHTMLInputButtonToggle, ItsNatButtonToggleInternal {
33:
34: /**
35: * Creates a new instance of ItsNatHTMLInputButtonToggleImpl
36: */
37: public ItsNatHTMLInputButtonToggleImpl(HTMLInputElement element,
38: NameValue[] artifacts,
39: ItsNatHTMLComponentManagerImpl componentMgr) {
40: super (element, artifacts, componentMgr);
41: }
42:
43: public ToggleButtonModel getToggleButtonModel() {
44: return (ToggleButtonModel) dataModel;
45: }
46:
47: public void setToggleButtonModel(ToggleButtonModel dataModel) {
48: setDataModel(dataModel);
49: }
50:
51: public boolean isSelected() {
52: return getButtonModel().isSelected();
53: }
54:
55: public void setSelected(boolean b) {
56: getButtonModel().setSelected(b);
57: }
58:
59: public Object createDefaultModelInternal() {
60: return createDefaultButtonModel();
61: }
62:
63: public ButtonModel createDefaultButtonModel() {
64: return new ToggleButtonModel();
65: }
66:
67: public void syncUIWithDataModel() {
68: super .syncUIWithDataModel();
69:
70: ItsNatButtonToggleBasedSharedImpl.syncUIWithDataModel(this );
71: }
72:
73: public ItsNatButtonToggleUI getItsNatButtonToggleUI() {
74: return (ItsNatButtonToggleUI) compUI;
75: }
76:
77: public void setUISelected(boolean selected) {
78: ItsNatButtonToggleUI compUI = getItsNatButtonToggleUI();
79:
80: // Hay un caso de envío "redundante" al servidor y es cuando activamos
81: // otro radio button, el Group llamará al actualmente activado para desactivar
82: // el componente no tiene constancia de pulsación (pues se ha pulsado otro)
83: // por lo que no se inhibe el envío de modificación al cliente,
84: // pero no importa el código es mínimo y es una operación redundante (funciona bien)
85:
86: boolean wasDisabled = disableSendCodeToRequesterIfServerUpdating(); // Evitamos así que llegue al requester si no debe llegar (pero sí a los observadores)
87:
88: try {
89: compUI.setSelected(selected);
90: } finally {
91: if (wasDisabled)
92: enableSendCodeToRequester();
93: }
94: }
95: }
|