/*
*
* Perforce/JBuilder Opentool
* Copyright (C) 2001 David Freels
*
* 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;
import com.borland.primetime.*;
import com.borland.primetime.actions.*;
import com.borland.primetime.node.*;
import com.borland.jbuilder.*;
import com.borland.primetime.ide.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Vector;
import com.dafreels.opentools.actions.ui.SubmitDialog;
import com.dafreels.opentools.properties.*;
import com.dafreels.opentools.command.*;
import com.dafreels.opentools.Main;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company: DF Systems
* @author David Freels
* @version 1.0
*/
public class SubmitAction extends BrowserAction
{
private final static String newLine = System.getProperty("line.separator");
private final SubmitDialog _sd = new SubmitDialog(Browser.getActiveBrowser(),
"Perforce Change Specification", false);
public SubmitAction()
{
super("Submit");
}
public void actionPerformed(Browser browser)
{
//Get a list of the selected nodes
Node[] nodes = browser.getProjectView().getSelectedNodes(browser.getActiveProject());
//Get the change list
StringBuffer changeList = new StringBuffer("");
//Get a list of files
CommandTool.runCommand("opened", false, false, false);
String cl = CommandTool.getOutput();
java.util.Vector data = new java.util.Vector();
java.util.Vector files = new java.util.Vector();
java.util.Vector dataInteg = new java.util.Vector();
//Create a file list
String tmp = "";
while(cl.indexOf(newLine) != -1) // && cl.indexOf("#") != -1)
{
data = new java.util.Vector();
tmp = cl.substring(0, cl.indexOf(newLine));
cl = cl.substring(cl.indexOf(newLine) + newLine.length());
if(tmp.lastIndexOf("//") != -1)
{
tmp = tmp.substring(tmp.lastIndexOf("//"));
}
if(tmp.indexOf("#") > -1)
{
tmp = tmp.substring(0, tmp.indexOf("#"));
}
if(!dataInteg.contains(tmp) && tmp.indexOf("//") == 0)
{
data.add(new Boolean("true"));
data.add(tmp.trim());
dataInteg.add(tmp.trim());
files.add(data);
}
}
//This is no longer needed
dataInteg = null;
tmp = null;
//Displat the dialog
_sd.showSubmit(files);
//Return if the user clicks cancel
if(!_sd.getState())
{
return;
}
//Create the changeList
changeList.append("Change: new"+newLine);
changeList.append(" "+newLine);
changeList.append("Client: "+PerforceGroup.CLIENTSPEC.getValue(browser.getActiveProject())+newLine);
changeList.append(" "+newLine);
changeList.append("User: "+PerforceGroup.USERNAME.getValue(browser.getActiveProject())+newLine);
changeList.append(" "+newLine);
changeList.append("Status: new "+newLine);
changeList.append(" "+newLine);
changeList.append("Description: "+newLine);
//Add the description given by the user
changeList.append(_sd.getDescription());
changeList.append(" "+newLine);
changeList.append("Files: "+newLine);
//Get the files list from the dialog
files = _sd.getFiles();
Vector v;
//Add the files to the changeList
for(int i = 0; i < files.size(); i++)
{
v = (Vector) files.elementAt(i);
changeList.append("\t"+v.elementAt(1)+newLine);
}
//Create the command
StringBuffer sb = new StringBuffer("submit -i");
//Run the command
CommandTool.runCommand(sb.toString(), true, true, false);
while(!CommandTool.isStreamReady())
{
//do nothing
}
CommandTool.writeToOut(changeList.toString());
CommandTool.refreshNodes(nodes);
}
}