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.status.*;
import org.netbeans.lib.cvsclient.file.FileStatus;
import org.openide.filesystems.FileObject;

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

/** This class implements the cvs status command.
 *
 * @author mkleint
 */
public class CvsStatus extends CacheUpdatingFsCommand {
    
    StatusCommand command;

    /**
     * Holds value of property includeTags.
     */
    private boolean includeTags;
    
    /**
     * to be recursive is default behaviour of command.
     */
    private boolean recursive = true;    
    
    private FsStatus statusImpl;
    
    /** Creates cvs status 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 CvsStatus(File[] filesToCheck, ClientProvider fs) {
        super(fs);
        setFiles(filesToCheck);
        statusImpl = new StatusImpl();
    }
    
    /** Creates cvs status command.
     */    
    public CvsStatus() {
        super();
        statusImpl = new StatusImpl();
    }
    
    public CvsCommand getImpl() {
        return statusImpl;
    }    
    
    public FsStatus getStatusImpl() {
        return statusImpl;
    }
    
    public String getName() {
        return NbBundle.getBundle(CvsStatus.class).getString("CvsStatus.name"); // NOI18N
    }

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

    
    protected void initCommand(boolean commandIsRunning) {
        // here the the commands is initiated just right before running the command
        clearCommandList();
        int dirNum = 0;
        StatusCommand 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 StatusCommand();
//                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 StatusCommand();
//        command.setDirectoryCheck(false);
        command.setFiles(singleFiles);
        setCommandArguments(command);
        toDoCommands.addElement(command);
        // just add oen command to the queue
        super.initCommand(commandIsRunning);
    }
    
    protected void finishedCommand() {
        // called when the communication with server ends and the command thread is about to end..
        // used for calling visualizer stuff..
        fireUpdateCache();
        super.finishedCommand();
    }
    
    protected void beforeEachExecute() {
        super.beforeEachExecute();
    }
        
    protected void afterEachExecute() {
        super.afterEachExecute();
    }
    
    protected void executeFailed(Exception exc) {
        fireUpdateCache();
        stopCommand();
        super.executeFailed(exc);
    }
 
    /** Called when file status information has been received
     */
    public void fileInfoGenerated(FileInfoEvent e) {
        StatusInformation info = (StatusInformation)e.getInfoContainer();
        if (info != null) {
            updateCache(info);
        }
        super.fileInfoGenerated(e);
    }
    
    /** Getter for property includeTags, equals the -v switch in command-line cvs.
     * @return Value of property includeTags.
     */
    public boolean isIncludeTags()
    {
        return includeTags;
    }

    /** Setter for property includeTags, equals the -v switch in command-line cvs.
     * @param inclTags New value of property includeTags.
     */
    public void setIncludeTags(boolean inclTags)
    {
        includeTags = inclTags;
    }
    
    /** 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 StatusImpl extends FsStatus implements FileSystemCommandImpl { public FileSystemCommand getOuterClassInstance() { return CvsStatus.this; } public void setFileObjects(FileObject[] fileObjects) { CvsStatus.this.setFileObjects(fileObjects); } /** 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) { CvsStatus.this.setRecursive(recursive); } public void addCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) { CvsStatus.this.addCommandErrorListener(commErrListener); } /** 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 CvsStatus.this.isRecursive(); } /** 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) { CvsStatus.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) { CvsStatus.this.removeDisplayerListener(listener); } public void removeCommandErrorListener(org.netbeans.modules.javacvs.events.CommandErrorListener commErrListener) { CvsStatus.this.removeCommandErrorListener(commErrListener); } /** Getter for property includeTags, equals the -v switch in command-line cvs. * @return Value of property includeTags. */ public boolean isIncludeTags() { return CvsStatus.this.isIncludeTags(); } /** Setter for property includeTags, equals the -v switch in command-line cvs. * @param inclTags New value of property includeTags. */ public void setIncludeTags(boolean inclTags) { CvsStatus.this.setIncludeTags(inclTags); } /** Starts the thread with the command - executes the run() method. */ public void startCommand() { CvsStatus.this.startCommand(); } public FsGlobalOptions getGlobalOptions() { FsGlobalOptions retValue; retValue = new FsGlobalOptionsImpl(CvsStatus.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.