OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2012, the Dart project authors. |
| 3 * |
| 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 |
| 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * |
| 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 |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
| 12 * the License. |
| 13 */ |
| 14 |
| 15 package com.google.dart.tools.ui.internal.filesview; |
| 16 |
| 17 import com.google.dart.tools.ui.DartPluginImages; |
| 18 |
| 19 import org.eclipse.core.filesystem.EFS; |
| 20 import org.eclipse.core.filesystem.IFileStore; |
| 21 import org.eclipse.core.runtime.CoreException; |
| 22 import org.eclipse.core.runtime.IAdapterFactory; |
| 23 import org.eclipse.core.runtime.NullProgressMonitor; |
| 24 import org.eclipse.core.runtime.Platform; |
| 25 import org.eclipse.jface.resource.ImageDescriptor; |
| 26 import org.eclipse.ui.model.IWorkbenchAdapter; |
| 27 import org.eclipse.ui.model.WorkbenchAdapter; |
| 28 |
| 29 import java.util.ArrayList; |
| 30 import java.util.List; |
| 31 |
| 32 /** |
| 33 * A representation of a sdk library (e.g. dart:core, dart:io, ...). |
| 34 */ |
| 35 class SdkLibraryNode { |
| 36 |
| 37 static class SdkLibraryWorkbenchAdapter extends WorkbenchAdapter implements IA
dapterFactory { |
| 38 @SuppressWarnings("rawtypes") |
| 39 @Override |
| 40 public Object getAdapter(Object adaptableObject, Class adapterType) { |
| 41 if (adapterType == IWorkbenchAdapter.class) { |
| 42 return this; |
| 43 } else { |
| 44 return null; |
| 45 } |
| 46 } |
| 47 |
| 48 @SuppressWarnings("rawtypes") |
| 49 @Override |
| 50 public Class[] getAdapterList() { |
| 51 return new Class[] {IWorkbenchAdapter.class}; |
| 52 } |
| 53 |
| 54 @Override |
| 55 public ImageDescriptor getImageDescriptor(Object object) { |
| 56 return DartPluginImages.DESC_DART_LIB_FILE; |
| 57 } |
| 58 |
| 59 @Override |
| 60 public String getLabel(Object object) { |
| 61 return ((SdkLibraryNode) object).toString(); |
| 62 } |
| 63 } |
| 64 |
| 65 static { |
| 66 Platform.getAdapterManager().registerAdapters(new SdkLibraryWorkbenchAdapter
(), |
| 67 SdkLibraryNode.class); |
| 68 } |
| 69 |
| 70 private IFileStore root; |
| 71 |
| 72 public SdkLibraryNode(IFileStore root) { |
| 73 this.root = root; |
| 74 } |
| 75 |
| 76 public IFileStore[] getFiles() { |
| 77 try { |
| 78 List<IFileStore> members = filteredMembers(root); |
| 79 |
| 80 return members.toArray(new IFileStore[members.size()]); |
| 81 } catch (CoreException e) { |
| 82 return new IFileStore[0]; |
| 83 } |
| 84 } |
| 85 |
| 86 @Override |
| 87 public String toString() { |
| 88 return "dart:" + root.getName(); |
| 89 } |
| 90 |
| 91 private List<IFileStore> filteredMembers(IFileStore file) throws CoreException
{ |
| 92 List<IFileStore> children = new ArrayList<IFileStore>(); |
| 93 |
| 94 for (IFileStore child : file.childStores(EFS.NONE, new NullProgressMonitor()
)) { |
| 95 String name = child.getName(); |
| 96 if (!(name.startsWith("."))) { |
| 97 children.add(child); |
| 98 } |
| 99 } |
| 100 |
| 101 return children; |
| 102 } |
| 103 |
| 104 } |
OLD | NEW |