Java Code Examples for org.netbeans.api.project.ProjectManager#Result

The following examples show how to use org.netbeans.api.project.ProjectManager#Result . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhysicalView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Image swap(Image base, int type) {
    if (!root) { // do not use icon on root node in Files tab
        FileObject folder = getOriginal().getLookup().lookup(FileObject.class);
        if (folder != null && folder.isFolder()) {
            ProjectManager.Result r = ProjectManager.getDefault().isProject2(folder);
            if (r != null) {
                Icon icon = r.getIcon();
                
                if (icon != null) {
                    Image img = ImageUtilities.icon2Image(icon);
                    try {
                        //#217008
                        DataFolder df = getOriginal().getLookup().lookup(DataFolder.class);
                        img = FileUIUtils.getImageDecorator(folder.getFileSystem()).annotateIcon(img, type, df.files());
                    } catch (FileStateInvalidException e) {
                        // no fs, do nothing
                    }
                    return img;
                }
            }
        }
    }
    return base;
}
 
Example 2
Source File: ModulesNodeFactory.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
private void findModules() {
    List<Node> nodes = new ArrayList<>();
    Collection<? extends ProjectFactory2> factory2s = Lookup.getDefault().lookupAll(ProjectFactory2.class);
    Enumeration<? extends FileObject> childrens = project.getProjectDirectory().getChildren(false);
    while (childrens.hasMoreElements()) {
        FileObject fo = childrens.nextElement();
        if (fo.isFolder()) {
            for (ProjectFactory2 factory2 : factory2s) {
                ProjectManager.Result result = factory2.isProject2(fo);
                if (result != null) {
                    nodes.add(new SubProjectNode(result, fo, project));
                    break;
                }
            }
        }
    }
    setKeys(nodes);
}
 
Example 3
Source File: ProjectChooserAccessory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ProjectManager.Result getProjectResult(File dir) {
    FileObject fo = FileUtil.toFileObject(dir);
    if (fo != null && /* #60518 */ fo.isFolder()) {
        return ProjectManager.getDefault().isProject2(fo);
    } else {
        return null;
    }

}
 
Example 4
Source File: ProjectChooserAccessory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void run() {
    if (!lookingForIcon.isDirectory()) {
        synchronized (this) {
            lookingForIcon = null;
        }
        return;
    }
    File d = FileUtil.normalizeFile(lookingForIcon);
    ProjectManager.Result r = getProjectResult(d);
    Icon icon;
    if (r != null) {
        icon = r.getIcon();
        if (icon == null) {
            Project p = getProject(d);
            if (p != null) {
                icon = ProjectUtils.getInformation(p).getIcon();
            } else {
                icon = chooser.getFileSystemView().getSystemIcon(lookingForIcon);
            }
        }
    } else {
        try {
            icon = chooser.getFileSystemView().getSystemIcon(lookingForIcon);
        } catch (NullPointerException ex) {
            //#159646: Workaround for JDK issue #6357445
            // Can happen when a file was deleted on disk while project
            // dialog was still open. In that case, throws an exception
            // repeatedly from FSV.gSI during repaint.
            icon = null;
        }
    }
    synchronized (this) {
        knownProjectIcons.put(lookingForIcon, icon);
        lookingForIcon = null;
    }
    chooser.repaint();
}
 
Example 5
Source File: ProjectConvertorFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
@CheckForNull
public ProjectManager.Result isProject2(@NonNull FileObject projectDirectory) {
    Parameters.notNull("projectDirectory", projectDirectory);   //NOI18N
    final ProjectConvertor.Result res = isProjectImpl(projectDirectory);
    return res != null ?
        toProjectManagerResult(res) :
        null;
}
 
Example 6
Source File: FileTreeView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Image getFolderIcon (File file) {
    FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(file));
    Icon icon = null;
    if (fo != null) {
        try {
            ProjectManager.Result res = ProjectManager.getDefault().isProject2(fo);
            if (res != null) {
                icon = res.getIcon();
            }
        } catch (IllegalArgumentException ex) {
            Logger.getLogger(FileTreeView.class.getName()).log(Level.INFO, null, ex);
        }
    }
    return icon == null ? FileTreeView.getFolderIcon() : ImageUtilities.icon2Image(icon);
}
 
