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;
015:
016: import javax.swing.DefaultListSelectionModel;
017: import javax.swing.ListSelectionModel;
018: import org.itsnat.comp.ItsNatTable;
019: import org.itsnat.comp.ItsNatTableHeader;
020: import org.itsnat.comp.ItsNatTableHeaderCellRenderer;
021: import org.itsnat.comp.ui.ItsNatTableHeaderCellUI;
022: import org.itsnat.comp.ui.ItsNatTableHeaderUI;
023: import org.itsnat.core.ItsNatException;
024: import org.itsnat.core.event.ParamTransport;
025: import org.w3c.dom.Element;
026: import org.w3c.dom.Node;
027: import org.w3c.dom.events.Event;
028: import org.w3c.dom.events.MouseEvent;
029:
030: /**
031: *
032: * @author jmarranz
033: */
034: public abstract class ItsNatTableHeaderImpl extends
035: ItsNatElementComponentImpl implements ItsNatTableHeader {
036: protected ItsNatTableHeaderCellRenderer renderer;
037: protected ItsNatTableImpl tableComp;
038: protected ListSelectionModelMgrImpl selModelMgr;
039:
040: /**
041: * Creates a new instance of ItsNatTableHeaderImpl
042: */
043: public ItsNatTableHeaderImpl(ItsNatTableImpl tableComp,
044: Element headerElem) {
045: // El element puede ser nulo (no hay header)
046: super (headerElem, null, tableComp
047: .getItsNatComponentManagerImpl());
048:
049: this .tableComp = tableComp;
050:
051: ItsNatComponentManagerImpl componentMgr = getItsNatComponentManagerImpl();
052:
053: setItsNatTableHeaderCellRenderer(componentMgr
054: .createDefaultItsNatTableHeaderCellRenderer());
055: }
056:
057: public void setDefaultListSelectionModel() {
058: ListSelectionModel selModel = new DefaultListSelectionModel();
059: selModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
060: setListSelectionModel(selModel);
061: }
062:
063: public Class getStructureClass() {
064: // La estructura se debe obtener a través de ItsNatTable
065: return null;
066: }
067:
068: public Object createDefaultStructure() {
069: return null;
070: }
071:
072: public void enableEventListeners() {
073: // Por ahora nada porque los eventos (click de selección de la columna)
074: // pues en el header se procesan en la clase Table asociada
075: }
076:
077: public ItsNatTable getItsNatTable() {
078: return (ItsNatTable) tableComp;
079: }
080:
081: public ItsNatTableHeaderUI getItsNatTableHeaderUI() {
082: return (ItsNatTableHeaderUI) compUI;
083: }
084:
085: public ItsNatTableHeaderCellRenderer getItsNatTableHeaderCellRenderer() {
086: return renderer;
087: }
088:
089: public void setItsNatTableHeaderCellRenderer(
090: ItsNatTableHeaderCellRenderer renderer) {
091: this .renderer = renderer;
092: }
093:
094: public void bindDataModel() {
095: throw new ItsNatException("INTERNAL ERROR");
096: }
097:
098: public void unbindDataModel() {
099: throw new ItsNatException("INTERNAL ERROR");
100: }
101:
102: public void syncUIWithDataModel() {
103: throw new ItsNatException("INTERNAL ERROR");
104: }
105:
106: public Object createDefaultModelInternal() {
107: return null;
108: }
109:
110: protected ParamTransport[] getParamTransports(String type) {
111: return null;
112: }
113:
114: public ListSelectionModel getListSelectionModel() {
115: if (selModelMgr == null)
116: return null;
117: return selModelMgr.getListSelectionModel();
118: }
119:
120: public void unsetListSelectionModel() {
121: if (selModelMgr != null)
122: selModelMgr.dispose();
123: // No anulamos el selModelMgr para que se pueda recuperar el ListSelectionModel después de un dispose
124: }
125:
126: public void setListSelectionModel(ListSelectionModel selectionModel) {
127: unsetListSelectionModel();
128:
129: int size = getItsNatTable().getTableModel().getColumnCount();
130: this .selModelMgr = ListSelectionModelMgrImpl
131: .newListSelectionModelMgr(selectionModel, size);
132: }
133:
134: public int getSelectedIndex() {
135: return getListSelectionModel().getMinSelectionIndex();
136: }
137:
138: public void setSelectedIndex(int index) {
139: getListSelectionModel().setSelectionInterval(index, index);
140: }
141:
142: public ItsNatTableHeaderCellUI processEvent(Node nodeClicked,
143: boolean toggle, boolean extend) {
144: // Es llamado desde ItsNatTableImpl
145: // Vemos si ha sido pulsada la cabecera
146:
147: ItsNatTableHeaderUI headerUI = getItsNatTableHeaderUI();
148: ItsNatTableHeaderCellUI colCellInfo = headerUI
149: .getItsNatTableHeaderCellUIFromNode(nodeClicked);
150: if (colCellInfo == null)
151: return null;
152:
153: int column = colCellInfo.getIndex();
154: changeColumnSelection(column, toggle, extend);
155:
156: return colCellInfo;
157: }
158:
159: public void changeColumnSelection(int columnIndex, boolean toggle,
160: boolean extend) {
161: ListSelectionModel csm = getListSelectionModel();
162:
163: boolean selected = csm.isSelectedIndex(columnIndex);
164:
165: selModelMgr.changeSelectionModel(columnIndex, toggle, extend,
166: selected);
167: }
168:
169: }
|