Search in sources :

Example 1 with OSTask

use of org.adempiere.webui.util.OSTask in project adempiere by adempiere.

the class WTask method executeTask.

//  ATask
public void executeTask() {
    Runnable runnable = new Runnable() {

        public void run() {
            //get full control of desktop
            org.zkoss.zk.ui.Desktop desktop = WTask.this.getDesktop();
            String cmd = Msg.parseTranslation(Env.getCtx(), m_task.getOS_Command()).trim();
            if (cmd == null || cmd.equals(""))
                info.setContent("Cannot execute '" + m_task.getOS_Command() + "'");
            OSTask osTask = new OSTask(cmd);
            osTask.start();
            while (true) {
                try {
                    Thread.sleep(500);
                    Executions.activate(desktop, 500);
                    try {
                        StringBuffer sb = new StringBuffer();
                        sb.append(osTask.getOut()).append("<br>-----------<br>").append(osTask.getErr()).append("<br>-----------");
                        info.setContent(sb.toString().replace("\n", "<br>"));
                        if (!osTask.isAlive()) {
                            confirmPanel.getButton(ConfirmPanel.A_CANCEL).setEnabled(false);
                            confirmPanel.getOKButton().setEnabled(true);
                            break;
                        }
                    } finally {
                        //release full control of desktop
                        Executions.deactivate(desktop);
                    }
                } catch (DesktopUnavailableException e) {
                    log.log(Level.FINE, e.getLocalizedMessage(), e);
                    osTask.interrupt();
                    break;
                } catch (InterruptedException e) {
                    log.log(Level.FINE, e.getLocalizedMessage(), e);
                    osTask.interrupt();
                    break;
                }
            }
        }
    };
    taskThread = new Thread(runnable);
    taskThread.start();
}
Also used : OSTask(org.adempiere.webui.util.OSTask) DesktopUnavailableException(org.zkoss.zk.ui.DesktopUnavailableException)

Aggregations

OSTask (org.adempiere.webui.util.OSTask)1 DesktopUnavailableException (org.zkoss.zk.ui.DesktopUnavailableException)1