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 java.beans.*;
import org.openide.filesystems.FileObject;
import org.netbeans.modules.javacvs.*;
import org.netbeans.lib.cvsclient.event.*;
import org.netbeans.lib.cvsclient.command.annotate.*;
import org.netbeans.lib.cvsclient.command.*;
import org.netbeans.modules.javacvs.commands.*;
import org.netbeans.modules.javacvs.*;
import org.netbeans.modules.javacvs.customizers.AnnotateParamInput;
import org.netbeans.modules.javacvs.events.*;
/** This class implements the cvs Annotate command.
 *
 * @author mkleint
 */
public class CvsAnnotate extends FileSystemCommand {

    /**
     * Use head revision if a revision meeting criteria set by switches -r/-D
     * (tag/date) is not found.
     */
    private boolean useHeadIfNotFound;

    /**
     * equals the -D switch of command line cvs.
     */
    private String annotateByDate;

    /**
     * Equals the -r switch of command-line cvs.
     */
    private String annotateByRevision;
    
    /**
     * to be recursive is default behaviour of command.
     */
    private boolean recursive = true;
    
    private FsAnnotate annotateImpl;
    
    /** Creates new CvsAnnotate instance
     */
    public CvsAnnotate(File[] filesToCheck, ClientProvider fs) {
        super(fs);
        setFiles(filesToCheck);
        annotateImpl = new AnnotateImpl();
    }
    
    /** Creates new CvsAnnotate instance
     */
    public CvsAnnotate() {
        super();
        annotateImpl = new AnnotateImpl();
    }
    
    public String getName() {
        return NbBundle.getBundle(CvsAnnotate.class).getString("CvsAnnotate.name"); // NOI18N
    }
    
    public CvsCommand getImpl() {
        return annotateImpl;
    }
    
    public FsAnnotate getAnnotateImpl() {
        return annotateImpl;
    }
    
    protected void initCommand(boolean commandIsRunning) {
        // here the the commands is initiated just right before running the command
        clearCommandList();
        int dirNum = 0;
        AnnotateCommand 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 status command is sent separately..
                //that way just one UI component is run after finish of the command
                command = new AnnotateCommand();
                //              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 status 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 AnnotateCommand();
        //        command.setDirectoryCheck(false);
        command.setFiles(singleFiles);
        setCommandArguments(command);
        toDoCommands.addElement(command);
        // just add oen command to the queue
        super.initCommand(commandIsRunning);
    }
    
    
    protected void beforeEachExecute() {
        super.beforeEachExecute();
    }
    
    protected void afterEachExecute() {
        super.afterEachExecute();
    }
    
    protected void executeFailed(Exception exc) {
        stopCommand();
        super.executeFailed(exc);
    }
    
    /**
     * Called when file status information has been received
     */
    public void fileInfoGenerated(FileInfoEvent e) {
        super.fileInfoGenerated(e);
    }
    
    
    /**
     * return the library command that is considered main command.
     * that one is used for loading from
     */
    protected Class getMainCvsCommand() {
        return AnnotateCommand.class;
    }
    /**
     * Getter for property useHeadIfNotFound.
     * @return Value of property useHeadIfNotFound.
     */
    public boolean isUseHeadIfNotFound()
    {
        return useHeadIfNotFound;
    }

    /**
     * Setter for property useHeadIfNotFound.
     * @param useHeadIfNotFound New value of property useHeadIfNotFound.
     */
    public void setUseHeadIfNotFound(boolean useHeadIfNotFound)
    {
        this.useHeadIfNotFound = useHeadIfNotFound;
    }

    /**
     * Getter for property annotateByDate.
     * @return Value of property annotateByDate.
     */
    public String getAnnotateByDate()
    {
        return annotateByDate;
    }

    /**
     * Setter for property annotateByDate.
     * @param annotateByDate New value of property annotateByDate.
     */
    public void setAnnotateByDate(String annotateByDate)
    {
        this.annotateByDate = annotateByDate;
    }

