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.javacvs.commands;


import org.openide.util.NbBundle;
import java.io.*;
import java.util.*;

import org.netbeans.lib.cvsclient.event.*;
import org.netbeans.lib.cvsclient.command.*;
import org.netbeans.lib.cvsclient.command.watchers.*;
import org.openide.filesystems.FileObject;

import org.netbeans.modules.javacvs.*;
import org.netbeans.modules.javacvs.commands.*;
import org.netbeans.modules.javacvs.events.*;

/** This class implements the cvs watchers command.
 *
 * @author mkleint
 */
public class CvsWatchers extends FileSystemCommand {
    
    /**
     * to be recursive is default behaviour of command.
     */
    private boolean recursive = true;    
    
    private FsWatchers watchersImpl;
    
    /** Creates cvs Watchers command.
     * @param filesToCheck Files/dirs that are used for the command.
     *
     * @deprecated Should be used as bean.
     * @param fs ClientProvider object that gives the command context.
     */
    public CvsWatchers(File[] filesToCheck, ClientProvider fs) {
        super(fs);
        setFiles(filesToCheck);
        watchersImpl = new WatchersImpl();
    }
    
    /** Creates cvs Watchers command.
     */    
    public CvsWatchers() {
        super();
        watchersImpl = new WatchersImpl();
    }
    
    public CvsCommand getImpl() {
        return watchersImpl;
    }    
    
    public FsWatchers getWatchersImpl() {
        return watchersImpl;
    }
    
    public String getName() {
        return NbBundle.getBundle(CvsWatchers.class).getString("CvsWatchers.BeanName"); // NOI18N
    }

    protected Class getMainCvsCommand() {
        return WatchersCommand.class;
    }

    
    protected void initCommand(boolean commandIsRunning) {
        // here the the commands is initiated just right before running the command
        clearCommandList();
        int dirNum = 0;
        WatchersCommand command;
        File[] files = new File[getFiles().length];
        System.arraycopy(getFiles(),0,files,0, getFiles().length);
        
        for (int index = 0; index < files.length; index++) {
            if (files[index].isDirectory()) {
                // each directory Watchers command is sent separately..
                //that way just one UI component is run after finish of the command
                command = new WatchersCommand();
//                command.setDirectoryCheck(true);
                File[] fls = new File[1];
                fls[0] = files[index];
                command.setFiles(fls);
                setCommandArguments(command);
                toDoCommands.addElement(command);
                files[index] = null;
                dirNum = dirNum + 1;
            }
        }
        // now proceed all single files in one batch.
        if (dirNum == files.length) {
            super.initCommand(commandIsRunning);            
            return; // no files to check Watchers on.
        }
        File[] singleFiles = new File[files.length - dirNum];
        int singleIndex = 0;
        for (int ind = 0; ind < files.length; ind++) {
            if (files[ind] != null) {
                singleFiles[singleIndex] = files[ind];
                singleIndex = singleIndex + 1;
            }
        }
        command = new WatchersCommand();
//        command.setDirectoryCheck(false);
        command.setFiles(singleFiles);
        setCommandArguments(command);
        toDoCommands.addElement(command);
        // just add oen command to the queue
        super.initCommand(commandIsRunning);
    }
    
    
    protected void executeFailed(Exception exc) {
        stopCommand();
        super.executeFailed(exc);
    }
 
    /** Setter for property recursive, equals the -l/-R switches in command-line cvs.
     *
     * @param recursive if true, equals -R 
* if false, equals -l */ public void setRecursive(boolean recursive) { this.recursive = recursive; } /** Getter for property recursive, equals the -l/-R switch in command-line cvs. * @return Returns if the command should be recursive. */ public boolean isRecursive() { return recursive; } public class WatchersImpl extends FsWatchers implements FileSystemCommandImpl { public FileSystemCommand getOuterClassInstance() { return CvsWatchers.this; } public void setFileObjects(FileObject[] fileObjects) { CvsWatchers.this.setFileObjects(fileObjects); } /** Getter for property recursive, equals the -l/-R switch in command-line cvs. * @return Returns if the command should be recursive. */ public boolean isRecursive() { return CvsWatchers.this.isRecursive(); } /** Setter for property recursive, equals the -l/-R switches in command-line cvs. * * @param recursive if true, equals -R
* if false, equals -l */ public void setRecursive(boolean recursive) { CvsWatchers.this.setRecursive(recursive); } public void addCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) { CvsWatchers.this.addCommandErrorListener(commErrListener); } /** Add a CommandDisplayerListener to the FilesystemCommand. *
All UI communication and display of output should be handled via the CommandDisplayerListeners. * * @param listener The listener to add. * */ public void addDisplayerListener(CommandDisplayerListener listener) { CvsWatchers.this.addDisplayerListener(listener); } /** Removes a CommandDisplayerListener from the FilesystemCommand. * All the listeners are removed once the command ends. * * @param listener the listener to remove */ public void removeDisplayerListener(CommandDisplayerListener listener) { CvsWatchers.this.removeDisplayerListener(listener); } public void removeCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) { CvsWatchers.this.removeCommandErrorListener(commErrListener); } /** Starts the thread with the command - executes the run() method. */ public void startCommand() { CvsWatchers.this.startCommand(); } public FsGlobalOptions getGlobalOptions() { FsGlobalOptions retValue; retValue = new FsGlobalOptionsImpl(CvsWatchers.this.getGlobalOptions()); return retValue; } } }
... 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.