PageRenderTime 16ms CodeModel.GetById 11ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/Console/console/commando/CommandoThread.java

#
Java | 123 lines | 78 code | 10 blank | 35 comment | 10 complexity | 10715191b2f0126490a225846863197e MD5 | raw file
  1/*
  2 * CommandoThread.java - Thread that runs commando commands
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2001 Slava Pestov
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package console.commando;
 24
 25//{{{ Imports
 26import console.*;
 27import javax.swing.*;
 28import java.util.Vector;
 29import org.gjt.sp.jedit.*;
 30import org.gjt.sp.util.Log;
 31//}}}
 32// {{{ commandothread class
 33class CommandoThread extends Thread
 34{
 35	//{{{ CommandoThread constructor
 36	/**
 37	 * @param console the console to execute the command.
 38	 * @param commands actually a Vector of command objects
 39	 */
 40	CommandoThread(Console console, Vector<CommandoHandler.Command> commands)
 41	{
 42		this.console = console;
 43		this.commands = commands;
 44	} //}}}
 45
 46	//{{{ run() method
 47	public void run()
 48	{
 49		final View view = console.getView();
 50
 51		final CommandoHandler.Command[] lastCommand = new CommandoHandler.Command[1];
 52		final boolean[] returnValue = new boolean[] { true };
 53
 54		for(int i = 0; i < commands.size(); i++)
 55		{
 56			final CommandoHandler.Command command =
 57				(CommandoHandler.Command)commands.elementAt(i);
 58			final Shell shell = console.setShell(command.shell);
 59			// final Shell shell = Shell.getShell(command.shell);
 60			if(shell == null)
 61			{
 62				SwingUtilities.invokeLater(new Runnable()
 63				{
 64					public void run()
 65					{
 66						GUIUtilities.error(view,"commando.bad-shell",
 67							new String[] { command.shell });
 68					}
 69				});
 70
 71				return;
 72			}
 73
 74			try
 75			{
 76				SwingUtilities.invokeAndWait(new Runnable()
 77				{
 78					public void run()
 79					{
 80						//{{{ Get confirmation if bad exit status...
 81						if(!returnValue[0])
 82						{
 83							if(GUIUtilities.confirm(view,
 84								"commando.exit-status",
 85								new String[] { lastCommand[0].command },
 86								JOptionPane.YES_NO_OPTION,
 87								JOptionPane.ERROR_MESSAGE)
 88								!= JOptionPane.YES_OPTION)
 89								return;
 90						} //}}}
 91
 92						//{{{ Get confirmation if user specified...
 93						if(command.confirm)
 94						{
 95							if(GUIUtilities.confirm(view,
 96								"commando.confirm",
 97								new String[] { command.command },
 98								JOptionPane.YES_NO_OPTION,
 99								JOptionPane.QUESTION_MESSAGE)
100								!= JOptionPane.YES_OPTION)
101								return;
102						} //}}}
103
104						Output out = console.getOutput();
105						if (command.toBuffer)
106							out = new BufferOutput(console, command.mode);
107						console.run(shell, null,  out, null, command.command);
108					}
109				});
110			}
111			catch(Exception e)
112			{
113			}
114
115			returnValue[0] = shell.waitFor(console);
116			lastCommand[0] = command;
117		}
118	} //}}}
119	// {{{ Data Members
120	private Console console;
121	private Vector<CommandoHandler.Command> commands;
122	// }}}
123}// }}}