Coverage Report - org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor
 
Classes in this File Line Coverage Branch Coverage Complexity
SWTBotEclipseEditor
44%
65/145
75%
3/4
1.264
SWTBotEclipseEditor$1
100%
13/13
N/A
1.264
SWTBotEclipseEditor$2
60%
3/5
N/A
1.264
SWTBotEclipseEditor$3
66%
6/9
50%
2/4
1.264
SWTBotEclipseEditor$4
0%
0/10
0%
0/2
1.264
SWTBotEclipseEditor$5
100%
3/3
N/A
1.264
SWTBotEclipseEditor$6
63%
7/11
50%
1/2
1.264
SWTBotEclipseEditor$7
100%
5/5
N/A
1.264
 
 1  2
 /*******************************************************************************
 2  
  * Copyright (c) 2008-2009 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  
  *     Ketan Patel - https://bugs.eclipse.org/bugs/show_bug.cgi?id=259837
 11  
  *     Ralf Ebert www.ralfebert.de - (bug 271630) SWTBot Improved RCP / Workbench support
 12  
  *******************************************************************************/
 13  
 package org.eclipse.swtbot.eclipse.finder.widgets;
 14  
 
 15  
 import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
 16  
 import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
 17  
 import static org.hamcrest.Matchers.any;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Arrays;
 21  
 import java.util.List;
 22  
 
 23  
 import org.eclipse.jface.action.IAction;
 24  
 import org.eclipse.jface.bindings.keys.KeyStroke;
 25  
 import org.eclipse.swt.SWT;
 26  
 import org.eclipse.swt.custom.Bullet;
 27  
 import org.eclipse.swt.custom.StyleRange;
 28  
 import org.eclipse.swt.custom.StyledText;
 29  
 import org.eclipse.swt.graphics.Color;
 30  
 import org.eclipse.swt.graphics.RGB;
 31  
 import org.eclipse.swt.widgets.Control;
 32  
 import org.eclipse.swt.widgets.Event;
 33  
 import org.eclipse.swt.widgets.Shell;
 34  
 import org.eclipse.swt.widgets.Table;
 35  
 import org.eclipse.swt.widgets.Widget;
 36  
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
 37  
 import org.eclipse.swtbot.eclipse.finder.exceptions.QuickFixNotFoundException;
 38  
 import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
 39  
 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 40  
 import org.eclipse.swtbot.swt.finder.keyboard.Keyboard;
 41  
 import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
 42  
 import org.eclipse.swtbot.swt.finder.matchers.AbstractMatcher;
 43  
 import org.eclipse.swtbot.swt.finder.results.VoidResult;
 44  
 import org.eclipse.swtbot.swt.finder.results.WidgetResult;
 45  
 import org.eclipse.swtbot.swt.finder.utils.MessageFormat;
 46  
 import org.eclipse.swtbot.swt.finder.utils.Position;
 47  
 import org.eclipse.swtbot.swt.finder.waits.WaitForObjectCondition;
 48  
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
 49  
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
 50  
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
 51  
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
 52  
 import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
 53  
 import org.eclipse.ui.IEditorReference;
 54  
 import org.eclipse.ui.texteditor.ITextEditor;
 55  
 import org.hamcrest.Description;
 56  
 import org.hamcrest.Matcher;
 57  
 import org.hamcrest.SelfDescribing;
 58  
 
 59  
 /**
 60  
  * This represents an eclipse editor item.
 61  
  * 
 62  
  * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 63  
  * @author Ralf Ebert www.ralfebert.de (bug 271630)
 64  
  * @version $Id$
 65  
  */
 66  
 public class SWTBotEclipseEditor extends SWTBotEditor {
 67  
 
 68  2
         private final SWTBotStyledText        styledText;
 69  
 
 70  
         /**
 71  
          * Constructs an instance of the given object.
 72  
          * 
 73  
          * @param editorReference the editor reference.
 74  
          * @param bot the instance of {@link SWTWorkbenchBot} which will be used to drive operations on behalf of this
 75  
          *            object.
 76  
          * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
 77  
          * @since 2.0
 78  
          */
 79  
         public SWTBotEclipseEditor(IEditorReference editorReference, SWTWorkbenchBot bot) throws WidgetNotFoundException {
 80  3
                 super(editorReference, bot);
 81  3
                 this.styledText = new SWTBotStyledText(widget());
 82  3
         }
 83  
 
 84  
         /**
 85  
          * Constructs an instance for the given editorReference.
 86  
          * 
 87  
          * @param editorReference the part reference.
 88  
          * @param bot the helper bot.
 89  
          * @param description the description of the editor part.
 90  
          */
 91  
         public SWTBotEclipseEditor(IEditorReference editorReference, SWTWorkbenchBot bot, SelfDescribing description) {
 92  0
                 super(editorReference, bot, description);
 93  0
                 this.styledText = new SWTBotStyledText(widget());
 94  0
         }
 95  
 
 96  
         private StyledText widget() {
 97  3
                 List<? extends Widget> findWidgets = findWidgets(widgetOfType(StyledText.class));
 98  3
                 return (StyledText) findWidgets.get(findWidgets.size() - 1);
 99  
         }
 100  
 
 101  
         /**
 102  
          * @return the styledText
 103  
          */
 104  
         public SWTBotStyledText getStyledText() {
 105  0
                 return styledText;
 106  
         }
 107  
 
 108  
         /**
 109  
          * @return the editor reference for this view.
 110  
          * @deprecated use {@link SWTBotWorkbenchPart#getReference()} instead
 111  
          */
 112  
         public IEditorReference getEditorReference() {
 113  0
                 return getReference();
 114  
         }
 115  
 
 116  
         /**
 117  
          * Applys a quick fix item at the given index.
 118  
          * 
 119  
          * @param quickFixIndex the index of the quickfix item to apply.
 120  
          * @throws WidgetNotFoundException if the quickfix could not be found.
 121  
          */
 122  
         public void quickfix(int quickFixIndex) {
 123  0
                 WaitForObjectCondition<SWTBotTable> quickFixTableCondition = quickFixAppears(any(SWTBotTable.class));
 124  0
                 waitUntil(quickFixTableCondition);
 125  0
                 SWTBotTable quickFixTable = quickFixTableCondition.get(0);
 126  0
                 selectProposal(quickFixTable, quickFixIndex);
 127  0
         }
 128  
 
 129  
         /**
 130  
          * Applys a quick fix item with the given name.
 131  
          * 
 132  
          * @param quickFixName the name of the quick fix to apply.
 133  
          */
 134  
         public void quickfix(String quickFixName) {
 135  0
                 WaitForObjectCondition<SWTBotTable> quickFixTable = quickFixAppears(tableWithRow(quickFixName));
 136  0
                 waitUntil(quickFixTable);
 137  0
                 selectProposal(quickFixTable.get(0), quickFixName);
 138  0
         }
 139  
 
 140  
         /**
 141  
          * Finds all the quickfixes in the quickfix list.
 142  
          * 
 143  
          * @return the list of all available quickfixes.
 144  
          * @since 1.2
 145  
          */
 146  
         public List<String> getQuickFixes() {
 147  0
                 WaitForObjectCondition<SWTBotTable> quickFixTableCondition = quickFixAppears(any(SWTBotTable.class));
 148  0
                 waitUntil(quickFixTableCondition);
 149  0
                 SWTBotTable quickFixTable = quickFixTableCondition.get(0);
 150  0
                 List<String> proposals = getRows(quickFixTable);
 151  0
                 makeProposalsDisappear();
 152  0
                 return proposals;
 153  
         }
 154  
 
 155  
         /**
 156  
          * Gets the quick fix item count.
 157  
          * 
 158  
          * @return the number of quickfix items in the quickfix proposals.
 159  
          * @since 1.2
 160  
          */
 161  
         public int getQuickfixListItemCount() {
 162  0
                 WaitForObjectCondition<SWTBotTable> quickFixTableCondition = quickFixAppears(any(SWTBotTable.class));
 163  0
                 waitUntil(quickFixTableCondition);
 164  0
                 SWTBotTable quickFixTable = quickFixTableCondition.get(0);
 165  0
                 return quickFixTable.rowCount();
 166  
         }
 167  
 
 168  
         /**
 169  
          * Attempst to applys the quick fix.
 170  
          * <p>
 171  
          * FIXME: this needs a lot of optimization.
 172  
          * </p>
 173  
          * 
 174  
          * @param proposalTable the table containing the quickfix.
 175  
          * @param proposalText the name of the quickfix to apply.
 176  
          */
 177  
         private void selectProposal(SWTBotTable proposalTable, String proposalText) {
 178  1
                 log.debug(MessageFormat.format("Trying to select proposal {0}", proposalText)); //$NON-NLS-1$
 179  1
                 if (proposalTable.containsItem(proposalText)) {
 180  1
                         selectProposal(proposalTable, proposalTable.indexOf(proposalText));
 181  1
                         return;
 182  
                 }
 183  0
                 throw new QuickFixNotFoundException("Quickfix options not found. Giving up."); //$NON-NLS-1$
 184  
         }
 185  
 
 186  
         /**
 187  
          * Applies the specified quickfix.
 188  
          * 
 189  
          * @param proposalTable the table containing the quickfix.
 190  
          * @param proposalIndex the index of the quickfix.
 191  
          */
 192  
         private void selectProposal(final SWTBotTable proposalTable, final int proposalIndex) {
 193  1
                 log.debug(MessageFormat.format("Trying to select proposal with index {0}", proposalIndex)); //$NON-NLS-1$
 194  1
                 UIThreadRunnable.asyncExec(new VoidResult() {
 195  
                         public void run() {
 196  1
                                 Table table = proposalTable.widget;
 197  2
                                 log.debug(MessageFormat.format("Selecting row [{0}] {1} in {2}", proposalIndex, table.getItem(proposalIndex).getText(), //$NON-NLS-1$
 198  1
                                                 table));
 199  1
                                 table.setSelection(proposalIndex);
 200  1
                                 Event event = new Event();
 201  1
                                 event.type = SWT.Selection;
 202  1
                                 event.widget = table;
 203  1
                                 event.item = table.getItem(proposalIndex);
 204  1
                                 table.notifyListeners(SWT.Selection, event);
 205  1
                                 table.notifyListeners(SWT.DefaultSelection, event);
 206  1
                         }
 207  
                 });
 208  1
         }
 209  
 
 210  
         /**
 211  
          * Gets the quick fix table.
 212  
          *
 213  
          * @param proposalShell the shell containing the quickfixes.
 214  
          * @return the table containing the quickfix.
 215  
          */
 216  2
         private SWTBotTable getProposalTable() {
 217  2
                 log.debug("Finding table containing proposals.");
 218  
                 try {
 219  2
                         Table table = bot.widget(widgetOfType(Table.class), activatePopupShell().widget);
 220  2
                         SWTBotTable swtBotTable = new SWTBotTable(table);
 221  2
                         log.debug(MessageFormat.format("Found table containing proposals -- {0}", getRows(swtBotTable)));
 222  2
                         return swtBotTable;
 223  0
                 } catch (Exception e) {
 224  0
                         throw new QuickFixNotFoundException("Quickfix options not found. Giving up.", e); //$NON-NLS-1$
 225  
                 }
 226  
         }
 227  
 
 228  
         /**
 229  
          * Gets the auto completion proposal matching the given text..
 230  
          * 
 231  
          * @param insertText the proposal text to type before auto completing
 232  
          * @return the list of proposals
 233  
          * @throws TimeoutException if the autocomplete shell did not close in time.
 234  
          * @since 1.2
 235  
          */
 236  
         @SuppressWarnings("all")
 237  
         public List<String> getAutoCompleteProposals(String insertText) {
 238  1
                 typeText(insertText);
 239  1
                 WaitForObjectCondition<SWTBotTable> autoCompleteAppears = autoCompleteAppears(tableWithRowIgnoringCase(insertText));
 240  1
                 waitUntil(autoCompleteAppears);
 241  1
                 final SWTBotTable autoCompleteTable = autoCompleteAppears.get(0);
 242  1
                 List<String> proposals = getRows(autoCompleteTable);
 243  1
                 makeProposalsDisappear();
 244  1
                 return proposals;
 245  
         }
 246  
 
 247  
         /**
 248  
          * Auto completes the given proposal.
 249  
          * 
 250  
          * @param insertText the text to be inserted before activating the auto-complete.
 251  
          * @param proposalText the auto-completion proposal to select from the list.
 252  
          */
 253  
         public void autoCompleteProposal(String insertText, String proposalText) {
 254  1
                 typeText(insertText);
 255  1
                 WaitForObjectCondition<SWTBotTable> autoCompleteTable = autoCompleteAppears(tableWithRow(proposalText));
 256  1
                 waitUntil(autoCompleteTable);
 257  1
                 selectProposal(autoCompleteTable.get(0), proposalText);
 258  1
         }
 259  
 
 260  
         /**
 261  
          * Gets the context menu in the editor.
 262  
          * 
 263  
          * @param text the context menu item.
 264  
          * @return the menu
 265  
          * @throws WidgetNotFoundException if the menu with the specified text could not be found.
 266  
          * @see org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot#contextMenu(java.lang.String)
 267  
          */
 268  
         public SWTBotMenu contextMenu(String text) throws WidgetNotFoundException {
 269  0
                 return styledText.contextMenu(text);
 270  
         }
 271  
 
 272  
         /**
 273  
          * Gets the current position of the cursor. The returned position will contain a 0-based line and column.
 274  
          * 
 275  
          * @return the position of the cursor.
 276  
          * @see SWTBotStyledText#cursorPosition()
 277  
          */
 278  
         public Position cursorPosition() {
 279  0
                 return styledText.cursorPosition();
 280  
         }
 281  
 
 282  
         /**
 283  
          * Gets if the object's widget is enabled.
 284  
          * 
 285  
          * @return <code>true</code> if the widget is enabled.
 286  
          * @see org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot#isEnabled()
 287  
          */
 288  
         public boolean isEnabled() {
 289  0
                 return styledText.isEnabled();
 290  
         }
 291  
 
 292  
         /**
 293  
          * Gets the current selection.
 294  
          * 
 295  
          * @return The selected string.
 296  
          */
 297  
         public String getSelection() {
 298  0
                 return styledText.getSelection();
 299  
         }
 300  
 
 301  
         /**
 302  
          * Gets the style text.
 303  
          * 
 304  
          * @param line the line number, 0 based.
 305  
          * @param column the column number, 0 based.
 306  
          * @return the {@link StyleRange} at the specified location
 307  
          * @see SWTBotStyledText#getStyle(int, int)
 308  
          */
 309  
         public StyleRange getStyle(int line, int column) {
 310  0
                 return styledText.getStyle(line, column);
 311  
         }
 312  
 
 313  
         /**
 314  
          * Gets the text of this object's widget.
 315  
          * 
 316  
          * @return the text on the styledtext.
 317  
          * @see org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot#getText()
 318  
          */
 319  
         public String getText() {
 320  2
                 return styledText.getText();
 321  
         }
 322  
 
 323  
         /**
 324  
          * @param line the line number, 0 based.
 325  
          * @param column the column number, 0 based.
 326  
          * @param text the text to be typed at the specified location
 327  
          * @see SWTBotStyledText#typeText(int, int, java.lang.String)
 328  
          * @since 1.0
 329  
          */
 330  
         public void typeText(int line, int column, String text) {
 331  0
                 styledText.typeText(line, column, text);
 332  0
         }
 333  
 
 334  
         /**
 335  
          * @param text the text to be typed at the location of the caret. *
 336  
          * @see SWTBotStyledText#typeText(java.lang.String)
 337  
          * @since 1.0
 338  
          */
 339  
         public void typeText(String text) {
 340  2
                 styledText.typeText(text);
 341  2
         }
 342  
 
 343  
         /**
 344  
          * @param line the line number, 0 based.
 345  
          * @param column the column number, 0 based.
 346  
          * @param text the text to be inserted at the specified location
 347  
          * @see SWTBotStyledText#insertText(int, int, java.lang.String)
 348  
          */
 349  
         public void insertText(int line, int column, String text) {
 350  0
                 styledText.insertText(line, column, text);
 351  0
         }
 352  
 
 353  
         /**
 354  
          * @param text the text to be inserted at the location of the caret.
 355  
          * @see SWTBotStyledText#insertText(java.lang.String)
 356  
          */
 357  
         public void insertText(String text) {
 358  0
                 styledText.insertText(text);
 359  0
         }
 360  
 
 361  
         /**
 362  
          * @param text the text to be typed at the location of the caret.
 363  
          * @param interval the interval between consecutive key strokes.
 364  
          * @see SWTBotStyledText#typeText(java.lang.String, int)
 365  
          * @since 1.0
 366  
          */
 367  
         public void typeText(String text, int interval) {
 368  0
                 styledText.typeText(text, interval);
 369  0
         }
 370  
 
 371  
         /**
 372  
          * Sets the caret at the specified location.
 373  
          * 
 374  
          * @param position the position of the caret.
 375  
          */
 376  
         public void navigateTo(Position position) {
 377  0
                 styledText.navigateTo(position);
 378  0
         }
 379  
 
 380  
         /**
 381  
          * @param line the line number, 0 based.
 382  
          * @param column the column number, 0 based.
 383  
          * @see SWTBotStyledText#navigateTo(int, int)
 384  
          */
 385  
         public void navigateTo(int line, int column) {
 386  2
                 styledText.navigateTo(line, column);
 387  2
         }
 388  
 
 389  
         /**
 390  
          * Notifies of the keyboard event.
 391  
          * <p>
 392  
          * FIXME need some work for CTRL|SHIFT + 1 the 1 is to be sent as '!' in this case.
 393  
          * </p>
 394  
          * 
 395  
          * @param modificationKeys the modification keys.
 396  
          * @param c the character.
 397  
          * @see Event#character
 398  
          * @see Event#stateMask
 399  
          * @deprecated use {@link #pressShortcut(int, char)} instead. This api will be removed.
 400  
          */
 401  
         public void notifyKeyboardEvent(int modificationKeys, char c) {
 402  0
                 styledText.notifyKeyboardEvent(modificationKeys, c);
 403  0
         }
 404  
 
 405  
         /**
 406  
          * Notifies of keyboard event.
 407  
          * 
 408  
          * @param modificationKeys the modification key.
 409  
          * @param c the character.
 410  
          * @param keyCode any special keys (function keys, arrow or navigation keys etc.)
 411  
          * @see Event#keyCode
 412  
          * @see Event#character
 413  
          * @see Event#stateMask
 414  
          * @deprecated use {@link #pressShortcut(int, int, char)} instead. This api will be removed.
 415  
          */
 416  
         public void notifyKeyboardEvent(int modificationKeys, char c, int keyCode) {
 417  0
                 styledText.notifyKeyboardEvent(modificationKeys, c, keyCode);
 418  0
         }
 419  
 
 420  
         /**
 421  
          * Presses the shortcut specified by the given keys.
 422  
          * 
 423  
          * @param modificationKeys the combination of {@link SWT#ALT} | {@link SWT#CTRL} | {@link SWT#SHIFT} |
 424  
          *            {@link SWT#COMMAND}.
 425  
          * @param c the character.
 426  
          * @see Keyboard#pressShortcut(KeyStroke...)
 427  
          * @see Keystrokes#toKeys(int, char)
 428  
          */
 429  
         public void pressShortcut(int modificationKeys, char c) {
 430  0
                 styledText.pressShortcut(modificationKeys, c);
 431  0
         }
 432  
 
 433  
         /**
 434  
          * Presses the shortcut specified by the given keys.
 435  
          * 
 436  
          * @param modificationKeys the combination of {@link SWT#ALT} | {@link SWT#CTRL} | {@link SWT#SHIFT} |
 437  
          *            {@link SWT#COMMAND}.
 438  
          * @param keyCode the keyCode, these may be special keys like F1-F12, or navigation keys like HOME, PAGE_UP
 439  
          * @param c the character
 440  
          * @see Keystrokes#toKeys(int, char)
 441  
          */
 442  
         public void pressShortcut(int modificationKeys, int keyCode, char c) {
 443  0
                 styledText.pressShortcut(modificationKeys, keyCode, c);
 444  0
         }
 445  
 
 446  
         /**
 447  
          * Presses the shortcut specified by the given keys.
 448  
          * 
 449  
          * @param keys the keys to press
 450  
          * @see Keyboard#pressShortcut(KeyStroke...)
 451  
          * @see Keystrokes
 452  
          */
 453  
         public void pressShortcut(KeyStroke... keys) {
 454  0
                 styledText.pressShortcut(keys);
 455  0
         }
 456  
 
 457  
         /**
 458  
          * @param line the line number, 0 based.
 459  
          * @param column the column number, 0 based.
 460  
          * @param length the length of the selection.
 461  
          * @see SWTBotStyledText#selectRange(int, int, int)
 462  
          */
 463  
         public void selectRange(int line, int column, int length) {
 464  0
                 styledText.selectRange(line, column, length);
 465  0
         }
 466  
 
 467  
         /**
 468  
          * @param line the line number to select, 0 based.
 469  
          * @see SWTBotStyledText#selectLine(int)
 470  
          * @since 1.1
 471  
          */
 472  
         public void selectLine(int line) {
 473  0
                 styledText.selectLine(line);
 474  0
         }
 475  
 
 476  
         /**
 477  
          * Selects the text on the current line.
 478  
          * 
 479  
          * @see SWTBotStyledText#selectCurrentLine()
 480  
          * @since 1.1
 481  
          */
 482  
         public void selectCurrentLine() {
 483  0
                 styledText.selectCurrentLine();
 484  0
         }
 485  
 
 486  
         /**
 487  
          * @see SWTBotStyledText#setFocus()
 488  
          */
 489  
         public void setFocus() {
 490  1
                 styledText.setFocus();
 491  1
         }
 492  
 
 493  
         /**
 494  
          * @param text the text to set.
 495  
          * @see SWTBotStyledText#setText(java.lang.String)
 496  
          */
 497  
         public void setText(String text) {
 498  0
                 styledText.setText(text);
 499  0
         }
 500  
 
 501  
         /**
 502  
          * @return the bullet on the current line.
 503  
          * @see SWTBotStyledText#getBulletOnCurrentLine()
 504  
          */
 505  
         public Bullet getBulletOnCurrentLine() {
 506  0
                 return styledText.getBulletOnCurrentLine();
 507  
         }
 508  
 
 509  
         /**
 510  
          * @param line the line number, 0 based.
 511  
          * @return the bullet on the given line.
 512  
          * @see SWTBotStyledText#getBulletOnLine(int)
 513  
          */
 514  
         public Bullet getBulletOnLine(int line) {
 515  0
                 return styledText.getBulletOnLine(line);
 516  
         }
 517  
 
 518  
         /**
 519  
          * @param line the line number, 0 based.
 520  
          * @param column the column number, 0 based.
 521  
          * @param length the length.
 522  
          * @return the styles in the specified range.
 523  
          * @see SWTBotStyledText#getStyles(int, int, int)
 524  
          */
 525  
         public StyleRange[] getStyles(int line, int column, int length) {
 526  0
                 return styledText.getStyles(line, column, length);
 527  
         }
 528  
 
 529  
         /**
 530  
          * @return the text on the current line, without the line delimiters.
 531  
          * @see SWTBotStyledText#getTextOnCurrentLine()
 532  
          */
 533  
         public String getTextOnCurrentLine() {
 534  0
                 return styledText.getTextOnCurrentLine();
 535  
         }
 536  
 
 537  
         /**
 538  
          * Get the text on line number given as parameter.
 539  
          * Note that in eclipse editors, folding has no incidence on line numbers.
 540  
          * @param line the line number, 0 based.
 541  
          * @return the text on the given line number, without the line delimiters.
 542  
          * @see SWTBotStyledText#getTextOnLine(int)
 543  
          */
 544  
         public String getTextOnLine(int line) {
 545  0
                 return styledText.getTextOnLine(line);
 546  
         }
 547  
 
 548  
         /**
 549  
          * @return <code>true</code> if the styledText has a bullet on the given line, <code>false</code> otherwise.
 550  
          * @see SWTBotStyledText#hasBulletOnCurrentLine()
 551  
          */
 552  
         public boolean hasBulletOnCurrentLine() {
 553  0
                 return styledText.hasBulletOnCurrentLine();
 554  
         }
 555  
 
 556  
         /**
 557  
          * @param line the line number, 0 based.
 558  
          * @return <code>true</code> if the styledText has a bullet on the given line, <code>false</code> otherwise.
 559  
          * @see SWTBotStyledText#hasBulletOnLine(int)
 560  
          */
 561  
         public boolean hasBulletOnLine(int line) {
 562  0
                 return styledText.hasBulletOnLine(line);
 563  
         }
 564  
 
 565  
         /**
 566  
          * Gets the background color of the widget.
 567  
          * 
 568  
          * @return the background color on the widget, or <code>null</code> if the widget is not an instance of
 569  
          *         {@link Control}.
 570  
          * @since 1.3
 571  
          * @see org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot#backgroundColor()
 572  
          */
 573  
         public Color backgroundColor() {
 574  0
                 return styledText.backgroundColor();
 575  
         }
 576  
 
 577  
         /**
 578  
          * Gets the foreground color of the widget.
 579  
          * 
 580  
          * @return the foreground color on the widget, or <code>null</code> if the widget is not an instance of
 581  
          *         {@link Control}.
 582  
          * @since 1.3
 583  
          * @see org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot#foregroundColor()
 584  
          */
 585  
         public Color foregroundColor() {
 586  0
                 return styledText.foregroundColor();
 587  
         }
 588  
 
 589  
         /**
 590  
          * Gets the color of the background on the specified line.
 591  
          * 
 592  
          * @param line the line number, 0 based.
 593  
          * @return the RGB of the line background color of the specified line.
 594  
          * @since 1.3
 595  
          * @see SWTBotStyledText#getLineBackground(int)
 596  
          */
 597  
         public RGB getLineBackground(int line) {
 598  0
                 return styledText.getLineBackground(line);
 599  
         }
 600  
 
 601  
         /**
 602  
          * Gets the number of lines in the {@link StyledText}.
 603  
          * 
 604  
          * @return the number of lines in the {@link StyledText}.
 605  
          */
 606  
         public int getLineCount(){
 607  0
                 return styledText.getLineCount();
 608  
         }
 609  
 
 610  
         /**
 611  
          * Gets all the lines in the editor.
 612  
          * 
 613  
          * @return the lines in the editor.
 614  
          */
 615  
         public List<String> getLines() {
 616  0
                 return styledText.getLines();
 617  
         }
 618  
 
 619  
         /**
 620  
          * Gets the tooltip of this object's widget.
 621  
          * 
 622  
          * @return the tooltip on the widget.
 623  
          * @see org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot#getToolTipText()
 624  
          * @since 1.3
 625  
          */
 626  
         public String getToolTipText() {
 627  0
                 return styledText.getToolTipText();
 628  
         }
 629  
 
 630  0
         private void makeProposalsDisappear() {
 631  
                 // clear away all content assists for next retry.
 632  1
                 log.debug("Making proposals disappear.");
 633  1
                 setFocus();
 634  1
         }
 635  
 
 636  
         private Matcher<SWTBotTable> tableWithRow(final String itemText) {
 637  1
                 return new AbstractMatcher<SWTBotTable>() {
 638  
 
 639  
                         protected boolean doMatch(Object item) {
 640  1
                                 return ((SWTBotTable) item).containsItem(itemText);
 641  
                         }
 642  
 
 643  
                         public void describeTo(Description description) {
 644  0
                                 description.appendText("table with item (").appendText(itemText).appendText(")");
 645  0
                         }
 646  
                 };
 647  
         }
 648  
 
 649  
         private Matcher<SWTBotTable> tableWithRowIgnoringCase(final String itemText) {
 650  1
                 final String lowerCaseText = itemText.toLowerCase();
 651  1
                 return new AbstractMatcher<SWTBotTable>() {
 652  
 
 653  
                         protected boolean doMatch(Object item) {
 654  1
                                 List<String> rows = getRows((SWTBotTable) item);
 655  2
                                 for (String row : rows) {
 656  1
                                         if (row.toLowerCase().startsWith(lowerCaseText)) {
 657  1
                                                 return true;
 658  
                                         }
 659  
                                 }
 660  0
                                 return false;
 661  
                         }
 662  
 
 663  
                         public void describeTo(Description description) {
 664  0
                                 description.appendText("table with item (").appendText(itemText).appendText(")");
 665  0
                         }
 666  
                 };
 667  
         }
 668  
 
 669  
         private WaitForObjectCondition<SWTBotTable> quickFixAppears(Matcher<SWTBotTable> tableMatcher) {
 670  0
                 return new WaitForObjectCondition<SWTBotTable>(tableMatcher) {
 671  
                         protected List<SWTBotTable> findMatches() {
 672  
                                 try {
 673  0
                                         activateQuickFixShell();
 674  0
                                         SWTBotTable quickFixTable = getProposalTable();
 675  0
                                         if (matcher.matches(quickFixTable))
 676  0
                                                 return Arrays.asList(quickFixTable);
 677  0
                                 } catch (Throwable e) {
 678  0
                                         makeProposalsDisappear();
 679  
                                 }
 680  0
                                 return null;
 681  
                         }
 682  
 
 683  
                         public String getFailureMessage() {
 684  0
                                 return "Could not find auto complete proposal using matcher " + matcher;
 685  
                         }
 686  
 
 687  
                 };
 688  
         }
 689  
 
 690  
         /**
 691  
          * This activates the popup shell.
 692  
          * 
 693  
          * @return The shell.
 694  
          */
 695  
         private SWTBotShell activatePopupShell() {
 696  2
                 log.debug("Activating quickfix shell."); //$NON-NLS-1$
 697  
                 try {
 698  2
                         Shell mainWindow = syncExec(new WidgetResult<Shell>() {
 699  
                                 public Shell run() {
 700  2
                                         return styledText.widget.getShell();
 701  
                                 }
 702  
                         });
 703  2
                         SWTBotShell shell = bot.shell("", mainWindow); //$NON-NLS-1$
 704  2
                         shell.activate();
 705  2
                         log.debug("Activated quickfix shell."); //$NON-NLS-1$
 706  2
                         return shell;
 707  0
                 } catch (Exception e) {
 708  0
                         throw new QuickFixNotFoundException("Quickfix popup not found. Giving up.", e); //$NON-NLS-1$
 709  
                 }
 710  
         }
 711  
 
 712  
         private WaitForObjectCondition<SWTBotTable> autoCompleteAppears(Matcher<SWTBotTable> tableMatcher) {
 713  2
                 return new WaitForObjectCondition<SWTBotTable>(tableMatcher) {
 714  
                         protected List<SWTBotTable> findMatches() {
 715  
                                 try {
 716  2
                                         activateAutoCompleteShell();
 717  2
                                         SWTBotTable autoCompleteTable = getProposalTable();
 718  2
                                         if (matcher.matches(autoCompleteTable)) {
 719  2
                                                 SWTBotEclipseEditor.this.log.debug("matched table, returning");
 720  2
                                                 return Arrays.asList(autoCompleteTable);
 721  
                                         }
 722  0
                                 } catch (Throwable e) {
 723  0
                                         makeProposalsDisappear();
 724  
                                 }
 725  0
                                 return null;
 726  
                         }
 727  
 
 728  
                         public String getFailureMessage() {
 729  0
                                 return "Could not find auto complete proposal using matcher " + matcher;
 730  
                         }
 731  
 
 732  
                 };
 733  
         }
 734  
 
 735  2
         private void activateAutoCompleteShell() {
 736  2
                 invokeAction("ContentAssistProposal");
 737  2
         }
 738  
 
 739  
         private void invokeAction(final String actionId) {
 740  2
                 final IAction action = ((ITextEditor) partReference.getEditor(false)).getAction(actionId);
 741  2
                 syncExec(new VoidResult() {
 742  
                         public void run() {
 743  2
                                 log.debug(MessageFormat.format("Activating action with id {0}", actionId));
 744  2
                                 action.run();
 745  2
                         }
 746  
                 });
 747  2
         }
 748  
 
 749  1
         private List<String> getRows(SWTBotTable table) {
 750  4
                 int rowCount = table.rowCount();
 751  4
                 List<String> result = new ArrayList<String>();
 752  11
                 for (int i = 0; i < rowCount; i++)
 753  7
                         result.add(table.cell(i, 0));
 754  4
                 return result;
 755  
         }
 756  
 
 757  0
         private void activateQuickFixShell() {
 758  0
                 invokeAction("QuickAssist");
 759  0
         }
 760  
 
 761  
         private void waitUntil(WaitForObjectCondition<SWTBotTable> table) {
 762  2
                 bot.waitUntil(table, 10000);
 763  2
         }
 764  
 
 765  
 }