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

import javax.swing.JButton;
import org.netbeans.modules.cvsclient.IndependantClient;
import org.netbeans.modules.cvsclient.FsCommandFactory;
import org.netbeans.lib.cvsclient.command.FileInfoContainer;
import java.util.ArrayList;
import java.util.LinkedList;
import org.netbeans.lib.cvsclient.command.add.AddInformation;
import org.netbeans.modules.cvsclient.commands.*;
import org.openide.*;
import java.lang.reflect.Method;
import javax.accessibility.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.table.TableColumn;
import javax.swing.table.JTableHeader;
import org.openide.util.NbBundle;
import org.netbeans.modules.javacvs.commands.CvsAdd;
import org.netbeans.modules.javacvs.commands.CvsCommit;
import java.awt.Dialog;
import org.netbeans.modules.javacvs.commands.ClientProvider;
import org.netbeans.modules.vcscore.util.table.*;
import org.openide.DialogDisplayer;


public class AddInfoPanel extends DefaultInfoPanel  {
    
    ArrayList resultList;
    ArrayList listeners;
    CvsAdd command;
    TableInfoModel model;
    private boolean stopped;
    private ActionListener stopActionListener;
    
    
    /** Creates new form UpdateInfoPanel */
    public AddInfoPanel(CvsAdd comm) {
        initComponents ();
        initAccessibility();
        btnCommit.setMnemonic (NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.commitButton.mnemonic").charAt (0)); //NOI18N
        btnViewLog.setMnemonic (NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.logButton.mnemonic").charAt (0)); //NOI18N
        btnStop.setMnemonic (NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.stopButton.mnemonic").charAt (0)); //NOI18N
        command = comm;
        setPreferredSize(new java.awt.Dimension(450, 300));
        setMinimumSize(new java.awt.Dimension(450, 200));        
        stopped = false;
        model = new GrowingTableInfoModel();
        Class classa = AddInformation.class;
        String  column1 = NbBundle.getBundle(AddInfoPanel.class).getString("AddTableInfoModel.type"); //NOI18N
        String  column2 = NbBundle.getBundle(AddInfoPanel.class).getString("AddTableInfoModel.fileName"); //NOI18N
        String  column3 = NbBundle.getBundle(AddInfoPanel.class).getString("AddTableInfoModel.path"); //NOI18N
        try {
            Method method1 = classa.getMethod("getType", null);    //NOI18N 
            Method method2 = classa.getMethod("getFile", null);     //NOI18N
            model.setColumnDefinition(0, column1, method1, true, new AddTypeComparator());
            ClientProvider prov = command.getClientProvider();            
            model.setColumnDefinition(1, column2, method2, true, new FileComparator());
            model.setColumnDefinition(2, column3, method2, true, new PathComparator(prov.getLocalPath()));
        } catch (NoSuchMethodException exc) {
            Thread.dumpStack();
        } catch (SecurityException exc2) {
            Thread.dumpStack();
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the FormEditor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        pnlButtons = new javax.swing.JPanel();
        btnViewLog = new javax.swing.JButton();
        btnStop = new javax.swing.JButton();
        btnCommit = new javax.swing.JButton();
        spCentral = new javax.swing.JScrollPane();
        tblAdded = new javax.swing.JTable();

        setLayout(new java.awt.GridBagLayout());

        pnlButtons.setLayout(new java.awt.GridBagLayout());

        btnViewLog.setText(org.openide.util.NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.logButton"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(17, 5, 11, 0);
        pnlButtons.add(btnViewLog, gridBagConstraints);

        btnStop.setText(org.openide.util.NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.stopButton"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(17, 5, 11, 11);
        pnlButtons.add(btnStop, gridBagConstraints);

        btnCommit.setText(org.openide.util.NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.commitButton"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.9;
        gridBagConstraints.insets = new java.awt.Insets(17, 12, 11, 0);
        pnlButtons.add(btnCommit, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        add(pnlButtons, gridBagConstraints);

        spCentral.setPreferredSize(new java.awt.Dimension(250, 60));
        tblAdded.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        spCentral.setViewportView(tblAdded);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11);
        add(spCentral, gridBagConstraints);

    }//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCommit;
    private javax.swing.JButton btnViewLog;
    private javax.swing.JScrollPane spCentral;
    private javax.swing.JButton btnStop;
    private javax.swing.JTable tblAdded;
    private javax.swing.JPanel pnlButtons;
    // End of variables declaration//GEN-END:variables
    
    private static final java.util.ResourceBundle bundle = NbBundle.getBundle(AddInfoPanel.class);   // NOI18N
    
    private void initAccessibility() {
        
        AccessibleContext context = this.getAccessibleContext();
        context.setAccessibleDescription(bundle.getString("ACSD_AddInfoPanel"));
        
        context = btnCommit.getAccessibleContext();
        context.setAccessibleDescription(bundle.getString("ACSD_AddInfoPanel.btnCommit"));
        
        context = btnViewLog.getAccessibleContext();
        context.setAccessibleDescription(bundle.getString("ACSD_AddInfoPanel.btnViewLog"));
        
        context = btnStop.getAccessibleContext();
        context.setAccessibleDescription(bundle.getString("ACSD_AddInfoPanel.btnStop"));

        context = tblAdded.getAccessibleContext();
        context.setAccessibleDescription(bundle.getString("ACSD_AddInfoPanel.tblAdded"));
        context.setAccessibleName(bundle.getString("ACSN_AddInfoPanel.tblAdded"));
        
    }
    
    
/** 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() {
        tblAdded.setModel(model);
        TableColumn col = tblAdded.getColumnModel().getColumn(0);
        col.setPreferredWidth(80);
          // HACK to set the width of column at desired size
        
//        String title = NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.dialogTitle") + " " + command.getName();
//        setName(title);
        setName(command.getName());
        stopActionListener = new StopActionListener();
        btnStop.addActionListener(stopActionListener);
        btnViewLog.setEnabled(false);
        btnCommit.setEnabled(false);
        javax.swing.SwingUtilities.invokeLater(new Runnable () {
            public void run () {
                open();
            }
        });         
/*        options[0] = NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.stopButton");
        dd.setOptions(options);
        Object[] empty = new Object[1];
        dd.setClosingOptions(empty); // none are closing
        dd.setButtonListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                shutDownCommand();
            }
        });
        javax.swing.SwingUtilities.invokeLater(new Runnable () {
            public void run () {
                Dialog dial = TopManager.getDefault().createDialog(dd);
                dial.setModal(false);
                dial.show();
            }
        });
 */
    }
    
    protected void shutDownCommand() {
        // we can do that because it's running from other thread then command and won't kill itself
        if (btnStop != null) {
            btnStop.setText(NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.stopping")); //NOI18N
            btnStop.setEnabled(false);
        }
        command.hardCommandStop();
        stopped = true;
//        displayOutputData();
    }
    
    
    /** Does the actual display - docking into the javacvs Mode,
     *  displaying as single Dialog.. whatever.
     */
    public void displayOutputData() {
/*        if (!isOpened()) {
            return;
        }
 */
//        int size;
        boolean anyScheduled = anyScheduledFiles();
        // forces the NbPresenter to keep the user's resizing.
        if (stopped || !anyScheduled || isRunningFromRuntime()) {
        } else {
            btnCommit.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    performCommit();
                }
            });
            btnCommit.setEnabled(true);
        }
        
        btnStop.setText(NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.closeButton")); //NOI18N
        btnStop.setMnemonic(NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.closeButton.mnemonic").charAt (0)); //NOI18N
        btnStop.setEnabled(true);
        btnStop.removeActionListener(stopActionListener);
        btnStop.addActionListener(new CloseActionListener());
        btnViewLog.addActionListener(new ViewLogActionListener(btnViewLog));
        btnViewLog.setEnabled(true);
        
/*        Object[] options = new Object[size];
        final String log = NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.logButton");
        JButton btnClose = new JButton(NbBundle.getBundle(AddInfoPanel.class)
                                 .getString("AddInfoPanel.closeButton"));
        btnClose.setDefaultCapable(true);
        final String commit = NbBundle.getBundle(AddInfoPanel.class).getString("AddInfoPanel.commitButton");
        options[size - 1] = btnClose;
        options[size - 2] = log;
        Object[] closing = new Object[size - 1];
        if (!stopped && anyScheduled && !isRunningFromRuntime()) {
            options[0] = commit;
            closing[0] = options[0];            
        }
        closing[size - 2] = options[size - 1];
        dd.setValue(btnClose); // HACK
        dd.setOptions(options);
        dd.setClosingOptions(closing); // all are closing
        dd.setButtonListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                if (evt.getActionCommand().equals(commit)) {
                    performCommit();
                }
                if (evt.getActionCommand().equals(log)) {
                    doShowCommandLog();
                }    
            }
        });
 */
        JTableHeader head = tblAdded.getTableHeader();
        head.setUpdateTableInRealTime(true);
        ColumnSortListener listen = new ColumnSortListener(tblAdded);
        head.addMouseListener(listen);
    }

    private boolean anyScheduledFiles() {
        int rowCount = model.getRowCount();
        for (int index = 0; index < rowCount; index++) {
            AddInformation addInfo = (AddInformation)model.getElementAt(index);
            if (!addInfo.isDirectory()) {
                return true;
            }
        }
        return false;
    }
    
    private void performCommit() {
//        if (!command.getClientProvider() instanceof IndependantClient) return;
        IndependantClient provider = (IndependantClient)command.getClientProvider();
        if (provider.isOffLine()) return;
        int rowCount = model.getRowCount();
        LinkedList fileList = new LinkedList();
        for (int index = 0; index < rowCount; index++) {
            AddInformation addInfo = (AddInformation)model.getElementAt(index);
            if (!addInfo.isDirectory()) {
                fileList.add(addInfo.getFile());
            }
        }
        if (fileList.size() > 0) {
            File[] fileArray = new File[fileList.size()];
            fileArray = (File[])fileList.toArray(fileArray);
            FsCommandFactory fact = (FsCommandFactory)FsCommandFactory.getInstance();
            CvsCommit myStat = (CvsCommit)fact.createCommand(
                           CvsCommit.class,  true, fileArray, provider);
            fact.addIndependantRuntime(myStat);
            fact.showCustomizerAndRun(myStat, false, false);
        } else {
            //TODO.. message??
            String noScheduled = NbBundle.getBundle(AddInfoPanel.class)
                          .getString("AddInfoPanel.noScheduledAvailable"); //NOI18N
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(noScheduled));
        }
    }
    
    /**
     * this one is called when the command's execution  fails for any reason.
     */
    public void showExecutionFailed(Exception exception) {
//       if (isOpened()) {
             displayOutputData();        
//       }
    }
    
    /**
     * This is the last method to be called in the displayer.
     * Is called when the execution finishes. Any filan touchups can be made here.
     */
    public void showFinishedCommand() {
             displayOutputData();        
    }
    
    /**
     * This method is the first one that is called during execution.
     * Here any initial setup of the displayer can be made.
     */
    public void showStartCommand() {
            displayFrameWork();        
    }
    
    
    /**
     * When the library command's builder generates a FileInfoContainer object, the
     * Displayer is notified.
     * @param info - the generated information object
     */
    public void showFileInfoGenerated(FileInfoContainer info) {
        if (info instanceof AddInformation) {
            model.addElement(info);
                javax.swing.SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        tblAdded.changeSelection(model.getRowCount(), 0, false, false);
                    }
                });
        }
    }
    
}
... 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.