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.commands.status;

import java.io.*;
import java.util.*;
import javax.swing.tree.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import org.openide.util.*;
import org.netbeans.lib.cvsclient.command.status.*;
import org.netbeans.lib.cvsclient.command.FileInfoContainer;
import org.netbeans.lib.cvsclient.file.FileStatus;
import org.netbeans.modules.cvsclient.NbJavaCvsStatusManager;
import org.netbeans.modules.javacvs.caching.CvsCacheFile;
import org.netbeans.modules.javacvs.commands.JavaCvsStatusManager;
import org.netbeans.modules.cvsclient.commands.*;
import org.netbeans.modules.vcscore.util.table.*;


import org.netbeans.modules.javacvs.commands.CvsStatus;
import org.netbeans.modules.javacvs.commands.FileSystemCommand;
import java.lang.reflect.Method;
import org.netbeans.modules.cvsclient.FsCommandFactory;
/**
 *
 * @author  mkleint
 * @version
 */
public class StatusTreeInfoPanel extends AbstractTreeInfoPanel 
                                 implements PersistentCommandDisplayer {
    
    private StatusInfoPanel statPanel;
    private StatusInformation clearStatusInfo;
    private CvsStatus command;
    private Class fsCommand;
    
    private javax.swing.JCheckBox cbUptodate;
    private javax.swing.JCheckBox cbModified;
    private javax.swing.JCheckBox cbNeedsPatch;
    private javax.swing.JCheckBox cbNeedsMerge;
    private javax.swing.JCheckBox cbHasConflict;
    private javax.swing.JCheckBox cbLocAdded;
    private javax.swing.JCheckBox cbLocRemoved;
    private javax.swing.JCheckBox cbNeedsCheckout;
    private javax.swing.JCheckBox cbUnknown;
    private javax.swing.JLabel    lblCount;
    private javax.swing.JLabel lblTitle;    
    private int totalCount;
    private int selectedCount;
    
    private JRadioButton btnAll;
    private String btnAll_Title;
    private String btnJustModified_Title;
    private JRadioButton btnJustModified;
    private int currentFilter = FILTER_ALL;
    private static final int FILTER_ALL = 0;
    private static final int FILTER_MODIFIED = 1;
    
    private JavaCvsStatusManager statusManager;
    
    /** Creates new form StatusTreeInfoPanel */
    public StatusTreeInfoPanel(File topDir, CvsStatus statusComm) {
        super(topDir);
//        insideListRenderer.setDefaultTab(30);
        command = statusComm;
        // add buttons now
        initButtons();
        statusManager = NbJavaCvsStatusManager.getInstance();
        postInit();
    }
    
    
    public void setCommand(CvsStatus comm) {
        command = comm;
    }
  
    private void initPanelComponents() {
    }    
    
    private void initClearInfo() {
        clearStatusInfo = new StatusInformation();
        clearStatusInfo.setFile(new File("")); // NOI18N
        clearStatusInfo.setRepositoryFileName(""); // NOI18N
        clearStatusInfo.setRepositoryRevision(""); // NOI18N
        clearStatusInfo.setWorkingRevision(""); // NOI18N
        clearStatusInfo.setStatus(FileStatus.UNKNOWN);
        clearStatusInfo.setStickyDate(""); // NOI18N
        clearStatusInfo.setStickyOptions(""); // NOI18N
        clearStatusInfo.setStickyTag(""); // NOI18N
    }
    
    
    protected void setPanel(Object infoData) {
        StatusInformation statData = (StatusInformation)infoData;
        statPanel.setData(statData);
    }
    
    protected JComponent initPanel() {
        initClearInfo();
        statPanel = new StatusInfoPanel(command);
        setClearPanel();
        return statPanel;
    }
    
    protected void setClearPanel() {
        statPanel.setData(clearStatusInfo);
    }
    
    protected boolean canBeAdded(StatusInformation sInfo) {
        if (sInfo.getStatus() == FileStatus.UP_TO_DATE && cbUptodate.isSelected()) return true;
        if (sInfo.getStatus() == FileStatus.MODIFIED && cbModified.isSelected()) return true;
        if (sInfo.getStatus() == FileStatus.ADDED && cbLocAdded.isSelected()) return true;
        if (sInfo.getStatus() == FileStatus.REMOVED && cbLocRemoved.isSelected()) return true;
        if (sInfo.getStatus() == FileStatus.NEEDS_CHECKOUT && cbNeedsCheckout.isSelected()) return true;
        if (sInfo.getStatus() == FileStatus.NEEDS_MERGE && cbNeedsMerge.isSelected()) return true;
        if (sInfo.getStatus() == FileStatus.NEEDS_PATCH && cbNeedsPatch.isSelected()) return true;
        if (sInfo.getStatus() == FileStatus.HAS_CONFLICTS && cbHasConflict.isSelected()) return true;
        if (sInfo.getStatus() == FileStatus.UNKNOWN && cbUnknown.isSelected()) return true;
        return false;
    }
    
    protected boolean addToList(FileInfoContainer info) {
        StatusInformation sInfo = (StatusInformation)info;
        return canBeAdded(sInfo);
    }
    
    protected void addFileNode(FileInfoContainer info,DefaultMutableTreeNode parent) {
        StatusInformation sInfo = (StatusInformation)info;
        totalCount = totalCount + 1;
        if (canBeAdded(sInfo)) {
            DefaultMutableTreeNode child = new DefaultMutableTreeNode(info);
            parent.add(child);
            selectedCount = selectedCount + 1;
        }
    }
    
    
    private void checkBoxChanged() {
        totalCount = 0;
        selectedCount = 0;
        recreateModel();
        Integer selCount = new Integer(selectedCount);
        Integer totCount = new Integer(totalCount);
        String txt = NbBundle.getMessage(StatusTreeInfoPanel.class, "StatusTreeInfoPanel.lblCount", // NOI18N
                                selCount.toString(), totCount.toString());
        lblCount.setText(txt);
    }
    
    private void initButtons() {
        JPanel panel = getButtonPanel();
        cbUptodate = new javax.swing.JCheckBox();
        cbModified = new javax.swing.JCheckBox();
        cbLocAdded = new javax.swing.JCheckBox();
        cbLocRemoved = new javax.swing.JCheckBox();
        cbNeedsCheckout = new javax.swing.JCheckBox();
        cbNeedsMerge = new javax.swing.JCheckBox();
        lblTitle = new javax.swing.JLabel();
        lblCount = new javax.swing.JLabel();
        cbNeedsPatch = new javax.swing.JCheckBox();
        cbHasConflict = new javax.swing.JCheckBox();
        cbUnknown = new javax.swing.JCheckBox();
        panel.setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints1;

        lblTitle.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.lblTitle.text")); // NOI18N
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 0;
        gridBagConstraints1.weightx = 1.0;
        gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 11);
        panel.add(lblTitle, gridBagConstraints1);

        cbUptodate.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbUptodate.text")); // NOI18N
        cbUptodate.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbUptodate.mnemonic").charAt(0)); // NOI18N
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 1;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets (5, 24, 0, 0);
        panel.add(cbUptodate, gridBagConstraints1);
        
        cbModified.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbModified.text")); // NOI18N
        cbModified.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbModified.mnemonic").charAt(0)); // NOI18N        
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 1;
        gridBagConstraints1.gridy = 1;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets (5, 12, 0, 11);
        panel.add(cbModified, gridBagConstraints1);
        
        cbLocAdded.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbLocAdded.text")); // NOI18N
        cbLocAdded.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbLocAdded.mnemonic").charAt(0)); // NOI18N        
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 2;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets (0, 24, 0, 0);
        panel.add(cbLocAdded, gridBagConstraints1);
        
        cbLocRemoved.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbLocRemoved.text")); // NOI18N
        cbLocRemoved.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbLocRemoved.mnemonic").charAt(0)); // NOI18N        
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 1;
        gridBagConstraints1.gridy = 2;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets (0, 12, 0, 11);
        panel.add(cbLocRemoved, gridBagConstraints1);
        
        cbNeedsMerge.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbNeedsMerge.text")); // NOI18N
        cbNeedsMerge.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbNeedsMerge.mnemonic").charAt(0)); // NOI18N
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 3;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets (0, 24, 0, 0);
        panel.add(cbNeedsMerge, gridBagConstraints1);

        cbNeedsPatch.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbNeedsPatch.text")); // NOI18N
        cbNeedsPatch.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbNeedsPatch.mnemonic").charAt(0)); // NOI18N
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 1;
        gridBagConstraints1.gridy = 3;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets (0, 12, 0, 11);
        panel.add(cbNeedsPatch, gridBagConstraints1);

        cbNeedsCheckout.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbNeedsCheckout.text")); // NOI18N
        cbNeedsCheckout.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbNeedsCheckout.mnemonic").charAt(0)); // NOI18N
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 4;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets (0, 24, 0, 0);
        panel.add(cbNeedsCheckout, gridBagConstraints1);
        
        cbHasConflict.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbHasConflicts.text")); // NOI18N
        cbHasConflict.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbHasConflicts.mnemonic").charAt(0)); // NOI18N
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 1;
        gridBagConstraints1.gridy = 4;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets (0, 12, 0, 11);
        panel.add(cbHasConflict, gridBagConstraints1);

        cbUnknown.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbUnknown.text")); // NOI18N
        cbUnknown.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.cbUnknown.mnemonic").charAt(0)); // NOI18N
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 5;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints1.insets = new java.awt.Insets (0, 24, 0, 0);
        panel.add(cbUnknown, gridBagConstraints1);
        
        lblCount.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/status/Bundle").getString("StatusTreeInfoPanel.lblCount")); // NOI18N
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 6;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints1.insets = new java.awt.Insets(12, 12, 2, 11);
        panel.add(lblCount, gridBagConstraints1);
        
//---- END OF COPIED STUFF ===========================================================================
// ===================*******************************************=====================================
        ActionListener listener = (new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkBoxChanged();
            }
        });
        cbUptodate.addActionListener(listener);
        cbModified.addActionListener(listener);
        cbNeedsPatch.addActionListener(listener);
        cbNeedsMerge.addActionListener(listener);
        cbHasConflict.addActionListener(listener);
        cbLocAdded.addActionListener(listener);
        cbLocRemoved.addActionListener(listener);
        cbNeedsCheckout.addActionListener(listener);
        cbUnknown.addActionListener(listener);
        cbUptodate.setSelected(true);
        cbModified.setSelected(true);
        cbNeedsPatch.setSelected(true);
        cbNeedsMerge.setSelected(true);
        cbHasConflict.setSelected(true);
        cbLocAdded.setSelected(true);
        cbLocRemoved.setSelected(true);
        cbNeedsCheckout.setSelected(true);
        cbUnknown.setSelected(true);
    }
    
    public Component getTreeCellRendererComponent(JTree tree, Object value, 
                                                    boolean sel, boolean expanded, 
                                                    boolean leaf, int row, boolean hasFocus) {
      Component comp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
      if (comp instanceof JLabel) {
          JLabel label = (JLabel) comp;
          DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
          if (node != null) {
              Object userObj = node.getUserObject();
              if (userObj != null) {
                 if (userObj instanceof StatusInformation) { //is statusInfo
                      StatusInformation info = (StatusInformation)userObj;
                      String status = statusManager.getStatus(statusManager.convertStatus(info.getStatus()));
                      label.setText(info.getFile().getName() + "  [" + status + "]"); // NOI18N
                  }
              }
          }
          
      }
      return comp;
  }
