alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.cvsclient.caching;

/**
 *
 * @author  Milos Kleint
 */
import org.netbeans.modules.javacvs.commands.CacheUpdatingFsCommand;
import org.netbeans.modules.vcscore.cache.CacheHandler;
import org.netbeans.modules.javacvs.commands.ClientProvider;
import java.io.File;
import java.io.FileFilter;
import java.util.*;
import org.openide.util.NbBundle;
import org.netbeans.lib.cvsclient.command.status.StatusCommand;

public class OfflineRefreshCommand extends CacheUpdatingFsCommand {

    /** Holds value of property recursive. */
    private boolean recursive;
    
    public OfflineRefreshCommand(File[] filesToCheck) {
        super();
        setRefreshing(false);
        setFiles(filesToCheck);
    }
    
    /** Creates cvs status command.
     */    
    public OfflineRefreshCommand() {
        super();
        setRefreshing(false);
    }
    
   
            // for dirs to be recursively refreshed, perform check wheather they are CVS dirs. If not..
    // search for all it's subdirs that are..
    private File[] findRelevantDirs(File[] files) {
        LinkedList localOnes = new LinkedList();
        LinkedList okFiles = new LinkedList();
        if (files == null) {
            return null;
        }
        for (int index = 0; index < files.length; index++) {
            File file = files[index];
            if (file.isDirectory()) {
                File[] cvsDir = file.listFiles(new FileFilter() {
                    public boolean accept(File f) {
                        if (f.isDirectory() && f.getName().equalsIgnoreCase("CVS")) return true; // NOI18N
                        return false;
                    }
                });
                if (cvsDir.length == 0)  {
                    localOnes.add(file);
//                    cacheObject.fireCacheHandlerEvent(FileSystemCache.EVENT_CHANGED, file);
                }
                else okFiles.add(file);
            } else {
                // okFiles.add(file);
                // files are not included.. recursive refresh makes no sense for them
            }
        }
        if (localOnes.size() == 0) {
            // everything is ok.. return the initial file[] array.
            return files;
        } 
        Iterator it = localOnes.iterator();
        while (it.hasNext()) {
            File main = (File)it.next();
            File[] toFind = main.listFiles();
            if (toFind.length > 0) {
                toFind = findRelevantDirs(toFind);
                if (toFind.length > 0) {
                    for (int ind = 0; ind < toFind.length; ind++) {
                        okFiles.add(toFind[ind]);
                    }
                }
            }
        }
        File[] toReturn = new File[okFiles.size()];
        toReturn = (File[])okFiles.toArray(toReturn);
        return toReturn;
    }    

    /** set the files/dirs that the command operates on. Not directly used here,
     * but subclasses use it in 99% of cases. They should set it before starting a
     * command, according to the nodes selected or otherwise.. and feed it to
     * undelying library commands.
     * @deprecated Use the setFileObjects() methods intead where possible. The setFiles() method might disappear soon.
     * @param fls array of files that the comamnds is executed upon.
     */
    public void setFiles(File[] fls) {
        super.setFiles(findRelevantDirs(fls));
    }
    
    /** Needs to return a  correct org.netbeans.lib.cvsclient.command.Command.java subclass.
     * 
Is crutial for correct functionality of the parseCvsArguments(String) method. * @return Should return any subclass of org.netbeans.lib.cvsclient.command.Command.java subclass that is a cvs command. * */ protected Class getMainCvsCommand() { return StatusCommand.class; } public String getName() { return NbBundle.getBundle(OfflineRefreshCommand.class).getString("OfflineRefreshCommand.name"); } /** This method is called when all commands in the queue were already successfully finished. *
* Fires the FinishDisplayerEvent */ protected void finishedCommand() { super.finishedCommand(); fireUpdateCache(); } /** This method is used for setting up the filesystem command. Here the queue of commands should be created, depending on the value of the properties. * Fires the StartDisplayerEvent * @param commandIsRunning True is called from within the run() method. Otherwise needs to be set to false. * */ protected void initCommand(boolean commandIsRunning) { setFullEntriesUpdate(true); prepareCache(getFiles(), isRecursive()); super.initCommand(commandIsRunning); } /** Getter for property recursive. * @return Value of property recursive. */ public boolean isRecursive() { return this.recursive; } /** Setter for property recursive. * @param recursive New value of property recursive. */ public void setRecursive(boolean recursive) { this.recursive = recursive; } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.