Source Code Cross Referenced for Listcell.java in  » Ajax » zk » org » zkoss » zul » 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 » zk » org.zkoss.zul 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Listcell.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Fri Aug  5 13:06:17     2005, Created by tomyeh
010:        }}IS_NOTE
011:
012:        Copyright (C) 2005 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        	This program is distributed under GPL Version 2.0 in the hope that
016:        	it will be useful, but WITHOUT ANY WARRANTY.
017:        }}IS_RIGHT
018:         */
019:        package org.zkoss.zul;
020:
021:        import java.util.List;
022:        import java.util.Iterator;
023:
024:        import org.zkoss.xml.HTMLs;
025:
026:        import org.zkoss.zk.ui.Component;
027:        import org.zkoss.zk.ui.UiException;
028:
029:        import org.zkoss.zul.impl.LabelImageElement;
030:
031:        /**
032:         * A list cell.
033:         *
034:         * @author tomyeh
035:         */
036:        public class Listcell extends LabelImageElement {
037:            private Object _value;
038:            private int _span = 1;
039:
040:            public Listcell() {
041:            }
042:
043:            public Listcell(String label) {
044:                setLabel(label);
045:            }
046:
047:            public Listcell(String label, String src) {
048:                setLabel(label);
049:                setImage(src);
050:            }
051:
052:            /** Returns the list box that it belongs to.
053:             */
054:            public Listbox getListbox() {
055:                final Component comp = getParent();
056:                return comp != null ? (Listbox) comp.getParent() : null;
057:            }
058:
059:            /** Returns the list item that it belongs to.
060:             * @deprecated As of release 2.4.1, due to confusion
061:             */
062:            public Listitem getListitem() {
063:                return (Listitem) getParent();
064:            }
065:
066:            /** Returns the list header that is in the same column as
067:             * this cell, or null if not available.
068:             */
069:            public Listheader getListheader() {
070:                final Listbox listbox = getListbox();
071:                if (listbox != null) {
072:                    final Listhead lcs = listbox.getListhead();
073:                    if (lcs != null) {
074:                        final int j = getColumnIndex();
075:                        final List lcschs = lcs.getChildren();
076:                        if (j < lcschs.size())
077:                            return (Listheader) lcschs.get(j);
078:                    }
079:                }
080:                return null;
081:            }
082:
083:            /** Returns the column index of this cell, starting from 0.
084:             */
085:            public int getColumnIndex() {
086:                int j = 0;
087:                for (Iterator it = getParent().getChildren().iterator(); it
088:                        .hasNext(); ++j)
089:                    if (it.next() == this )
090:                        break;
091:                return j;
092:            }
093:
094:            /** Returns the maximal length for this cell.
095:             * If listbox's mold is "select", it is the same as
096:             * {@link Listbox#getMaxlength}
097:             * If not, it is the same as the correponding {@link #getListheader}'s 
098:             * {@link Listheader#getMaxlength}.
099:             *
100:             * <p>Note: {@link Listitem#getMaxlength} is the same as {@link Listbox#getMaxlength}.
101:             */
102:            public int getMaxlength() {
103:                final Listbox listbox = getListbox();
104:                if (listbox == null)
105:                    return 0;
106:                if (listbox.inSelectMold())
107:                    return listbox.getMaxlength();
108:                final Listheader lc = getListheader();
109:                return lc != null ? lc.getMaxlength() : 0;
110:            }
111:
112:            /** Returns the value.
113:             * <p>Default: null.
114:             * <p>Note: the value is application dependent, you can place
115:             * whatever value you want.
116:             */
117:            public Object getValue() {
118:                return _value;
119:            }
120:
121:            /** Sets the value.
122:             * @param value the value.
123:             * <p>Note: the value is application dependent, you can place
124:             * whatever value you want.
125:             */
126:            public void setValue(Object value) {
127:                _value = value;
128:            }
129:
130:            /** Returns number of columns to span this cell.
131:             * Default: 1.
132:             */
133:            public int getSpan() {
134:                return _span;
135:            }
136:
137:            /** Sets the number of columns to span this cell.
138:             * <p>It is the same as the colspan attribute of HTML TD tag.
139:             */
140:            public void setSpan(int span) {
141:                if (_span != span) {
142:                    _span = span;
143:                    smartUpdate("colspan", Integer.toString(_span));
144:                }
145:            }
146:
147:            //-- super --//
148:            public void setWidth(String width) {
149:                throw new UnsupportedOperationException(
150:                        "Set listheader's width instead");
151:            }
152:
153:            //-- Internal use only --//
154:            /** Returns the prefix of the first column (in HTML tags), null if this
155:             * is not first column. Called only by listcell.dsp.
156:             */
157:            public String getColumnHtmlPrefix() {
158:                final Listitem item = getListitem();
159:                final Listbox listbox = getListbox();
160:                if (listbox != null && item.getFirstChild() == this ) {
161:                    final StringBuffer sb = new StringBuffer(64);
162:                    if (listbox.isCheckmark()) {
163:                        sb.append("<input type=\"").append(
164:                                listbox.isMultiple() ? "checkbox" : "radio")
165:                                .append('"');
166:                        if (item.isDisabled())
167:                            sb.append(" disabled=\"disabled\"");
168:                        if (item.isSelected())
169:                            sb.append(" checked=\"checked\"");
170:
171:                        sb.append(" id=\"").append(item.getUuid()).append(
172:                                "!cm\" z.type=\"Lcfc\"/>");
173:                        return sb.toString();
174:                    } else if (isFocusRequired(listbox, item)) {
175:                        sb.append("<a href=\"javascript:;\" id=\"").append(
176:                                item.getUuid()).append(
177:                                "!sel\" z.type=\"Lcfc\"> </a>");
178:                        return sb.toString();
179:                    }
180:                }
181:
182:                //To make the listbox's height more correct, we have to generate &nbsp;
183:                //for empty cell. Otherwise, IE will make the height too small
184:                final boolean empty = getImage() == null
185:                        && getLabel().length() == 0 && getChildren().isEmpty();
186:                return empty ? "&nbsp;" : null;
187:
188:            }
189:
190:            /** Returns the postfix of the first column (in HTML tags), null if this
191:             * is not first column. Called only by listcell.jsp.
192:             */
193:            public String getColumnHtmlPostfix() {
194:                return null;
195:            }
196:
197:            /** Returns whether this cell requires focus.
198:             */
199:            private boolean isFocusRequired(Listbox listbox, Component parent) {
200:                final Listitem sel = listbox.getSelectedItem();
201:                return parent == sel
202:                        || (sel == null && ((Listitem) parent).getIndex() == 0);
203:            }
204:
205:            //-- super --//
206:            public String getOuterAttrs() {
207:                final String attrs = super .getOuterAttrs();
208:
209:                final Listheader header = getListheader();
210:                final String clkattrs = getAllOnClickAttrs(false);
211:                if (header == null && clkattrs == null && _span == 1)
212:                    return attrs;
213:
214:                final StringBuffer sb = new StringBuffer(64).append(attrs);
215:                if (header != null)
216:                    sb.append(header.getColAttrs());
217:                if (clkattrs != null)
218:                    sb.append(clkattrs);
219:                if (_span != 1)
220:                    HTMLs.appendAttribute(sb, "colspan", _span);
221:
222:                return sb.toString();
223:            }
224:
225:            /** Returns the attributes used by the embedded HTML LABEL tag.
226:             * It returns text-relevant styles only.
227:             * <p>Used only by component developer.
228:             */
229:            public String getLabelAttrs() {
230:                final String style = HTMLs.getTextRelevantStyle(getRealStyle());
231:                return style.length() > 0 ? " style=\"" + style + '"' : "";
232:            }
233:
234:            //-- Component --//
235:            public void setParent(Component parent) {
236:                if (parent != null && !(parent instanceof  Listitem))
237:                    throw new UiException("Wrong parent: " + parent);
238:                super .setParent(parent);
239:            }
240:
241:            public void invalidate() {
242:                final Listbox listbox = getListbox();
243:                if (listbox != null && listbox.inSelectMold()) {
244:                    getParent().invalidate();
245:                    //if HTML select, the cell doesn't exists in client
246:                } else {
247:                    super.invalidate();
248:                }
249:            }
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.