Source Code Cross Referenced for ProgressViewerContentProvider.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » progress » 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 » ui workbench » org.eclipse.ui.internal.progress 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2006 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:         *******************************************************************************/package org.eclipse.ui.internal.progress;
011:
012:        import java.util.HashSet;
013:        import java.util.Iterator;
014:        import java.util.Set;
015:
016:        import org.eclipse.core.runtime.IProgressMonitor;
017:        import org.eclipse.core.runtime.IStatus;
018:        import org.eclipse.core.runtime.Status;
019:        import org.eclipse.core.runtime.jobs.Job;
020:        import org.eclipse.ui.internal.progress.FinishedJobs.KeptJobsListener;
021:        import org.eclipse.ui.progress.WorkbenchJob;
022:
023:        /**
024:         * The ProgressViewerContentProvider is the content provider progress viewers.
025:         */
026:        public class ProgressViewerContentProvider extends
027:                ProgressContentProvider {
028:            protected AbstractProgressViewer progressViewer;
029:
030:            private KeptJobsListener keptJobListener;
031:
032:            private Set keptJobs = new HashSet();
033:
034:            /**
035:             * Create a new instance of the receiver.
036:             * 
037:             * @param structured
038:             *            The Viewer we are providing content for
039:             * @param debug
040:             *           If true debug information will be shown
041:             * 			 if the debug flag in the ProgressManager is true.
042:             * @param showFinished
043:             *            A boolean that indicates whether or not the finished jobs
044:             *            should be shown.
045:             */
046:            public ProgressViewerContentProvider(
047:                    AbstractProgressViewer structured, boolean debug,
048:                    boolean showFinished) {
049:                super (debug);
050:                progressViewer = structured;
051:                if (showFinished) {
052:                    FinishedJobs.getInstance()
053:                            .addListener(getKeptJobListener());
054:                }
055:            }
056:
057:            /**
058:             * Return a listener for kept jobs.
059:             * 
060:             * @return KeptJobsListener
061:             */
062:            private KeptJobsListener getKeptJobListener() {
063:                keptJobListener = new KeptJobsListener() {
064:
065:                    /*
066:                     * (non-Javadoc)
067:                     * 
068:                     * @see org.eclipse.ui.internal.progress.FinishedJobs.KeptJobsListener#finished(org.eclipse.ui.internal.progress.JobTreeElement)
069:                     */
070:                    public void finished(JobTreeElement jte) {
071:                        keptJobs.add(jte);
072:                        final JobTreeElement element = jte;
073:                        Job updateJob = new WorkbenchJob("Refresh finished") {//$NON-NLS-1$
074:                            /* (non-Javadoc)
075:                             * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
076:                             */
077:                            public IStatus runInUIThread(
078:                                    IProgressMonitor monitor) {
079:                                refresh(new Object[] { element });
080:                                return Status.OK_STATUS;
081:                            }
082:                        };
083:                        updateJob.setSystem(true);
084:                        updateJob.schedule();
085:
086:                    }
087:
088:                    /*
089:                     * (non-Javadoc)
090:                     * 
091:                     * @see org.eclipse.ui.internal.progress.FinishedJobs.KeptJobsListener#removed(org.eclipse.ui.internal.progress.JobTreeElement)
092:                     */
093:                    public void removed(JobTreeElement jte) {
094:                        //null indicates they are all removed
095:                        if (jte == null) {
096:                            keptJobs.clear();
097:                        } else {
098:                            keptJobs.remove(jte);
099:                        }
100:                        final JobTreeElement element = jte;
101:                        Job updateJob = new WorkbenchJob("Remove finished") {//$NON-NLS-1$
102:                            /* (non-Javadoc)
103:                             * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
104:                             */
105:                            public IStatus runInUIThread(
106:                                    IProgressMonitor monitor) {
107:                                if (element == null) {
108:                                    refresh();
109:                                } else {
110:                                    ProgressViewerContentProvider.this 
111:                                            .remove(new Object[] { element });
112:                                }
113:                                return Status.OK_STATUS;
114:                            }
115:                        };
116:                        updateJob.setSystem(true);
117:                        updateJob.schedule();
118:
119:                    }
120:
121:                };
122:                return keptJobListener;
123:            }
124:
125:            /*
126:             * (non-Javadoc)
127:             * 
128:             * @see org.eclipse.ui.internal.progress.IProgressUpdateCollector#refresh()
129:             */
130:            public void refresh() {
131:                progressViewer.refresh(true);
132:            }
133:
134:            /*
135:             * (non-Javadoc)
136:             * 
137:             * @see org.eclipse.ui.internal.progress.IProgressUpdateCollector#refresh(org.eclipse.ui.internal.progress.JobTreeElement[])
138:             */
139:            public void refresh(Object[] elements) {
140:                Object[] refreshes = getRoots(elements, true);
141:                for (int i = 0; i < refreshes.length; i++) {
142:                    progressViewer.refresh(refreshes[i], true);
143:                }
144:            }
145:
146:            /*
147:             * (non-Javadoc)
148:             * 
149:             * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
150:             */
151:            public Object[] getElements(Object inputElement) {
152:                Object[] elements = super .getElements(inputElement);
153:
154:                if (keptJobs.size() == 0) {
155:                    return elements;
156:                }
157:                if (elements.length == 0) {
158:                    return keptJobs.toArray();
159:                }
160:
161:                Set all = new HashSet();
162:
163:                for (int i = 0; i < elements.length; i++) {
164:                    Object element = elements[i];
165:                    all.add(element);
166:                    if (keptJobs.contains(element)) {
167:                        keptJobs.remove(element);
168:                    }
169:
170:                }
171:
172:                Iterator keptIterator = keptJobs.iterator();
173:                while (keptIterator.hasNext()) {
174:                    JobInfo next = (JobInfo) keptIterator.next();
175:                    GroupInfo group = next.getGroupInfo();
176:                    if (group == null)
177:                        all.add(next);
178:                    else
179:                        all.add(group);
180:                }
181:                return all.toArray();
182:            }
183:
184:            /**
185:             * Get the root elements of the passed elements as we only show roots.
186:             * Replace the element with its parent if subWithParent is true
187:             * 
188:             * @param elements
189:             *            the array of elements.
190:             * @param subWithParent
191:             *            sub with parent flag.
192:             * @return Object[]
193:             */
194:            private Object[] getRoots(Object[] elements, boolean subWithParent) {
195:                if (elements.length == 0) {
196:                    return elements;
197:                }
198:                HashSet roots = new HashSet();
199:                for (int i = 0; i < elements.length; i++) {
200:                    JobTreeElement element = (JobTreeElement) elements[i];
201:                    if (element.isJobInfo()) {
202:                        GroupInfo group = ((JobInfo) element).getGroupInfo();
203:                        if (group == null) {
204:                            roots.add(element);
205:                        } else {
206:                            if (subWithParent) {
207:                                roots.add(group);
208:                            }
209:                        }
210:                    } else {
211:                        roots.add(element);
212:                    }
213:                }
214:                return roots.toArray();
215:            }
216:
217:            public void add(Object[] elements) {
218:                progressViewer.add(elements);
219:
220:            }
221:
222:            public void remove(Object[] elements) {
223:                progressViewer.remove(elements);
224:
225:            }
226:
227:            /*
228:             * (non-Javadoc)
229:             * 
230:             * @see org.eclipse.jface.viewers.IContentProvider#dispose()
231:             */
232:            public void dispose() {
233:                super.dispose();
234:                if (keptJobListener != null) {
235:                    FinishedJobs.getInstance().removeListener(keptJobListener);
236:                }
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.