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

The following are Jave code examples for showing how to use isVirtual() 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: ExtractInterfaceRefactoringPlugin.java   View Source Code Vote up 6 votes
@Override
public Problem fastCheckParameters() {
    Problem result = null;
    
    String newName = refactoring.getInterfaceName();
    
    if (!Utilities.isJavaIdentifier(newName)) {
        result = createProblem(result, true, NbBundle.getMessage(ExtractInterfaceRefactoringPlugin.class, "ERR_InvalidIdentifier", newName)); // NOI18N
        return result;
    }
    
    FileObject primFile = refactoring.getSourceType().getFileObject();
    FileObject folder = primFile.getParent();
    FileObject[] children = folder.getChildren();
    for (FileObject child: children) {
        if (!child.isVirtual() && child.getName().equalsIgnoreCase(newName) && "java".equalsIgnoreCase(child.getExt())) { // NOI18N
            result = createProblem(result, true, NbBundle.getMessage(ExtractInterfaceRefactoringPlugin.class, "ERR_ClassClash", newName, pkgName)); // NOI18N
            return result;
        }
    }

    return super.fastCheckParameters();
}
 
Example 2
Project: incubator-netbeans   File: ExtractSuperclassRefactoringPlugin.java   View Source Code Vote up 6 votes
@Override
public Problem fastCheckParameters() {
    Problem result = null;
    
    String newName = refactoring.getSuperClassName();
    
    if (!Utilities.isJavaIdentifier(newName)) {
        result = createProblem(result, true, NbBundle.getMessage(ExtractSuperclassRefactoringPlugin.class, "ERR_InvalidIdentifier", newName)); // NOI18N
        return result;
    }
    
    FileObject primFile = refactoring.getSourceType().getFileObject();
    FileObject folder = primFile.getParent();
    FileObject[] children = folder.getChildren();
    for (FileObject child: children) {
        if (!child.isVirtual() && child.getName().equals(newName) && "java".equals(child.getExt())) { // NOI18N
            result = createProblem(result, true, NbBundle.getMessage(ExtractSuperclassRefactoringPlugin.class, "ERR_ClassClash", newName, pkgName)); // NOI18N
            return result;
        }
    }

    return super.fastCheckParameters();
}
 
Example 3
Project: incubator-netbeans   File: NewProjectIterator.java   View Source Code Vote up 6 votes
private static void collectFiles(FileObject parent, Collection<FileObject> accepted, SharabilityQuery.Sharability parentSharab) {
    for (FileObject fo : parent.getChildren()) {
        if (!VisibilityQuery.getDefault().isVisible(fo)) {
            // #66765: ignore invisible files/folders, like CVS subdirectory
            continue;
        }
        SharabilityQuery.Sharability sharab;
        if (parentSharab == SharabilityQuery.Sharability.UNKNOWN || parentSharab == SharabilityQuery.Sharability.MIXED) {
            sharab = SharabilityQuery.getSharability(fo);
        } else {
            sharab = parentSharab;
        }
        if (sharab == SharabilityQuery.Sharability.NOT_SHARABLE) {
            continue;
        }
        if (fo.isData() && !fo.isVirtual()) {
            accepted.add(fo);
        } else if (fo.isFolder()) {
            accepted.add(fo);
            collectFiles(fo, accepted, sharab);
        }
    }
}
 
Example 4
Project: incubator-netbeans   File: MimeTypesTracker.java   View Source Code Vote up 6 votes
private static Object [] findTarget(String [] path) {
    FileObject target = FileUtil.getConfigRoot();
    boolean isTarget = 0 == path.length;
    
    for (int i = 0; i < path.length; i++) {
        FileObject f = target.getFileObject(path[i]);

        if (f == null || !f.isFolder() || !f.isValid() || f.isVirtual()) {
            break;
        } else {
            target = f;
            isTarget = i + 1 == path.length;
        }
    }
    
    return new Object [] { target, Boolean.valueOf(isTarget) };
}
 
Example 5
Project: incubator-netbeans   File: AntBasedProjectFactorySingleton.java   View Source Code Vote up 5 votes
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 6
Project: incubator-netbeans   File: SourcesCurrentModel.java   View Source Code Vote up 5 votes
private static void addSourceRoots(ClassPath ecp,
                                   List<FileObject> allSourceRoots,
                                   Set<FileObject> preferredRoots) {
    FileObject[] sourceRoots = ecp.getRoots();
    for (FileObject fr : sourceRoots) {
        if (!preferredRoots.contains(fr) && !fr.isVirtual()) {
            allSourceRoots.add(fr);
            preferredRoots.add(fr);
        }
    }
}
 
