1 19 20 package org.netbeans.spi.project.support; 21 22 import java.beans.PropertyChangeListener ; 23 import java.io.File ; 24 import javax.swing.Icon ; 25 import javax.swing.event.ChangeListener ; 26 import org.netbeans.api.project.FileOwnerQuery; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.api.project.ProjectManager; 29 import org.netbeans.api.project.ProjectUtils; 30 import org.netbeans.api.project.SourceGroup; 31 import org.netbeans.api.project.Sources; 32 import org.netbeans.api.queries.SharabilityQuery; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileUtil; 35 36 40 public class GenericSources { 41 42 private GenericSources() {} 43 44 51 public static Sources genericOnly(Project p) { 52 return new GenericOnlySources(p); 53 } 54 55 private static final class GenericOnlySources implements Sources { 56 57 private final Project p; 58 59 GenericOnlySources(Project p) { 60 this.p = p; 61 } 62 63 public SourceGroup[] getSourceGroups(String type) { 64 if (type.equals(Sources.TYPE_GENERIC)) { 65 return new SourceGroup[] { 66 group(p, p.getProjectDirectory(), "generic", ProjectUtils.getInformation(p).getDisplayName(), 68 null, null), 69 }; 70 } else { 71 return new SourceGroup[0]; 72 } 73 } 74 75 public void addChangeListener(ChangeListener listener) {} 76 77 public void removeChangeListener(ChangeListener listener) {} 78 79 } 80 81 93 public static SourceGroup group(Project p, FileObject rootFolder, String name, String displayName, Icon icon, Icon openedIcon) { 94 if (name == null) { 95 throw new NullPointerException ("Cannot specify a null name for a source group"); } 97 return new Group(p, rootFolder, name, displayName, icon, openedIcon); 98 } 99 100 private static final class Group implements SourceGroup { 101 102 private final Project p; 103 private final FileObject rootFolder; 104 private final String name; 105 private final String displayName; 106 private final Icon icon; 107 private final Icon openedIcon; 108 109 Group(Project p, FileObject rootFolder, String name, String displayName, Icon icon, Icon openedIcon) { 110 this.p = p; 111 this.rootFolder = rootFolder; 112 this.name = name; 113 this.displayName = displayName; 114 this.icon = icon; 115 this.openedIcon = openedIcon; 116 } 117 118 public FileObject getRootFolder() { 119 return rootFolder; 120 } 121 122 public String getName() { 123 return name; 124 } 125 126 public String getDisplayName() { 127 return displayName; 128 } 129 130 public Icon getIcon(boolean opened) { 131 return opened ? icon : openedIcon; 132 } 133 134 public boolean contains(FileObject file) throws IllegalArgumentException { 135 if (file != rootFolder && !FileUtil.isParentOf(rootFolder, file)) { 136 throw new IllegalArgumentException (); 137 } 138 if (p != null) { 139 if (file.isFolder() && file != p.getProjectDirectory() && ProjectManager.getDefault().isProject(file)) { 140 return false; 142 } 143 if (FileOwnerQuery.getOwner(file) != p) { 144 return false; 145 } 146 } 147 File f = FileUtil.toFile(file); 148 if (f != null) { 149 return SharabilityQuery.getSharability(f) != SharabilityQuery.NOT_SHARABLE; 151 } else { 152 return true; 154 } 155 } 156 157 public void addPropertyChangeListener(PropertyChangeListener l) { 158 } 160 161 public void removePropertyChangeListener(PropertyChangeListener l) { 162 } 164 165 public String toString() { 166 return "GenericSources.Group[name=" + name + ",rootFolder=" + rootFolder + "]"; } 168 169 } 170 171 } 172 | Popular Tags |