Coverage Report - org.eclipse.swtbot.swt.finder.utils.SWTBotEvents
 
Classes in this File Line Coverage Branch Coverage Complexity
SWTBotEvents
72%
60/83
16%
7/42
14
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2008 Ketan Padegaonkar and others.
 3  
  * All rights reserved. This program and the accompanying materials
 4  
  * are made available under the terms of the Eclipse Public License v1.0
 5  
  * which accompanies this distribution, and is available at
 6  
  * http://www.eclipse.org/legal/epl-v10.html
 7  
  *
 8  
  * Contributors:
 9  
  *     Ketan Padegaonkar - initial API and implementation
 10  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.swt.finder.utils;
 12  
 
 13  
 import java.util.Map.Entry;
 14  
 
 15  
 import org.eclipse.swt.SWT;
 16  
 import org.eclipse.swt.events.ArmEvent;
 17  
 import org.eclipse.swt.events.ControlEvent;
 18  
 import org.eclipse.swt.events.DisposeEvent;
 19  
 import org.eclipse.swt.events.FocusEvent;
 20  
 import org.eclipse.swt.events.HelpEvent;
 21  
 import org.eclipse.swt.events.KeyEvent;
 22  
 import org.eclipse.swt.events.MenuEvent;
 23  
 import org.eclipse.swt.events.ModifyEvent;
 24  
 import org.eclipse.swt.events.MouseEvent;
 25  
 import org.eclipse.swt.events.PaintEvent;
 26  
 import org.eclipse.swt.events.SelectionEvent;
 27  
 import org.eclipse.swt.events.ShellEvent;
 28  
 import org.eclipse.swt.events.TraverseEvent;
 29  
 import org.eclipse.swt.events.TreeEvent;
 30  
 import org.eclipse.swt.events.VerifyEvent;
 31  
 import org.eclipse.swt.widgets.Event;
 32  
 import org.eclipse.swt.widgets.Menu;
 33  
 
 34  
 /**
 35  
  * This maps SWT events to the Strings.
 36  
  *
 37  
  * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 38  
  * @version $Id$
 39  
  */
 40  1
 public abstract class SWTBotEvents {
 41  
 
 42  1
         private static final BidiMap<String, Integer>        EVENTS        = new BidiMap<String, Integer>();
 43  
         static {
 44  1
                 EVENTS.put("Activate", SWT.Activate); //$NON-NLS-1$
 45  1
                 EVENTS.put("Arm", SWT.Arm); //$NON-NLS-1$
 46  1
                 EVENTS.put("Close", SWT.Close); //$NON-NLS-1$
 47  1
                 EVENTS.put("Collapse", SWT.Collapse); //$NON-NLS-1$
 48  1
                 EVENTS.put("Deactivate", SWT.Deactivate); //$NON-NLS-1$
 49  1
                 EVENTS.put("DefaultSelection", SWT.DefaultSelection); //$NON-NLS-1$
 50  1
                 EVENTS.put("Deiconify", SWT.Deiconify); //$NON-NLS-1$
 51  1
                 EVENTS.put("Dispose", SWT.Dispose); //$NON-NLS-1$
 52  1
                 EVENTS.put("DragDetect", SWT.DragDetect); //$NON-NLS-1$
 53  1
                 EVENTS.put("EraseItem", SWT.EraseItem); //$NON-NLS-1$
 54  1
                 EVENTS.put("Expand", SWT.Expand); //$NON-NLS-1$
 55  1
                 EVENTS.put("FocusIn", SWT.FocusIn); //$NON-NLS-1$
 56  1
                 EVENTS.put("FocusOut", SWT.FocusOut); //$NON-NLS-1$
 57  1
                 EVENTS.put("HardKeyDown", SWT.HardKeyDown); //$NON-NLS-1$
 58  1
                 EVENTS.put("HardKeyUp", SWT.HardKeyUp); //$NON-NLS-1$
 59  1
                 EVENTS.put("Help", SWT.Help); //$NON-NLS-1$
 60  1
                 EVENTS.put("Hide", SWT.Hide); //$NON-NLS-1$
 61  1
                 EVENTS.put("Iconify", SWT.Iconify); //$NON-NLS-1$
 62  1
                 EVENTS.put("KeyDown", SWT.KeyDown); //$NON-NLS-1$
 63  1
                 EVENTS.put("KeyUp", SWT.KeyUp); //$NON-NLS-1$
 64  1
                 EVENTS.put("MeasureItem", SWT.MeasureItem); //$NON-NLS-1$
 65  1
                 EVENTS.put("MenuDetect", SWT.MenuDetect); //$NON-NLS-1$
 66  1
                 EVENTS.put("Modify", SWT.Modify); //$NON-NLS-1$
 67  1
                 EVENTS.put("MouseDoubleClick", SWT.MouseDoubleClick); //$NON-NLS-1$
 68  1
                 EVENTS.put("MouseDown", SWT.MouseDown); //$NON-NLS-1$
 69  1
                 EVENTS.put("MouseEnter", SWT.MouseEnter); //$NON-NLS-1$
 70  1
                 EVENTS.put("MouseExit", SWT.MouseExit); //$NON-NLS-1$
 71  1
                 EVENTS.put("MouseHover", SWT.MouseHover); //$NON-NLS-1$
 72  1
                 EVENTS.put("MouseMove", SWT.MouseMove); //$NON-NLS-1$
 73  1
                 EVENTS.put("MouseUp", SWT.MouseUp); //$NON-NLS-1$
 74  1
                 EVENTS.put("MouseWheel", SWT.MouseWheel); //$NON-NLS-1$
 75  1
                 EVENTS.put("Move", SWT.Move); //$NON-NLS-1$
 76  1
                 EVENTS.put("Paint", SWT.Paint); //$NON-NLS-1$
 77  1
                 EVENTS.put("PaintItem", SWT.PaintItem); //$NON-NLS-1$
 78  1
                 EVENTS.put("Resize", SWT.Resize); //$NON-NLS-1$
 79  1
                 EVENTS.put("Selection", SWT.Selection); //$NON-NLS-1$
 80  1
                 EVENTS.put("SetData", SWT.SetData); //$NON-NLS-1$
 81  1
                 EVENTS.put("Settings", SWT.Settings); // note: this event only goes to Display //$NON-NLS-1$
 82  1
                 EVENTS.put("Show", SWT.Show); //$NON-NLS-1$
 83  1
                 EVENTS.put("Traverse", SWT.Traverse); //$NON-NLS-1$
 84  1
                 EVENTS.put("Verify", SWT.Verify); //$NON-NLS-1$
 85  
         }
 86  
 
 87  
         /**
 88  
          * Converts the event to a string for display.
 89  
          *
 90  
          * @param event the event.
 91  
          * @return the string representation of the display.
 92  
          */
 93  
         public static String toString(int event) {
 94  7715
                 return EVENTS.getKey(event);
 95  
         }
 96  
 
 97  
         /**
 98  
          * Lists all the events.
 99  
          *
 100  
          * @return all the events.
 101  
          */
 102  
         public static int[] events() {
 103  0
                 int[] events = new int[EVENTS.size()];
 104  0
                 int i = 0;
 105  
 
 106  0
                 for (Entry<String, Integer> entry : EVENTS) {
 107  0
                         events[i++] = entry.getValue();
 108  
                 }
 109  
 
 110  0
                 return events;
 111  
         }
 112  
 
 113  
         /**
 114  
          * @param event the event to be converted to a string.
 115  
          * @return the typed event corresponding to the <code>event</code>.
 116  
          */
 117  
         public static String toString(Event event) {
 118  7715
                 String toString = toString(event.type) + " [" + event.type + "]: "; //$NON-NLS-1$ //$NON-NLS-2$
 119  7715
                 switch (event.type) {
 120  
                 case SWT.KeyDown:
 121  
                 case SWT.KeyUp:
 122  0
                         toString += new KeyEvent(event).toString();
 123  0
                         break;
 124  
                 case SWT.MouseDown:
 125  
                 case SWT.MouseUp:
 126  
                 case SWT.MouseMove:
 127  
                 case SWT.MouseEnter:
 128  
                 case SWT.MouseExit:
 129  
                 case SWT.MouseDoubleClick:
 130  
                 case SWT.MouseWheel:
 131  
                 case SWT.MouseHover:
 132  3986
                         toString += new MouseEvent(event).toString();
 133  3986
                         break;
 134  
                 case SWT.Paint:
 135  0
                         toString += new PaintEvent(event).toString();
 136  0
                         break;
 137  
                 case SWT.Move:
 138  
                 case SWT.Resize:
 139  0
                         toString += new ControlEvent(event).toString();
 140  0
                         break;
 141  
                 case SWT.Dispose:
 142  0
                         toString += new DisposeEvent(event).toString();
 143  0
                         break;
 144  
                 case SWT.Selection:
 145  
                 case SWT.DefaultSelection:
 146  937
                         toString += new SelectionEvent(event).toString();
 147  937
                         break;
 148  
                 case SWT.FocusIn:
 149  
                 case SWT.FocusOut:
 150  1155
                         toString += new FocusEvent(event).toString();
 151  1155
                         break;
 152  
                 case SWT.Expand:
 153  
                 case SWT.Collapse:
 154  29
                         toString += new TreeEvent(event).toString();
 155  29
                         break;
 156  
                 case SWT.Iconify:
 157  
                 case SWT.Deiconify:
 158  
                 case SWT.Close:
 159  
                 case SWT.Activate:
 160  
                 case SWT.Deactivate:
 161  1572
                         toString += new ShellEvent(event).toString();
 162  1572
                         break;
 163  
                 case SWT.Show:
 164  
                 case SWT.Hide:
 165  0
                         toString += event.widget instanceof Menu ? new MenuEvent(event).toString() : event.toString();
 166  0
                         break;
 167  
                 case SWT.Modify:
 168  4
                         toString += new ModifyEvent(event).toString();
 169  4
                         break;
 170  
                 case SWT.Verify:
 171  0
                         toString += new VerifyEvent(event).toString();
 172  0
                         break;
 173  
                 case SWT.Help:
 174  0
                         toString += new HelpEvent(event).toString();
 175  0
                         break;
 176  
                 case SWT.Arm:
 177  0
                         toString += new ArmEvent(event).toString();
 178  0
                         break;
 179  
                 case SWT.Traverse:
 180  0
                         toString += new TraverseEvent(event).toString();
 181  0
                         break;
 182  
                 case SWT.HardKeyDown:
 183  
                 case SWT.HardKeyUp:
 184  
                 case SWT.DragDetect:
 185  
                 case SWT.MenuDetect:
 186  
                 case SWT.SetData:
 187  
                 default:
 188  32
                         toString += event.toString();
 189  
                 }
 190  7715
                 return toString;
 191  
         }
 192  
 }