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