Example 7
Source File: AntBasedProjectFactorySingleton.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override Result isProject2(FileObject projectDirectory) {
    if (FileUtil.toFile(projectDirectory) == null) {
        return null;
    }
    FileObject projectFile = projectDirectory.getFileObject(PROJECT_XML_PATH);
    //#54488: Added check for virtual
    if (projectFile == null || !projectFile.isData() || projectFile.isVirtual()) {
        return null;
    }
    File projectDiskFile = FileUtil.toFile(projectFile);
    //#63834: if projectFile exists and projectDiskFile does not, do nothing:
    if (projectDiskFile == null) {
        return null;
    }
    try {
        Document projectXml = loadProjectXml(projectDiskFile);
        if (projectXml != null) {
            Element typeEl = XMLUtil.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N
            if (typeEl != null) {
                String type = XMLUtil.findText(typeEl);
                if (type != null) {
                    AntBasedProjectType provider = findAntBasedProjectType(type);
                    if (provider != null) {
                        if (provider instanceof AntBasedGenericType) {
                            return new ProjectManager.Result(((AntBasedGenericType)provider).getIcon());
                        } else {
                            //put special icon?
                            return new ProjectManager.Result(null);
                        }
                    }
                }
            }
        }
    } catch (IOException ex) {
        LOG.log(Level.FINE, "Failed to load the project.xml file.", ex);
    }
    // better have false positives than false negatives (according to the ProjectManager.isProject/isProject2 javadoc.
    return new ProjectManager.Result(null);
}
 
Example 8
Source File: ModulesNodeFactory.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public SubProjectNode(ProjectManager.Result result, FileObject fo, Project project) {
    super(Children.LEAF, Lookups.fixed(fo));
    this.result = result;
    this.fo = fo;
    this.project = project;
    if (result.getDisplayName() != null) {
        setDisplayName(result.getDisplayName());
    } else {
        setDisplayName(fo.getName());
    }
}
 
Example 9
Source File: NbAndroidProjectFactory.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
public ProjectManager.Result isProject2(FileObject fo) {
    if (isProject(fo)) {
        return new ProjectManager.Result(new ImageIcon(IMG_PROJECT_ICON));
    } else if (isRootProject(fo)) {
        return new ProjectManager.Result(new ImageIcon(IMG_PROJECT_ROOT_ICON));
    }
    return null;
}
 
Example 10
Source File: NbMavenProjectFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override ProjectManager.Result isProject2(FileObject projectDirectory) {
    if (isProject(projectDirectory)) {
        return new ProjectManager.Result(ImageUtilities.loadImageIcon("org/netbeans/modules/maven/resources/Maven2Icon.gif", true)); //NOI18N
    }
    return null;
}
 
Example 11
Source File: NbGradleProjectFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public ProjectManager.Result isProject2(FileObject dir) {
    return isProject(dir) ? new ProjectManager.Result(NbGradleProject.getIcon()) : null;
}
 
Example 12
Source File: LibrariesTestUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public ProjectManager.Result isProject(FileObject projectDirectory) throws IllegalArgumentException {
    return null;
}
 
Example 13
Source File: ProjectConvertorFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NonNull
private ProjectManager.Result toProjectManagerResult(@NonNull final ProjectConvertor.Result res) {
    return new ProjectManager.Result(res.getDisplayName(), null, res.getIcon());
}
 
Example 14
Source File: ProjectManagerImplementation.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Check whether a given directory is likely to contain a project without
 * actually loading it. The returned {@link org.netbeans.api.project.ProjectManager.Result} object contains additional
 * information about the found project.
 * Should be faster and use less memory than {@link #findProject} when called
 * on a large number of directories.
 * <p>The result is not guaranteed to be accurate; there may be false positives
 * (directories for which <code>isProject</code> is non-null but {@link #findProject}
 * will return null), for example if there is trouble loading the project.
 * False negatives are possible only if there are bugs in the project factory.</p>
 * <p>Acquires read access.</p>
 * <p class="nonnormative">
 * You do <em>not</em> need to call this method if you just plan to call {@link #findProject}
 * afterwards. It is intended for only those clients which would discard the
 * result of {@link #findProject} other than to check for null, and which
 * can also tolerate false positives.
 * </p>
 * @param projectDirectory a directory which may be some project's top directory
 * @return Result object if the directory is likely to contain a project according to
 *              some registered {@link ProjectFactory}, or null if not a project folder.
 * @throws IllegalArgumentException if the supplied file object is null or not a folder
 */
@CheckForNull
ProjectManager.Result isProject(@NonNull FileObject projectDirectory) throws IllegalArgumentException;
 
Example 15
Source File: ProjectFactory2.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Test whether a given directory probably refers to a project recognized by this factory
 * without actually trying to create it.
 * <p>Should be as fast as possible as it might be called sequentially on a
 * lot of directories.</p>
 * <p>Need not be definite; it is permitted to return null or throw an exception
 * from {@link #loadProject} even when returning <code>Result</code> instance from this
 * method, in case the directory looked like a project directory but in fact
 * had something wrong with it.</p>
 * <p>Will be called inside read access.</p>
 * @param projectDirectory a directory which might refer to a project
 * @return Result instance if this factory recognizes it, or null if the directory is not recognized
 */
ProjectManager.Result isProject2(FileObject projectDirectory);