Example usage for org.eclipse.jface.bindings.keys KeyStroke isComplete

List of usage examples for org.eclipse.jface.bindings.keys KeyStroke isComplete

Introduction

In this page you can find the example usage for org.eclipse.jface.bindings.keys KeyStroke isComplete.

Prototype

public final boolean isComplete() 

Source Link

Document

Returns whether or not this key stroke is complete.

Usage

From source file:com.rcpcompany.test.utils.ui.UITestUtils.java

License:Open Source License

/**
 * Posts the specified keystroke to the specified control which will get focus.
 * //from  www  .java 2 s .c  o m
 * @param c
 *            the control
 * @param stroke
 *            the text representation of the key-stroke
 */
public static void postKeyStroke(Control c, String stroke) {
    assertNotNull(c);
    assertFalse(c.isDisposed());

    KeyStroke keyStroke = null;
    try {
        keyStroke = KeyStroke.getInstance(stroke);
    } catch (final ParseException ex) {
        fail(stroke + ": " + ex.getMessage());
        return;
    }
    assertTrue(stroke + ": not complete", keyStroke.isComplete());
    // LogUtils.debug(c, stroke + " --> " + keyStroke);

    Event event;

    c.setFocus();

    postModifierKeys(c, keyStroke, true);

    event = new Event();
    event.type = SWT.KeyDown;
    event.stateMask = keyStroke.getModifierKeys();
    event.keyCode = keyStroke.getNaturalKey();
    event.character = (char) event.keyCode;
    event.widget = c;

    // System.out.println("e:: " + ToStringUtils.toString(event));

    assertTrue(stroke + ": post KeyDown", c.getDisplay().post(event));

    event = new Event();
    event.type = SWT.KeyUp;
    event.stateMask = keyStroke.getModifierKeys();
    event.keyCode = keyStroke.getNaturalKey();
    event.character = (char) event.keyCode;
    event.widget = c;

    // System.out.println("e:: " + ToStringUtils.toString(event));

    assertTrue(stroke + ": post KeyUp", c.getDisplay().post(event));

    postModifierKeys(c, keyStroke, false);

    yield();
}

From source file:com.rcpcompany.test.utils.ui.UITestUtils.java

License:Open Source License

/**
 * Posts a mouse event for the specified control and point.
 * /*from  w ww .  j a v a  2  s.  co  m*/
 * @param modifiers
 *            a key stroke specification - only the modifier part is used
 * @param button
 *            the pressed button
 * @param c
 *            the control
 * @param noClicks
 *            the number of clicks
 * @param p
 *            the point
 */
public static void postMouseDown(String modifiers, final int button, final Control c, final int noClicks) {
    final long now = System.currentTimeMillis();

    if (lastMouseOperationExpireTime > now) {
        sleep((int) (lastMouseOperationExpireTime - now));
    }

    KeyStroke keyStroke = null;
    try {
        if (modifiers != null) {
            keyStroke = KeyStroke.getInstance(modifiers);
            assertTrue(keyStroke.isComplete());
        }
    } catch (final ParseException ex) {
        fail(ex.getMessage());
    }

    if (keyStroke != null) {
        c.setFocus();
        postModifierKeys(c, keyStroke, true);
    }

    swtListen(new Runnable() {
        @Override
        public void run() {
            final Event e = new Event();
            for (int i = 1; i <= noClicks; i++) {
                e.type = SWT.MouseDown;
                e.widget = c;
                e.button = button;
                e.count = i;
                // LogUtils.debug(e,
                // "#" + i + ": " + ToStringUtils.toString(e));
                assertTrue(c.getDisplay().post(e));

                /*
                 * Problem on MACOSX: the event handler for the MouseDown event, seems to be actively waiting for
                 * the MouseUp event. While this happens, Display.readAndDispatch is blocked. Not event timer events
                 * are executed, only system events.
                 * 
                 * The "solution" seems to be to avoid all waiting at this point!
                 */
                // sleep(50);
                // yield();

                e.type = SWT.MouseUp;
                e.widget = c;
                e.button = button;
                e.count = i;
                // LogUtils.debug(e,
                // "#" + i + ": " + ToStringUtils.toString(e));
                assertTrue(c.getDisplay().post(e));
                // sleep(50);
            }

        }
    });
    yield();

    if (keyStroke != null) {
        postModifierKeys(c, keyStroke, false);
    }

    lastMouseOperationExpireTime = now + c.getDisplay().getDoubleClickTime() + 50;
}

