org.eclipse.swtbot.eclipse.finder.widgets
Class SWTBotEclipseEditor

java.lang.Object
  extended by org.eclipse.swtbot.eclipse.finder.widgets.SWTBotWorkbenchPart<IEditorReference>
      extended by org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor
          extended by org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor

public class SWTBotEclipseEditor
extends SWTBotEditor

This represents an eclipse editor item.

Version:
$Id$
Author:
Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>, Ralf Ebert www.ralfebert.de (bug 271630)

Field Summary
 
Fields inherited from class org.eclipse.swtbot.eclipse.finder.widgets.SWTBotWorkbenchPart
bot, log, partReference
 
Constructor Summary
SWTBotEclipseEditor(IEditorReference editorReference, SWTWorkbenchBot bot)
          Constructs an instance of the given object.
SWTBotEclipseEditor(IEditorReference editorReference, SWTWorkbenchBot bot, SelfDescribing description)
          Constructs an instance for the given editorReference.
 
Method Summary
 void autoCompleteProposal(String insertText, String proposalText)
          Auto completes the given proposal.
 Color backgroundColor()
          Gets the background color of the widget.
 SWTBotMenu contextMenu(String text)
          Gets the context menu in the editor.
 Position cursorPosition()
          Gets the current position of the cursor.
 Color foregroundColor()
          Gets the foreground color of the widget.
 List<String> getAutoCompleteProposals(String insertText)
          Gets the auto completion proposal matching the given text..
 Bullet getBulletOnCurrentLine()
           
 Bullet getBulletOnLine(int line)
           
 IEditorReference getEditorReference()
          Deprecated. use SWTBotWorkbenchPart.getReference() instead
 RGB getLineBackground(int line)
          Gets the color of the background on the specified line.
 int getLineCount()
          Gets the number of lines in the StyledText.
 List<String> getLines()
          Gets all the lines in the editor.
 List<String> getQuickFixes()
          Finds all the quickfixes in the quickfix list.
 int getQuickfixListItemCount()
          Gets the quick fix item count.
 String getSelection()
          Gets the current selection.
 StyleRange getStyle(int line, int column)
          Gets the style text.
 SWTBotStyledText getStyledText()
           
 StyleRange[] getStyles(int line, int column, int length)
           
 String getText()
          Gets the text of this object's widget.
 String getTextOnCurrentLine()
           
 String getTextOnLine(int line)
          Get the text on line number given as parameter.
 String getToolTipText()
          Gets the tooltip of this object's widget.
 boolean hasBulletOnCurrentLine()
           
 boolean hasBulletOnLine(int line)
           
 void insertText(int line, int column, String text)
           
 void insertText(String text)
           
 boolean isEnabled()
          Gets if the object's widget is enabled.
 void navigateTo(int line, int column)
           
 void navigateTo(Position position)
          Sets the caret at the specified location.
 void notifyKeyboardEvent(int modificationKeys, char c)
          Deprecated. use pressShortcut(int, char) instead. This api will be removed.
 void notifyKeyboardEvent(int modificationKeys, char c, int keyCode)
          Deprecated. use pressShortcut(int, int, char) instead. This api will be removed.
 void pressShortcut(int modificationKeys, char c)
          Presses the shortcut specified by the given keys.
 void pressShortcut(int modificationKeys, int keyCode, char c)
          Presses the shortcut specified by the given keys.
 void pressShortcut(KeyStroke... keys)
          Presses the shortcut specified by the given keys.
 void quickfix(int quickFixIndex)
          Applys a quick fix item at the given index.
 void quickfix(String quickFixName)
          Applys a quick fix item with the given name.
 void selectCurrentLine()
          Selects the text on the current line.
 void selectLine(int line)
           
 void selectRange(int line, int column, int length)
           
 void setFocus()
          Sets focus on the current part.
 void setText(String text)
           
 void typeText(int line, int column, String text)
           
 void typeText(String text)
           
 void typeText(String text, int interval)
           
 
Methods inherited from class org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor
close, isActive, isDirty, save, saveAndClose, show, toTextEditor
 
Methods inherited from class org.eclipse.swtbot.eclipse.finder.widgets.SWTBotWorkbenchPart
assertActive, bot, findWidget, findWidgets, getReference, getTitle, getToolbarButtons, getWidget, toolbarButton, toolbarDropDownButton, toolbarPushButton, toolbarRadioButton, toolbarToggleButton
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SWTBotEclipseEditor

public SWTBotEclipseEditor(IEditorReference editorReference,
                           SWTWorkbenchBot bot)
                    throws WidgetNotFoundException
Constructs an instance of the given object.

Parameters:
editorReference - the editor reference.
bot - the instance of SWTWorkbenchBot which will be used to drive operations on behalf of this object.
Throws:
WidgetNotFoundException - if the widget is null or widget has been disposed.
Since:
2.0

SWTBotEclipseEditor

