Source Code Cross Referenced for BookmarkContentProvider.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » views » bookmarkexplorer » 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 ide » org.eclipse.ui.views.bookmarkexplorer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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.views.bookmarkexplorer;
011:
012:        import java.util.ArrayList;
013:        import java.util.List;
014:
015:        import org.eclipse.core.resources.IMarker;
016:        import org.eclipse.core.resources.IMarkerDelta;
017:        import org.eclipse.core.resources.IResource;
018:        import org.eclipse.core.resources.IResourceChangeEvent;
019:        import org.eclipse.core.resources.IResourceChangeListener;
020:        import org.eclipse.core.resources.IResourceDelta;
021:        import org.eclipse.core.resources.IWorkspace;
022:        import org.eclipse.core.runtime.CoreException;
023:        import org.eclipse.jface.viewers.IBasicPropertyConstants;
024:        import org.eclipse.jface.viewers.IStructuredContentProvider;
025:        import org.eclipse.jface.viewers.Viewer;
026:        import org.eclipse.swt.widgets.Control;
027:
028:        /**
029:         * Provides content for the bookmark navigator
030:         */
031:        class BookmarkContentProvider implements  IStructuredContentProvider,
032:                IResourceChangeListener, IBasicPropertyConstants {
033:
034:            private IResource input;
035:
036:            private Viewer viewer;
037:
038:            /**
039:             * The constructor.
040:             */
041:            public BookmarkContentProvider(BookmarkNavigator bookmarksView) {
042:                super ();
043:            }
044:
045:            /**
046:             * The visual part that is using this content provider is about
047:             * to be disposed. Deallocate all allocated SWT resources.
048:             */
049:            public void dispose() {
050:                IResource resource = (IResource) viewer.getInput();
051:                if (resource != null) {
052:                    resource.getWorkspace().removeResourceChangeListener(this );
053:                }
054:            }
055:
056:            /**
057:             * Returns all the bookmarks that should be shown for
058:             * the current settings.
059:             */
060:            Object[] getBookmarks(IResource resource) {
061:                try {
062:                    return resource.findMarkers(IMarker.BOOKMARK, true,
063:                            IResource.DEPTH_INFINITE);
064:                } catch (CoreException e) {
065:                    return new Object[0];
066:                }
067:            }
068:
069:            public Object[] getChildren(Object element) {
070:                // If the input element is a workbench return a list
071:                // of the existing bookmarks.  Otherwise, return an empty list.
072:                if (element instanceof  IResource) {
073:                    return getBookmarks((IResource) element);
074:                } else {
075:                    return new Object[0];
076:                }
077:            }
078:
079:            public Object[] getElements(Object element) {
080:                return getChildren(element);
081:            }
082:
083:            /**
084:             * Recursively walks over the resource delta and gathers all marker deltas.  Marker
085:             * deltas are placed into one of the three given vectors depending on
086:             * the type of delta (add, remove, or change).
087:             */
088:            void getMarkerDeltas(IResourceDelta delta, List additions,
089:                    List removals, List changes) {
090:                IMarkerDelta[] markerDeltas = delta.getMarkerDeltas();
091:                for (int i = 0; i < markerDeltas.length; i++) {
092:                    IMarkerDelta markerDelta = markerDeltas[i];
093:                    IMarker marker = markerDelta.getMarker();
094:                    switch (markerDelta.getKind()) {
095:                    case IResourceDelta.ADDED:
096:                        if (markerDelta.isSubtypeOf(IMarker.BOOKMARK)) {
097:                            additions.add(marker);
098:                        }
099:                        break;
100:                    case IResourceDelta.REMOVED:
101:                        if (markerDelta.isSubtypeOf(IMarker.BOOKMARK)) {
102:                            removals.add(marker);
103:                        }
104:                        break;
105:                    case IResourceDelta.CHANGED:
106:                        if (markerDelta.isSubtypeOf(IMarker.BOOKMARK)) {
107:                            changes.add(marker);
108:                        }
109:                        break;
110:                    }
111:                }
112:
113:                //recurse on child deltas
114:                IResourceDelta[] children = delta.getAffectedChildren();
115:                for (int i = 0; i < children.length; i++) {
116:                    getMarkerDeltas(children[i], additions, removals, changes);
117:                }
118:            }
119:
120:            /* (non-Javadoc)
121:             * Method declared on ITreeContentProvider,
122:             */
123:            public Object getParent(Object element) {
124:                return input;
125:            }
126:
127:            /**
128:             * hasChildren method comment.
129:             */
130:            public boolean hasChildren(Object element) {
131:                if (element instanceof  IWorkspace) {
132:                    return true;
133:                } else {
134:                    return false;
135:                }
136:            }
137:
138:            public void inputChanged(Viewer newViewer, Object oldInput,
139:                    Object newInput) {
140:                if (oldInput == null) {
141:                    IResource resource = (IResource) newInput;
142:                    resource.getWorkspace().addResourceChangeListener(this );
143:                }
144:                this .viewer = newViewer;
145:                this .input = (IResource) newInput;
146:            }
147:
148:            /**
149:             * The workbench has changed.  Process the delta and provide updates to the viewer,
150:             * inside the UI thread.
151:             *
152:             * @see IResourceChangeListener#resourceChanged
153:             */
154:            public void resourceChanged(final IResourceChangeEvent event) {
155:
156:                // gather all marker changes from the delta.
157:                // be sure to do this in the calling thread, 
158:                // as the delta is destroyed when this method returns
159:                final List additions = new ArrayList();
160:                final List removals = new ArrayList();
161:                final List changes = new ArrayList();
162:
163:                IResourceDelta delta = event.getDelta();
164:                if (delta == null) {
165:                    return;
166:                }
167:                getMarkerDeltas(delta, additions, removals, changes);
168:
169:                // update the viewer based on the marker changes, in the UI thread
170:                if (additions.size() + removals.size() + changes.size() > 0) {
171:                    viewer.getControl().getDisplay().asyncExec(new Runnable() {
172:                        public void run() {
173:                            // This method runs inside an asyncExec.  The widget may have been destroyed
174:                            // by the time this is run.  Check for this and do nothing if so.
175:                            Control ctrl = viewer.getControl();
176:                            if (ctrl == null || ctrl.isDisposed()) {
177:                                return;
178:                            }
179:
180:                            viewer.refresh();
181:                        }
182:                    });
183:                }
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.