/*
*
* Perforce/JBuilder Opentool
* Copyright (C) 2002 Mark Ackerman
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.dafreels.opentools.actions.ui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.text.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.dnd.peer.*;
import java.io.*;
import com.dafreels.opentools.actions.*;
import com.dafreels.opentools.properties.*;
import com.dafreels.opentools.*;
import com.dafreels.vcs.command.*;
import com.dafreels.vcs.util.*;
import com.borland.primetime.actions.*;
import com.borland.primetime.ide.*;
/**
* <p>Title: Perforce Open Tool </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: RMA</p>
* @author Mark Ackerman
*
*/
public class SubmittedChangeListDialog extends JDialog
{
private static final String SLASH_SLASH = "//";
private static final String DEFAULT = "default";
private static final String CHANGE = "Change";
private static final String NEW = "new";
private JTable _changeListTable;
private DefaultTableModel _model;
private Object[] _columns = new Object[]{ "ChangeList", "Date", "User", "Description" };
/**
* create a new ChangeList dialog
* @param parent the Frame owner
* @param modal true for a modal dialog
*/
public SubmittedChangeListDialog(Frame parent, boolean modal)
{
super(parent, modal);
setTitle("Submitted Perforce Changelists");
getContentPane().setLayout(new BorderLayout());
JPanel centerPanel = new JPanel(new GridBagLayout());
getContentPane().add(centerPanel, BorderLayout.CENTER);
createToolbar();
_model = new DefaultTableModel( _columns, 0);
_changeListTable = new JTable(_model)
{
public boolean isCellEditable(int row, int col)
{
return false;
}
};
TableColumnModel tc = _changeListTable.getColumnModel();
tc.getColumn(0).setMinWidth(25);
tc.getColumn(0).setMinWidth(25);
tc.getColumn(1).setMinWidth(30);
tc.getColumn(1).setMinWidth(30);
tc.getColumn(2).setMinWidth(40);
tc.getColumn(2).setMinWidth(40);
_changeListTable.setGridColor(_changeListTable.getBackground());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(5,5,0,5);
gbc.weightx = 1.0;
gbc.weighty = 1.0;
centerPanel.add(new JScrollPane(_changeListTable), gbc);
JButton button = new JButton("OK");
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.SOUTH;
gbc.fill = GridBagConstraints.NONE;
gbc.insets = new Insets(5,5,0,5);
centerPanel.add(button, gbc);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
});
_changeListTable.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if ( SwingUtilities.isRightMouseButton(e))
{
displayPopupMenu(e.getPoint());
}
if ( e.getClickCount() == 2)
{
describeChangeList(e.getPoint());
/*
int row = _changeListTable.rowAtPoint(e.getPoint());
if ( row == -1 )
{
return;
}
String changeNum = (String)_changeListTable.getValueAt(row,0);
try
{
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
Vector changeList = getChangeList();
new DescribeAction(changeNum, changeList);
}
finally
{
setCursor(Cursor.getDefaultCursor());
}
*/
}
}
});
pack();
setLocationRelativeTo(getParent());
}
protected void describeChangeList(Point pt)
{
int row = _changeListTable.rowAtPoint(pt);
if ( row == -1 )
{
return;
}
String changeNum = (String)_changeListTable.getValueAt(row,0);
describeChangeList(changeNum);
}
protected void describeChangeList(String changeNum)
{
try
{
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
Vector changeList = getChangeList();
new DescribeAction(changeNum, changeList);
}
finally
{
setCursor(Cursor.getDefaultCursor());
}
}
protected void displayPopupMenu(Point p)
{
if ( p == null )
{
return;
}
int row = _changeListTable.rowAtPoint(p);
if ( row == -1 )
{
return;
}
_changeListTable.getSelectionModel().setSelectionInterval(row, row);
final String changeNum = (String)_changeListTable.getValueAt(row, 0);
JPopupMenu popup = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Describe ChangeList "+changeNum);
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
describeChangeList(changeNum);
}
});
popup.add(menuItem);
JMenuItem menu = new JMenu("Integrate");
popup.add(menu);
menuItem = new JMenuItem("using BranchSpec");
menu.add(menuItem);
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
integrateBranchSpec(changeNum);
}
});
/*
popup.addSeparator();
menuItem = new JMenuItem("Refresh");
popup.add(menuItem);
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
*/
popup.show(_changeListTable, (int)p.getX(), (int)p.getY());
}
protected void integrateBranchSpec(String changeNum)
{
FileIntegrateDialog dialog= new FileIntegrateDialog(Browser.getActiveBrowser(),
isModal());
dialog.setSelectedFiles(getFilesForChangeList(changeNum));
dialog.setChangeListNumber(changeNum);
dialog.setVisible(true);
}
protected void createToolbar()
{
}
protected Vector getChangeList()
{
int rowCnt = _changeListTable.getRowCount();
Vector v = new Vector(rowCnt);
for (int i = 0; i < rowCnt; i++ )
{
v.add(_changeListTable.getValueAt(i, 0));
}
return v;
}
/**
* fill this dialog with the contents of formatter
* @param formatter the output from the <code>opened</code> command
*/
public void fillForm(MessageFormatter formatter)
{
String message, arg;
SimpleAttributeSet attrs;
PropertyInterface props = Main.m_props;
formatter.getNextMessage(); // throw away first line
MessageWriter.outputErrorMessages(MessageFormatter.getInstance());
int idx;
String file, cmd, change, type;
boolean locked;
_model = new DefaultTableModel(_columns, 0);
/* entries look like
Change 445 on 2002/06/03 by shannon@JAROD
Fixed an error with reading the id from the data lineA
*/
StringTokenizer tokenizer;
while( (message = formatter.getNextMessage()) != null)
{
if ( !message.startsWith(CHANGE))
{
continue;
}
readChange(message, formatter);
}
_changeListTable.setModel(_model);
}
private void readChange(String message,MessageFormatter formatter)
{
String line;
StringTokenizer tokenizer = new StringTokenizer(message, " ");
if (tokenizer.countTokens() < 6 )
{
System.out.println("fillForm: invalid Change line "+message);
return;
}
Vector row = null;
try
{
System.out.println("reading changelist "+ message);
row = new Vector(4);
tokenizer.nextToken(); // Change
row.add(tokenizer.nextToken()); // change #
tokenizer.nextToken(); // on
row.add(tokenizer.nextToken()); // date
tokenizer.nextToken(); // by
row.add(tokenizer.nextToken()); // user
line = formatter.getNextMessage(); // s/b a blank line
if (line == null )
{
return;
}
if (line.length() == 0 )
{
line = formatter.getNextMessage();
}
if ( line == null )
{
return;
}
if ( line.charAt(0) == '\t' )
{
row.add(line.substring(1, line.length()-1));
}
}
finally
{
if ( row != null )
{
_model.addRow(row);
}
}
}
protected java.util.List getFilesForChangeList(String changeNum)
{
Command cmd = new Command(Command.DESCRIBE);
cmd.addPath("-s");
cmd.addPath(changeNum);
CommandTool.runCommand(cmd, Main.m_props);
MessageFormatter fmt = MessageFormatter.getInstance();
String line;
if ( fmt.getErrorMessageCount() > 0 )
{
MessageWriter.outputErrorMessages(fmt);
}
int idx;
ArrayList files = new ArrayList();
while ((line = fmt.getNextMessage())!= null )
{
if ( line.startsWith("..."))
{
line = line.substring(4);
idx = line.indexOf("#");
if ( idx == -1 )
{
files.add(line);
}
else
{
line = line.substring(0,idx);
files.add(line);
}
}
}
return files;
}
}