public SWTBotEclipseEditor(IEditorReference editorReference,
                           SWTWorkbenchBot bot,
                           SelfDescribing description)
Constructs an instance for the given editorReference.

Parameters:
editorReference - the part reference.
bot - the helper bot.
description - the description of the editor part.
Method Detail

getStyledText

public SWTBotStyledText getStyledText()
Returns:
the styledText

getEditorReference

public IEditorReference getEditorReference()
Deprecated. use SWTBotWorkbenchPart.getReference() instead

Returns:
the editor reference for this view.

quickfix

public void quickfix(int quickFixIndex)
Applys a quick fix item at the given index.

Parameters:
quickFixIndex - the index of the quickfix item to apply.
Throws:
WidgetNotFoundException - if the quickfix could not be found.

quickfix

public void quickfix(String quickFixName)
Applys a quick fix item with the given name.

Parameters:
quickFixName - the name of the quick fix to apply.

getQuickFixes

public List<String> getQuickFixes()
Finds all the quickfixes in the quickfix list.

Returns:
the list of all available quickfixes.
Since:
1.2

getQuickfixListItemCount

public int getQuickfixListItemCount()
Gets the quick fix item count.

Returns:
the number of quickfix items in the quickfix proposals.
Since:
1.2

getAutoCompleteProposals

public List<String> getAutoCompleteProposals(String insertText)
Gets the auto completion proposal matching the given text..

Parameters:
insertText - the proposal text to type before auto completing
Returns:
the list of proposals
Throws:
TimeoutException - if the autocomplete shell did not close in time.
Since:
1.2

autoCompleteProposal

public void autoCompleteProposal(String insertText,
                                 String proposalText)
Auto completes the given proposal.

Parameters:
insertText - the text to be inserted before activating the auto-complete.
proposalText - the auto-completion proposal to select from the list.

contextMenu

public SWTBotMenu contextMenu(String text)
                       throws WidgetNotFoundException
Gets the context menu in the editor.

Parameters:
text - the context menu item.
Returns:
the menu
Throws:
WidgetNotFoundException - if the menu with the specified text could not be found.
See Also:
AbstractSWTBot.contextMenu(java.lang.String)

cursorPosition

public Position cursorPosition()
Gets the current position of the cursor. The returned position will contain a 0-based line and column.

Returns:
the position of the cursor.
See Also:
SWTBotStyledText.cursorPosition()

isEnabled

public boolean isEnabled()
Gets if the object's widget is enabled.

Returns:
true if the widget is enabled.
See Also:
AbstractSWTBot.isEnabled()

getSelection

public String getSelection()
Gets the current selection.

Returns:
The selected string.

getStyle

public StyleRange getStyle(int line,
                           int column)
Gets the style text.

Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
Returns:
the StyleRange at the specified location
See Also:
SWTBotStyledText.getStyle(int, int)

getText

public String getText()
Gets the text of this object's widget.

Returns:
the text on the styledtext.
See Also:
AbstractSWTBot.getText()

typeText

public void typeText(int line,
                     int column,
                     String text)
Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
text - the text to be typed at the specified location
Since:
1.0
See Also:
SWTBotStyledText.typeText(int, int, java.lang.String)

typeText

public void typeText(String text)
Parameters:
text - the text to be typed at the location of the caret. *
Since:
1.0
See Also:
SWTBotStyledText.typeText(java.lang.String)

insertText

public void insertText(int line,
                       int column,
                       String text)
Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
text - the text to be inserted at the specified location
See Also:
SWTBotStyledText.insertText(int, int, java.lang.String)

insertText

public void insertText(String text)
Parameters:
text - the text to be inserted at the location of the caret.
See Also:
SWTBotStyledText.insertText(java.lang.String)

typeText

public void typeText(String text,
                     int interval)
Parameters:
text - the text to be typed at the location of the caret.
interval - the interval between consecutive key strokes.
Since:
1.0
See Also:
SWTBotStyledText.typeText(java.lang.String, int)

navigateTo

public void navigateTo(Position position)
Sets the caret at the specified location.

Parameters:
position - the position of the caret.

navigateTo

public void navigateTo(int line,
                       int column)
Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
See Also:
SWTBotStyledText.navigateTo(int, int)

notifyKeyboardEvent

public void notifyKeyboardEvent(int modificationKeys,
                                char c)
Deprecated. use pressShortcut(int, char) instead. This api will be removed.

Notifies of the keyboard event.

FIXME need some work for CTRL|SHIFT + 1 the 1 is to be sent as '!' in this case.

Parameters:
modificationKeys - the modification keys.
c - the character.
See Also:
Event.character, Event.stateMask

notifyKeyboardEvent

public void notifyKeyboardEvent(int modificationKeys,
                                char c,
                                int keyCode)
Deprecated. use pressShortcut(int, int, char) instead. This api will be removed.

Notifies of keyboard event.

