OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 | 14 |
15 package com.google.dart.tools.ui.internal.filesview; | 15 package com.google.dart.tools.ui.internal.filesview; |
16 | 16 |
17 import org.eclipse.core.filesystem.EFS; | 17 import org.eclipse.core.filesystem.EFS; |
18 import org.eclipse.core.filesystem.IFileStore; | 18 import org.eclipse.core.filesystem.IFileStore; |
19 import org.eclipse.core.resources.IContainer; | 19 import org.eclipse.core.resources.IContainer; |
20 import org.eclipse.core.resources.IProject; | |
21 import org.eclipse.core.resources.IResource; | 20 import org.eclipse.core.resources.IResource; |
22 import org.eclipse.core.resources.IResourceChangeEvent; | 21 import org.eclipse.core.resources.IResourceChangeEvent; |
23 import org.eclipse.core.resources.IResourceChangeListener; | 22 import org.eclipse.core.resources.IResourceChangeListener; |
| 23 import org.eclipse.core.resources.IWorkspaceRoot; |
24 import org.eclipse.core.resources.ResourcesPlugin; | 24 import org.eclipse.core.resources.ResourcesPlugin; |
25 import org.eclipse.core.runtime.CoreException; | 25 import org.eclipse.core.runtime.CoreException; |
26 import org.eclipse.jface.viewers.ITreeContentProvider; | 26 import org.eclipse.jface.viewers.ITreeContentProvider; |
27 import org.eclipse.jface.viewers.Viewer; | 27 import org.eclipse.jface.viewers.Viewer; |
28 import org.eclipse.swt.widgets.Display; | 28 import org.eclipse.swt.widgets.Display; |
29 | 29 |
30 import java.util.ArrayList; | 30 import java.util.ArrayList; |
| 31 import java.util.Arrays; |
| 32 import java.util.HashMap; |
31 import java.util.List; | 33 import java.util.List; |
| 34 import java.util.Map; |
32 | 35 |
33 /** | 36 /** |
34 * Files view content provider. | 37 * Files view content provider. |
35 */ | 38 */ |
36 public class ResourceContentProvider implements ITreeContentProvider, IResourceC
hangeListener { | 39 public class ResourceContentProvider implements ITreeContentProvider, IResourceC
hangeListener { |
37 private static final IResource[] NO_CHILDREN = new IResource[0]; | 40 private static final IResource[] NO_CHILDREN = new IResource[0]; |
38 | 41 |
39 private Viewer viewer; | 42 private Viewer viewer; |
40 | 43 |
41 // Synthetic libraries node support | 44 private Map<IFileStore, SdkLibraryNode> sdkChildMap; |
42 // private Map<IFileStore, DartLibrary> fileStoreMap; | |
43 | 45 |
44 public ResourceContentProvider() { | 46 public ResourceContentProvider() { |
45 ResourcesPlugin.getWorkspace().addResourceChangeListener(this); | 47 ResourcesPlugin.getWorkspace().addResourceChangeListener(this); |
46 } | 48 } |
47 | 49 |
48 @Override | 50 @Override |
49 public void dispose() { | 51 public void dispose() { |
50 ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); | 52 ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); |
51 } | 53 } |
52 | 54 |
53 @Override | 55 @Override |
54 public Object[] getChildren(Object element) { | 56 public Object[] getChildren(Object element) { |
55 try { | 57 try { |
56 if (element instanceof IProject) { | 58 if (element instanceof IWorkspaceRoot) { |
57 return getProjectChildren((IProject) element); | 59 IWorkspaceRoot root = (IWorkspaceRoot) element; |
| 60 |
| 61 List<Object> children = new ArrayList<Object>(); |
| 62 |
| 63 children.addAll(Arrays.asList(root.members())); |
| 64 children.add(SdkDirectoryNode.INSTANCE); |
| 65 |
| 66 return children.toArray(); |
58 } else if (element instanceof IContainer) { | 67 } else if (element instanceof IContainer) { |
59 IContainer container = (IContainer) element; | 68 IContainer container = (IContainer) element; |
60 return filteredMembers(container).toArray(); | 69 return filteredMembers(container).toArray(); |
61 } else if (element instanceof IFileStore) { | 70 } else if (element instanceof IFileStore) { |
62 IFileStore fileStore = (IFileStore) element; | 71 IFileStore fileStore = (IFileStore) element; |
63 return fileStore.childStores(EFS.NONE, null); | 72 return fileStore.childStores(EFS.NONE, null); |
| 73 } else if (element instanceof SdkDirectoryNode) { |
| 74 return ((SdkDirectoryNode) element).getLibraries(); |
| 75 } else if (element instanceof SdkLibraryNode) { |
| 76 return ((SdkLibraryNode) element).getFiles(); |
64 } | 77 } |
65 // Synthetic libraries node support | |
66 // else if (element instanceof DartLibraryImpl) { | |
67 // return getLibraryChildren((DartLibraryImpl) element); | |
68 // } | |
69 } catch (CoreException ce) { | 78 } catch (CoreException ce) { |
70 //fall through | 79 //fall through |
71 } | 80 } |
| 81 |
72 return NO_CHILDREN; | 82 return NO_CHILDREN; |
73 } | 83 } |
74 | 84 |
75 @Override | 85 @Override |
76 public Object[] getElements(Object inputElement) { | 86 public Object[] getElements(Object inputElement) { |
77 return getChildren(inputElement); | 87 return getChildren(inputElement); |
78 } | 88 } |
79 | 89 |
80 @Override | 90 @Override |
81 public Object getParent(Object element) { | 91 public Object getParent(Object element) { |
82 if (element instanceof IResource) { | 92 if (element instanceof IResource) { |
83 return ((IResource) element).getParent(); | 93 return ((IResource) element).getParent(); |
84 } else if (element instanceof IFileStore) { | 94 } else if (element instanceof IFileStore) { |
85 IFileStore fileStore = (IFileStore) element; | 95 IFileStore fileStore = (IFileStore) element; |
86 IFileStore parent = fileStore.getParent(); | |
87 // Synthetic libraries node support | |
88 // if (getFileStoreMap().containsKey(parent)) { | |
89 // return getFileStoreMap().get(parent); | |
90 // } | |
91 | 96 |
92 return parent; | 97 if (getSdkParent(fileStore) != null) { |
| 98 return getSdkParent(fileStore); |
| 99 } |
| 100 |
| 101 return fileStore.getParent(); |
| 102 } else if (element instanceof SdkLibraryNode) { |
| 103 return SdkDirectoryNode.INSTANCE; |
93 } else { | 104 } else { |
94 return null; | 105 return null; |
95 } | 106 } |
96 } | 107 } |
97 | 108 |
98 @Override | 109 @Override |
99 public boolean hasChildren(Object element) { | 110 public boolean hasChildren(Object element) { |
100 try { | |
101 if (element instanceof IProject) { | |
102 return filteredMembers((IProject) element).size() > 0; | |
103 } | |
104 } catch (CoreException exception) { | |
105 return false; | |
106 } | |
107 | |
108 return getChildren(element).length > 0; | 111 return getChildren(element).length > 0; |
109 } | 112 } |
110 | 113 |
111 @Override | 114 @Override |
112 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | 115 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
113 this.viewer = viewer; | 116 this.viewer = viewer; |
114 } | 117 } |
115 | 118 |
116 @Override | 119 @Override |
117 public void resourceChanged(IResourceChangeEvent event) { | 120 public void resourceChanged(IResourceChangeEvent event) { |
118 Display.getDefault().asyncExec(new Runnable() { | 121 Display.getDefault().asyncExec(new Runnable() { |
119 @Override | 122 @Override |
120 public void run() { | 123 public void run() { |
121 viewer.refresh(); | 124 viewer.refresh(); |
122 } | 125 } |
123 }); | 126 }); |
124 } | 127 } |
125 | 128 |
| 129 private Map<IFileStore, SdkLibraryNode> createSdkChildMap() { |
| 130 Map<IFileStore, SdkLibraryNode> map = new HashMap<IFileStore, SdkLibraryNode
>(); |
| 131 |
| 132 for (SdkLibraryNode library : SdkDirectoryNode.INSTANCE.getLibraries()) { |
| 133 for (IFileStore child : library.getFiles()) { |
| 134 map.put(child, library); |
| 135 } |
| 136 } |
| 137 |
| 138 return map; |
| 139 } |
| 140 |
126 private List<IResource> filteredMembers(IContainer container) throws CoreExcep
tion { | 141 private List<IResource> filteredMembers(IContainer container) throws CoreExcep
tion { |
127 List<IResource> children = new ArrayList<IResource>(); | 142 List<IResource> children = new ArrayList<IResource>(); |
128 | 143 |
129 for (IResource child : container.members()) { | 144 for (IResource child : container.members()) { |
130 String name = child.getName(); | 145 String name = child.getName(); |
131 if (!(name.startsWith("."))) { | 146 if (!(name.startsWith("."))) { |
132 children.add(child); | 147 children.add(child); |
133 } | 148 } |
134 } | 149 } |
135 | 150 |
136 return children; | 151 return children; |
137 } | 152 } |
138 | 153 |
139 // Synthetic libraries node support | 154 private SdkLibraryNode getSdkParent(IFileStore fileStore) { |
140 // private Map<IFileStore, DartLibrary> getFileStoreMap() { | 155 if (sdkChildMap == null) { |
141 // if (fileStoreMap == null) { | 156 sdkChildMap = createSdkChildMap(); |
142 // fileStoreMap = new HashMap<IFileStore, DartLibrary>(); | 157 } |
143 // | |
144 // try { | |
145 // for (DartLibrary lib : DartModelManager.getInstance().getDartModel().g
etBundledLibraries()) { | |
146 // if (lib instanceof DartLibraryImpl) { | |
147 // DartLibraryImpl library = (DartLibraryImpl) lib; | |
148 // | |
149 // IFileStore libraryFileStore = getLibraryFileStore(library); | |
150 // | |
151 // fileStoreMap.put(libraryFileStore, library); | |
152 // } | |
153 // } | |
154 // } catch (CoreException exception) { | |
155 // DartToolsPlugin.log(exception); | |
156 // } | |
157 // } | |
158 // | |
159 // return fileStoreMap; | |
160 // } | |
161 | 158 |
162 // private Object[] getLibraryChildren(DartLibraryImpl library) throws CoreExce
ption { | 159 return sdkChildMap.get(fileStore); |
163 // IFileStore libraryFileStore = getLibraryFileStore(library); | |
164 // | |
165 // if (libraryFileStore != null) { | |
166 // return libraryFileStore.childStores(EFS.NONE, null); | |
167 // } else { | |
168 // return NO_CHILDREN; | |
169 // } | |
170 // } | |
171 | |
172 // private IFileStore getLibraryFileStore(DartLibraryImpl library) throws CoreE
xception { | |
173 // URI uri = library.getLibrarySourceFile().getUri(); | |
174 // | |
175 // if (SystemLibraryManager.isDartUri(uri)) { | |
176 // SystemLibraryManager libraryManager = SystemLibraryManagerProvider.getSy
stemLibraryManager(); | |
177 // | |
178 // uri = libraryManager.translateDartUri(uri); | |
179 // } | |
180 // | |
181 // if ("file".equals(uri.getScheme())) { | |
182 // IFileStore fileStore = EFS.getStore(uri); | |
183 // | |
184 // return fileStore.getParent(); | |
185 // } else { | |
186 // return null; | |
187 // } | |
188 // } | |
189 | |
190 private Object[] getProjectChildren(IProject project) throws CoreException { | |
191 List<Object> children = new ArrayList<Object>(); | |
192 | |
193 List<IResource> resources = filteredMembers(project); | |
194 for (IResource resource : resources) { | |
195 children.add(resource); | |
196 } | |
197 // Synthetic libraries node support | |
198 // if (DartProjectNature.hasDartNature(project)) { | |
199 // DartProject dartProject = DartCore.create(project); | |
200 // for (DartLibrary library : getSystemLibraries(dartProject.getDartLibrari
es())) { | |
201 // children.add(library); | |
202 // } | |
203 // } | |
204 | |
205 return children.toArray(); | |
206 } | 160 } |
207 | 161 |
208 // Synthetic libraries node support | |
209 // private Set<DartLibrary> getSystemLibraries(DartLibrary[] libraries) throws
CoreException { | |
210 // Set<DartLibrary> results = new HashSet<DartLibrary>(); | |
211 // | |
212 // for (DartLibrary library : libraries) { | |
213 // for (DartLibrary lib : library.getImportedLibraries()) { | |
214 // if (!lib.isLocal()) { | |
215 // results.add(lib); | |
216 // } | |
217 // } | |
218 // } | |
219 // | |
220 // // TODO(pquitslund): the model should handle this. | |
221 // DartLibrary coreLibrary = DartModelManager.getInstance().getDartModel().ge
tCoreLibrary(); | |
222 // if (!coreLibrary.isLocal()) { | |
223 // results.add(coreLibrary); | |
224 // } | |
225 // | |
226 // return results; | |
227 // } | |
228 | |
229 } | 162 } |
OLD | NEW |