From source file:com.rcpcompany.uibindings.extests.BaseTestUtils.java

License:Open Source License

/**
 * Posts the specified keystroke to the specified control which will get focus.
 * //from  ww  w  . ja  v a 2 s .  co  m
 * 
 * @param c the control
 * @param stroke the text representation of the key-stroke
 */
public static void postKeyStroke(Control c, String stroke) {
    KeyStroke keyStroke = null;
    try {
        keyStroke = KeyStroke.getInstance(stroke);
    } catch (final ParseException ex) {
        fail(stroke + ": " + ex.getMessage());
    }
    assertTrue(stroke + ": not complete", keyStroke.isComplete());
    // LogUtils.debug(c, stroke + " --> " + keyStroke);

    Event event;

    c.setFocus();

    postModifierKeys(c, keyStroke, true);

    event = new Event();
    event.type = SWT.KeyDown;
    event.stateMask = keyStroke.getModifierKeys();
    event.keyCode = keyStroke.getNaturalKey();
    event.character = (char) event.keyCode;
    event.widget = c;

    // System.out.println("e:: " + ToStringUtils.toString(event));

    assertTrue(stroke + ": post KeyDown", c.getDisplay().post(event));

    event = new Event();
    event.type = SWT.KeyUp;
    event.stateMask = keyStroke.getModifierKeys();
    event.keyCode = keyStroke.getNaturalKey();
    event.character = (char) event.keyCode;
    event.widget = c;

    // System.out.println("e:: " + ToStringUtils.toString(event));

    assertTrue(stroke + ": post KeyUp", c.getDisplay().post(event));

    postModifierKeys(c, keyStroke, false);

    yield();
}

From source file:com.rcpcompany.uibindings.extests.BaseTestUtils.java

License:Open Source License

/**
 * Posts a mouse event for the specified control and point.
 * /*from   w ww  .j a v  a2 s. c om*/
 * @param modifiers a key stroke specification - only the modifier part is used
 * @param button TODO
 * @param c the control
 * @param noClicks the number of clicks
 * @param p the point
 */
public static void postMouseDown(String modifiers, int button, final Control c, int noClicks) {
    final long now = System.currentTimeMillis();

    if (lastMouseOperationExpireTime > now) {
        sleep((int) (lastMouseOperationExpireTime - now));
    }

    KeyStroke keyStroke = null;
    try {
        if (modifiers != null) {
            keyStroke = KeyStroke.getInstance(modifiers);
            assertTrue(keyStroke.isComplete());
        }
    } catch (final ParseException ex) {
        fail(ex.getMessage());
    }

    final Event e = new Event();

    if (keyStroke != null) {
        c.setFocus();
        postModifierKeys(c, keyStroke, true);
    }

    for (int i = 1; i <= noClicks; i++) {
        e.type = SWT.MouseDown;
        e.button = button;
        e.count = i;
        assertTrue(c.getDisplay().post(e));
        // yield();

        e.type = SWT.MouseUp;
        e.button = button;
        e.count = i;
        // LogUtils.debug(e, ToStringUtils.toString(e));
        assertTrue(c.getDisplay().post(e));
        yield();
    }

    if (keyStroke != null) {
        postModifierKeys(c, keyStroke, false);
    }

    lastMouseOperationExpireTime = now + c.getDisplay().getDoubleClickTime() + 50;
}