/*  
  public Component getListCellRendererComponent(javax.swing.JList list,Object value,int index,boolean isSelected,boolean cellHasFocus) {
      JLabel comp = (JLabel) super.getListCellRendererComponent(list, 
                                                              value, index, isSelected, cellHasFocus);
      StatusInformation info = (StatusInformation) value;
      String name = comp.getText();
      name = statusManager.getStatus(statusManager.convertStatus(info.getStatus())) + "\t" + name;
      comp.setText(name);
      return comp;
  }
  */  
  /** Does the actual display - docking into the javacvs Mode, 
 *  displaying as single Dialog.. whatever.
 */
  public void displayOutputData() {
      String title = NbBundle.getMessage(StatusTreeInfoPanel.class, "CvsStatus.dialogTitle", topDirectory.getName()); // NOI18N
      FsCommandFactory.displayOutputPanel(title, this);

  }
  
  /** in this method the displayer should use the data returned by the command to
 * produce it's own data structures/ fill in UI components
 * @param resultList - the data from the command. It is assumed the Displayer 
 * knows what command the data comes from and most important in what format. 
 * (which FileInfoContainer class is used).
 */
  public void setDataToDisplay(Collection resultList) {
      totalCount = 0;
      selectedCount = 0;
      super.setDataToDisplay(resultList);
      Integer selCount = new Integer(selectedCount);
      Integer totCount = new Integer(totalCount);
      String txt = NbBundle.getMessage(StatusTreeInfoPanel.class, "StatusTreeInfoPanel.lblCount", // NOI18N
                              selCount.toString(), totCount.toString());
      lblCount.setText(txt);
  }
  
  /** to be overidden in case more than the filemane is to be displaed in the Table
   * it needs to be a tablemodel implementing the CommandTableModel methods
 */
  protected TableInfoModel createTableModel() {
        TableInfoModel model = new TableInfoModel();
        Class classa = StatusInformation.class;
        String  column1 = NbBundle.getBundle(StatusTreeInfoPanel.class).getString("StatusTableInfoModel.status"); // NOI18N
        String  column2 = NbBundle.getBundle(StatusTreeInfoPanel.class).getString("StatusTableInfoModel.fileName"); // NOI18N
        try {
            Method method1 = classa.getMethod("getStatus", null);     // NOI18N
            Method method2 = classa.getMethod("getFile", null);     // NOI18N
            model.setColumnDefinition(0, column1, method1, true, new StatusComparator());
            model.setColumnDefinition(1, column2, method2, true, new FileComparator());
        } catch (NoSuchMethodException exc) {
            Thread.dumpStack();
        } catch (SecurityException exc2) {
            Thread.dumpStack();
        }
        return model;
  }  

  /** Does the actual display - docking into the javacvs Mode, 
   *  displaying as single Dialog.. whatever.
 */
/*  public void displayOutputData(int moment,Object data) {
      if (moment == CommandDisplayer.MOMENT_AFTER_EACH_EXECUTE) {
          Collection col = (Collection)data;
         setDataToDisplay(col);
         displayOutputData();          
      }
  }  
 */
  
  public JComponent getComponent() {
      return this;
  }
  
  public Object getComparisonData() {
      return topDirectory;
  }
  
  /**
   * Persistent stuff...
   */
  public boolean equalDisplayedData(File file, Class type, Object comparisonData) {
      if (!getClass().equals(type)) return false;
      if (topDirectory == null || 
                !topDirectory.equals(file)) {
          return false;
      }
      return true;
  }
  
  public File getFileDisplayed() {
      return topDirectory;
  }
  
  
  public String getCommandSwitches() {
      return command.getCVSArguments();
  }
  
  
  public FileSystemCommand getFileSystemCommand() {
      return command;
  }
  
}
... 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.