Example 7
Project: incubator-netbeans   File: PropertyPanel.java   View Source Code Vote up 5 votes
private void resourceTextKeyReleased(java.awt.event.KeyEvent evt) {
    if (!innerResourceTextContent.equals(resourceText.getText())
            && resourceText.getText().trim().length() != 0) {
        String bundlePath = resourceText.getText()
                                .replaceAll("[.]", "/")  //NOI18N
                                .concat(".properties");  //NOI18N
        FileObject resourceFO = Util.getResource(file, bundlePath);

        if ((resourceFO != null) && resourceFO.isValid() && !resourceFO.isVirtual()) {
            try {
                setResource(DataObject.find(resourceFO));
                warningLabel.setText("");  //NOI18N
            } catch (DataObjectNotFoundException ex) {
                Exceptions.printStackTrace(ex);
            }
        } else {
            warningLabel.setText(
                   I18nUtil.getBundle().getString("LBL_InvalidBundle")  //NOI18N
                   + bundlePath);  //NOI18N
            setEmptyResource();
        }
    } else {
        warningLabel.setText("");  //NOI18N
        if ("".equals(resourceText.getText())) {
            setEmptyResource();
        }
    }
}
 
Example 8
Project: incubator-netbeans   File: SourceUtils.java   View Source Code Vote up 4 votes
/**
 * Returns classes declared in the given source file which have the main method.
 * @param fo source file
 * @return the classes containing main method
 * @throws IllegalArgumentException when file does not exist or is not a java source file.
 */
public static Collection<ElementHandle<TypeElement>> getMainClasses (final @NonNull FileObject fo) {
    Parameters.notNull("fo", fo);   //NOI18N
    if (!fo.isValid()) {
        throw new IllegalArgumentException ("FileObject : " + FileUtil.getFileDisplayName(fo) + " is not valid.");  //NOI18N
    }
    if (fo.isVirtual()) {
        throw new IllegalArgumentException ("FileObject : " + FileUtil.getFileDisplayName(fo) + " is virtual.");  //NOI18N
    }
    final JavaSource js = JavaSource.forFileObject(fo);        
    if (js == null) {
        throw new IllegalArgumentException ();
    }
    try {
        final LinkedHashSet<ElementHandle<TypeElement>> result = new LinkedHashSet<> ();
        js.runUserActionTask(new Task<CompilationController>() {            
            @Override
            public void run(final CompilationController control) throws Exception {
                if (control.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED).compareTo (JavaSource.Phase.ELEMENTS_RESOLVED)>=0) {
                    final List<TypeElement>  types = new ArrayList<>();
                    final ElementScanner6<Void,Void> visitor = new ElementScanner6<Void, Void>() {
                        @Override
                        public Void visitType(TypeElement e, Void p) {
                            if (e.getEnclosingElement().getKind() == ElementKind.PACKAGE
                               || e.getModifiers().contains(Modifier.STATIC)) {
                                types.add(e);
                                return super.visitType(e, p);
                            } else {
                                return null;
                            }
                        }
                    };
                    visitor.scan(control.getTopLevelElements(), null);
                    for (TypeElement type : types) {
                        for (ExecutableElement exec :  ElementFilter.methodsIn(control.getElements().getAllMembers(type))) {
                            if (SourceUtils.isMainMethod(exec)) {
                                result.add (ElementHandle.create(type));
                            }
                        }
                    }
                }
            }                

        }, true);
        return result;
    } catch (IOException ioe) {
        Exceptions.printStackTrace(ioe);
        return Collections.<ElementHandle<TypeElement>>emptySet();
    }		
}
 
Example 9
Project: incubator-netbeans   File: PaletteSwitch.java   View Source Code Vote up 4 votes
PaletteController getPaletteFromTopComponent( TopComponent tc, boolean mustBeShowing, boolean isOpened ) {
        if( null == tc || (!tc.isShowing() && mustBeShowing) )
            return null;
        
        PaletteController pc = (PaletteController)tc.getLookup().lookup( PaletteController.class );
        //#231997 - TopComponent.getSubComponents() can be called from EDT only
        //The only drawback of commenting out the code below is that a split view of
        //a form designer showing source and design hides the palette window
        //when the source split is the active one and some other TopComponent is activated
//	if (pc == null && isOpened) {
//	    TopComponent.SubComponent[] subComponents = tc.getSubComponents();
//	    for (int i = 0; i < subComponents.length; i++) {
//		TopComponent.SubComponent subComponent = subComponents[i];
//		Lookup subComponentLookup = subComponent.getLookup();
//		if (subComponentLookup != null) {
//		    pc = (PaletteController) subComponentLookup.lookup(PaletteController.class);
//		    if (pc != null && (subComponent.isActive() || subComponent.isShowing())) {
//			break;
//		    }
//		}
//	    }
//	}
        if( null == pc && isOpened ) {
            //check if there's any palette assigned to TopComponent's mime type
            Node[] activeNodes = tc.getActivatedNodes();
            if( null != activeNodes && activeNodes.length > 0 ) {
                DataObject dob = activeNodes[0].getLookup().lookup( DataObject.class );
                if( null != dob ) {
                    while( dob instanceof DataShadow ) {
                        dob = ((DataShadow)dob).getOriginal();
                    }
                    FileObject fo = dob.getPrimaryFile();
                    if( !fo.isVirtual() ) {
                        String mimeType = fo.getMIMEType();
                        pc = getPaletteFromMimeType( mimeType );
                    }
                }
            }
        }
        return pc;
    }
 
