Java Code Examples for org.openide.filesystems.FileObject.isFolder()

The following are Jave code examples for showing how to use isFolder() of the org.openide.filesystems.FileObject class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: GoToOppositeAction.java   View Source Code Vote up 6 votes
/**
         */
        @NbBundle.Messages({"# {0} - class",
        "MSG_test_class_not_found=Test class for class {0} was not found.",
        "# {0} - package",
        "MSG_testsuite_class_not_found=Test class for package {0} was not found.",
        "MSG_testsuite_class_not_found_def_pkg=Test class for the default package was not found."})
        private void displayNoOppositeLocationFound() {
            String sourceClsName;
            FileObject fileObj = currLocation.getFileObject();
            sourceClsName = srcClassPath.getResourceName(fileObj, '.', false);
//            String msgKey = !fileObj.isFolder()
//                            ? "MSG_test_class_not_found"                //NOI18N
//                            : (sourceClsName.length() != 0)
//                              ? "MSG_testsuite_class_not_found"         //NOI18N
//                              : "MSG_testsuite_class_not_found_def_pkg";//NOI18N
//            callback.foundLocation(currLocation.getFileObject(),
//                    new LocationResult(NbBundle.getMessage(getClass(), msgKey, sourceClsName)));
            String error = !fileObj.isFolder()
                            ? Bundle.MSG_test_class_not_found(sourceClsName)
                            : (sourceClsName.length() != 0)
                              ? Bundle.MSG_testsuite_class_not_found(sourceClsName)
                              : Bundle.MSG_testsuite_class_not_found_def_pkg();
            callback.foundLocation(currLocation.getFileObject(),
                    new LocationResult(error));
        }
 
Example 2
Project: incubator-netbeans   File: TemplatesPanel.java   View Source Code Vote up 6 votes
private boolean acceptTemplate (FileObject fo) {
    if (fo.isFolder() &&
        (TEMPLATES_FOLDER+"/Properties").equals(fo.getPath())) {
        
        return false;
    }
    boolean attachListener;
    synchronized (filesWeListenOn) {
        attachListener = filesWeListenOn.add(fo);
    }
    if (attachListener) {
        FileChangeListener fileChangeListener = FileUtil.weakFileChangeListener(this, fo);
        fo.addFileChangeListener(fileChangeListener);
    }
    if (isTemplate (fo) || fo.isFolder()) {
        Object o = fo.getAttribute ("simple"); // NOI18N
        return o == null || Boolean.TRUE.equals (o);
    } else {
        return false;
    }
}
 
Example 3
Project: incubator-netbeans   File: SettingsType.java   View Source Code Vote up 6 votes
private void addUsersFiles(FileObject mimeFolder, String profileId, boolean fullScan, Map<String, List<Object []>> files) {
    if (profileId == null) {
        FileObject settingHome = mimeFolder.getFileObject(settingTypeId);
        if (settingHome != null && settingHome.isFolder()) {
            if (isUsingProfiles) {
                FileObject [] profileHomes = settingHome.getChildren();
                for(FileObject f : profileHomes) {
                    if (f.isFolder()) {
                        String id = f.getNameExt();
                        addFiles(f, fullScan, files, id, f, false, false);
                    }
                }
            } else {
                addFiles(settingHome, fullScan, files, null, null, false, false);
            }
        }
    } else {
        FileObject folder = mimeFolder.getFileObject(settingTypeId + "/" + profileId); //NOI18N
        if (folder != null && folder.isFolder()) {
            addFiles(folder, fullScan, files, profileId, folder, false, false);
        }
    }
}
 
