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.actions;

import org.netbeans.modules.vcscore.actions.*;
import org.openide.filesystems.*;
import org.netbeans.modules.cvsclient.*;
import org.netbeans.modules.cvsclient.commands.*;
import org.netbeans.modules.javacvs.commands.*;
import java.util.*;

/**
 * this class handles the default case of straight cvs command
 * implementation..
 * @author  Milos Kleint
 */
public abstract class DefaultCallBackCommandAction extends CallBackCommandAction {

    protected int usedUiMode;
    private LinkedList commandList;
    private LinkedList displList;
    
    /** Creates new UpdateCommandAction */
    public DefaultCallBackCommandAction() {
    }

    /**
     * Is called from the ActionSupporter when it starts iterating the
     * collected filesystems and fileobjects..
     * Can be used for initial settings, eg. to create a common displayer for everyone.
     * 
     */
    public void initCallBack(JavaCvsActionSupporter supporter) {
        // does nothing by default..
        super.initCallBack(supporter);
        usedUiMode = NbJavaCvsFileSystem.MODE_NOVICE;
//        skipDisplayers = true;
        commandList = new LinkedList();
        displList = new LinkedList();
    }
    
    /**
     * method is called from the ActionSupporter and executes the action on the fileobjects..
     *
     */
    public void performCallBack(NbJavaCvsFileSystem fs, FileObject[] fos) {
        if (fs.checkOffLine()) return;
        // now set the common command switch entering mode..
        //  ADVANCED has precedence over COMMAND-LINE which has precedence over NOVICE
        if (fs.getUiMode() == NbJavaCvsFileSystem.MODE_ADVANCED) {
            usedUiMode = fs.getUiMode();
        } else if (fs.getUiMode() == NbJavaCvsFileSystem.MODE_COMMAND_LINE
                    && usedUiMode == NbJavaCvsFileSystem.MODE_NOVICE) {
            usedUiMode = fs.getUiMode();
        }
        if (usedUiMode == NbJavaCvsFileSystem.MODE_NOVICE && isSwitched()) {
            usedUiMode = NbJavaCvsFileSystem.MODE_ADVANCED;
        }
        
        boolean skipDisplayers = !FsCommandFactory.getFsInstance().showDisplayerWhenLimited(getCommandClass())
                        && (fs.getDisplayType() == NbJavaCvsFileSystem.DISP_TYPE_LIMITED);
        FileSystemCommand comm = FsCommandFactory.getFsInstance().createCommand(getCommandClass(), true, fos, fs.createClientProvider());
        fs.prepareCommand(comm);
        commandList.add(comm);
        displList.add(skipDisplayers ? Boolean.TRUE : Boolean.FALSE);
    }

    /**
     * Gets the last command processed.
     * the call to DefaultCallBackCommandAction.finishCallBack()
     * clears the references.
     */
    protected FileSystemCommand getLastCommandInstance() {
        if (commandList != null && commandList.size() > 0) {
            return (FileSystemCommand)commandList.getLast();
        }
        return null;
    }
    
    /**
     * returns the list of commands..
     * DefaultCallBackCommandAction.initCallBack() initializes the value, and
     * the call to DefaultCallBackCommandAction.finishCallBack()
     * clears the reference.
     */
    protected List getCommandList() {
        return commandList;
    }
    
    /**
     * returns the list of boolean values that indicate wheather the displayer is used..
     * DefaultCallBackCommandAction.initCallBack() initializes the value, and
     * the call to DefaultCallBackCommandAction.finishCallBack()
     * clears the reference.
     */
    protected List getDisplList() {
        return displList;
    }

    /**
     * Is called from the ActionSupporter when it stops iterating the
     * collected filesystems and fileobjects..
     * Can be used for clean up, etc.
     * 
     */
    public void finishCallBack() {
        if (commandList.size() != 0) {
            // we got some command's we have to run.. thus show the right customizer for them
            if (usedUiMode == NbJavaCvsFileSystem.MODE_COMMAND_LINE) {
                FsCommandFactory.getFsInstance().doShowCustomizerAndRun(commandList, new CommandLineParamInput(), displList);
                return;
            }
            
            boolean skipParams = false;
            if (usedUiMode == NbJavaCvsFileSystem.MODE_NOVICE) {
                skipParams = true;
            }
            FsCommandFactory.getFsInstance().showCustomizerAndRun(commandList, displList, skipParams);
        }
        clearReferences();
    }
    
    protected void clearReferences() {
        commandList = null;
        displList = null;
    }
    
    /**
     * Each action needs to define which cvs command it belongs to.
     */
    protected abstract Class getCommandClass();
    
    /**
     * when included in the popup menu, this property denotes if the action has
     * switchable customizer. if true and with the right user Interface mode,
     * such action will be appended the 3 dots if CTRL is pressed.
     *
     */
    public boolean isSwitchable() {
        return true;
    }
    
}
... 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.