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-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */


package org.netbeans.modules.cvsclient.commands;

import org.openide.DialogDisplayer;

import java.util.*;
import java.io.IOException;
import java.io.File;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.text.StyledDocument;
import java.awt.*;
import java.awt.event.*;
import org.netbeans.lib.cvsclient.command.update.*;
import org.netbeans.lib.cvsclient.event.MessageEvent;
import org.netbeans.modules.javacvs.events.*;
import org.netbeans.modules.vcscore.util.Debug;
import org.netbeans.modules.vcscore.commands.*;
import org.netbeans.modules.vcscore.util.TopComponentCloseListener;
import org.netbeans.modules.cvsclient.NbJavaCvsFileSystem;
import org.netbeans.modules.javacvs.commands.*;
import org.openide.util.NbBundle;
import org.openide.filesystems.*;
import org.openide.*;
import javax.accessibility.*;

public class CommandLineInfoPanel implements CommandDisplayerListener {
    
//    DialogDescriptor dd;
    private StringBuffer toAdd;
    boolean wasShown;
    private FileSystemCommand command;
    private CommandOutputVisualizer panel;
    private ArrayList closeListeners = new ArrayList();
    private java.awt.event.ActionListener killListener = null;
    
    /** Creates new form UpdateInfoPanel */
    public CommandLineInfoPanel(FileSystemCommand fscommand) {
//        initComponents ();
        command = fscommand;
        killListener = new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent event) {
                 String name = command.getName();
                 NotifyDescriptor.Confirmation nd = new NotifyDescriptor.Confirmation (
                    java.text.MessageFormat.format(NbBundle.getBundle(CommandOutputPanel.class).getString("CommandOutputVisualizer.killCommand"), // NOI18N
                                                   new Object[] { name }),
                    NotifyDescriptor.Confirmation.OK_CANCEL_OPTION);
                if (NotifyDescriptor.Confirmation.OK_OPTION.equals (DialogDisplayer.getDefault().notify (nd))) {
                       shutDownCommand();
                }
            }
        };
        String name = fscommand.getName();
        String viewName = NbBundle.getMessage(CommandOutputPanel.class, "CommandOutputVisualizer.name", // NOI18N
                                new Object[] { name });
        File[] files = fscommand.getFiles();
        StringBuffer filesString = new StringBuffer(" "); // NOI18N
        if (files != null && (!fscommand.getClass().equals(CvsCheckout.class))) {
            for (int i = 0; i < files.length; i++) {
                if (files[i] != null) {
                    filesString.append(files[i].getName());
                    filesString.append(" "); // NOI18N
                }
            }
        }
        String execString = "cvs " + fscommand.getGlobalOptions().getCVSCommand() + " "  + fscommand.getCVSCommand() + filesString.toString(); // NOI18N
        panel = new CommandOutputVisualizer(killListener, execString, viewName);
        wasShown = false;
    }
   
/** this method should be used with Choosers to display the dialog.. 
 * then later the displayOutputData will just present the datat gotten from server
 * Reason: to have something displayer right away..
 * This method is to be called when creating the command and Chooser.
 */
    public void displayFrameWork() {
        panel.open((org.openide.windows.Workspace) null);
        wasShown = true;
    }
    
    private void shutDownCommand() {
        // we can do that because it's running from other thread then command and won't kill itself
        command.hardCommandStop();
        panel.setExitStatus(VcsCommandExecutor.INTERRUPTED);
    }
    
    public void showExecutionFailed(Exception exception) {
        // do change the buttons.
        if (!wasShown) {
            displayFrameWork();
        }
        panel.setExitStatus(VcsCommandExecutor.FAILED);
    }
    
    public void messageGenerated(MessageEvent e) {
        if (!wasShown) {
            displayFrameWork();
        }
        if (e.getMessage().equals("")) { // NOI18N
            return;
        }
        if (e.isTagged()) {
            String line = e.getMessage();
            if (line.charAt(0) == '+' || line.charAt(0) == '-') {
                return;
            } 
            if (toAdd == null) {
                toAdd = new StringBuffer();
            }
            if (line.equals("newline")) { // NOI18N
                panel.stdOutputLine(toAdd.toString());                
                toAdd = null; // NOI18N
            } else {
                int index = line.indexOf(' ');
                if (index > 0) {
                    toAdd = toAdd.append(line.substring(index + 1));
                }
            }
            
        }
        else {
            if (toAdd != null) {
                panel.stdOutputLine(toAdd.toString());                
                toAdd = null;
            }
            if (e.isError()) {
                panel.errOutputLine(e.getMessage()); // NOI18N
            } else { 
                panel.stdOutputLine(e.getMessage()); // NOI18N
            }
        }    
//        JScrollBar bar = spCentral.getVerticalScrollBar();
//        bar.setValue(bar.getMaximum());
    }
    
    public void showBeforeEachExecute(org.netbeans.lib.cvsclient.command.Command currentCommand) {
    }
    
    public void showFinishedCommand() {
        // do change the buttons.
        if (!wasShown) {
            displayFrameWork();
        }
        panel.setExitStatus(VcsCommandExecutor.SUCCEEDED);
    }
    
    public void showStartCommand() {
        displayFrameWork();
    }
    
    public void showAfterEachExecute() {
    }
    
    public void showFileInfoGenerated(org.netbeans.lib.cvsclient.command.FileInfoContainer info) {
    }

}
... 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.