PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package console.commando;
  23. //{{{ Imports
  24. import console.*;
  25. import javax.swing.*;
  26. import java.util.Vector;
  27. import org.gjt.sp.jedit.*;
  28. import org.gjt.sp.util.Log;
  29. //}}}
  30. // {{{ commandothread class
  31. class CommandoThread extends Thread
  32. {
  33. //{{{ CommandoThread constructor
  34. /**
  35. * @param console the console to execute the command.
  36. * @param commands actually a Vector of command objects
  37. */
  38. CommandoThread(Console console, Vector<CommandoHandler.Command> commands)
  39. {
  40. this.console = console;
  41. this.commands = commands;
  42. } //}}}
  43. //{{{ run() method
  44. public void run()
  45. {
  46. final View view = console.getView();
  47. final CommandoHandler.Command[] lastCommand = new CommandoHandler.Command[1];
  48. final boolean[] returnValue = new boolean[] { true };
  49. for(int i = 0; i < commands.size(); i++)
  50. {
  51. final CommandoHandler.Command command =
  52. (CommandoHandler.Command)commands.elementAt(i);
  53. final Shell shell = console.setShell(command.shell);
  54. // final Shell shell = Shell.getShell(command.shell);
  55. if(shell == null)
  56. {
  57. SwingUtilities.invokeLater(new Runnable()
  58. {
  59. public void run()
  60. {
  61. GUIUtilities.error(view,"commando.bad-shell",
  62. new String[] { command.shell });
  63. }
  64. });
  65. return;
  66. }
  67. try
  68. {
  69. SwingUtilities.invokeAndWait(new Runnable()
  70. {
  71. public void run()
  72. {
  73. //{{{ Get confirmation if bad exit status...
  74. if(!returnValue[0])
  75. {
  76. if(GUIUtilities.confirm(view,
  77. "commando.exit-status",
  78. new String[] { lastCommand[0].command },
  79. JOptionPane.YES_NO_OPTION,
  80. JOptionPane.ERROR_MESSAGE)
  81. != JOptionPane.YES_OPTION)
  82. return;
  83. } //}}}
  84. //{{{ Get confirmation if user specified...
  85. if(command.confirm)
  86. {
  87. if(GUIUtilities.confirm(view,
  88. "commando.confirm",
  89. new String[] { command.command },
  90. JOptionPane.YES_NO_OPTION,
  91. JOptionPane.QUESTION_MESSAGE)
  92. != JOptionPane.YES_OPTION)
  93. return;
  94. } //}}}
  95. Output out = console.getOutput();
  96. if (command.toBuffer)
  97. out = new BufferOutput(console, command.mode);
  98. console.run(shell, null, out, null, command.command);
  99. }
  100. });
  101. }
  102. catch(Exception e)
  103. {
  104. }
  105. returnValue[0] = shell.waitFor(console);
  106. lastCommand[0] = command;
  107. }
  108. } //}}}
  109. // {{{ Data Members
  110. private Console console;
  111. private Vector<CommandoHandler.Command> commands;
  112. // }}}
  113. }// }}}