Java Code Examples for org.eclipse.swt.widgets.Display#update()

The following examples show how to use org.eclipse.swt.widgets.Display#update() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Deprecated
protected void sleep(long i) throws InterruptedException {
	Display displ = Display.getCurrent();
	if (displ != null) {
		long timeToGo = System.currentTimeMillis() + i;
		while (System.currentTimeMillis() < timeToGo) {
			if (!displ.readAndDispatch()) {
				displ.sleep();
			}
		}
		displ.update();
	}
	else {
		Thread.sleep(i);
	}
}
 
Example 2
/**
 * Makes the main display thread sleep, so it gives a chance to other
 * threads needing the main display to execute
 *
 * @param waitTimeMillis
 *            time to wait in millisecond
 */
public static void delayThread(final long waitTimeMillis) {
    final Display display = Display.getCurrent();
    if (display != null) {
        final long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
        while (System.currentTimeMillis() < endTimeMillis) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
            display.update();
        }
    } else {
        try {
            Thread.sleep(waitTimeMillis);
        } catch (final InterruptedException e) {
            // Ignored
        }
    }
}
 
Example 3
/**
 * Runs the event loop for the given shell.
 * 
 * @param loopShell
 *            the shell
 */
private void runEventLoop(Shell loopShell)
{
	// Use the display provided by the shell if possible
	Display display = loopShell.getDisplay();
	while (!loopShell.isDisposed())
	{
		try
		{
			if (!display.readAndDispatch())
			{
				display.sleep();
			}
		}
		catch (Throwable e)
		{
			// FIXME Handle exception in some way
			// exceptionHandler.handleException(e);
		}
	}
	if (!display.isDisposed())
		display.update();
}
 
Example 4
public MultiLineListExample(IJaretTableModel tableModel) {
    _tableModel = tableModel;
    _shell = new Shell(Display.getCurrent());
    _shell.setText("jaret table multilinelist");
    createControls();
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(280, 400);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 5
public SimpleModelExample(IJaretTableModel tableModel) {
    _tableModel = tableModel;
    _shell = new Shell(Display.getCurrent());
    _shell.setText("simple jaret table example");
    createControls();
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(1000, 700);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 6
public TableHierarchicalExample(IHierarchicalJaretTableModel hierarchicalModel) {
    _shell = new Shell(Display.getCurrent());
    _shell.setText("jaret table hierarchical example");
    createControls(hierarchicalModel);
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(400, 700);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 7
public TableExample(IJaretTableModel tableModel) {
    _tableModel = tableModel;
    _shell = new Shell(Display.getCurrent());
    _shell.setText("jaret table example");
    createControls();
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(1000, 700);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 8
public MultiLineListExample(IJaretTableModel tableModel) {
    _tableModel = tableModel;
    _shell = new Shell(Display.getCurrent());
    _shell.setText("jaret table multilinelist");
    createControls();
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(280, 400);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 9
public SimpleModelExample(IJaretTableModel tableModel) {
    _tableModel = tableModel;
    _shell = new Shell(Display.getCurrent());
    _shell.setText("simple jaret table example");
    createControls();
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(1000, 700);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 10
public TableHierarchicalExample(IHierarchicalJaretTableModel hierarchicalModel) {
    _shell = new Shell(Display.getCurrent());
    _shell.setText("jaret table hierarchical example");
    createControls(hierarchicalModel);
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(400, 700);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 11
public TableExample(IJaretTableModel tableModel) {
    _tableModel = tableModel;
    _shell = new Shell(Display.getCurrent());
    _shell.setText("jaret table example");
    createControls();
    _shell.open();
    Display display;
    display = _shell.getDisplay();
    _shell.pack();
    _shell.setSize(1000, 700);

    /*
     * do the event loop until the shell is closed to block the call
     */
    while (_shell != null && !_shell.isDisposed()) {
        try {
            if (!display.readAndDispatch())
                display.sleep();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    display.update();
}
 
Example 12
protected void sleep(long i) throws InterruptedException {
	Display displ = Display.getCurrent();
	if (displ != null) {
		long timeToGo = System.currentTimeMillis() + i;
		while (System.currentTimeMillis() < timeToGo) {
			if (!displ.readAndDispatch()) {
				displ.sleep();
			}
		}
		displ.update();
	}
	else {
		Thread.sleep(i);
	}
}
 
Example 13
private <T> void sleepWhile(Predicate<T> test, Provider<T> input, long timeOutInMillis) {
	Display display = Display.getCurrent();
	long timeToGo = System.currentTimeMillis() + timeOutInMillis;
	while (System.currentTimeMillis() < timeToGo && test.apply(input.get())) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
	display.update();
}
 
Example 14
public static void delay(long waitTimeMillis) {
  Display display = Display.getCurrent();

  // If this is the UI thread, then process input.
  if (display != null) {

    /*
     * We set up a timer on the UI thread that fires after the desired wait
     * time. We do this because we want to make sure that the UI thread wakes
     * up from a display.sleep() call. We set a flag in the runnable so that
     * we can terminate the wait loop.
     */
    final boolean[] hasDeadlineTimerFiredPtr = {false};

    display.timerExec((int) waitTimeMillis, new Runnable() {
      public void run() {

        /*
         * We don't have to worry about putting a lock around the update/read
         * of this variable. It is only accessed by the UI thread, and there
         * is only one UI thread.
         */
        hasDeadlineTimerFiredPtr[0] = true;
      }
    });

    while (!hasDeadlineTimerFiredPtr[0]) {

      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }

    display.update();
  } else {
    try {
      // Otherwise, perform a simple sleep.
      Thread.sleep(waitTimeMillis);
    } catch (InterruptedException e) {
      // Ignored
    }
  }
}
 
Example 15
/**
 * Waits for the specified number of milliseconds.
 */
public static void delay(long waitTimeMillis) {
  Display display = Display.getCurrent();

  // If this is the UI thread, then process input.
  if (display != null) {

    /*
     * We set up a timer on the UI thread that fires after the desired wait time. We do this
     * because we want to make sure that the UI thread wakes up from a display.sleep() call. We
     * set a flag in the runnable so that we can terminate the wait loop.
     */
    final boolean[] hasDeadlineTimerFiredPtr = {false};

    display.timerExec((int) waitTimeMillis, new Runnable() {
      @Override
      public void run() {

        /*
         * We don't have to worry about putting a lock around the update/read of this variable. It
         * is only accessed by the UI thread, and there is only one UI thread.
         */
        hasDeadlineTimerFiredPtr[0] = true;
      }
    });

    while (!hasDeadlineTimerFiredPtr[0]) {

      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }

    display.update();
  } else {
    try {
      // Otherwise, perform a simple sleep.
      Thread.sleep(waitTimeMillis);
    } catch (InterruptedException e) {
      // Ignored
    }
  }
}
 
Example 16
private void processOutstandingEvents() {
	Display display= getDisplay();
	if (display != null && !display.isDisposed())
		display.update();
}