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

The following examples show how to use org.eclipse.swt.widgets.Display#update() . 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 check out the related API usage on the sidebar.
Example 1
Source File: AbstractWorkbenchTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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
Source File: ProjectModelTestData.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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
Source File: QuickMenuDialog.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
Source File: MultiLineListExample.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: SimpleModelExample.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: TableHierarchicalExample.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: TableExample.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: MultiLineListExample.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: SimpleModelExample.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: TableHierarchicalExample.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: TableExample.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: AbstractWorkbenchTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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
Source File: RenameStrategyTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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
Source File: SWTUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
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
Source File: TestUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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
Source File: TypeHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void processOutstandingEvents() {
	Display display= getDisplay();
	if (display != null && !display.isDisposed())
		display.update();
}