Package net.sourceforge.fullsync.fs

Examples of net.sourceforge.fullsync.fs.File


    Collection<File> srcFiles = src.getChildren();
    Collection<File> dstFiles = new ArrayList<File>(dst.getChildren());

    for (File sfile : srcFiles) {
      File dfile = dst.getChild(sfile.getName());
      if (dfile == null) {
        dfile = dst.createChild(sfile.getName(), sfile.isDirectory());
      }
      else {
        dstFiles.remove(dfile);
      }

      synchronizeNodes(sfile, dfile, rules, parent);
    }

    for (File dfile : dstFiles) {
      File sfile = src.getChild(dfile.getName());
      if (sfile == null) {
        sfile = src.createChild(dfile.getName(), dfile.isDirectory());
      }

      synchronizeNodes(sfile, dfile, rules, parent);
View Full Code Here


  public State getState(File buffered) throws DataParseException, IOException {
    if (!buffered.isBuffered()) {
      return new State(State.NodeInSync, buffered.exists() ? Location.Both : Location.None);
    }

    File source = buffered.getUnbuffered();
    BufferedFile destination = (BufferedFile) buffered;

    if (!source.exists()) {
      if (!destination.exists()) {
        return new State(State.NodeInSync, Location.None);
      }
      else {
        return new State(State.Orphan, Location.Destination);
      }
    }
    else if (!destination.exists()) {
      return new State(State.Orphan, Location.Source);
    }

    if (source.isDirectory()) {
      if (destination.isDirectory()) {
        return new State(State.NodeInSync, Location.Both);
      }
      else {
        return new State(State.DirHereFileThere, Location.Source);
View Full Code Here

  }

  private File buildNode(final File parent, final FileObject file) throws FileSystemException {
    String name = file.getName().getBaseName();

    File n = new AbstractFile(this, name, parent, file.getType() == FileType.FOLDER, true);
    if (file.getType() == FileType.FILE) {
      FileContent content = file.getContent();
      n.setLastModified(content.getLastModifiedTime());
      n.setSize(content.getSize());
    }
    return n;
  }
View Full Code Here

    return fs.isAvailable();
  }

  @Override
  public File createChild(File dir, String name, boolean directory) throws IOException {
    File n = dir.getUnbuffered().getChild(name);
    if (n == null) {
      n = dir.getUnbuffered().createChild(name, directory);
    }
    BufferedFile bf = new AbstractBufferedFile(this, n, dir, directory, false);
    return bf;
View Full Code Here

      }
    }
  }

  protected void loadFromBuffer() throws IOException {
    File fsRoot = fs.getRoot();
    File f = fsRoot.getChild(".syncfiles");

    root = new AbstractBufferedFile(this, fsRoot, null, true, true);
    if ((f == null) || !f.exists() || f.isDirectory()) {
      if (isMonitoringFileSystem()) {
        updateFromFileSystem(root);
      }
      return;
    }
    ByteArrayOutputStream out;
    InputStream reader = null;
    try {
      out = new ByteArrayOutputStream((int) f.getSize());

      InputStream in = new GZIPInputStream(f.getInputStream());
      int i;
      byte[] block = new byte[1024];
      while ((i = in.read(block)) > 0) {
        out.write(block, 0, i);
      }
View Full Code Here

    }
    return elem;
  }

  public void saveToBuffer() throws IOException {
    File fsRoot = fs.getRoot();
    File node = fsRoot.getChild(".syncfiles");
    if ((node == null) || !node.exists()) {
      node = root.createChild(".syncfiles", false);
    }
    OutputStream out = null;

    try {
      DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      Document doc = docBuilder.newDocument();

      Element e = doc.createElement("SyncFiles");
      e.appendChild(serializeFile(root, doc));
      doc.appendChild(e);

      out = new GZIPOutputStream(node.getOutputStream());

      TransformerFactory fac = TransformerFactory.newInstance();
      fac.setAttribute("indent-number", 2);
      Transformer tf = fac.newTransformer();
      DOMSource source = new DOMSource(doc);
View Full Code Here

  protected void executeTask(Task task) {
    try {
      // TODO lock tasks here

      Action action = task.getCurrentAction();
      File source = task.getSource();
      File destination = task.getDestination();

      switch (action.getType()) {
        case Action.Add:
        case Action.Update:
          if (action.getLocation() == Location.Destination) {
            if (source.isDirectory()) {
              storeDirCreation(task, destination);
            }
            else {
              storeFileCopy(task, source, destination);
            }
          }
          else if (action.getLocation() == Location.Source) {
            if (destination.isDirectory()) {
              storeDirCreation(task, source);
            }
            else {
              storeFileCopy(task, destination, source);
            }
View Full Code Here

      public void treeExpanded(final TreeEvent evt) {
        TreeItem item = (TreeItem) evt.item;
        TreeItem[] childrens = item.getItems();
        for (TreeItem children : childrens) {
          if (children.getData(EXPANDED_KEY) == null) {
            File file = (File) children.getData();
            try {
              addChildren(file, children);
            }
            catch (IOException e) {
              ExceptionHandler.reportException(e);
            }
            children.setData(EXPANDED_KEY, new Object());
          }
        }
      }
    });
    directoryTree.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(final SelectionEvent evt) {
        buttonSetFilter.setEnabled(true);
        TreeItem item = (TreeItem) evt.item;
        FileFilter currentItemFilter = (FileFilter) item.getData(FILTER_KEY);
        if (currentItemFilter != null) {
          buttonRemoveFilter.setEnabled(true);
        }
        else {
          buttonRemoveFilter.setEnabled(false);
        }
      }
    });
    // buttons next to the tree
    Composite compositeButtons = new Composite(c, SWT.NONE);
    GridLayout compositeButtonsLayout = new GridLayout();
    compositeButtonsLayout.makeColumnsEqualWidth = true;
    GridData compositeButtonsData = new GridData();
    compositeButtonsData.grabExcessVerticalSpace = true;
    compositeButtonsData.verticalAlignment = SWT.FILL;
    compositeButtons.setLayoutData(compositeButtonsData);
    compositeButtons.setLayout(compositeButtonsLayout);

    // add filter button
    buttonSetFilter = new Button(compositeButtons, SWT.PUSH | SWT.CENTER);
    GridData buttonSetFilterData = new GridData();
    buttonSetFilterData.widthHint = UISettings.BUTTON_WIDTH;
    buttonSetFilter.setLayoutData(buttonSetFilterData);
    buttonSetFilter.setText("Set Filter...");
    buttonSetFilter.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(final SelectionEvent evt) {
        TreeItem[] selectedItems = directoryTree.getSelection();
        if (selectedItems.length > 0) {
          TreeItem selectedItem = selectedItems[0];
          FileFilter currentItemFilter = (FileFilter) selectedItem.getData(FILTER_KEY);
          FileFilterPage dialog = new FileFilterPage(m_parent.getShell(), currentItemFilter);
          dialog.show();
          FileFilter newfilter = dialog.getFileFilter();
          if (newfilter != null) {
            selectedItem.setData(FILTER_KEY, newfilter);
            treeItemsWithFilter.add(selectedItem);
            File file = (File) selectedItem.getData();
            itemsMap.put(file.getPath(), newfilter);
            markItem(selectedItem);
            buttonRemoveFilter.setEnabled(true);
          }
        }
      }
    });

    // remove filter button
    buttonRemoveFilter = new Button(compositeButtons, SWT.PUSH | SWT.CENTER);
    GridData buttonRemoveFilterData = new GridData();
    buttonRemoveFilterData.widthHint = UISettings.BUTTON_WIDTH;
    buttonRemoveFilter.setLayoutData(buttonRemoveFilterData);
    buttonRemoveFilter.setText("Remove Filter");
    buttonRemoveFilter.setEnabled(false);
    buttonRemoveFilter.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(final SelectionEvent evt) {
        TreeItem[] selectedItems = directoryTree.getSelection();
        if (selectedItems.length > 0) {
          TreeItem selectedItem = selectedItems[0];
          treeItemsWithFilter.remove(selectedItem);
          File file = (File) selectedItem.getData();
          itemsMap.remove(file.getPath());
          unmarkItem(selectedItem);
        }
      }
    });
View Full Code Here

  private void drawDirectoryTree() {
    directoryTree.setRedraw(false);
    directoryTree.removeAll();
    try {
      File rootFile = sourceSite.getRoot();
      for (File file : rootFile.getChildren()) {
        if (file.isDirectory()) {
          TreeItem item = new TreeItem(directoryTree, SWT.NULL);
          item.setText(file.getName());
          item.setImage(GuiController.getInstance().getImage("Node_Directory.png"));
          item.setData(file);
View Full Code Here

  private FileFilterTree getFileFilterTree() {
    FileFilterTree fileFilterTree = new FileFilterTree();
    for (TreeItem item : treeItemsWithFilter) {
      FileFilter itemFilter = (FileFilter) item.getData(FILTER_KEY);
      File itemFile = (File) item.getData();
      fileFilterTree.addFileFilter(itemFile.getPath(), itemFilter);
    }
    return fileFilterTree;
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.fullsync.fs.File

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.