Source Code Cross Referenced for ListViewer.java in  » IDE-Eclipse » jface » org » eclipse » jface » viewers » 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 » IDE Eclipse » jface » org.eclipse.jface.viewers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *     Brad Reynolds - bug 141435
011:         *     Tom Schindl <tom.schindl@bestsolution.at> - bug 157309, 177619
012:         *******************************************************************************/package org.eclipse.jface.viewers;
013:
014:        import java.util.List;
015:
016:        import org.eclipse.core.runtime.Assert;
017:        import org.eclipse.swt.SWT;
018:        import org.eclipse.swt.graphics.Rectangle;
019:        import org.eclipse.swt.widgets.Composite;
020:        import org.eclipse.swt.widgets.Control;
021:
022:        /**
023:         * A concrete viewer based on an SWT <code>List</code> control.
024:         * <p>
025:         * This class is not intended to be subclassed. It is designed to be
026:         * instantiated with a pre-existing SWT <code>List</code> control and configured
027:         * with a domain-specific content provider, label provider, element filter (optional),
028:         * and element sorter (optional).
029:         * <p>
030:         * Note that the SWT <code>List</code> control only supports the display of strings, not icons.
031:         * If you need to show icons for items, use <code>TableViewer</code> instead.
032:         * </p>
033:         * 
034:         * @see TableViewer
035:         */
036:        public class ListViewer extends AbstractListViewer {
037:
038:            /**
039:             * This viewer's list control.
040:             */
041:            private org.eclipse.swt.widgets.List list;
042:
043:            /**
044:             * Creates a list viewer on a newly-created list control under the given parent.
045:             * The list control is created using the SWT style bits <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>.
046:             * The viewer has no input, no content provider, a default label provider, 
047:             * no sorter, and no filters.
048:             *
049:             * @param parent the parent control
050:             */
051:            public ListViewer(Composite parent) {
052:                this (parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL
053:                        | SWT.BORDER);
054:            }
055:
056:            /**
057:             * Creates a list viewer on a newly-created list control under the given parent.
058:             * The list control is created using the given SWT style bits.
059:             * The viewer has no input, no content provider, a default label provider, 
060:             * no sorter, and no filters.
061:             *
062:             * @param parent the parent control
063:             * @param style the SWT style bits
064:             */
065:            public ListViewer(Composite parent, int style) {
066:                this (new org.eclipse.swt.widgets.List(parent, style));
067:            }
068:
069:            /**
070:             * Creates a list viewer on the given list control.
071:             * The viewer has no input, no content provider, a default label provider, 
072:             * no sorter, and no filters.
073:             *
074:             * @param list the list control
075:             */
076:            public ListViewer(org.eclipse.swt.widgets.List list) {
077:                this .list = list;
078:                hookControl(list);
079:            }
080:
081:            /* (non-Javadoc)
082:             * Method declared on Viewer.
083:             */
084:            public Control getControl() {
085:                return list;
086:            }
087:
088:            /**
089:             * Returns this list viewer's list control.
090:             *
091:             * @return the list control
092:             */
093:            public org.eclipse.swt.widgets.List getList() {
094:                return list;
095:            }
096:
097:            /*
098:             * Non-Javadoc.
099:             * Method defined on StructuredViewer.
100:             */
101:            public void reveal(Object element) {
102:                Assert.isNotNull(element);
103:                int index = getElementIndex(element);
104:                if (index == -1) {
105:                    return;
106:                }
107:                // algorithm patterned after List.showSelection()
108:                int count = list.getItemCount();
109:                if (count == 0) {
110:                    return;
111:                }
112:                int height = list.getItemHeight();
113:                Rectangle rect = list.getClientArea();
114:                int topIndex = list.getTopIndex();
115:                int visibleCount = Math.max(rect.height / height, 1);
116:                int bottomIndex = Math.min(topIndex + visibleCount, count) - 1;
117:                if ((topIndex <= index) && (index <= bottomIndex)) {
118:                    return;
119:                }
120:                int newTop = Math.min(Math.max(index - (visibleCount / 2), 0),
121:                        count - 1);
122:                list.setTopIndex(newTop);
123:            }
124:
125:            /* (non-Javadoc)
126:             * @see org.eclipse.jface.viewers.AbstractListViewer#listAdd(java.lang.String, int)
127:             */
128:            protected void listAdd(String string, int index) {
129:                list.add(string, index);
130:            }
131:
132:            /* (non-Javadoc)
133:             * @see org.eclipse.jface.viewers.AbstractListViewer#listSetItem(int, java.lang.String)
134:             */
135:            protected void listSetItem(int index, String string) {
136:                list.setItem(index, string);
137:            }
138:
139:            /* (non-Javadoc)
140:             * @see org.eclipse.jface.viewers.AbstractListViewer#listGetSelectionIndices()
141:             */
142:            protected int[] listGetSelectionIndices() {
143:                return list.getSelectionIndices();
144:            }
145:
146:            /* (non-Javadoc)
147:             * @see org.eclipse.jface.viewers.AbstractListViewer#listGetItemCount()
148:             */
149:            protected int listGetItemCount() {
150:                return list.getItemCount();
151:            }
152:
153:            /* (non-Javadoc)
154:             * @see org.eclipse.jface.viewers.AbstractListViewer#listSetItems(java.lang.String[])
155:             */
156:            protected void listSetItems(String[] labels) {
157:                list.setItems(labels);
158:            }
159:
160:            /* (non-Javadoc)
161:             * @see org.eclipse.jface.viewers.AbstractListViewer#listRemoveAll()
162:             */
163:            protected void listRemoveAll() {
164:                list.removeAll();
165:            }
166:
167:            /* (non-Javadoc)
168:             * @see org.eclipse.jface.viewers.AbstractListViewer#listRemove(int)
169:             */
170:            protected void listRemove(int index) {
171:                list.remove(index);
172:            }
173:
174:            /* (non-Javadoc)
175:             * @see org.eclipse.jface.viewers.AbstractListViewer#listSelectAndShow(int[])
176:             */
177:            protected void listSetSelection(int[] ixs) {
178:                list.setSelection(ixs);
179:            }
180:
181:            /* (non-Javadoc)
182:             * @see org.eclipse.jface.viewers.AbstractListViewer#listDeselectAll()
183:             */
184:            protected void listDeselectAll() {
185:                list.deselectAll();
186:            }
187:
188:            /* (non-Javadoc)
189:             * @see org.eclipse.jface.viewers.AbstractListViewer#listShowSelection()
190:             */
191:            protected void listShowSelection() {
192:                list.showSelection();
193:            }
194:
195:            /* (non-Javadoc)
196:             * @see org.eclipse.jface.viewers.AbstractListViewer#listGetTopIndex()
197:             */
198:            protected int listGetTopIndex() {
199:                return list.getTopIndex();
200:            }
201:
202:            /*
203:             * (non-Javadoc)
204:             * @see org.eclipse.jface.viewers.AbstractListViewer#listSetTopIndex(int)
205:             */
206:            protected void listSetTopIndex(int index) {
207:                list.setTopIndex(index);
208:            }
209:
210:            /* (non-Javadoc)
211:             * @see org.eclipse.jface.viewers.AbstractListViewer#setSelectionToWidget(java.util.List, boolean)
212:             */
213:            protected void setSelectionToWidget(List in, boolean reveal) {
214:                if (reveal) {
215:                    super .setSelectionToWidget(in, reveal);
216:                } else {
217:                    if (in == null || in.size() == 0) { // clear selection
218:                        list.deselectAll();
219:                    } else {
220:                        int n = in.size();
221:                        int[] ixs = new int[n];
222:                        int count = 0;
223:                        for (int i = 0; i < n; ++i) {
224:                            Object el = in.get(i);
225:                            int ix = getElementIndex(el);
226:                            if (ix >= 0) {
227:                                ixs[count++] = ix;
228:                            }
229:                        }
230:                        if (count < n) {
231:                            System.arraycopy(ixs, 0, ixs = new int[count], 0,
232:                                    count);
233:                        }
234:                        list.deselectAll();
235:                        list.select(ixs);
236:                    }
237:                }
238:            }
239:
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.