本文整理汇总了Java中org.openide.filesystems.FileObject.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.getParent方法的具体用法?Java FileObject.getParent怎么用?Java FileObject.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.filesystems.FileObject
的用法示例。
在下文中一共展示了FileObject.getParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: overwriteDBSchema
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Overwrites <code>dbschemaFile</code> with the contents of
* <code>schemaElement</code>.
*/
private static void overwriteDBSchema(SchemaElement schemaElement, FileObject dbschemaFile, DBIdentifier dbschemaName) throws IOException {
try {
schemaElement.setName(dbschemaName);
} catch (DBException e) {
IOException ioe = new IOException(e);
throw ioe;
}
// cannot just overwrite the file, DBSchemaDataObject would not
// notice the file has changed.
FileObject parent = dbschemaFile.getParent();
String fileName = dbschemaFile.getName();
String fileExt = dbschemaFile.getExt();
dbschemaFile.delete();
FileObject newDBSchemaFile = parent.createData(fileName, fileExt);
writeSchemaElement(schemaElement, newDBSchemaFile);
}
示例2: overwriteDBSchema
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Overwrites <code>dbschemaFile</code> with the contents of
* <code>schemaElement</code>.
*/
private static void overwriteDBSchema(SchemaElement schemaElement, FileObject dbschemaFile, DBIdentifier dbschemaName) throws IOException {
try {
schemaElement.setName(dbschemaName);
} catch (DBException e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
// cannot just overwrite the file, DBSchemaDataObject would not
// notice the file has changed.
FileObject parent = dbschemaFile.getParent();
String fileName = dbschemaFile.getName();
String fileExt = dbschemaFile.getExt();
dbschemaFile.delete();
FileObject newDBSchemaFile = parent.createData(fileName, fileExt);
writeSchemaElement(schemaElement, newDBSchemaFile);
}
示例3: fileRenamedImpl
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private void fileRenamedImpl(final FileRenameEvent fe) {
try {
FileObject fo = fe.getFile();
Project owning = getOwningMavenProject(fo);
if (owning == null) {
return;
}
Tuple base = findAppropriateResourceRoots(fo, owning);
if (base != null) {
handleCopyFileToDestDir(base, fo, owning);
FileObject parent = fo.getParent();
String path;
if (FileUtil.isParentOf(base.root, parent)) {
path = FileUtil.getRelativePath(base.root, fo.getParent()) +
"/" + fe.getName() + "." + fe.getExt(); //NOI18N
} else {
path = fe.getName() + "." + fe.getExt(); //NOI18N
}
handleDeleteFileInDestDir(fo, path, base, owning);
}
} catch (IOException e) {
LOG.log(Level.INFO, null, e);
}
}
示例4: getSharedLibraryFolderLocation
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private FileObject getSharedLibraryFolderLocation() {
String libLoc = helper.getLibrariesLocation();
if (libLoc != null) {
String libLocEval = evaluator.evaluate(libLoc);
if (libLocEval != null) {
final File file = helper.resolveFile(libLocEval);
FileObject libLocFO = FileUtil.toFileObject(file);
if (libLocFO != null) {
//#126366 this can happen when people checkout the project but not the libraries description
//that is located outside the project
FileObject libLocParent = libLocFO.getParent();
return libLocParent;
}
}
}
return null;
}
示例5: getText
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Override
public String getText( TabData tab ) {
if( !settings.isShowFolderName() )
return null;
if( tab.getComponent() instanceof TopComponent ) {
TopComponent tc = ( TopComponent ) tab.getComponent();
DataObject dob = tc.getLookup().lookup( DataObject.class );
if( null != dob ) {
FileObject fo = dob.getPrimaryFile();
if( fo.isData() ) {
FileObject folder = fo.getParent();
if( null != folder ) {
String folderName = folder.getNameExt() + pathSeparator;
String defaultText = tab.getText();
return merge( folderName, defaultText );
}
}
}
}
return null;
}
示例6: getFileObject
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public FileObject getFileObject() {
//source does not exist
FileObject file = SourceUtils.getFile(el, cpInfo);
//tzezula: Very strange and probably useless
if (file == null && source != null) {
FileObject fo = URLMapper.findFileObject(source);
if (fo == null) {
log.log(Level.INFO, "There is no fileobject for source: " +source + ". Was this file removed?");
return file;
}
file = fo;
if (fo.getNameExt().endsWith(FileObjects.SIG)) {
//NOI18N
//conversion sig -> class
String pkgName = FileObjects.convertPackage2Folder(qualName);
StringTokenizer tk = new StringTokenizer(pkgName, "/"); //NOI18N
for (int i = 0; fo != null && i <= tk.countTokens(); i++) {
fo = fo.getParent();
}
if (fo != null) {
try {
URL url = fo.getURL();
URL sourceRoot = null;//XXX: Index.getSourceRootForClassFolder(url);
if (sourceRoot != null) {
FileObject root = URLMapper.findFileObject(sourceRoot);
String resourceName = FileUtil.getRelativePath(fo, URLMapper.findFileObject(source));
file = root.getFileObject(resourceName.replace('.'+FileObjects.SIG, '.'+FileObjects.CLASS)); //NOI18N
} else {
Logger.getLogger(TreePathHandle.class.getName()).fine("Index.getSourceRootForClassFolder(url) returned null for url=" + url); //NOI18N
}
} catch (FileStateInvalidException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
return file;
}
示例7: isWatched
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public static boolean isWatched(FileObject fo) {
Ext<?> ext = ext();
if (ext == null) {
return false;
}
if (fo.isData()) {
fo = fo.getParent();
}
return ext.isWatched(fo);
}
示例8: findPathPlain
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private Node findPathPlain(FileObject fo, FileObject groupRoot, Node rootNode) {
FileObject folder = fo.isFolder() ? fo : fo.getParent();
String relPath = FileUtil.getRelativePath(groupRoot, folder);
List<String> path = new ArrayList<String>();
StringTokenizer strtok = new StringTokenizer(relPath, "/"); // NOI18N
while (strtok.hasMoreTokens()) {
String token = strtok.nextToken();
path.add(token);
}
try {
Node folderNode = folder.equals(groupRoot) ? rootNode : NodeOp.findPath(rootNode, Collections.enumeration(path));
if (fo.isFolder()) {
return folderNode;
} else {
Node[] childs = folderNode.getChildren().getNodes(true);
for (int i = 0; i < childs.length; i++) {
DataObject dobj = childs[i].getLookup().lookup(DataObject.class);
if (dobj != null && dobj.getPrimaryFile().getNameExt().equals(fo.getNameExt())) {
return childs[i];
}
}
}
} catch (NodeNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例9: categorizeErrorRules
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private static void categorizeErrorRules( List<Pair<Rule,FileObject>> rules,
Map<String, Map<String,List<ErrorRule>>> dest,
FileObject rootFolder) {
dest.clear();
for( Pair<Rule,FileObject> pair : rules ) {
Rule rule = pair.getA();
FileObject fo = pair.getB();
String mime = FileUtil.getRelativePath(rootFolder, fo.getParent());
if (mime.length() == 0) {
mime = "text/x-java"; //TODO: use a predefined constant
}
if ( rule instanceof ErrorRule ) {
Map<String, List<ErrorRule>> map = dest.get(mime);
if (map == null) {
dest.put(mime, map = new HashMap<String, List<ErrorRule>>());
// first encounter the MIME type; read the 'inherit' rule from
// the rule folder. Further definitions
FileObject mimeFolder = fo.getParent();
Object o = mimeFolder.getAttribute("inherit.rules");
if (Boolean.TRUE == o) {
Map<String, List<ErrorRule>> inheritMap = dest.get("text/x-java");
for (String c : inheritMap.keySet()) {
map.put(c, new ArrayList<ErrorRule>(inheritMap.get(c)));
}
}
}
addRule( (ErrorRule)rule, map );
}
else {
LOG.log( Level.WARNING, "The rule defined in " + fo.getPath() + "is not instance of ErrorRule" );
}
}
}
示例10: destroy
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Override
public void destroy() throws IOException {
FileObject parent = dataFolder.getPrimaryFile().getParent();
// First; delete all files except packages
DataObject ch[] = dataFolder.getChildren();
boolean empty = true;
for( int i = 0; ch != null && i < ch.length; i++ ) {
if ( !ch[i].getPrimaryFile().isFolder() ) {
ch[i].delete();
}
else {
empty = false;
}
}
// If empty delete itself
if ( empty ) {
super.destroy();
}
// Second; delete empty super packages
while( !parent.equals( root ) && parent.getChildren().length == 0 ) {
FileObject newParent = parent.getParent();
parent.delete();
parent = newParent;
}
}
示例11: testFilesScannedAfterRenameOfFolder193243
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testFilesScannedAfterRenameOfFolder193243() throws Exception {
final TestHandler handler = new TestHandler();
final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests");
logger.setLevel (Level.FINEST);
logger.addHandler(handler);
final FileObject testFo = FileUtil.createData(this.srcRootWithFiles1, "rename/A.foo");
final MutableClassPathImplementation mcpi1 = new MutableClassPathImplementation ();
mcpi1.addResource(this.srcRootWithFiles1);
final ClassPath cp1 = ClassPathFactory.createClassPath(mcpi1);
globalPathRegistry_register(SOURCES,new ClassPath[]{cp1});
assertTrue (handler.await());
indexerFactory.indexer.setExpectedFile(new URL[]{new URL(this.srcRootWithFiles1.toURL()+"renamed/A.foo")}, new URL[]{testFo.toURL()}, new URL[0]);
eindexerFactory.indexer.setExpectedFile(new URL[0], new URL[]{testFo.toURL()}, new URL[0]);
final FileObject parent = testFo.getParent();
final FileLock lock = parent.lock();
try {
parent.rename(lock, "renamed", null);
} finally {
lock.releaseLock();
}
assertTrue(indexerFactory.indexer.awaitDeleted(TIME));
assertTrue(eindexerFactory.indexer.awaitDeleted());
assertTrue(indexerFactory.indexer.awaitIndex(TIME));
assertTrue(eindexerFactory.indexer.awaitIndex());
assertEquals(0, eindexerFactory.indexer.getIndexCount());
assertEquals(1, eindexerFactory.indexer.getDeletedCount());
assertEquals(0, eindexerFactory.indexer.getDirtyCount());
assertEquals(1, indexerFactory.indexer.getIndexCount());
assertEquals(1, indexerFactory.indexer.getDeletedCount());
assertEquals(0, indexerFactory.indexer.getDirtyCount());
}
示例12: canBePasted
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private static boolean canBePasted(final DataObject[] dataObjects, final DataFolder targetFolder, final int operation) throws FileStateInvalidException {
final Set<DataObject> pasteableDataObjects = new HashSet<DataObject> ();
final FileObject folder = targetFolder.getPrimaryFile();
DataObject[] folderChildren = targetFolder.getChildren();
for (int j = 0; j < dataObjects.length; j++) {
final DataObject dataObject = dataObjects[j];
final FileObject fo = dataObject.getPrimaryFile ();
if (!isAction(dataObject) || !fo.getFileSystem().isDefault()) {
break;
}
final boolean isCopyPaste = operation == LoaderTransfer.CLIPBOARD_COPY && dataObject.isCopyAllowed();
final boolean isCutPaste = operation == LoaderTransfer.CLIPBOARD_CUT && dataObject.isMoveAllowed() &&
!(fo.getParent() == folder);//prevents from cutting into the same folder where it was
if (isCopyPaste || isCutPaste) {
boolean isDuplicate = false;
for( int i=0; i<folderChildren.length; i++ ) {
if( 0 == folderChildren[i].getName().compareTo( dataObject.getName() ) ) {
isDuplicate = true;
break;
}
}
if( !isDuplicate )
pasteableDataObjects.add(dataObject);
}
}
return (pasteableDataObjects.size() == dataObjects.length);
}
示例13: getProjectForBuildScript
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public static Project getProjectForBuildScript(String fileName) {
FileObject projectFO = FileUtil.toFileObject(new File(fileName));
while (projectFO != null) {
try {
if (projectFO.isFolder()) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "Trying: {0}", projectFO); //NOI18N
}
Project p = ProjectManager.getDefault().findProject(projectFO);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "Got: {0}", ((p != null) ? getProjectName(p) : null)); //NOI18N
}
if (p != null) {
return p;
}
}
projectFO = projectFO.getParent();
} catch (IOException e) {
ProfilerLogger.severe("Got: IOException : " + e.getMessage()); //NOI18N
}
}
return null;
}
示例14: getDisableFilterAction
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Checks if the parsing errors are filtered for this file or any of its
* parent folders.
*
* @param file
* @return
*/
private static SetFilterAction getDisableFilterAction(@NonNull FileObject file) {
FileObject source = file;
for (; file != null && FileOwnerQuery.getOwner(file) != null; file = file.getParent()) {
if (file.getAttribute(DISABLE_ERROR_CHECKS_KEY) != null) {
return new SetFileFilterAction(source, file, false);
}
}
return null;
}
示例15: testStartupExtender
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Test public void testStartupExtender() throws Exception {
File wd = workDir;
FileObject fo = FileUtil.toFileObject(wd);
FileObject java = FileUtil.createData(fo, "prj/A.java");
FileObject prj = java.getParent();
String prjPath = FileUtil.toFile(prj).getAbsolutePath();
Lookup.getDefault().lookup(MockProjectFactory.class).prjDir = prj;
checkProperties(JavaRunner.QUICK_RUN, Arrays.asList("execute.file", java, "platform.java", "J", JavaRunner.PROP_RUN_JVMARGS, Collections.singleton("-ea")),
Arrays.asList("classname", "A", "platform.java", "J", "classpath", prjPath + File.separatorChar, "encoding", "UTF-8", "work.dir", FileUtil.toFile(prj).getAbsolutePath(), JavaRunner.PROP_RUN_JVMARGS, "-ea -Ddir=prj -Dvm=j2se", "platform.bootcp", JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries().toString()));
checkProperties(JavaRunner.QUICK_DEBUG, Arrays.asList("execute.file", java, "platform.java", "J", JavaRunner.PROP_RUN_JVMARGS, Collections.singleton("-ea")),
Arrays.asList("classname", "A", "platform.java", "J", "classpath", prjPath + File.separatorChar, "encoding", "UTF-8", "work.dir", FileUtil.toFile(prj).getAbsolutePath(), JavaRunner.PROP_RUN_JVMARGS, "-ea", "platform.bootcp", JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries().toString()));
checkProperties(JavaRunner.QUICK_RUN, Arrays.asList(JavaRunner.PROP_WORK_DIR, prj, JavaRunner.PROP_CLASSNAME, "A", JavaRunner.PROP_EXECUTE_CLASSPATH, ClassPath.EMPTY, "platform.java", "J", JavaRunner.PROP_RUN_JVMARGS, Collections.singleton("-ea")),
Arrays.asList("classname", "A", "platform.java", "J", "classpath", "", "encoding", "UTF-8", "work.dir", FileUtil.toFile(prj).getAbsolutePath(), JavaRunner.PROP_APPLICATION_ARGS, "", JavaRunner.PROP_RUN_JVMARGS, "-ea -Ddir=prj -Dvm=j2se", "platform.bootcp", JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries().toString()));
}