private void change(FileEvent fe) {
   synchronized (saveActions) {
     for (AtomicAction a : saveActions) {
       if (fe.firedFrom(a)) {
         return;
       }
     }
   }
   String path;
   FileObject f = fe.getFile();
   synchronized (modifiedMetadataPaths) {
     if (f.equals(resolveFileObject(PROJECT_XML_PATH))) {
       if (modifiedMetadataPaths.contains(PROJECT_XML_PATH)) {
         // #68872: don't do anything if the given file has non-saved changes:
         return;
       }
       path = PROJECT_XML_PATH;
       projectXmlValid = false;
     } else if (f.equals(resolveFileObject(PRIVATE_XML_PATH))) {
       if (modifiedMetadataPaths.contains(PRIVATE_XML_PATH)) {
         // #68872: don't do anything if the given file has non-saved changes:
         return;
       }
       path = PRIVATE_XML_PATH;
       privateXmlValid = false;
     } else {
       LOG.log(
           Level.WARNING,
           "#184132: unexpected file change in {0}; possibly deleted project?",
           f);
       return;
     }
   }
   fireExternalChange(path);
 }
Ejemplo n.º 2
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.º 3
0
 public Transferable paste() throws IOException {
   assert this.op != DnDConstants.ACTION_NONE;
   for (int ni = 0; ni < nodes.length; ni++) {
     FileObject fo = srcRoot;
     if (!nodes[ni].isDefaultPackage) {
       String pkgName = nodes[ni].getName();
       StringTokenizer tk = new StringTokenizer(pkgName, "."); // NOI18N
       while (tk.hasMoreTokens()) {
         String name = tk.nextToken();
         FileObject tmp = fo.getFileObject(name, null);
         if (tmp == null) {
           tmp = fo.createFolder(name);
         }
         fo = tmp;
       }
     }
     DataFolder dest = DataFolder.findFolder(fo);
     DataObject[] children = nodes[ni].dataFolder.getChildren();
     boolean cantDelete = false;
     for (int i = 0; i < children.length; i++) {
       if (children[i].getPrimaryFile().isData()
           && VisibilityQuery.getDefault().isVisible(children[i].getPrimaryFile())) {
         // Copy only the package level
         children[i].copy(dest);
         if (this.op == DnDConstants.ACTION_MOVE) {
           try {
             children[i].delete();
           } catch (IOException ioe) {
             cantDelete = true;
           }
         }
       } else {
         cantDelete = true;
       }
     }
     if (this.op == DnDConstants.ACTION_MOVE && !cantDelete) {
       try {
         FileObject tmpFo = nodes[ni].dataFolder.getPrimaryFile();
         FileObject originalRoot = nodes[ni].root;
         assert tmpFo != null && originalRoot != null;
         while (!tmpFo.equals(originalRoot)) {
           if (tmpFo.getChildren().length == 0) {
             FileObject tmpFoParent = tmpFo.getParent();
             tmpFo.delete();
             tmpFo = tmpFoParent;
           } else {
             break;
           }
         }
       } catch (IOException ioe) {
         // Not important
       }
     }
   }
   return ExTransferable.EMPTY;
 }
Ejemplo n.º 4
0
  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();
        }
      }
    }
  }
Ejemplo n.º 5
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.º 6
0
  /** Finds all empty parents of given package and deletes them */
  private void cleanEmptyKeys(FileObject fo) {
    FileObject parent = fo.getParent();

    // Special case for default package
    if (root.equals(parent)) {
      PackageNode n = get(parent);
      // the default package is considered empty if it only contains folders,
      // regardless of the contents of these folders (empty or not)
      if (n != null && PackageDisplayUtils.isEmpty(root, false)) {
        remove(root);
      }
      return;
    }

    while (FileUtil.isParentOf(root, parent)) {
      PackageNode n = get(parent);
      if (n != null && n.isLeaf()) {
        remove(parent);
      }
      parent = parent.getParent();
    }
  }
Ejemplo n.º 7
0
    public void setName(String name) {
      PackageRenameHandler handler = getRenameHandler();
      if (handler != null) {
        handler.handleRename(this, name);
        return;
      }

      if (isDefaultPackage) {
        return;
      }
      String oldName = getName();
      if (oldName.equals(name)) {
        return;
      }
      if (!isValidPackageName(name)) {
        DialogDisplayer.getDefault()
            .notify(
                new NotifyDescriptor.Message(
                    NbBundle.getMessage(PackageViewChildren.class, "MSG_InvalidPackageName"),
                    NotifyDescriptor.INFORMATION_MESSAGE));
        return;
      }
      name = name.replace('.', '/') + '/'; // NOI18N
      oldName = oldName.replace('.', '/') + '/'; // NOI18N
      int i;
      for (i = 0; i < oldName.length() && i < name.length(); i++) {
        if (oldName.charAt(i) != name.charAt(i)) {
          break;
        }
      }
      i--;
      int index = oldName.lastIndexOf('/', i); // NOI18N
      String commonPrefix = index == -1 ? null : oldName.substring(0, index);
      String toCreate = (index + 1 == name.length()) ? "" : name.substring(index + 1); // NOI18N
      try {
        FileObject commonFolder =
            commonPrefix == null ? this.root : this.root.getFileObject(commonPrefix);
        FileObject destination = commonFolder;
        StringTokenizer dtk = new StringTokenizer(toCreate, "/"); // NOI18N
        while (dtk.hasMoreTokens()) {
          String pathElement = dtk.nextToken();
          FileObject tmp = destination.getFileObject(pathElement);
          if (tmp == null) {
            tmp = destination.createFolder(pathElement);
          }
          destination = tmp;
        }
        FileObject source = this.dataFolder.getPrimaryFile();
        DataFolder sourceFolder = DataFolder.findFolder(source);
        DataFolder destinationFolder = DataFolder.findFolder(destination);
        DataObject[] children = sourceFolder.getChildren();
        for (int j = 0; j < children.length; j++) {
          if (children[j].getPrimaryFile().isData()) {
            children[j].move(destinationFolder);
          }
        }
        while (!commonFolder.equals(source)) {
          if (source.getChildren().length == 0) {
            FileObject tmp = source;
            source = source.getParent();
            tmp.delete();
          } else {
            break;
          }
        }
      } catch (IOException ioe) {
        ErrorManager.getDefault().notify(ioe);
      }
    }