1 14 package org.compiere.apps; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import javax.swing.*; 19 20 import org.compiere.util.*; 21 import org.compiere.plaf.*; 22 23 29 public class ATask extends JFrame implements ActionListener 30 { 31 36 static public void start (final String title, final String command) 37 { 38 new Thread () 39 { 40 public void run() 41 { 42 new ATask(title, command); 43 } 44 }.start(); 45 } 47 48 49 50 51 55 public ATask() 56 { 57 this("",""); 58 } 60 65 public ATask (String title, String command) 66 { 67 super (title); 68 Log.trace(Log.l1_User, "ATask", title + " - " + command); 69 try 70 { 71 jbInit(); 72 } 73 catch(Exception e) 74 { 75 Log.error("ATask",e); 76 } 77 AEnv.showCenterScreen(this); 78 executeCommand (command); 79 } 81 private Task m_task = null; 82 83 84 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 85 private JScrollPane infoScrollPane = new JScrollPane(); 86 private JTextArea info = new JTextArea(); 87 88 92 private void jbInit() throws Exception 93 { 94 CompiereColor.setBackground(this); 95 info.setEditable(false); 96 info.setBackground(CompierePLAF.getFieldBackground_Inactive()); 97 infoScrollPane.getViewport().add(info, null); 98 infoScrollPane.setPreferredSize(new Dimension(500,300)); 99 this.getContentPane().add(infoScrollPane, BorderLayout.CENTER); 100 this.getContentPane().add(confirmPanel, BorderLayout.SOUTH); 101 confirmPanel.addActionListener(this); 103 confirmPanel.getOKButton().setEnabled(false); 104 } 106 110 public void executeCommand (String command) 111 { 112 String cmd = Msg.parseTranslation(Env.getCtx(), command); 113 Log.trace(Log.l3_Util, "ATask.executeCommand", cmd); 114 if (command == null || command.equals("")) 115 return; 116 117 if (m_task != null && m_task.isAlive()) 118 m_task.interrupt(); 119 120 m_task = new Task(cmd); 121 m_task.start(); 122 123 while (true) 124 { 125 try 127 { 128 Thread.sleep(500); 129 } 130 catch (InterruptedException ioe) 131 { 132 Log.error("ATask.executeCommand", ioe); 133 } 134 StringBuffer sb = new StringBuffer (); 136 sb.append(m_task.getOut()).append("\n-------\n") 137 .append(m_task.getErr()).append("\n-------"); 138 info.setText(sb.toString()); 139 140 if (!m_task.isAlive()) 142 { 143 confirmPanel.getCancelButton().setEnabled(false); 144 confirmPanel.getOKButton().setEnabled(true); 145 break; 146 } 147 } 148 Log.trace(Log.l3_Util, "ATask.executeCommand - done"); 149 } 151 155 public void actionPerformed (ActionEvent e) 156 { 157 if (m_task != null && m_task.isAlive()) 158 m_task.interrupt(); 159 dispose(); 160 } 162 } | Popular Tags |