Java Code Examples for org.openide.filesystems.FileObject#isVirtual()
The following examples show how to use
org.openide.filesystems.FileObject#isVirtual() .
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: ImportWorldForgeAction.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void scanFiles(FileObject folder) { FileObject[] files = folder.getChildren(); for (FileObject fileObject : files) { if (fileObject.isFolder() && !fileObject.isVirtual()) { scanFiles(fileObject); } else if (fileObject.getPath().endsWith(".mesh.xml")) { // replaceMeshMatName(fileObject); //TODO: workaround if (!fileObject.getName().equals("campfire.mesh")) { modelNames.add(getRelativeAssetPath(fileObject.getPath())); } } else if ("material".equals(fileObject.getExt())) { // replaceMaterialMatName(fileObject); String name = getMaterialName(fileObject); if (name != null) { addMaterialRef(name, getRelativeAssetPath(fileObject.getPath())); } } } }
Example 2
Source File: ExtractSuperclassRefactoringPlugin.java From netbeans with Apache License 2.0 | 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
Source File: MimeTypesTracker.java From netbeans with Apache License 2.0 | 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, isTarget}; }
Example 4
Source File: NewProjectIterator.java From netbeans with Apache License 2.0 | 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 5
Source File: WebProject.java From netbeans with Apache License 2.0 | 6 votes |
private void handleCopyFileToDestDir(FileObject fo) throws IOException { if (fo.isVirtual()) { return; } FileObject persistenceXmlDir = getWebModule().getPersistenceXmlDir(); if (persistenceXmlDir != null && FileUtil.isParentOf(persistenceXmlDir, fo) && "persistence.xml".equals(fo.getNameExt())) { // NOI18N handleCopyFileToDestDir("WEB-INF/classes/META-INF", persistenceXmlDir, fo); // NOI18N return; } FileObject webInf = getWebModule().resolveWebInf(docBaseValue, webInfValue, true, true); FileObject docBase = getWebModule().resolveDocumentBase(docBaseValue, false); if (webInf != null && FileUtil.isParentOf(webInf, fo) && !(webInf.getParent() != null && webInf.getParent().equals(docBase))) { handleCopyFileToDestDir("WEB-INF", webInf, fo); // NOI18N return; } if (docBase != null && FileUtil.isParentOf(docBase, fo)) { handleCopyFileToDestDir(null, docBase, fo); return; } }
Example 6
Source File: WSITModelSupport.java From netbeans with Apache License 2.0 | 6 votes |
/** Creates new empty main client configuration file * */ static FileObject createMainConfig(FileObject folder, Collection<FileObject> createdFiles) { FileObject mainConfig = null; try { mainConfig = FileUtil.createData(folder, CONFIG_WSDL_CLIENT_PREFIX + "." + MAIN_CONFIG_EXTENSION); //NOI18N if ((mainConfig != null) && (mainConfig.isValid()) && !(mainConfig.isVirtual())) { if (createdFiles != null) { createdFiles.add(mainConfig); } FileWriter fw = new FileWriter(FileUtil.toFile(mainConfig)); fw.write(NbBundle.getMessage(WSITEditor.class, "EMPTY_WSDL")); //NOI18N fw.close(); mainConfig.refresh(true); } } catch (IOException ex) { ex.printStackTrace(); } return mainConfig; }
Example 7
Source File: ExtractInterfaceRefactoringPlugin.java From netbeans with Apache License 2.0 | 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 8
Source File: WSITModelSupport.java From netbeans with Apache License 2.0 | 6 votes |
public static WSDLModel getModelForService(Service service, FileObject implClass, Project p, boolean create, Collection<FileObject> createdFiles) { try { String wsdlUrl = service.getLocalWsdlFile(); if (wsdlUrl == null) { // WS from Java if ((implClass == null) || (!implClass.isValid() || implClass.isVirtual())) { logger.log(Level.INFO, "Implementation class is null or not valid, or just virtual: " + implClass + ", service: " + service); return null; } return getModelForServiceFromJava(implClass, p, create, createdFiles); } else { if (p == null) return null; JAXWSSupport supp = JAXWSSupport.getJAXWSSupport(p.getProjectDirectory()); return getModelForServiceFromWsdl(supp, service); } } catch (IOException ex) { logger.log(Level.INFO, null, ex); } catch (Exception e) { logger.log(Level.INFO, null, e); } return null; }
Example 9
Source File: MavenWSITModelSupport.java From netbeans with Apache License 2.0 | 5 votes |
public static WSDLModel getModel(Node node, Project project, JAXWSLightSupport jaxWsSupport, JaxWsService jaxService, UndoManagerHolder umHolder, boolean create, Collection<FileObject> createdFiles) throws MalformedURLException, Exception { WSDLModel model = null; boolean isClient = !jaxService.isServiceProvider(); if (isClient) { model = getModelForClient(project, jaxWsSupport, jaxService, create, createdFiles); } else { //it is a service FileObject implClass = node.getLookup().lookup(FileObject.class); try { String wsdlUrl = jaxService.getLocalWsdl(); if (wsdlUrl == null) { // WS from Java if ((implClass == null) || (!implClass.isValid() || implClass.isVirtual())) { logger.log(Level.INFO, "Implementation class is null or not valid, or just virtual: " + implClass + ", service: " + jaxService); return null; } return WSITModelSupport.getModelForServiceFromJava(implClass, project, create, createdFiles); } else { if (project == null) return null; return getModelForServiceFromWsdl(jaxWsSupport, jaxService); } } catch (Exception e) { logger.log(Level.INFO, null, e); } } if ((model != null) && (umHolder != null) && (umHolder.getUndoManager() == null)) { UndoManager undoManager = new UndoManager(); model.addUndoableEditListener(undoManager); //maybe use WeakListener instead umHolder.setUndoManager(undoManager); } return model; }
Example 10
Source File: CleanupProjectAction.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void scanFiles(final FileObject folder, final ArrayList<String> paths) { FileObject[] children = folder.getChildren(); for (FileObject fileObject : children) { boolean stay = false; if (fileObject.isFolder() && !fileObject.isVirtual()) { scanFiles(fileObject, paths); stay = true; } else if (fileObject.isData()) { if ("png".equalsIgnoreCase(fileObject.getExt()) || "jpg".equalsIgnoreCase(fileObject.getExt()) || "dds".equalsIgnoreCase(fileObject.getExt()) || "dae".equalsIgnoreCase(fileObject.getExt()) || "bmp".equalsIgnoreCase(fileObject.getExt())) { for (String path : paths) { if (fileObject.getPath().endsWith(path)) { stay = true; } } if (!stay) { try { Logger.getLogger(CleanupProjectAction.class.getName()).log(Level.INFO, "Delete unused file {0}", fileObject); fileObject.delete(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } } } }
Example 11
Source File: AntBasedProjectFactorySingleton.java From netbeans with Apache License 2.0 | 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 12
Source File: WebCopyOnSave.java From netbeans with Apache License 2.0 | 5 votes |
/** Copies a content file to an appropriate destination directory, * if applicable and relevant. */ private void copyFileToDestDir(FileObject fo) throws IOException { if (!fo.isVirtual()) { final FileObject documentBase = findWebDocRoot(fo); if (documentBase != null) { // inside docbase final String path = FileUtil.getRelativePath(documentBase, fo); if (!isSynchronizationAppropriate(path)) { return; } final J2eeModule j2eeModule = getJ2eeModule(); if (j2eeModule == null) { return; } final FileObject webBuildBase = j2eeModule.getContentDirectory(); if (webBuildBase != null) { // project was built if (FileUtil.isParentOf(documentBase, webBuildBase) || FileUtil.isParentOf(webBuildBase, documentBase)) { //cannot copy into self return; } FileObject destFile = ensureDestinationFileExists(webBuildBase, path, fo.isFolder()); File fil = FileUtil.normalizeFile(FileUtil.toFile(destFile)); copySrcToDest(fo, destFile); fireArtifactChange(Collections.singleton(ArtifactListener.Artifact.forFile(fil))); } } } }
Example 13
Source File: PropertyPanel.java From netbeans with Apache License 2.0 | 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 14
Source File: SourcesCurrentModel.java From netbeans with Apache License 2.0 | 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 15
Source File: InnerToOuterRefactoringPlugin.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Problem fastCheckParameters() { Problem result = null; String newName = refactoring.getClassName(); if (!Utilities.isJavaIdentifier(newName)) { result = createProblem(result, true, NbBundle.getMessage(InnerToOuterRefactoringPlugin.class, "ERR_InvalidIdentifier", newName)); // NOI18N return result; } String referenceName = refactoring.getReferenceName(); if(referenceName != null) { if (referenceName.length() < 1) { result = new Problem(true, NbBundle.getMessage(InnerToOuterRefactoringPlugin.class, "ERR_EmptyReferenceName")); // NOI18N return result; } else { if (!Utilities.isJavaIdentifier(referenceName)) { result = new Problem(true, NbBundle.getMessage(InnerToOuterRefactoringPlugin.class, "ERR_InvalidIdentifier", referenceName)); // 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(InnerToOuterRefactoringPlugin.class, "ERR_ClassClash", newName, folder.getName())); // NOI18N return result; } } return super.fastCheckParameters(); }
Example 16
Source File: PaletteSwitch.java From netbeans with Apache License 2.0 | 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 17
Source File: AntBasedProjectFactorySingleton.java From netbeans with Apache License 2.0 | 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 18
Source File: Util.java From netbeans with Apache License 2.0 | 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; }