Ejemplo n.º 1
0
    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;
      }
    }
Ejemplo n.º 2
0
 @Override
 protected DataObject handleCopyRename(DataFolder df, String name, String ext) throws IOException {
   FileObject fo = getPrimaryEntry().copyRename(df.getPrimaryFile(), name, ext);
   DataObject dob = DataObject.find(fo);
   // TODO invoke refactoring here (if needed)
   return dob;
 }
Ejemplo n.º 3
0
 /**
  * Constructs a new instance of PackageNode.
  *
  * <p>
  *
  * @param root root of the package.
  * @param folder a package within root.
  */
 public PackageNode(FileObject root, DataFolder folder) {
   // DataFolder children are loaded on demand.
   super(
       folder.getNodeDelegate(),
       isEmpty(folder) ? Children.LEAF : folder.createNodeChildren(FILTER));
   sourcePkg = folder.getPrimaryFile();
   String path = FileUtil.getRelativePath(root, sourcePkg);
   displayName = path.replace('/', '.');
 }
Ejemplo n.º 4
0
 private Image getMyIcon(int type) {
   FileObject folder = dataFolder.getPrimaryFile();
   String path = FileUtil.getRelativePath(root, folder);
   if (path == null) {
     // ???
     return null;
   }
   return PackageDisplayUtils.getIcon(folder, path.replace('/', '.'), isLeaf());
 }
Ejemplo n.º 5
0
 public String getShortDescription() {
   FileObject folder = dataFolder.getPrimaryFile();
   String path = FileUtil.getRelativePath(root, folder);
   if (path == null) {
     // ???
     return "";
   }
   return PackageDisplayUtils.getToolTip(folder, path.replace('/', '.'));
 }
Ejemplo n.º 6
0
 public String getDisplayName() {
   FileObject folder = dataFolder.getPrimaryFile();
   String path = FileUtil.getRelativePath(root, folder);
   if (path == null) {
     // ???
     return "";
   }
   return PackageDisplayUtils.getDisplayLabel(path.replace('/', '.'));
 }
Ejemplo n.º 7
0
 public PackageNode(FileObject root, DataFolder dataFolder, boolean empty) {
   super(
       dataFolder.getNodeDelegate(),
       empty ? Children.LEAF : dataFolder.createNodeChildren(NO_FOLDERS_FILTER),
       new ProxyLookup(
           new Lookup[] {
             Lookups.singleton(new NoFoldersContainer(dataFolder)),
             dataFolder.getNodeDelegate().getLookup(),
             Lookups.singleton(
                 PackageRootNode.alwaysSearchableSearchInfo(
                     SearchInfoFactory.createSearchInfo(
                         dataFolder.getPrimaryFile(),
                         false, // not recursive
                         new FileObjectFilter[] {SearchInfoFactory.VISIBILITY_FILTER}))),
           }));
   this.root = root;
   this.dataFolder = dataFolder;
   this.isDefaultPackage = root.equals(dataFolder.getPrimaryFile());
 }
Ejemplo n.º 8
0
  private void createFile() {
    if (result != null && result.indexOf('\\') == -1) { // NOI18N

      if (!targetFolder.getPrimaryFile().canWrite()) {
        return;
      }

      DataObject dObj = null;

      try {
        FileObject fo =
            type == TYPE_FILE
                ? FileUtil.createData(targetFolder.getPrimaryFile(), result)
                : FileUtil.createFolder(targetFolder.getPrimaryFile(), result);
        if (fo != null) {
          dObj = DataObject.find(fo);
        }
      } catch (DataObjectNotFoundException e) {
        // No data object no open
      } catch (IOException e) {
        // XXX
      }

      if (result != null) {
        // handle new template in SystemFileSystem
        DataObject rootDO = findTemplate("/Templates"); // NOI18N
        if (rootDO != null && dObj != null) {
          if (FileUtil.isParentOf(rootDO.getPrimaryFile(), dObj.getPrimaryFile())) {
            try {
              dObj.setTemplate(true);
            } catch (IOException e) {
              // can ignore
            }
          }
        }
      }
      if (dObj != null) {
        ProjectUtilities.openAndSelectNewObject(dObj);
      }
    }
  }