Parameters:
modificationKeys - the modification key.
c - the character.
keyCode - any special keys (function keys, arrow or navigation keys etc.)
See Also:
Event.keyCode, Event.character, Event.stateMask

pressShortcut

public void pressShortcut(int modificationKeys,
                          char c)
Presses the shortcut specified by the given keys.

Parameters:
modificationKeys - the combination of SWT.ALT | SWT.CTRL | SWT.SHIFT | SWT.COMMAND.
c - the character.
See Also:
Keyboard.pressShortcut(KeyStroke...), Keystrokes.toKeys(int, char)

pressShortcut

public void pressShortcut(int modificationKeys,
                          int keyCode,
                          char c)
Presses the shortcut specified by the given keys.

Parameters:
modificationKeys - the combination of SWT.ALT | SWT.CTRL | SWT.SHIFT | SWT.COMMAND.
keyCode - the keyCode, these may be special keys like F1-F12, or navigation keys like HOME, PAGE_UP
c - the character
See Also:
Keystrokes.toKeys(int, char)

pressShortcut

public void pressShortcut(KeyStroke... keys)
Presses the shortcut specified by the given keys.

Parameters:
keys - the keys to press
See Also:
Keyboard.pressShortcut(KeyStroke...), Keystrokes

selectRange

public void selectRange(int line,
                        int column,
                        int length)
Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
length - the length of the selection.
See Also:
SWTBotStyledText.selectRange(int, int, int)

selectLine

public void selectLine(int line)
Parameters:
line - the line number to select, 0 based.
Since:
1.1
See Also:
SWTBotStyledText.selectLine(int)

selectCurrentLine

public void selectCurrentLine()
Selects the text on the current line.

Since:
1.1
See Also:
SWTBotStyledText.selectCurrentLine()

setFocus

public void setFocus()
Description copied from class: SWTBotWorkbenchPart
Sets focus on the current part.

Overrides:
setFocus in class SWTBotEditor
See Also:
AbstractSWTBot.setFocus()

setText

public void setText(String text)
Parameters:
text - the text to set.
See Also:
SWTBotStyledText.setText(java.lang.String)

getBulletOnCurrentLine

public Bullet getBulletOnCurrentLine()
Returns:
the bullet on the current line.
See Also:
SWTBotStyledText.getBulletOnCurrentLine()

getBulletOnLine

public Bullet getBulletOnLine(int line)
Parameters:
line - the line number, 0 based.
Returns:
the bullet on the given line.
See Also:
SWTBotStyledText.getBulletOnLine(int)

getStyles

public StyleRange[] getStyles(int line,
                              int column,
                              int length)
Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
length - the length.
Returns:
the styles in the specified range.
See Also:
SWTBotStyledText.getStyles(int, int, int)

getTextOnCurrentLine

public String getTextOnCurrentLine()
Returns:
the text on the current line, without the line delimiters.
See Also:
SWTBotStyledText.getTextOnCurrentLine()

getTextOnLine

public String getTextOnLine(int line)
Get the text on line number given as parameter. Note that in eclipse editors, folding has no incidence on line numbers.

Parameters:
line - the line number, 0 based.
Returns:
the text on the given line number, without the line delimiters.
See Also:
SWTBotStyledText.getTextOnLine(int)

hasBulletOnCurrentLine

public boolean hasBulletOnCurrentLine()
Returns:
true if the styledText has a bullet on the given line, false otherwise.
See Also:
SWTBotStyledText.hasBulletOnCurrentLine()

hasBulletOnLine

public boolean hasBulletOnLine(int line)
Parameters:
line - the line number, 0 based.
Returns:
true if the styledText has a bullet on the given line, false otherwise.
See Also:
SWTBotStyledText.hasBulletOnLine(int)

backgroundColor

public Color backgroundColor()
Gets the background color of the widget.

Returns:
the background color on the widget, or null if the widget is not an instance of Control.
Since:
1.3
See Also:
AbstractSWTBot.backgroundColor()

foregroundColor

public Color foregroundColor()
Gets the foreground color of the widget.

Returns:
the foreground color on the widget, or null if the widget is not an instance of Control.
Since:
1.3
See Also:
AbstractSWTBot.foregroundColor()

getLineBackground

public RGB getLineBackground(int line)
Gets the color of the background on the specified line.

Parameters:
line - the line number, 0 based.
Returns:
the RGB of the line background color of the specified line.
Since:
1.3
See Also:
SWTBotStyledText.getLineBackground(int)

getLineCount

public int getLineCount()
Gets the number of lines in the StyledText.

Returns:
the number of lines in the StyledText.

getLines

public List<String> getLines()
Gets all the lines in the editor.

Returns:
the lines in the editor.

getToolTipText

public String getToolTipText()
Gets the tooltip of this object's widget.

Returns:
the tooltip on the widget.
Since:
1.3
See Also:
AbstractSWTBot.getToolTipText()