/** * Perform special enablement check in addition to the normal one. * * <p>protected boolean enable (Node[] nodes) { if (!super.enable(nodes)) { return false; } } * * <p>if (...) { ... } */ @Override protected boolean enable(Node[] nodes) { if (nodes.length == 0) { return false; } for (Node node : nodes) { DataObject dataObj = node.getCookie(DataObject.class); if (dataObj != null) { FileObject fileObj = dataObj.getPrimaryFile(); if ((fileObj == null) || !fileObj.isValid()) { continue; } Project prj = FileOwnerQuery.getOwner(fileObj); if ((prj == null) || (getSourceGroup(fileObj, prj) == null)) { continue; } if (TestUtil.isJavaFile(fileObj) || (node.getCookie(DataFolder.class) != null)) { return true; } } } return false; }
/** * Creates {@link JavaFileObject} for a NetBeans {@link FileObject} Any client which needs to * create {@link JavaFileObject} for java source file should use this factory method. * * @param {@link FileObject} for which the {@link JavaFileObject} should be created * @param {@link FileObject} root owning the file * @param renderNow if true the snap shot of the file is taken immediately * @return {@link JavaFileObject}, never returns null * @exception {@link IOException} may be thrown */ public static SourceFileObject nbFileObject( final FileObject file, final FileObject root, boolean renderNow) throws IOException { assert file != null; if (!file.isValid() || file.isVirtual()) { throw new InvalidFileException(file); } return new SourceFileObject(file, root /*, renderNow*/); // XXX }
// Non private only to be able to have the findNonExcludedPackages impl // in on place (PackageView) void add(FileObject fo, boolean empty) { String path = FileUtil.getRelativePath(root, fo); assert path != null : "Adding wrong folder " + fo + "(valid=" + fo.isValid() + ")" + "under root" + this.root + "(valid=" + this.root.isValid() + ")"; if (get(fo) == null) { names2nodes.put(path, empty ? NODE_NOT_CREATED_EMPTY : NODE_NOT_CREATED); } }
public void fileDeleted(FileEvent fe) { FileObject fo = fe.getFile(); if (FileUtil.isParentOf(root, fo) && isVisible(root, fo)) { if (fo.isFolder() || get(fo) != null) { removeSubTree(fo); // Now add the parent if necessary FileObject parent = fo.getParent(); if ((FileUtil.isParentOf(root, parent) || root.equals(parent)) && get(parent) == null && parent.isValid()) { // Candidate for adding if (!toBeRemoved(parent)) { add(parent, true); } } refreshKeysAsync(); } else { FileObject parent = fo.getParent(); final PackageNode n = get(parent); if (n != null) { // #61027: workaround to a deadlock when the package is being changed from non-leaf to // leaf: boolean leaf = n.isLeaf(); DataFolder df = n.getDataFolder(); boolean empty = n.isEmpty(df); if (leaf != empty) { SwingUtilities.invokeLater( new Runnable() { public void run() { n.updateChildren(); } }); } else { n.updateChildren(); } } // If the parent folder only contains folders remove it if (toBeRemoved(parent)) { remove(parent); refreshKeysAsync(); } } } }
protected Node[] createNodes(Object obj) { FileObject fo = root.getFileObject((String) obj); if (fo != null && fo.isValid()) { Object o = names2nodes.get(obj); PackageNode n; if (o == NODE_NOT_CREATED) { n = new PackageNode(root, DataFolder.findFolder(fo), false); } else if (o == NODE_NOT_CREATED_EMPTY) { n = new PackageNode(root, DataFolder.findFolder(fo), true); } else { n = new PackageNode(root, DataFolder.findFolder(fo)); } names2nodes.put(obj, n); return new Node[] {n}; } else { return new Node[0]; } }
private void loadPresets() { FileObject folder = FileUtil.getConfigFile("layoutpresets"); if (folder != null) { for (FileObject child : folder.getChildren()) { if (child.isValid() && child.hasExt("xml")) { try { InputStream stream = child.getInputStream(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(stream); Preset preset = new Preset(document); addPreset(preset); } catch (Exception ex) { ex.printStackTrace(); } } } } }
public static Action findAction(String key) { FileObject fo = FileUtil.getConfigFile(key); if (fo != null && fo.isValid()) { try { DataObject dob = DataObject.find(fo); InstanceCookie ic = dob.getCookie(InstanceCookie.class); if (ic != null) { Object instance = ic.instanceCreate(); if (instance instanceof Action) { Action a = (Action) instance; return a; } } } catch (Exception e) { ErrorManager.getDefault().notify(ErrorManager.WARNING, e); return null; } } return null; }
private DataObject getDataObject() { Import imprt = getReference(); FileObject fo = null; synchronized (imprt) { if (imprt == null) { return null; } fo = ResolverUtility.getImportedFileObject(imprt); } // to prevent IllegalArgumentException from DataObject.find(fo) if (fo == null || !fo.isValid()) { return null; } try { DataObject dObj = DataObject.find(fo); return dObj; } catch (DataObjectNotFoundException ex) { // ex.printStackTrace(); return null; } }
private void stateChangedImpl(List<FileObject> currentFiles) { Map<VisageSource, CancellableTask<CompilationInfo>> toRemove = new HashMap<VisageSource, CancellableTask<CompilationInfo>>(); Map<VisageSource, CancellableTask<CompilationInfo>> toAdd = new HashMap<VisageSource, CancellableTask<CompilationInfo>>(); synchronized (this) { List<FileObject> addedFiles = new ArrayList<FileObject>(currentFiles); List<FileObject> removedFiles = new ArrayList<FileObject>(file2Task.keySet()); addedFiles.removeAll(file2Task.keySet()); removedFiles.removeAll(currentFiles); // remove old tasks: for (FileObject r : removedFiles) { VisageSource source = file2JS.remove(r); if (source == null) { // TODO: log continue; } toRemove.put(source, file2Task.remove(r)); } // add new tasks: for (FileObject a : addedFiles) { if (a == null) continue; if (!a.isValid()) { continue; } VisageSource js = VisageSource.forFileObject(a); if (js != null) { CancellableTask<CompilationInfo> task = createTask(a); toAdd.put(js, task); file2Task.put(a, task); file2JS.put(a, js); } } } LOG.log(Level.FINEST, BEFORE_ADDING_REMOVING_TASKS); for (Entry<VisageSource, CancellableTask<CompilationInfo>> e : toRemove.entrySet()) { VisageTaskProcessor.removePhaseCompletionTask(e.getKey(), e.getValue()); } for (Entry<VisageSource, CancellableTask<CompilationInfo>> e : toAdd.entrySet()) { try { VisageTaskProcessor.addPhaseCompletionTask(e.getKey(), e.getValue(), phase, priority); // } catch (FileObjects.InvalidFileException ie) { // LOG.info("VisageSource.addPhaseCompletionTask called on deleted file"); // //NOI18N } catch (IOException ex) { ErrorManager.getDefault().notify(ex); } } }