| org.netbeans.modules.visualweb.gravy.TopComponentOperator org.netbeans.modules.visualweb.gravy.EditorOperator
EditorOperator | public class EditorOperator extends TopComponentOperator (Code) | | Handle an editor top component in NetBeans IDE. It enables to get, select, insert or
delete text, move caret, work with annotations and with toolbar buttons.
Majority of operations is done by JEditorPane API calls. If you want
to do operations by key navigation, use methods of JEditorPaneOperator
instance by
EditorOperator.txtEditorPane() . For example, call
txtEditorPane().changeCaretPosition(int) instead of
EditorOperator.setCaretPosition(int) .
Usage:
EditorOperator eo = new EditorOperator(filename);
eo.setCaretPositionToLine(10);
eo.insert("// My new comment\n");
eo.select("// My new comment");
eo.deleteLine(10);
eo.getToolbarButton("Toggle Bookmark").push();
// discard changes and close
eo.close(false);
// save changes and close
eo.close(true);
// try to close all opened documents (confirmation dialog may appear)
eo.closeAllDocuments();
// close all opened documents and discard all changes
eo.closeDiscardAll();
author: Jiri.Skrivanek@sun.com |
Constructor Summary | |
public | EditorOperator(String filename) Waits for the first opened editor with given name. | public | EditorOperator(String filename, int index) Waits for index-th opened editor with given name. | public | EditorOperator(ContainerOperator contOper, String filename) Waits for first open editor with given name in specified container. | public | EditorOperator(ContainerOperator contOper, String filename, int index) Waits for index-th opened editor with given name in specified container. |
Method Summary | |
public JComboBoxOperator | cboQuickBrowse() Returns operator of combo box showing members of the class. | public void | close(boolean save) Closes this editor by IDE API call and depending on given flag
it saves or discards changes. | static void | close(TopComponent tc, boolean save) Closes top component. | public void | closeAndCancelByPopup() | public static void | closeDiscardAll() Closes all opened documents and discards all changes by IDE API calls. | public boolean | contains(String text) Checks if editor window contains text specified as parameter text. | public void | delete(int offset, int length) Deletes given number of characters from specified possition. | public void | delete(int length) Deletes given number of characters from current caret possition. | public void | delete(int lineNumber, int column1, int column2) Deletes characters between column1 and column2 (both are included)
on the specified line. | public void | deleteLine(int line) Delete specified line. | public static String | getAnnotationShortDescription(Object annotation) Returns a short description of annotation. | public static String | getAnnotationType(Object annotation) Returns a string uniquely identifying annotation. | public Object[] | getAnnotations(int lineNumber) Gets an array of annotations attached to given line. | public Object[] | getAnnotations() Gets all annotations for current editor (Document). | public int | getLineNumber() Returns current line number. | public String | getText() Gets text from the currently opened Editor window. | public String | getText(int lineNumber) Gets text from specified line. | public JButtonOperator | getToolbarButton(String buttonTooltip) Return JButtonOperator representing a toolbar button found by given
tooltip within the Source Editor. | public JButtonOperator | getToolbarButton(int index) Return JButtonOperator representing index-th toolbar button within
the Source Editor. | public void | insert(String text) Inserts text to current position. | public void | insert(String text, int lineNumber, int column) Inserts text to position specified by line number and column. | public boolean | isModified() | public JLabelOperator | lblInputMode() Returns operator of label showing current input mode (INS/OVR -
insert/overwrite). | public JLabelOperator | lblRowColumn() Returns operator of label showing current row and column at the left
corner of the Source Editor window. | public JLabelOperator | lblStatusBar() Returns operator of status bar at the bottom of the Source Editor. | public void | pushDownArrowKey() | public void | pushEndKey() | public void | pushHomeKey() | public void | pushKey(int keyCode) Pushes key of requested key code. | public void | pushTabKey() | public void | pushToolbarPopupMenu(String popupPath) Pushes popup menu on toolbar. | public void | pushUpArrowKey() | public void | replace(String oldText, String newText) Replaces first occurence of oldText by newText. | public void | replace(String oldText, String newText, int index) Replaced index-th occurence of oldText by newText. | public void | save() Performs save action with optional verification. | public void | select(int lineNumber) Selects whole line specified by its number. | public void | select(int line1, int line2) Selects text between line1 and line2 (both are included). | public void | select(int lineNumber, int column1, int column2) Selects text in specified line on position defined by column1
and column2 (both are included). | public void | select(String text, int index) Selects index-th occurence of given text. | public void | select(String text) Selects first occurence of given text. | public void | setCaretPosition(int lineNumber, int column) | public void | setCaretPosition(int position) Sets caret to desired position. | public void | setCaretPosition(String text, int index, boolean before) Sets caret position before or after index-th occurence of given string. | public void | setCaretPosition(String text, boolean before) Sets caret position before or after first occurence of given string. | public void | setCaretPositionRelative(int relativeMove) Sets caret position relatively to current position. | public void | setCaretPositionToEndOfLine(int lineNumber) Sets caret position to the end of specified line. | public void | setCaretPositionToLine(int lineNumber) Sets caret position to the beginning of specified line. | public void | setQuickBrowse(String item) Selects item in quick browse combo box. | public JEditorPaneOperator | txtEditorPane() Returns operator of currently shown editor pane. | public void | verify() | public void | waitModified(boolean modified) Waits for given modified state of edited source. |
EditorOperator | public EditorOperator(String filename)(Code) | | Waits for the first opened editor with given name.
If not active, it is activated.
Parameters: filename - name of file showed in the editor (it used to be label of tab) |
EditorOperator | public EditorOperator(String filename, int index)(Code) | | Waits for index-th opened editor with given name.
If not active, it is activated.
Parameters: filename - name of file showed in the editor (it used to be label of tab) Parameters: index - index of editor to be find |
EditorOperator | public EditorOperator(ContainerOperator contOper, String filename)(Code) | | Waits for first open editor with given name in specified container.
If not active, it is activated.
Parameters: contOper - container where to search Parameters: filename - name of file showed in the editor (it used to be label of tab) |
EditorOperator | public EditorOperator(ContainerOperator contOper, String filename, int index)(Code) | | Waits for index-th opened editor with given name in specified container.
If not active, it is activated.
Parameters: contOper - container where to search Parameters: filename - name of file showed in the editor (it used to be label of tab) Parameters: index - index of editor to be find |
cboQuickBrowse | public JComboBoxOperator cboQuickBrowse()(Code) | | Returns operator of combo box showing members of the class. It
is applicable only for Java objects.
JComboBoxOperator instance of members combo box |
close | public void close(boolean save)(Code) | | Closes this editor by IDE API call and depending on given flag
it saves or discards changes.
Parameters: save - true - save changes, false - discard changes |
close | static void close(TopComponent tc, boolean save)(Code) | | Closes top component. It saves it or not depending on given flag.
Other top components like VCS outputs are closed directly.
It is package private because it is also used by EditorWindowOperator.
|
closeAndCancelByPopup | public void closeAndCancelByPopup()(Code) | | |
closeDiscardAll | public static void closeDiscardAll()(Code) | | Closes all opened documents and discards all changes by IDE API calls.
It works also if no file is modified, so it is a safe way how to close
documents and no block further execution.
|
contains | public boolean contains(String text)(Code) | | Checks if editor window contains text specified as parameter text.
Parameters: text - text to compare to true if text was found, false otherwise |
delete | public void delete(int offset, int length)(Code) | | Deletes given number of characters from specified possition.
Position of caret will not change.
Parameters: offset - position inside document (0 means the beginning) Parameters: length - number of characters to be deleted |
delete | public void delete(int length)(Code) | | Deletes given number of characters from current caret possition.
Position of caret will not change.
Parameters: length - number of characters to be deleted |
delete | public void delete(int lineNumber, int column1, int column2)(Code) | | Deletes characters between column1 and column2 (both are included)
on the specified line.
Parameters: lineNumber - number of line (beggining from 1) Parameters: column1 - column position where to start deleting (beggining from 1) Parameters: column2 - column position where to stop deleting (beggining from 1) |
deleteLine | public void deleteLine(int line)(Code) | | Delete specified line.
Position of caret will not change.
Parameters: line - number of line (beggining from 1) |
getAnnotationShortDescription | public static String getAnnotationShortDescription(Object annotation)(Code) | | Returns a short description of annotation. It is localized.
Parameters: annotation - instance of org.openide.text.Annotation a short description of annotation according to current locale |
getAnnotationType | public static String getAnnotationType(Object annotation)(Code) | | Returns a string uniquely identifying annotation. For editor bookmark
it is for example
org.netbeans.modules.editor.NbEditorKit.BOOKMARK_ANNOTATION_TYPE.
Parameters: annotation - instance of org.openide.text.Annotation a string uniquely identifying annotation See Also: EditorOperator.getAnnotations() See Also: EditorOperator.getAnnotations(int) |
getLineNumber | public int getLineNumber()(Code) | | Returns current line number.
number of line where the caret stays (first line == 1) |
getText | public String getText()(Code) | | Gets text from the currently opened Editor window.
a string representing whole content of the Editor window(including new line characters) |
getText | public String getText(int lineNumber)(Code) | | Gets text from specified line.
It might fail on the last line of a file because of issues
http://www.netbeans.org/issues/show_bug.cgi?id=24434 and
http://www.netbeans.org/issues/show_bug.cgi?id=24433.
Parameters: lineNumber - number of line (beggining from 1) a string representing content of the line including new linecharacter |
getToolbarButton | public JButtonOperator getToolbarButton(String buttonTooltip)(Code) | | Return JButtonOperator representing a toolbar button found by given
tooltip within the Source Editor.
Parameters: buttonTooltip - tooltip of toolbar button JButtonOperator instance of found toolbar button |
getToolbarButton | public JButtonOperator getToolbarButton(int index)(Code) | | Return JButtonOperator representing index-th toolbar button within
the Source Editor.
Parameters: index - index of toolbar button to find JButtonOperator instance of found toolbar button |
insert | public void insert(String text)(Code) | | Inserts text to current position. Caret will stand at the end
of newly inserted text.
Parameters: text - a string to be inserted |
insert | public void insert(String text, int lineNumber, int column)(Code) | | Inserts text to position specified by line number and column.
Caret will stand at the end of newly inserted text.
Parameters: text - a string to be inserted Parameters: lineNumber - number of line (beggining from 1) Parameters: column - column position (beggining from 1) |
isModified | public boolean isModified()(Code) | | Returns current modify state of edited source
boolean true when edited source is modified |
lblInputMode | public JLabelOperator lblInputMode()(Code) | | Returns operator of label showing current input mode (INS/OVR -
insert/overwrite).
JLabelOperator instance of input mode label |
lblRowColumn | public JLabelOperator lblRowColumn()(Code) | | Returns operator of label showing current row and column at the left
corner of the Source Editor window.
JLabelOperator instance of row:column label |
lblStatusBar | public JLabelOperator lblStatusBar()(Code) | | Returns operator of status bar at the bottom of the Source Editor.
JLabelOperator instance of status bar |
pushDownArrowKey | public void pushDownArrowKey()(Code) | | Pushes Down key (KeyEvent.VK_DOWN)
|
pushEndKey | public void pushEndKey()(Code) | | Pushes End key (KeyEvent.VK_END)
|
pushHomeKey | public void pushHomeKey()(Code) | | Pushes Home key (KeyEvent.VK_HOME)
|
pushKey | public void pushKey(int keyCode)(Code) | | Pushes key of requested key code.
|
pushTabKey | public void pushTabKey()(Code) | | Pushes Tab key (KeyEvent.VK_TAB)
|
pushToolbarPopupMenu | public void pushToolbarPopupMenu(String popupPath)(Code) | | Pushes popup menu on toolbar. It doesn't matter on which position it is
invoked, everytime it is the same. That's why popup menu is invoked on
the toolbar button with index 0. To switch toolbar on use Options ->
Editing -> Editor Settings -> Toolbar Visible -> true.
Parameters: popupPath - path to menu item (e.g. "Toolbar Visible") |
pushUpArrowKey | public void pushUpArrowKey()(Code) | | Pushes Up key (KeyEvent.VK_UP)
|
replace | public void replace(String oldText, String newText)(Code) | | Replaces first occurence of oldText by newText.
Parameters: oldText - text to be replaced Parameters: newText - text to write instead |
replace | public void replace(String oldText, String newText, int index)(Code) | | Replaced index-th occurence of oldText by newText.
Parameters: oldText - text to be replaced Parameters: newText - text to write instead Parameters: index - index of oldText occurence (first occurence has index 0) |
save | public void save()(Code) | | Performs save action with optional verification.
|
select | public void select(int lineNumber)(Code) | | Selects whole line specified by its number. Caret will stand at the
next available line.
Parameters: lineNumber - number of line (beggining from 1) |
select | public void select(int line1, int line2)(Code) | | Selects text between line1 and line2 (both are included). Caret will
stand behing the selection (at the next line if available).
Parameters: line1 - number of line where to begin (beggining from 1) Parameters: line2 - number of line where to finish (beggining from 1) |
select | public void select(int lineNumber, int column1, int column2)(Code) | | Selects text in specified line on position defined by column1
and column2 (both are included). Caret will stand at the end of
the selection.
Parameters: lineNumber - number of line (beggining from 1) Parameters: column1 - column position where selection starts (beggining from 1) Parameters: column2 - column position where selection ends (beggining from 1) |
select | public void select(String text, int index)(Code) | | Selects index-th occurence of given text.
Parameters: text - text to be selected Parameters: index - index of text occurence (first occurence has index 0) See Also: EditorOperator.select(String) |
setCaretPosition | public void setCaretPosition(int lineNumber, int column)(Code) | | Sets caret position to specified line and column
Parameters: lineNumber - line number where to set caret Parameters: column - column where to set caret (1 means beginning of the row) |
setCaretPosition | public void setCaretPosition(int position)(Code) | | Sets caret to desired position.
Parameters: position - a position to set caret to (number of characters fromthe beggining of the file - 0 means beginning of the file). |
setCaretPosition | public void setCaretPosition(String text, int index, boolean before)(Code) | | Sets caret position before or after index-th occurence of given string.
Parameters: text - text to be searched Parameters: index - index of text occurence (first occurence has index 0) Parameters: before - if true put caret before text, otherwise after. |
setCaretPosition | public void setCaretPosition(String text, boolean before)(Code) | | Sets caret position before or after first occurence of given string.
Parameters: text - text to be searched Parameters: before - if true put caret before text, otherwise after. |
setCaretPositionRelative | public void setCaretPositionRelative(int relativeMove)(Code) | | Sets caret position relatively to current position.
Parameters: relativeMove - count of charaters to move caret |
setCaretPositionToEndOfLine | public void setCaretPositionToEndOfLine(int lineNumber)(Code) | | Sets caret position to the end of specified line.
Lines are numbered from 1, so setCaretPosition(1) will set caret
to the end of the first line.
Parameters: lineNumber - number of line (beggining from 1) |
setCaretPositionToLine | public void setCaretPositionToLine(int lineNumber)(Code) | | Sets caret position to the beginning of specified line.
Lines are numbered from 1, so setCaretPosition(1) will set caret
to the beginning of the first line.
Parameters: lineNumber - number of line (beggining from 1) |
setQuickBrowse | public void setQuickBrowse(String item)(Code) | | Selects item in quick browse combo box.
Parameters: item - itme to be selected |
txtEditorPane | public JEditorPaneOperator txtEditorPane()(Code) | | Returns operator of currently shown editor pane.
JTabbedPaneOperator instance of editor pane |
verify | public void verify()(Code) | | Performs verification by accessing all sub-components
|
waitModified | public void waitModified(boolean modified)(Code) | | Waits for given modified state of edited source.
Parameters: modified - boolean true waits for file state change to modified, false for change tounmodified (saved).Throws TimeoutExpiredException when EditorOperator.WaitModifiedTimeout expires. |
|
|