'ProgressMonitor thread'에 해당되는 글 2건

ProgressMonitor with UI

Eclipse 2010. 8. 11. 18:03

IRunnableWithProgress runnable = new IRunnableWithProgress()
{

 public void run(IProgressMonitor progressMonitor)
 {

  ...
  progressMonitor.beginTask("Generating DDL(s)", count);

  ...

  }

  progressMonitor.done();
 }
};

progressMonitor.run(false, true, runnable); <- fork should be false

* void org.eclipse.jface.dialogs.ProgressMonitorDialog.run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException

If fork is set to false, the runnable will run in the UI thread and it is the runnable's responsibility to call Display.readAndDispatch() to ensure UI responsiveness.

Posted by zennken

출처: http://www.ibm.com/developerworks/kr/library/os-eclipse-custwiz/

문제: Child method에서 발생하는 메세지 다이얼로그를 열 수가 없다. 이유는 Thread.
핵심: InvocationTargetException을 이용하여 수행하고자 하는 메서드에서 던지는 Exception을 받아서 처리한다.


    /**
     * This method is called when 'Finish' button is pressed in
     * the wizard. We will create an operation and run it
     * using wizard as execution context.
     */
    public boolean performFinish() {
        final String containerName = page.getContainerName();
        final String fileName = page.getFileName();
        IRunnableWithProgress op = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                try {
                    doFinish(containerName, fileName, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        };
        try {
            getContainer().run(true, false, op);
        } catch (InterruptedException e) {
            return false;
        } catch (InvocationTargetException e) {
            Throwable realException = e.getTargetException();
            MessageDialog.openError(getShell(), "Error", realException.getMessage());
            return false;
        }
        return true;
    }
Posted by zennken
1

zennken

달력