Example 4
Project: incubator-netbeans   File: SaasServicesModel.java   View Source Code Vote up 6 votes
private void loadFromWebServicesHome() {
    for (FileObject fo : getWebServiceHome().getChildren()) {
        if (!fo.isFolder()) {
            continue;
        }
        for (FileObject file : fo.getChildren()) {
            if (!file.getNameExt().endsWith("-saas.xml")) { //NOI18N

                continue;
            }
            try {
                loadSaasServiceFile(file, true);
            } catch (Exception ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: JavadocAndSourceRootDetection.java   View Source Code Vote up 6 votes
/**
 * Finds all javadoc roots under the given base folder.
 * @param baseFolder the base folder to start search in; routine will traverse 5 folders
 * @param canceled the canceling support
 * @return the found javadoc roots
 * @since 1.56
 */
@NonNull
public static Set<? extends FileObject> findJavadocRoots(
        @NonNull final FileObject baseFolder,
        @NullAllowed final AtomicBoolean canceled) {
    Parameters.notNull("folder", baseFolder);   //NOI18N
    if (!baseFolder.isFolder()) {
        throw new IllegalArgumentException ("baseFolder must be folder: " + baseFolder);    //NOI18N
    }
    final Set<FileObject> result = new TreeSet<>((f1,f2) -> {
        final String f1p = FileUtil.getRelativePath(baseFolder, f1);
        final String f2p = FileUtil.getRelativePath(baseFolder, f2);
        return f1p.compareTo(f2p);
    });
    findAllJavadocRoots(
        baseFolder,
        result,
        canceled,
        false,
        0);
    return Collections.unmodifiableSet(result);
}
 
Example 6
Project: incubator-netbeans   File: TaskProvider.java   View Source Code Vote up 6 votes
private synchronized void refreshImpl(FileObject file) {
    LOG.log(Level.FINE, "refresh: {0}", file);
    
    if (scope == null || callback == null)
        return ; //nothing to refresh
    if (!scope.isInScope(file)) {
        if (!file.isFolder())
            return;
        
        //the given file may be a parent of some file that is in the scope:
        for (FileObject inScope : scope.getLookup().lookupAll(FileObject.class)) {
            if (FileUtil.isParentOf(file, inScope)) {
                enqueue(new Work(inScope, callback));
            }
        }
        
        return ;
    }
    
    LOG.log(Level.FINE, "enqueing work for: {0}", file);
    enqueue(new Work(file, callback));
}
 
Example 7
Project: incubator-netbeans   File: ModuleActions.java   View Source Code Vote up 6 votes
@CheckForNull private FileObject[] findTestSourcesFOs(@NonNull Lookup context, boolean allowFolders, boolean strict) {
    TYPE: for (String testType : project.supportedTestTypes()) {
        FileObject testSrcDir = project.getTestSourceDirectory(testType);
        if (testSrcDir != null) {
            FileObject[] files = ActionUtils.findSelectedFiles(context, testSrcDir, null, strict);
            if (files != null) {
                for (FileObject file : files) {
                    if (!(file.hasExt("java") || allowFolders && file.isFolder())) {
                        break TYPE;
                    }
                }
                return files;
            }
        }
    }
    return null;
}
 
Example 8
Project: incubator-netbeans   File: RelationshipMappingRefactoringFactory.java   View Source Code Vote up 6 votes
@Override
public RefactoringPlugin createInstance(AbstractRefactoring refactoring) {

    FileObject targetFile = refactoring.getRefactoringSource().lookup(FileObject.class);
    NonRecursiveFolder pkg = refactoring.getRefactoringSource().lookup(NonRecursiveFolder.class);
    TreePathHandle handle = refactoring.getRefactoringSource().lookup(TreePathHandle.class);

    boolean folder = targetFile != null && targetFile.isFolder();
    boolean javaPackage = pkg != null && RefactoringUtil.isOnSourceClasspath(pkg.getFolder());
    boolean javaFile = targetFile != null && RefactoringUtil.isJavaFile(targetFile);
    boolean javaMember = handle != null;

    if (refactoring instanceof RenameRefactoring) {
        RenameRefactoring rename = (RenameRefactoring) refactoring;
        if (!javaFile && !(javaPackage || folder) && javaMember) {
            return new RelationshipMappingRename(rename);
        }
    } else if (refactoring instanceof WhereUsedQuery) {
        WhereUsedQuery whereUsedQuery = (WhereUsedQuery) refactoring;
        return new RelationshipMappingWhereUsed(whereUsedQuery);
    }
    return null;
}
 
Example 9
Project: incubator-netbeans   File: CopyResourcesOnSave.java   View Source Code Vote up 6 votes
private static void copySrcToDest( FileObject srcFile, FileObject destFile) throws IOException {
    if (destFile != null && !srcFile.isFolder()) {
        InputStream is = null;
        OutputStream os = null;
        FileLock fl = null;
        try {
            is = srcFile.getInputStream();
            fl = destFile.lock();
            os = destFile.getOutputStream(fl);
            FileUtil.copy(is, os);
        } finally {
            if (is != null) {
                is.close();
            }
            if (os != null) {
                os.close();
            }
            if (fl != null) {
                fl.releaseLock();
            }
        }
    }
}
 
Example 10
Project: incubator-netbeans   File: ExternalReferenceDataNode.java   View Source Code Vote up 6 votes
protected Node[] createNodes(Node n) {
    DataObject dobj = (DataObject) n.getLookup().lookup(DataObject.class);
    if (dobj != null) {
        FileObject fobj = dobj.getPrimaryFile();
        if (fobj.isFolder() && fobj.getNameExt().equals("nbproject") &&
                fobj.getFileObject("project.xml") != null) {
            // It is the NetBeans project folder, ignore it.
            return new Node[0];
        }
        String fname = fobj.getNameExt();
        String ext = decorator.getDocumentType();
        if (fobj.isFolder() || fname.endsWith(ext)) {
            return super.createNodes(n);
        }
    }
    return new Node[0];
}
 
Example 11
Project: NBANDROID-V2   File: GradleAndroidSources.java   View Source Code Vote up 5 votes
@Override
public boolean contains(FileObject file) {
    if (file != rootFolder && !FileUtil.isParentOf(rootFolder, file)) {
        return false;
    }
    if (file.isFolder() && file != p.getProjectDirectory() && ProjectManager.getDefault().isProject(file)) {
        // #67450: avoid actually loading the nested project.
        return false;
    }
    if (FileOwnerQuery.getOwner(file) != p) {
        return false;
    }
    // MIXED, UNKNOWN, and SHARABLE -> include it
    return true; // SharabilityQuery.getSharability(file) != SharabilityQuery.Sharability.NOT_SHARABLE;
}
 
Example 12
Project: incubator-netbeans   File: PhysicalView.java   View Source Code Vote up 5 votes
public @Override String getShortDescription() {
    FileObject folder = getOriginal().getLookup().lookup(FileObject.class);
    if (folder != null && folder.isFolder()) {
        try {
            Project p = ProjectManager.getDefault().findProject(folder);
            if (p != null) {
                return ProjectUtils.getInformation(p).getDisplayName();
            }
        } catch (IOException x) {
            LOG.log(Level.FINE, null, x);
        }
    }
    return super.getShortDescription();
}
 
Example 13
Project: incubator-netbeans   File: PersistenceXmlPackageRename.java   View Source Code Vote up 5 votes
/**
 * Collects the names of the classes from the given folder, recursively if possible (i.e. the given
 * folder is not a NonRecursiveFolder).
 *
 * @return a list of fully qualified names of the classes in the given folder and its subfolders.
 */
private List<String> getClasses(FileObject folder, List<String> result){
    for (FileObject each : folder.getChildren()){
        if (each.isFolder()){
            getClasses(each, result);
        } else {
            result.add(JavaIdentifiers.getQualifiedName(each));
        }
    }
    return result;
}
 
Example 14
Project: incubator-netbeans   File: LanguageRegistry.java   View Source Code Vote up 5 votes
private static boolean isValidSubtype(FileObject subtypeFile) {
    if (!subtypeFile.isFolder()) {
        return false;
    }

    String typeName = subtypeFile.getNameExt();
    return MimePath.validate(null, typeName) && !typeName.equals("base"); //NOI18N
}
 
Example 15
Project: incubator-netbeans   File: FileBasedFileSystem.java   View Source Code Vote up 5 votes
@Override
public FileObject getTempFolder() throws IOException {
    FileObject tmpDir =  FileUtil.toFileObject(new File(System.getProperty("java.io.tmpdir")));
    if (tmpDir != null && tmpDir.isFolder() && tmpDir.isValid()) {
        return tmpDir;
    }
    throw new IOException("Cannot find temporary folder"); // NOI18N
}
 
Example 16
Project: incubator-netbeans   File: FolderNodeFactory.java   View Source Code Vote up 5 votes
public boolean acceptFileObject(FileObject fo) {
    String path = FileUtil.getRelativePath(root, fo);
    if (path == null) {
        return false;
    }
    if (fo.isFolder()) {
        path += "/"; // NOI18N
    }
    if (!matcher.matches(path, true)) {
        return false;
    }
    return VisibilityQuery.getDefault().isVisible( fo );
}
 
Example 17
Project: incubator-netbeans   File: BuildArtifactMapperImpl.java   View Source Code Vote up 5 votes
private static void copyRecursively(FileObject source, File target, Set<String> javaMimeTypes, String[] javaMimeTypesArr) throws IOException {
    if (!VisibilityQuery.getDefault().isVisible(source)) return ;
    
    if (source.isFolder()) {
        if (!target.exists()) {
            if (!target.mkdirs()) {
                throw new IOException("Cannot create folder: " + target.getAbsolutePath());
            }
        } else {
            if (!target.isDirectory()) {
                throw new IOException("Cannot create folder: " + target.getAbsolutePath() + ", already exists as a file.");
            }
        }

        FileObject[] listed = source.getChildren();

        if (listed == null) {
            return ;
        }

        for (FileObject f : listed) {
            if (f.isData() && javaMimeTypes.contains(FileUtil.getMIMEType(f, javaMimeTypesArr)))
                continue;

            copyRecursively(f, new File(target, f.getNameExt()), javaMimeTypes, javaMimeTypesArr);
        }
    } else {
        if (target.isDirectory()) {
            throw new IOException("Cannot create file: " + target.getAbsolutePath() + ", already exists as a folder.");
        }

        copyFile(source, target);
    }
}
 
Example 18
Project: incubator-netbeans   File: TestSupport.java   View Source Code Vote up 4 votes
public boolean isProject(FileObject dir) {
    FileObject testproject = dir.getFileObject("testproject");
    return testproject != null && testproject.isFolder();
}
 
Example 19
Project: incubator-netbeans   File: DefaultOpenFileImpl.java   View Source Code Vote up 4 votes
private void openInEDT(FileObject fileObject, DataObject dataObject, int line) {
    Class<? extends Node.Cookie> cookieClass;        
    Node.Cookie cookie;
    
    if ((line != -1)
        && (   ((cookie = dataObject.getCookie(cookieClass = EditorCookie.Observable.class)) != null)
            || ((cookie = dataObject.getCookie(cookieClass = EditorCookie.class)) != null) )) {
        boolean ret = openByCookie(cookie, cookieClass, line);
        if (!ret) {
            showNotPlainFileWarning(fileObject);
        }
        return;
    } 
                        
    /* try to open the object using the default action */
    Node dataNode = dataObject.getNodeDelegate();        
    Action action = dataNode.getPreferredAction();
    if ((action != null)
            && !(action instanceof FileSystemAction)
            && !(action instanceof ToolsAction)) {
        if (log.isLoggable(FINEST)) {
            log.log(FINEST, " - using preferred action "            //NOI18N
                    + "(\"{0}\" - {1}) for opening the file",       //NOI18N
                    new Object[]{action.getValue(Action.NAME),
                        action.getClass().getName()});
        }

        if (action instanceof ContextAwareAction) {
            action = ((ContextAwareAction) action)
              .createContextAwareInstance(dataNode.getLookup());
            if (log.isLoggable(FINEST)) {
                log.finest("    - it is a ContextAwareAction");     //NOI18N
                log.log(FINEST, "    - using a context-aware "      //NOI18N
                        + "instance instead (\"{0}\" - {1})",       //NOI18N
                        new Object[]{action.getValue(Action.NAME),
                            action.getClass().getName()});
            }
        }

        log.finest("   - will call action.actionPerformed(...)");   //NOI18N
        final Action a = action;
        final Node n = dataNode;
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {

            @Override
            public void run() {
                a.actionPerformed(new ActionEvent(n, 0, ""));
            }
        });
        return;
    }             
    String fileName = fileObject.getNameExt();
    /* Try to grab an editor/open/edit/view cookie and open the object: */
    StatusDisplayer.getDefault().setStatusText(
            NbBundle.getMessage(DefaultOpenFileImpl.class,
                                "MSG_opening",                      //NOI18N
                                fileName));
    boolean success = openDataObjectByCookie(dataObject, line);
    if (success) {
        return;
    }        
    if (fileObject.isFolder() || FileUtil.isArchiveFile(fileObject)) {
        // select it in explorer:
        final Node node = dataObject.getNodeDelegate();
        if (node != null) {
            WindowManager.getDefault().invokeWhenUIReady(new Runnable() {

                @Override
                public void run() {
                    NodeOperation.getDefault().explore(node);
                }
            });
            return;
        }
    }
    showNotPlainFileWarning(fileObject);
}
 
Example 20
Project: incubator-netbeans   File: ProjectManager.java   View Source Code Vote up 3 votes
/**
 * Find an open project corresponding to a given project directory.
 * Will be created in memory if necessary.
 * <p>
 * Acquires read access.
 * </p>
 * <p>
 * It is <em>not</em> guaranteed that the returned instance will be identical
 * to that which is created by the appropriate {@link ProjectFactory}. In
 * particular, the project manager is free to return only wrapper <code>Project</code>
 * instances which delegate to the factory's implementation. If you know your
 * factory created a particular project, you cannot safely cast the return value
 * of this method to your project type implementation class; you should instead
 * place an implementation of some suitable private interface into your project's
 * lookup, which would be safely proxied.
 * </p>
 * @param projectDirectory the project top directory
 * @return the project (object identity may or may not vary between calls)
 *         or null if the directory is not recognized as a project by any
 *         registered {@link ProjectFactory}
 *         (might be null even if {@link #isProject} returns true)
 * @throws IOException if the project was recognized but could not be loaded
 * @throws IllegalArgumentException if the supplied file object is null or not a folder
 */
@CheckForNull
public Project findProject(@NonNull final FileObject projectDirectory) throws IOException, IllegalArgumentException {
    if (projectDirectory == null) {
        throw new IllegalArgumentException("Attempted to pass a null directory to findProject"); // NOI18N
    }
    if (!projectDirectory.isFolder()) {
        throw new IllegalArgumentException("Attempted to pass a non-directory to findProject: " + projectDirectory); // NOI18N
    }
    return impl.findProject(projectDirectory);
}