    /**
     * Getter for property annotateByRevision.
     * @return Value of property annotateByRevision.
     */
    public String getAnnotateByRevision()
    {
        return annotateByRevision;
    }

    /**
     * Setter for property annotateByRevision.
     * @param annotateByRevision New value of property annotateByRevision.
     */
    public void setAnnotateByRevision(String annotateByRevision)
    {
        this.annotateByRevision = annotateByRevision;
    }    
    
    /** Sets recursive (-R switch) or local (-l switch) behaviour.
     */
    public void setRecursive(boolean recursive) {
        this.recursive = recursive;
    }
    
    /** Returns recursive (-R switch) or local (-l switch) behaviour.
     */
    public boolean isRecursive() {
        return recursive;
    }
    
    public class AnnotateImpl extends FsAnnotate implements FileSystemCommandImpl {
        public AnnotateImpl() {
        }

        public FileSystemCommand getOuterClassInstance() {
            return CvsAnnotate.this;
        }        
        
        /**
         * Getter for property useHeadIfNotFound.
         * @return Value of property useHeadIfNotFound.
         */
        public boolean isUseHeadIfNotFound() {
            return CvsAnnotate.this.isUseHeadIfNotFound();
        }
        
        /**
         * Setter for property useHeadIfNotFound.
         * @param useHeadIfNotFound New value of property useHeadIfNotFound.
         */
        public void setUseHeadIfNotFound(boolean useHeadIfNotFound) {
            CvsAnnotate.this.setUseHeadIfNotFound(useHeadIfNotFound);
        }
        
        /**
         * Getter for property annotateByDate.
         * @return Value of property annotateByDate.
         */
        public String getAnnotateByDate() {
            return CvsAnnotate.this.getAnnotateByDate();
        }
        
        /**
         * Setter for property annotateByDate.
         * @param annotateByDate New value of property annotateByDate.
         */
        public void setAnnotateByDate(String annotateByDate) {
            CvsAnnotate.this.setAnnotateByDate(annotateByDate);
        }
        
        /**
         * Getter for property annotateByRevision.
         * @return Value of property annotateByRevision.
         */
        public String getAnnotateByRevision() {
            return CvsAnnotate.this.getAnnotateByRevision();
        }
        
        /**
         * Setter for property annotateByRevision.
         * @param annotateByRevision New value of property annotateByRevision.
         */
        public void setAnnotateByRevision(String annotateByRevision) {
            CvsAnnotate.this.setAnnotateByRevision(annotateByRevision);
        }
        /** Returns recursive (-R switch) or local (-l switch) behaviour.
         */
        public boolean isRecursive() {
            return CvsAnnotate.this.isRecursive();
        }
        
        /** Sets recursive (-R switch) or local (-l switch) behaviour.
         */
        public void setRecursive(boolean recursive) {
            CvsAnnotate.this.setRecursive(recursive);
        }
        
        
        public void setFileObjects(FileObject[] fileObjects) {
            CvsAnnotate.this.setFileObjects(fileObjects);
        }
        
        public void addCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) {
            CvsAnnotate.this.addCommandErrorListener(commErrListener);
        }
        
        /** Clones the instance of the command.
         * @return Returns the cloned object.
         * @throws CloneNotSupportedException if clone is not supported by subclasses, it throws CloneNotSupportedException
         */
        public Object clone() throws CloneNotSupportedException {
            return new AnnotateImpl();
        }
        
        /** 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) { CvsAnnotate.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) { CvsAnnotate.this.removeDisplayerListener(listener); } public void removeCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) { CvsAnnotate.this.removeCommandErrorListener(commErrListener); } /** Starts the thread with the command - executes the run() method. */ public void startCommand() { CvsAnnotate.this.startCommand(); } public FsGlobalOptions getGlobalOptions() { FsGlobalOptions retValue; retValue = new FsGlobalOptionsImpl(CvsAnnotate.this.getGlobalOptions()); return retValue; } } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.