diff options
author | Dejan Gloszic | 2006-01-20 02:09:32 +0000 |
---|---|---|
committer | Dejan Gloszic | 2006-01-20 02:09:32 +0000 |
commit | a6f775c48702d0d69221477edb3b95a0fa2e8f73 (patch) | |
tree | 2a76827829e6111b43167832cdfa6678ea00b4fd /org.eclipse.ua.tests/base/org/eclipse/ua/tests/util | |
parent | a3b29a00a995e9d092998dbb03daf2bec742a419 (diff) | |
download | eclipse.platform.ua-a6f775c48702d0d69221477edb3b95a0fa2e8f73.tar.gz eclipse.platform.ua-a6f775c48702d0d69221477edb3b95a0fa2e8f73.tar.xz eclipse.platform.ua-a6f775c48702d0d69221477edb3b95a0fa2e8f73.zip |
*** empty log message ***v20060120
Diffstat (limited to 'org.eclipse.ua.tests/base/org/eclipse/ua/tests/util')
5 files changed, 0 insertions, 366 deletions
diff --git a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/DisplayUtil.java b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/DisplayUtil.java deleted file mode 100644 index cd7738b90..000000000 --- a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/DisplayUtil.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.ua.tests.util; - -import org.eclipse.swt.widgets.Display; - -/* - * Utility methods for working with Displays. - */ -public class DisplayUtil { - - /* - * Flushes and events in the UI thread queue. - */ - public static void flush() { - while(Display.getDefault().readAndDispatch()) { - } - } -} diff --git a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/Keyboard.java b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/Keyboard.java deleted file mode 100644 index 501599e77..000000000 --- a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/Keyboard.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.ua.tests.util; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; - -/* - * Allows pressing of keys programmatically. - */ -public class Keyboard { - - /* - * Press and hold a key down until keyUp called. - */ - public static void keyDown(char c, int modifiers) { - DisplayUtil.flush(); - Event event = new Event(); - event.type = SWT.KeyDown; - event.character = c; - event.stateMask = modifiers; - Display.getDefault().post(event); - DisplayUtil.flush(); - } - - /* - * Press and hold a key down until keyUp called. - */ - public static void keyDown(int keyCode, int modifiers) { - DisplayUtil.flush(); - Event event = new Event(); - event.type = SWT.KeyDown; - event.keyCode = keyCode; - event.stateMask = modifiers; - Display.getDefault().post(event); - DisplayUtil.flush(); - } - - /* - * Release a key that was previously called with keyDown. - */ - public static void keyUp(int keyCode, int modifiers) { - DisplayUtil.flush(); - Event event = new Event(); - event.type = SWT.KeyUp; - event.keyCode = keyCode; - event.stateMask = modifiers; - Display.getDefault().post(event); - DisplayUtil.flush(); - } - - /* - * Release a key that was previously called with keyDown. - */ - public static void keyUp(char c, int modifiers) { - DisplayUtil.flush(); - Event event = new Event(); - event.type = SWT.KeyUp; - event.character = c; - event.stateMask = modifiers; - Display.getDefault().post(event); - DisplayUtil.flush(); - } - - /* - * Press and release a key, programmatically. - */ - public static void press(int keyCode) { - press(keyCode, SWT.NONE); - } - - /* - * Press and release a key, programmatically. - */ - public static void press(char c) { - press(c, SWT.NONE); - } - - /* - * Press and release a key with the given modifiers (e.g. Alt, Ctrl). - */ - public static void press(int keyCode, int modifiers) { - /* - * First press each modifier. - */ - int[] array = separateModifiers(modifiers); - for (int i=0;i<array.length;++i) { - keyDown(array[i], SWT.NONE); - } - - /* - * Press and release the key. - */ - keyDown(keyCode, modifiers); - keyUp(keyCode, modifiers); - - /* - * Release each modifier. - */ - for (int i=0;i<array.length;++i) { - keyUp(array[i], SWT.NONE); - } - } - - /* - * Press and release a key with the given modifiers (e.g. Alt, Ctrl). - */ - public static void press(char c, int modifiers) { - /* - * First press each modifier. - */ - int[] array = separateModifiers(modifiers); - for (int i=0;i<array.length;++i) { - keyDown(array[i], SWT.NONE); - } - - /* - * Press and release the key. - */ - keyDown(c, modifiers); - keyUp(c, modifiers); - - /* - * Release each modifier. - */ - for (int i=0;i<array.length;++i) { - keyUp(array[i], SWT.NONE); - } - } - - /* - * Given the modifier flags, returns each modifier separately. For example, if you pass in - * (SWT.ALT | SWT.CTRL), it returns { SWT.ALT, SWT.CTRL }, in no particular order. - */ - private static int[] separateModifiers(int modifiers) { - List list = new ArrayList(); - for (int i=0;i<32;++i) { - int currentModifier = (1 << i); - if ((modifiers & currentModifier) != 0) { - list.add(new Integer(currentModifier)); - } - } - int[] array = new int[list.size()]; - for (int i=0;i<array.length;++i) { - array[i] = ((Integer)list.get(i)).intValue(); - } - return array; - } -} diff --git a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/TreeUtil.java b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/TreeUtil.java deleted file mode 100644 index 054d4dcf0..000000000 --- a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/TreeUtil.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.ua.tests.util; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; - -/* - * Utility methods for working with Trees. - */ -public class TreeUtil { - - /* - * Fully expands the given tree. - */ - public static void expandTree(Tree tree) { - tree.setFocus(); - TreeItem[] items = tree.getItems(); - for (int i=0;i<items.length;++i) { - tree.setSelection(new TreeItem[] { items[i] }); - Keyboard.press(SWT.ARROW_RIGHT); - } - } -} diff --git a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/WidgetChecker.java b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/WidgetChecker.java deleted file mode 100644 index 557702349..000000000 --- a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/WidgetChecker.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.ua.tests.util; - -import junit.framework.Assert; - -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Item; - -/* - * A utility for checking widget properties. - */ -public class WidgetChecker { - - /* - * Checks if the control is non-null, not disposed, and is visible. Msg is the - * description of the widget (e.g. "The Tree in the cheat sheets dialog"). - */ - public static void checkControl(String msg, Control c) { - Assert.assertNotNull("The following control was unexpectedly null: " + msg, c); - Assert.assertFalse("The following control was unexpectedly disposed: " + msg, c.isDisposed()); - Assert.assertTrue("The following control was unexpectedly not visible: " + msg, c.isVisible()); - } - - /* - * Checks if the item is non-null and not disposed. Msg is the description of the item - * (e.g. "Tree item in the cheat sheets dialog"). - */ - public static void checkItem(String msg, Item c) { - Assert.assertNotNull("The following item was unexpectedly null: " + msg, c); - Assert.assertFalse("The following item was unexpectedly disposed: " + msg, c.isDisposed()); - } -} diff --git a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/WidgetFinder.java b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/WidgetFinder.java deleted file mode 100644 index dec0cb02d..000000000 --- a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/WidgetFinder.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.ua.tests.util; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Tree; - -/* - * A utility for finding widgets inside dialogs. - */ -public class WidgetFinder { - - /* - * Finds all controls of the given type. - */ - public static Control[] findControls(Control c, Class type) { - if (c != null) { - if (c instanceof Composite) { - List allChildren = new ArrayList(); - Control[] children = ((Composite)c).getChildren(); - for (int i=0;i<children.length;++i) { - Control[] controls = findControls(children[i], type); - if (controls != null) { - allChildren.addAll(Arrays.asList(controls)); - } - } - - boolean isAssignable = type.isAssignableFrom(c.getClass()); - Control[] array = new Control[allChildren.size() + (isAssignable ? 1 : 0)]; - allChildren.toArray(array); - if (isAssignable) { - array[array.length - 1] = c; - } - return array; - } - else if (type.isAssignableFrom(c.getClass())) { - return new Control[] { c }; - } - } - return new Control[0]; - } - - /* - * Finds all the Trees under the given Control/Composite. - */ - public static Tree[] findTrees(Control c) { - Control[] controls = findControls(c, Tree.class); - Tree[] trees = new Tree[controls.length]; - System.arraycopy(controls, 0, trees, 0, controls.length); - return trees; - } - - /* - * Finds all the Labels under the given Control/Composite. - */ - public static Label[] findLabels(Control c) { - Control[] controls = findControls(c, Label.class); - Label[] labels = new Label[controls.length]; - System.arraycopy(controls, 0, labels, 0, controls.length); - return labels; - } - - /* - * Finds any widget that has a getText() method that matches the given text. - */ - public static boolean containsText(String text, Control c) { - // don't take \r into account when comparing - text = text.replaceAll("\r", ""); - - Control[] controls = findControls(c, Control.class); - for (int i=0;i<controls.length;++i) { - try { - Method m = controls[i].getClass().getMethod("getText", null); - Object obj = m.invoke(controls[i], null); - if (obj != null && obj instanceof String) { - String widgetText = (String)obj; - widgetText = widgetText.replaceAll("\r", ""); - if (text.equals(widgetText)) { - return true; - } - } - } - catch (Exception e) { - // the method didn't exist; skip this one - } - } - return false; - } -} |