Ejemplo n.º 9
0
    public java.awt.Image getOpenedIcon(int type) {
      java.awt.Image img = getMyOpenedIcon(type);

      try {
        FileObject fo = dataFolder.getPrimaryFile();
        Set set = new NonResursiveFolderSet(fo);
        img = fo.getFileSystem().getStatus().annotateIcon(img, type, set);
      } catch (FileStateInvalidException e) {
        // no fs, do nothing
      }

      return img;
    }
Ejemplo n.º 10
0
 /**
  * Initially overridden to support CVS status labels in package nodes.
  *
  * @return annotated display name
  */
 public String getHtmlDisplayName() {
   String name = getDisplayName();
   try {
     FileObject fo = dataFolder.getPrimaryFile();
     Set set = new NonResursiveFolderSet(fo);
     org.openide.filesystems.FileSystem.Status status = fo.getFileSystem().getStatus();
     if (status instanceof org.openide.filesystems.FileSystem.HtmlStatus) {
       name =
           ((org.openide.filesystems.FileSystem.HtmlStatus) status).annotateNameHtml(name, set);
     } else {
       name = status.annotateName(name, set);
     }
   } catch (FileStateInvalidException e) {
     // no fs, do nothing
   }
   return name;
 }
Ejemplo n.º 11
0
  @Override
  public void changedUpdate(javax.swing.event.DocumentEvent e) {

    String fileName = getFileName();

    if (fileName.length() == 0) {
      okOption.setEnabled(false);
      return;
    }

    FileObject fo = targetFolder.getPrimaryFile().getFileObject(fileName);
    if (fo != null) {
      okOption.setEnabled(false);
      return;
    }

    okOption.setEnabled(true);
  }
Ejemplo n.º 12
0
 protected @Override DataObject handleCreateFromTemplate(DataFolder df, String name)
     throws IOException {
   if (name == null
       && language != null
       && language.getGsfLanguage().getPreferredExtension() != null) {
     // special case: name is null (unspecified or from one-parameter createFromTemplate)
     name =
         FileUtil.findFreeFileName(
             df.getPrimaryFile(),
             getPrimaryFile().getName(),
             language.getGsfLanguage().getPreferredExtension());
   }
   //        else if (!language.getGsfLanguage().isIdentifierChar(c)
   // Utilities.isJavaIdentifier(name)) {
   //            throw new IOException (NbBundle.getMessage(GsfDataObject.class,
   // "FMT_Not_Valid_FileName", language.getDisplayName(), name));
   //        }
   // IndentFileEntry entry = (IndentFileEntry)getPrimaryEntry();
   // entry.initializeIndentEngine();
   try {
     templateLanguage = language;
     DataObject retValue = super.handleCreateFromTemplate(df, name);
     FileObject fo = retValue.getPrimaryFile();
     assert fo != null;
     //        ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
     //        String pkgName;
     //        if (cp != null) {
     //            pkgName = cp.getResourceName(fo.getParent(),'.',false);
     //        }
     //        else {
     //            pkgName = "";   //NOI18N
     //        }
     //        renameJDO (retValue, pkgName, name, this.getPrimaryFile().getName());
     return retValue;
   } finally {
     templateLanguage = null;
   }
 }
Ejemplo n.º 13
0
 /**
  * Determines if the given folder is empty or not.
  *
  * <p>
  *
  * @param folder data folder to check.
  * @return true if folder is empty, false otherwise.
  */
 private static boolean isEmpty(DataFolder folder) {
   if (folder == null) {
     return true;
   }
   return SourcesView.isEmpty(folder.getPrimaryFile());
 }
Ejemplo n.º 14
0
 private static boolean isEmpty(DataFolder dataFolder) {
   if (dataFolder == null) {
     return true;
   }
   return PackageDisplayUtils.isEmpty(dataFolder.getPrimaryFile());
 }
Ejemplo n.º 15
0
 public String getName() {
   String relativePath = FileUtil.getRelativePath(root, dataFolder.getPrimaryFile());
   return relativePath == null ? null : relativePath.replace('/', '.'); // NOI18N
 }
Ejemplo n.º 16
0
 public FileObject getFolder() {
   return folder.getPrimaryFile();
 }