本文整理汇总了Java中org.netbeans.api.project.Sources类的典型用法代码示例。如果您正苦于以下问题:Java Sources类的具体用法?Java Sources怎么用?Java Sources使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sources类属于org.netbeans.api.project包,在下文中一共展示了Sources类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initCombos
import org.netbeans.api.project.Sources; //导入依赖的package包/类
private void initCombos() {
Sources sources = ProjectUtils.getSources(project);
SourceGroup[] sourceGroupsJava = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
if (sourceGroupsJava == null) {
throw new IllegalStateException(
NbBundle.getMessage(FXMLTemplateWizardIterator.class,
"MSG_ConfigureFXMLPanel_SGs_Error")); // NOI18N
}
support = new SourceGroupSupport(JavaProjectConstants.SOURCES_TYPE_JAVA);
support.addSourceGroups(sourceGroupsJava); //must exist
comboBoxSourceRoot.setModel(new DefaultComboBoxModel(support.getSourceGroups().toArray()));
// SourceGroupSupport.SourceGroupProxy preselectedGroup = support.getParent().getCurrentSourceGroup();
// ignoreRootCombo = true;
// comboBoxSourceRoot.setSelectedItem(preselectedGroup);
// ignoreRootCombo = false;
// comboBoxPackage.getEditor().setItem(support.getParent().getCurrentPackageName());
updatePackages();
updateText();
updateResult();
}
示例2: updateRoots
import org.netbeans.api.project.Sources; //导入依赖的package包/类
private void updateRoots() {
Sources sources = ProjectUtils.getSources(project);
groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
if (groups == null || groups.length == 0) {
groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
}
int preselectedItem = 0;
for( int i = 0; i < groups.length; i++ ) {
if (fo!=null) {
try {
if (groups[i].contains(fo)) {
preselectedItem = i;
}
} catch (IllegalArgumentException e) {
// XXX this is a poor abuse of exception handling
// But can not find a better way
}
}
}
// Setup comboboxes
rootComboBox.setModel(new DefaultComboBoxModel(groups));
rootComboBox.setSelectedIndex(preselectedItem);
}
示例3: getSourceGroups
import org.netbeans.api.project.Sources; //导入依赖的package包/类
private static SourceGroup[] getSourceGroups(Project project) {
Sources projectSources = ProjectUtils.getSources(project);
// first, try to get resources
SourceGroup[] resources = projectSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
if (resources.length > 0) {
return resources;
}
// try to create it
SourceGroup resourcesSourceGroup = SourceGroupModifier.createSourceGroup(
project, JavaProjectConstants.SOURCES_TYPE_RESOURCES, JavaProjectConstants.SOURCES_HINT_MAIN);
if (resourcesSourceGroup != null) {
return new SourceGroup[] {resourcesSourceGroup};
}
// fallback to java sources
return projectSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
}
示例4: findSourceGroup
import org.netbeans.api.project.Sources; //导入依赖的package包/类
/**
* Finds a Java source group the given file belongs to.
*
* @param file {@literal FileObject} to find a {@literal SourceGroup} for
* @return the found {@literal SourceGroup}, or {@literal null} if the given
* file does not belong to any Java source group
*/
private static SourceGroup findSourceGroup(FileObject file) {
final Project project = FileOwnerQuery.getOwner(file);
if (project == null) {
return null;
}
Sources src = ProjectUtils.getSources(project);
SourceGroup[] srcGrps = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (SourceGroup srcGrp : srcGrps) {
FileObject rootFolder = srcGrp.getRootFolder();
if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file))
&& srcGrp.contains(file)) {
return srcGrp;
}
}
return null;
}
示例5: getDataFiles
import org.netbeans.api.project.Sources; //导入依赖的package包/类
public List<FileObject> getDataFiles() {
List<FileObject> files = new ArrayList<FileObject>();
Sources srcs = ProjectUtils.getSources(project);
SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (int i = 0; i < grps.length; i++) {
FileObject srcRoot = grps[i].getRootFolder();
if (srcRoot.getPath().endsWith("test/unit/src")) { // NOI18N
addFile("test", files); // NOI18N
} else {
files.add(srcRoot);
}
}
return files;
}
示例6: findSourceGroup
import org.netbeans.api.project.Sources; //导入依赖的package包/类
/**
* Finds a Java source group the given file belongs to.
*
* @param file {@code FileObject} to find a {@code SourceGroup} for
* @return the found {@code SourceGroup}, or {@code null} if the given
* file does not belong to any Java source group
*/
private static SourceGroup findSourceGroup(FileObject file) {
final Project project = FileOwnerQuery.getOwner(file);
if (project == null) {
return null;
}
Sources src = ProjectUtils.getSources(project);
SourceGroup[] srcGrps = src.getSourceGroups(SOURCES_TYPE_JAVA);
for (SourceGroup srcGrp : srcGrps) {
FileObject rootFolder = srcGrp.getRootFolder();
if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file))
&& srcGrp.contains(file)) {
return srcGrp;
}
}
return null;
}
示例7: isInScope
import org.netbeans.api.project.Sources; //导入依赖的package包/类
@Override
public boolean isInScope( FileObject resource ) {
if( null == resource || null == currentProjects )
return false;
for( Project p : currentProjects ) {
Sources sources = ProjectUtils.getSources( p );
SourceGroup[] groups = sources.getSourceGroups( Sources.TYPE_GENERIC );
for( SourceGroup group : groups ) {
FileObject rootFolder = group.getRootFolder();
if( FileUtil.isParentOf( rootFolder, resource ) || rootFolder.equals( resource ) )
return true;
}
}
return false;
}
示例8: getSourceGroup
import org.netbeans.api.project.Sources; //导入依赖的package包/类
/**
* Get the {@link SourceGroup} that contains the file.
* @param file the file to search for
* @param prj the project to get the list of {@link Sources} in which to search for the file
* @return the {@link SourceGroup} that contains the file or {@code null}
*/
public static SourceGroup getSourceGroup(FileObject file, Project prj) {
Sources src = ProjectUtils.getSources(prj);
String type = "";
Collection<? extends RootsProvider> providers = Lookup.getDefault().lookupAll(RootsProvider.class);
for (RootsProvider provider : providers) {
type = provider.getSourceRootType();
break;
}
SourceGroup[] srcGrps = src.getSourceGroups(type);
for (SourceGroup srcGrp : srcGrps) {
FileObject rootFolder = srcGrp.getRootFolder();
if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file))
&& srcGrp.contains(file)) {
return srcGrp;
}
}
return null;
}
示例9: findFile
import org.netbeans.api.project.Sources; //导入依赖的package包/类
private static @CheckForNull FileObject findFile(FileObject manifest, String path) {
Project prj = FileOwnerQuery.getOwner(manifest);
if (prj == null) {
return null;
}
Sources srcs = ProjectUtils.getSources(prj);
SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
if (grps.length == 0) // #143157: there needn't to be source group (yet)
return null;
ClassPath cp = ClassPath.getClassPath(grps[0].getRootFolder(), ClassPath.SOURCE);
if (cp == null) {
return null;
}
path = path.trim();
return cp.findResource(path);
}
示例10: actionPerformed
import org.netbeans.api.project.Sources; //导入依赖的package包/类
public void actionPerformed(ActionEvent e) {
if ( browseButton == e.getSource() ) {
FileObject fo=null;
// Show the browse dialog
if (getPanel().getSourceGroups()!=null) fo = BrowseFolders.showDialog(
getPanel().getSourceGroups(),
org.openide.loaders.DataFolder.class,
folderTextField.getText().replace( File.separatorChar, '/' ) );
else {
Sources sources = ProjectUtils.getSources(getPanel().getProject());
fo = BrowseFolders.showDialog( sources.getSourceGroups(
Sources.TYPE_GENERIC ),DataFolder.class,
folderTextField.getText().replace( File.separatorChar, '/' ) );
}
if ( fo != null && fo.isFolder() ) {
FileObject root = ((LocationItem)locationCB.getSelectedItem()).
getFileObject();
folderTextField.setText( FileUtil.getRelativePath( root, fo ) );
}
}
}
示例11: openFromClasspath
import org.netbeans.api.project.Sources; //导入依赖的package包/类
private static boolean openFromClasspath(FileObject fo, String value) {
int colonOffset = value.indexOf(":"); //NOI18N
String subPath = value.substring(colonOffset + 1);
Project project = FileOwnerQuery.getOwner(fo);
if (project != null) {
List<SourceGroup> groups = new ArrayList<>();
Sources sources = ProjectUtils.getSources(project);
groups.addAll(Arrays.asList(sources.getSourceGroups("doc_root"))); //NOI18N
groups.addAll(Arrays.asList(sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)));
for (SourceGroup sourceGroup : groups) {
FileObject fileObject = sourceGroup.getRootFolder().getFileObject(subPath);
if (fileObject != null) {
openFile(fileObject);
return true;
}
}
}
return false;
}
示例12: init
import org.netbeans.api.project.Sources; //导入依赖的package包/类
void init(Project p) {
Sources sources = ProjectUtils.getSources(p);
sources.addChangeListener(this);
SourceGroup[] groups = sources.getSourceGroups(Sources.TYPE_GENERIC);
roots = new FileObject[groups.length];
for (int i = 0; i < groups.length; i++) {
SourceGroup group = groups[i];
FileObject rootFolder = group.getRootFolder();
roots[i] = rootFolder;
rootFolder.addRecursiveListener(this);
//scan(rootFolder);
rootsToScan.add(rootFolder);
}
scanningTask = RP.post(this);
DependencyProjectProvider prov = p.getLookup().lookup(DependencyProjectProvider.class);
if (prov != null) {
projectDependencyManager = new ProjectDependencyManager(prov);
}
}
示例13: createData
import org.netbeans.api.project.Sources; //导入依赖的package包/类
private static Union2<LogicalViewProvider,org.openide.util.Pair<Sources,SourceGroup[]>> createData(
final Project p,
final int type) {
switch (type) {
case LOGICAL_VIEW:
final LogicalViewProvider lvp = p.getLookup().lookup(LogicalViewProvider.class);
if (lvp != null) {
return Union2.createFirst(lvp);
}
case PHYSICAL_VIEW:
final Sources s = ProjectUtils.getSources(p);
final SourceGroup[] groups = s.getSourceGroups(Sources.TYPE_GENERIC);
return Union2.createSecond(org.openide.util.Pair.of(s, groups));
default:
throw new IllegalArgumentException(Integer.toString(type));
}
}
示例14: setUp
import org.netbeans.api.project.Sources; //导入依赖的package包/类
public void setUp() throws Exception {
// in an attempt to find the cause of issue 90762
Logger.getLogger(PersistenceScopesHelper.class.getName()).setLevel(Level.FINEST);
// setup the project
FileObject scratch = TestUtil.makeScratchDir(this);
final FileObject projdir = scratch.createFolder("proj");
MockLookup.setLayersAndInstances();
// issue 90762: prevent AntProjectHelper from firing changes in a RP thread, which interferes with tests
// see APH.fireExternalChange
ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
public Void run() throws Exception{
J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.6"));
J2SEProjectGenerator.createProject(FileUtil.toFile(projdir), "proj", "foo.Main", "manifest.mf", null, false);
J2SEProjectGenerator.setDefaultSourceLevel(null);
return null;
}
});
project = ProjectManager.getDefault().findProject(projdir);
Sources src = project.getLookup().lookup(Sources.class);
SourceGroup[] groups = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
root = groups[0].getRootFolder();
provider = project.getLookup().lookup(J2SEPersistenceProvider.class);
persistenceLocation = new File(FileUtil.toFile(project.getProjectDirectory().getFileObject("src")), "META-INF");
}
示例15: findSourceGroup
import org.netbeans.api.project.Sources; //导入依赖的package包/类
/**
* Finds a Java source group the given file belongs to.
*
* @param file {@literal FileObject} to find a {@literal SourceGroup} for
* @return the found {@literal SourceGroup}, or {@literal null} if the given
* file does not belong to any Java source group
*/
private static SourceGroup findSourceGroup(FileObject file) {
final Project project = FileOwnerQuery.getOwner(file);
if (project == null) {
return null;
}
Sources src = ProjectUtils.getSources(project);
SourceGroup[] srcGrps = src.getSourceGroups(SOURCES_TYPE_JAVA);
for (SourceGroup srcGrp : srcGrps) {
FileObject rootFolder = srcGrp.getRootFolder();
if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file))
&& srcGrp.contains(file)) {
return srcGrp;
}
}
return null;
}