Example 10
Project: incubator-netbeans   File: AntBasedProjectFactorySingleton.java   View Source Code Vote up 4 votes
public @Override Project loadProject(FileObject projectDirectory, ProjectState state) throws IOException {
    if (FileUtil.toFile(projectDirectory) == null) {
        LOG.log(Level.FINER, "no disk dir {0}", projectDirectory);
        return null;
    }
    FileObject projectFile = projectDirectory.getFileObject(PROJECT_XML_PATH);
    if (projectFile == null) {
        LOG.log(Level.FINER, "no {0}/nbproject/project.xml", projectDirectory);
        return null;
    }
    //#54488: Added check for virtual
    if (!projectFile.isData() || projectFile.isVirtual()) {
        LOG.log(Level.FINE, "not concrete data file {0}/nbproject/project.xml", projectDirectory);
        return null;
    }
    File projectDiskFile = FileUtil.toFile(projectFile);
    //#63834: if projectFile exists and projectDiskFile does not, do nothing:
    if (projectDiskFile == null) {
        LOG.log(Level.FINE, "{0} not mappable to file", projectFile);
        return null;
    }
    Document projectXml = loadProjectXml(projectDiskFile);
    if (projectXml == null) {
        LOG.log(Level.FINE, "could not load {0}", projectDiskFile);
        return null;
    }
    Element typeEl = XMLUtil.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N
    if (typeEl == null) {
        LOG.log(Level.FINE, "no <type> in {0}", projectDiskFile);
        return null;
    }
    String type = XMLUtil.findText(typeEl);
    if (type == null) {
        LOG.log(Level.FINE, "no <type> text in {0}", projectDiskFile);
        return null;
    }
    AntBasedProjectType provider = findAntBasedProjectType(type);
    if (provider == null) {
        LOG.log(Level.FINE, "no provider for {0}", type);
        return null;
    }
    AntProjectHelper helper = HELPER_CALLBACK.createHelper(projectDirectory, projectXml, state, provider);
    Project project = provider.createProject(helper);
    synchronized (helper2Project) {
        project2Helper.put(project, new WeakReference<AntProjectHelper>(helper));
        helper2Project.put(helper, new WeakReference<Project>(project));
    }
    synchronized (AntBasedProjectFactorySingleton.class) {
        List<Reference<AntProjectHelper>> l = type2Projects.get(provider);
        if (l == null) {
            type2Projects.put(provider, l = new ArrayList<Reference<AntProjectHelper>>());
        }
        l.add(new WeakReference<AntProjectHelper>(helper));
    }
    return project;
}
 
Example 11
Project: incubator-netbeans   File: Util.java   View Source Code Vote up 4 votes
/** Shared enableness logic. Either DataObject.Container or EditorCookie must be present on all nodes.*/
    static boolean wizardEnabled(Node[] activatedNodes) {
        if (activatedNodes == null || activatedNodes.length == 0) {
            return false;
        }

        for (Node node : activatedNodes) {
            
            /*
             * This block of code fixes IssueZilla bug #63461:
             *
             *     Apisupport modules visualizes the contents of layer.xml
             *     in project view. The popup for folders in the layer.xml
             *     contains Tools->Internationalize->* actions.
             *
             *     Generally should hide on nonlocal files, I suppose.
             *
             * Local files are recognized by protocol of the corresponding URL -
             * local files are those that have protocol "file".
             */
            DataObject dobj = node.getCookie(DataObject.class);
            if (dobj != null) {
                FileObject primaryFile = dobj.getPrimaryFile();
                
                boolean isLocal;
                try {
                    isLocal = !primaryFile.isVirtual()
                              && primaryFile.isValid()
                              && primaryFile.getURL().getProtocol()
                                      .equals("file");                  //NOI18N
                } catch (FileStateInvalidException ex) {
                    isLocal = false;
                }
                
                if (isLocal == false) {
                    return false;
                }
            }
            
            Object container = node.getCookie(DataObject.Container.class);
            if (container != null) {
                continue;
            }
//            if (node.getCookie(EditorCookie.class) == null) {
//                return false;
//            }

	    if (dobj == null) {
                return false;
            }
	    
            Future<Project[]> openProjects = OpenProjects.getDefault().openProjects();
            if(!openProjects.isDone()) {
                return false;
            }
            
	    // check that the node has project
	    if (FileOwnerQuery.getOwner(dobj.getPrimaryFile()) == null) {
                return false;
            }
        }
        return true;
    }