Source Code Cross Referenced for ItsNatHTMLCellEditorBaseImpl.java in  » Ajax » ItsNat » org » itsnat » impl » comp » html » editor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » ItsNat » org.itsnat.impl.comp.html.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.editor;
015:
016:        import java.beans.PropertyVetoException;
017:        import javax.swing.AbstractCellEditor;
018:        import org.itsnat.comp.ItsNatComponent;
019:        import org.itsnat.comp.html.ItsNatHTMLInputCheckBox;
020:        import org.itsnat.comp.html.ItsNatHTMLInputText;
021:        import org.itsnat.comp.html.ItsNatHTMLInputTextFormatted;
022:        import org.itsnat.comp.html.ItsNatHTMLSelectComboBox;
023:        import org.itsnat.comp.html.ItsNatHTMLTextArea;
024:        import org.itsnat.core.ItsNatException;
025:        import org.itsnat.impl.comp.html.ItsNatHTMLComponentManagerImpl;
026:        import org.itsnat.impl.core.ItsNatDocumentImpl;
027:        import org.itsnat.impl.core.domutil.ItsNatDOMUtilInternal;
028:        import org.w3c.dom.Element;
029:        import org.w3c.dom.Node;
030:        import org.w3c.dom.events.Event;
031:        import org.w3c.dom.events.EventListener;
032:        import org.w3c.dom.html.HTMLInputElement;
033:        import org.w3c.dom.html.HTMLTextAreaElement;
034:
035:        /**
036:         *
037:         * @author jmarranz
038:         */
039:        public abstract class ItsNatHTMLCellEditorBaseImpl extends
040:                AbstractCellEditor implements  EventListener {
041:            protected EditorDelegate delegate;
042:
043:            /**
044:             * Creates a new instance of ItsNatHTMLCellEditorBaseImpl
045:             */
046:            public ItsNatHTMLCellEditorBaseImpl(ItsNatComponent compEditor,
047:                    ItsNatHTMLComponentManagerImpl componentMgr) {
048:                if (compEditor != null) {
049:                    if (compEditor instanceof  ItsNatHTMLInputText)
050:                        this .delegate = new EditorDelegateInputText(
051:                                (ItsNatHTMLInputText) compEditor);
052:                    else if (compEditor instanceof  ItsNatHTMLSelectComboBox)
053:                        this .delegate = new EditorDelegateComboBox(
054:                                (ItsNatHTMLSelectComboBox) compEditor);
055:                    else if (compEditor instanceof  ItsNatHTMLInputCheckBox)
056:                        this .delegate = new EditorDelegateCheckBox(
057:                                (ItsNatHTMLInputCheckBox) compEditor);
058:                    else if (compEditor instanceof  ItsNatHTMLTextArea)
059:                        this .delegate = new EditorDelegateTextArea(
060:                                (ItsNatHTMLTextArea) compEditor);
061:                    else
062:                        throw new ItsNatException(
063:                                "Component is not supported as editor: "
064:                                        + compEditor);
065:                } else {
066:                    this .delegate = new EditorDelegateInputText(componentMgr
067:                            .createItsNatHTMLInputText(null, null));
068:                }
069:            }
070:
071:            public Object getCellEditorValue() {
072:                return delegate.getCellEditorValue();
073:            }
074:
075:            public ItsNatComponent getCellEditorComponent(Object value,
076:                    Element cellElem) {
077:                ItsNatComponent compEditor = delegate.getCellEditorComponent();
078:                compEditor.removeEventListener("blur", this ); // Por si acaso no se recibió el blur en una anterior edición
079:
080:                Node nodeEditor = compEditor.getNode();
081:                cellElem.appendChild(nodeEditor); // Se detecta y se añaden los DOM listeners automáticamente en el componente, cuando se quite del árbol también se detecta y se quitan los listeners antes
082:
083:                delegate.setValue(value);
084:
085:                compEditor.addEventListener("blur", this );
086:
087:                return compEditor;
088:            }
089:
090:            public void handleEvent(Event evt) {
091:                String type = evt.getType();
092:                if (type.equals("blur")/* || type.equals("change")*/) {
093:                    ItsNatComponent compEditor = delegate
094:                            .getCellEditorComponent();
095:                    compEditor.removeEventListener("blur", this );
096:
097:                    stopCellEditing();
098:                }
099:            }
100:
101:            protected abstract class EditorDelegate {
102:                public abstract Object getCellEditorValue();
103:
104:                public abstract ItsNatComponent getCellEditorComponent();
105:
106:                public abstract void setValue(Object value);
107:            }
108:
109:            protected class EditorDelegateInputText extends EditorDelegate {
110:                protected ItsNatHTMLInputText compEditor;
111:
112:                public EditorDelegateInputText(ItsNatHTMLInputText compEditor) {
113:                    this .compEditor = compEditor;
114:                }
115:
116:                public Object getCellEditorValue() {
117:                    if (compEditor instanceof  ItsNatHTMLInputTextFormatted)
118:                        return ((ItsNatHTMLInputTextFormatted) compEditor)
119:                                .getValue();
120:                    else
121:                        return compEditor.getText();
122:                }
123:
124:                public ItsNatComponent getCellEditorComponent() {
125:                    return compEditor;
126:                }
127:
128:                public void setValue(Object value) {
129:                    String text = value.toString();
130:                    HTMLInputElement inputElem = compEditor
131:                            .getHTMLInputElement();
132:                    ItsNatDOMUtilInternal.setAttribute(inputElem, "size",
133:                            String.valueOf(text.length() + 1)); // El + 1 es para evitar el 0 en caso de cadena nula 
134:
135:                    if (compEditor instanceof  ItsNatHTMLInputTextFormatted) {
136:                        try {
137:                            ((ItsNatHTMLInputTextFormatted) compEditor)
138:                                    .setValue(value);
139:                        } catch (PropertyVetoException ex) {
140:                            throw new ItsNatException(ex);
141:                        }
142:                    } else
143:                        compEditor.setText(text);
144:
145:                    compEditor.focus();
146:
147:                    ItsNatDocumentImpl itsNatDoc = (ItsNatDocumentImpl) compEditor
148:                            .getItsNatDocument();
149:                    if (itsNatDoc.isMSIE())
150:                        compEditor.focus(); // El primero parece que falla en Internet Explorer 6         
151:                    //compEditor.select(); no es necesario, solucionaba el focus en MSIE
152:                }
153:            }
154:
155:            protected class EditorDelegateComboBox extends EditorDelegate {
156:                protected ItsNatHTMLSelectComboBox compEditor;
157:
158:                public EditorDelegateComboBox(
159:                        ItsNatHTMLSelectComboBox compEditor) {
160:                    this .compEditor = compEditor;
161:                }
162:
163:                public Object getCellEditorValue() {
164:                    return compEditor.getSelectedItem();
165:                }
166:
167:                public ItsNatComponent getCellEditorComponent() {
168:                    return compEditor;
169:                }
170:
171:                public void setValue(Object value) {
172:                    compEditor.setSelectedItem(value);
173:
174:                    compEditor.focus();
175:                }
176:            }
177:
178:            protected class EditorDelegateCheckBox extends EditorDelegate {
179:                protected ItsNatHTMLInputCheckBox compEditor;
180:
181:                public EditorDelegateCheckBox(ItsNatHTMLInputCheckBox compEditor) {
182:                    this .compEditor = compEditor;
183:                }
184:
185:                public Object getCellEditorValue() {
186:                    return Boolean.valueOf(compEditor.isSelected());
187:                }
188:
189:                public ItsNatComponent getCellEditorComponent() {
190:                    return compEditor;
191:                }
192:
193:                public void setValue(Object value) {
194:                    boolean selected = false;
195:                    if (value instanceof  Boolean)
196:                        selected = ((Boolean) value).booleanValue();
197:                    else if (value instanceof  String)
198:                        selected = value.equals("true");
199:
200:                    compEditor.setSelected(selected);
201:
202:                    compEditor.focus(); // Con uno basta
203:                    //compEditor.select(); no es necesario           
204:                }
205:            }
206:
207:            protected class EditorDelegateTextArea extends EditorDelegate {
208:                protected ItsNatHTMLTextArea compEditor;
209:
210:                public EditorDelegateTextArea(ItsNatHTMLTextArea compEditor) {
211:                    this .compEditor = compEditor;
212:                }
213:
214:                public Object getCellEditorValue() {
215:                    return compEditor.getText();
216:                }
217:
218:                public ItsNatComponent getCellEditorComponent() {
219:                    return compEditor;
220:                }
221:
222:                public void setValue(Object value) {
223:                    String text = value.toString();
224:                    HTMLTextAreaElement elem = compEditor
225:                            .getHTMLTextAreaElement();
226:
227:                    int maxNumCols = 1;
228:                    int rows = 0;
229:                    int cols = 0;
230:                    for (int i = 0; i < text.length(); i++) {
231:                        if (text.charAt(i) == '\n') {
232:                            rows++;
233:                            if (cols > maxNumCols)
234:                                maxNumCols = cols;
235:                            cols = 0;
236:                        } else
237:                            cols++;
238:                    }
239:                    if (cols > maxNumCols)
240:                        maxNumCols = cols;
241:                    maxNumCols += 4; // Para que sobre algo más (o al menos una pues el cero no vale)            
242:                    rows += 2; // Idem
243:                    elem.setCols(maxNumCols);
244:                    elem.setRows(rows);
245:                    compEditor.setText(text);
246:
247:                    compEditor.focus();
248:                    ItsNatDocumentImpl itsNatDoc = (ItsNatDocumentImpl) compEditor
249:                            .getItsNatDocument();
250:                    if (itsNatDoc.isMSIE())
251:                        compEditor.focus(); // El primero parece que falla en Internet Explorer 6         
252:                    //compEditor.select();  no es necesario, solucionaba el focus en MSIE    
253:                }
254:            }
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.