|
SWT LPEX v3.0.0 | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.lpex.core.LpexView
Use this class to manage an LPEX document view. It essentially provides all the editor widget programming support.
Creating an instance of this class creates a document view. When you're just extending an existing LPEX-based application, view management (creation, disposal) is usually that application's resposibility.
Lines and elements
Most methods that access the document text use as argument an element ordinal number. An element is any line of text displayed in the LPEX view, including show lines (such as imbedded informational and error messages, not saved with the document). A line represents one line (or record) in the actual document (and its underlying file), as displayed on the LPEX status line.
In general, a document parser skips and ignores show lines:
if (view.show(anElement)) { // ignore it } |
LpexCharStream also ignores them, and does not send them to a token manager.
During the processing of one parse unit (i.e., during one total-parse or one incremental-parse call from LpexCommonParser), requests to addMessage() and removeMessages() are stacked, and only processed afterwards. In other words, during one such call, the parser will see the same element numbers throughout the document - the messages will only be added and removed by LpexCommonParser when the parser returns.
In view of the above, a parser should not concern itself with changes in element numbers during a parse operation. If, however, your parser keeps (caches) information across parse calls from LpexCommonParser, you may consider keeping it in term of lines rather than elements (to retrieve the document line number of a non-show element, you can use lineOfElement()). Marks may also be set to tag particular elements for this purpose (see the mark editor parameter).
If your code itself inserts a series of show lines (for example, compiler error messages) in a view, the easiest way to do it is starting from the last (i.e., from the highest element number), and proceeding towards the first (lowest element number).
Nested Class Summary | |
---|---|
static class | LpexView.ViewInstantiationException
Indicates a failed attempt to create a new view. |
Constructor Summary | |
---|---|
LpexView()
Use this constructor to create an untitled document. | |
LpexView(boolean updateProfile)
Use this constructor to create an untitled document, indicating whether the updateProfile command should be called. | |
LpexView(LpexView lpexView)
Use this constructor to create a new document view from the specified document view. | |
LpexView(LpexView lpexView,
boolean updateProfile)
Use this constructor to create a new document view from the specified document view, indicating whether the updateProfile command should be called. | |
LpexView(String fileName)
Use this constructor to create a document from the specified file name. | |
LpexView(String fileName,
boolean updateProfile)
Use this constructor to create a document from the specified file name, indicating whether the updateProfile command should be called. | |
LpexView(String fileName,
String fileEncoding,
boolean updateProfile)
Use this constructor to create a document from the given file name, specifying its character encoding and indicating whether the updateProfile command should be called. |
Method Summary | |
---|---|
LpexAction | action(String actionString)
Retrieves the specified user-defined action. |
boolean | actionAvailable(int actionId)
Checks whether the specified action is available. |
int | actionId(String actionString)
Retrieves the id of the specified default or user-defined action. |
String | actionKey(int actionId)
Returns the primary key associated with the specified action. |
String | actionKeyText(int actionId)
Returns a translated text version of the primary key for the specified action. |
void | addLpexCursorListener(LpexCursorListener cursorListener)
Adds a cursor listener to this editor view. |
void | addLpexDocumentAdjustListener(LpexDocumentListener documentAdjustListener)
Adds a document-adjust listener to the editor document of this view. |
void | addLpexDocumentListener(LpexDocumentListener documentListener)
Adds a document listener to the editor document of this view. |
void | addLpexDocumentSectionListener(LpexDocumentSectionListener sectionListener)
Adds a document-section listener to the editor document of this view. |
void | addLpexKeyListener(LpexKeyListener keyListener)
Adds an LPEX key listener to this editor view. |
void | addLpexMarkListener(int markId,
LpexMarkListener markListener)
Adds a mark listener to the specified mark. |
void | addLpexViewListener(LpexViewListener viewListener)
Adds a view listener to this editor view. |
LpexView | blockView()
Returns the view with the selection, if any. |
int | charOffset(LpexDocumentLocation documentLocation,
int eolLength)
Returns a document (or document section) location's Unicode-character offset in its underlying file (section). |
long | classMask(String classNames)
Returns the bit-mask allocated in this view for the registered element class(es) named. |
LpexCommand | command(String commandString)
Retrieves the specified user-defined command. |
org.eclipse.swt.widgets.Widget | commandLineFocusWidget()
Returns the command line widget with the input focus, if any. |
int | currentElement()
Returns the ordinal number of the current (cursor) element in the document (or section of the document that is currently loaded in the editor). |
int | currentPosition()
Convenience method to retrieve the current (cursor) position within the current (cursor) element. |
boolean | defaultActionAvailable(int actionId)
Checks whether the specified default editor action is available. |
LpexAction | defineAction(String actionString,
LpexAction lpexAction)
Defines a user action. |
LpexCommand | defineCommand(String commandString,
LpexCommand lpexCommand)
Defines a user command. |
String | deletedMarkName(int markId)
Returns the name of the deleted mark with the id specified. |
void | dispose()
This method disposes the document view. |
void | doAction(int actionId)
Runs the specified action. |
boolean | doCommand(LpexDocumentLocation documentLocation,
String commandString)
Runs the specified command at the specified document (or document section) location. |
boolean | doCommand(String commandString)
Runs the specified command. |
LpexDocumentLocation | documentLocation()
Returns the view's current (cursor) location in the document (or section of the document that is currently loaded in the editor). |
LpexDocumentLocation | documentLocation(int charOffset,
int eolLength)
Returns the location in the document (or section of the document that is currently loaded in the editor) which corresponds to the given Unicode-character offset in its underlying file (section). |
int | documentViews()
Returns the number of views on this view's document. |
void | doDefaultAction(int actionId)
Runs the default editor action for the specified action id. |
boolean | doDefaultCommand(LpexDocumentLocation documentLocation,
String commandString)
Runs the specified default editor command. |
boolean | doDefaultCommand(String commandString)
Runs the specified default editor command. |
static boolean | doGlobalCommand(String commandString)
Runs the specified global command. |
long | elementClasses(int element)
Returns the bit-mask of the element classes set in an element of the document (or document section that is currently loaded in the editor). |
String | elementFullText(int element)
Returns the full text (i.e., including the sequence numbers, if set) of an element in the document (or document section currently loaded in the editor). |
int | elementOfLine(int line)
Returns the element for the specified line. |
int | elementOfRow(int row)
Returns the element in the document (or that section of the document that is currently loaded in the editor) which is displayed on the given screen row. |
void | elementParsed(int element)
Removes the specified element from the parse-pending list. |
int | elements()
Retrieves the number of elements in the document (or section of the document that is currently loaded in the editor). |
String | elementStyle(int element)
Returns the style string for an element in the document (or document section currently loaded in the editor). |
String | elementText(int element)
Returns the text of an element in the document (or document section currently loaded in the editor). |
static void | extendInstallProfile(Properties extension)
Extends the editor install profile. |
org.eclipse.swt.widgets.Shell | frame()
Retrieves the Shell that is used when dialogs are displayed. |
org.eclipse.swt.graphics.Font | getFont()
Returns the font in this view. |
static String | getLpexHelpPage(String lpexItem)
Returns the default HTML help panel for the editor item specified. |
static String | globalQuery(String parameter)
Queries a global editor parameter. |
boolean | isDisposed()
Returns whether the document view has been disposed. |
void | jump(int element,
int position)
Moves the cursor to the specified position in the document (or section of the document that is currently loaded in the editor). |
void | jump(LpexDocumentLocation documentLocation)
Moves the cursor to the specified position in the document (or section of the document that is currently loaded in the editor). |
boolean | keyAssigned(String keyString)
Checks whether the specified key is associated with an action. |
static String | keyText(String keyString)
Returns a translated text version of a key definition. |
String | lineFullText(int line)
Returns the full text (i.e., including the sequence numbers, if set) of a line in the document (or document section currently loaded in the editor). |
int | lineOfElement(int element)
Returns the line for the specified element. |
int | linesAfterEnd()
Returns the number of lines in the document following the currently-loaded document section. |
int | linesBeforeStart()
Returns the number of lines in the document prior to the currently-loaded document section. |
boolean | load(Reader reader)
Loads the entire text of the document (or document section) from the specified Reader. |
LpexView | lpexView(String documentName)
Returns a view handling the given document, if any. |
LpexNls | nls()
Retrieves the NLS object associated with this LpexView. |
int | notifyTruncateDocument(LpexDocumentListener listener,
int textLimit)
Issues document-listener notifications for the text-limit truncation of a document as done during save. |
void | notifyTruncateDocumentRestore(LpexDocumentListener listener,
int textLimit,
int firstTruncatedElement)
Issues document-listener notifications to restore the changes resulting from the text-limit truncation of a document as done during save. |
boolean | otherShow(int element)
Determines whether the specified element in the document (or document section that is currently loaded in the editor) is a show line for another document view. |
int | parsePending(int element)
Returns the parse-pending state of the specified element. |
LpexParser | parser()
Retrieves the current document parser for this view. |
String | query(String parameter)
Queries an editor parameter. |
String | query(String parameter,
LpexDocumentLocation documentLocation)
Queries an editor parameter. |
int | queryInt(String parameter)
Convenience method to query an editor integer parameter. |
int | queryInt(String parameter,
LpexDocumentLocation documentLocation)
Convenience method to query an editor integer parameter. |
boolean | queryOn(String parameter)
Convenience method to query an editor on/off parameter. |
boolean | queryOn(String parameter,
LpexDocumentLocation documentLocation)
Convenience method to query an editor on/off parameter. |
long | registerClass(String className)
Registers the specified element class in this view. |
void | removeLpexCursorListener(LpexCursorListener cursorListener)
Removes a cursor listener from this editor view. |
void | removeLpexDocumentAdjustListener(LpexDocumentListener documentAdjustListener)
Removes a document-adjust listener from the editor document of this view. |
void | removeLpexDocumentListener(LpexDocumentListener documentListener)
Removes a document listener from the editor document of this view. |
void | removeLpexDocumentSectionListener(LpexDocumentSectionListener sectionListener)
Removes a document-section listener from the editor document of this view. |
void | removeLpexKeyListener(LpexKeyListener keyListener)
Removes the specified LPEX key listener from this editor view. |
void | removeLpexMarkListener(int markId,
LpexMarkListener markListener)
Removes a mark listener from the specified mark. |
void | removeLpexMarkListener(LpexMarkListener markListener)
Removes a mark listener from all the marks in this document view for which it is registered. |
void | removeLpexViewListener(LpexViewListener viewListener)
Removes a view listener from this editor view. |
boolean | save(Writer writer)
Saves the entire text of the document (or document section currently loaded in the editor) to the specified Writer. |
static void | setClassLoader(ClassLoader classLoader)
Sets an alternative class loader to be used by the editor. |
void | setElementClasses(int element,
long classes)
Sets the element classes bit-mask in an element of the document (or document section that is currently loaded in the editor). |
void | setElementStyle(int element,
String style)
Sets the style string for an element in the document (or section of the document that is currently loaded in the editor). |
void | setElementText(int element,
String text)
Sets the text for an element in the document (or document section that is currently loaded in the editor). |
void | setFont(org.eclipse.swt.graphics.Font swtFont)
Sets a new font in this view. |
void | setFrame(org.eclipse.swt.widgets.Shell frame)
Sets the Shell that should be used when dialogs are displayed. |
boolean | setLinesOutsideDocumentSection(int linesBeforeStart,
int linesAfterEnd)
Sets the number of lines in the complete document that are outside the boundaries of the currently-loaded document section. |
void | setSaveWriter(Writer writer)
Sets the Writer object for the saveToWriter action. |
void | setText(String text)
Sets the entire text of the document (or document section). |
void | setWindow(LpexWindow lpexWindow)
Use this method to associate an LPEX window with this document view. |
boolean | show(int element)
Returns the show setting for an element in the document (or document section that is currently loaded in the editor). |
String | text()
Retrieves the entire text of the document (or document section currently loaded in the editor). |
void | triggerAction(int actionId)
Runs the specified action. |
void | triggerAction(int actionId,
boolean record)
Runs the specified action and optionally records it if keystroke recording is in progress. |
void | trimDocument()
Trims any trailing blanks in the text of a document, as done during save. |
LpexWindow | window()
Returns the LPEX window currently associated with this view. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public LpexView(String fileName, String fileEncoding, boolean updateProfile)
If you specify null for fileEncoding, the native (platform's default) encoding will be used. If you specify an empty String (""), the editor will attempt to detect the file encoding, and will default to the native encoding if unsuccessful.
If you specify true for updateProfile, then the updateProfile command will be called with the default settings. If you specify false, then updateProfile will not be called; you can then change updateProfile. settings and issue the updateProfile command later.
public LpexView(String fileName, boolean updateProfile)
If you specify true for updateProfile, then the updateProfile command will be called with the default settings. If you specify false, then updateProfile will not be called; you can then change the updateProfile settings and issue the updateProfile command later.
public LpexView(String fileName)
The updateProfile command will be called, with the default settings.
public LpexView()
The updateProfile command will be called, with the default settings.
public LpexView(boolean updateProfile)
If you specify true for updateProfile, then the updateProfile command will be called with the default settings. If you specify false, then updateProfile will not be called; you can then change the updateProfile settings and issue the updateProfile command later.
public LpexView(LpexView lpexView) throws LpexView.ViewInstantiationException
The updateProfile command will be called, with the default settings.
public LpexView(LpexView lpexView, boolean updateProfile) throws LpexView.ViewInstantiationException
If you specify true for updateProfile, then the updateProfile command will be called with the default settings. If you specify false, then updateProfile will not be called; you can then change the updateProfile settings and issue the updateProfile command later.
Method Detail |
public void dispose()
public boolean isDisposed()
public void setWindow(LpexWindow lpexWindow)
public LpexWindow window()
public int documentViews()
public LpexNls nls()
public void setText(String text)
This method is similar to the load editor command. It will clear the undo stack, reset the changes count, and issue updateProfile for all of the views of the current document.
public String text()
public boolean load(Reader reader)
This method is similar to the load editor command. It will clear the undo stack, reset the changes count, and issue updateProfile for all of the views of the current document.
public boolean save(Writer writer)
public void setSaveWriter(Writer writer)
Example of using saveToWriter with an OutputStreamWriter:
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(bytes, "UTF-8"); lpexView.setSaveWriter(writer); lpexView.triggerAction(lpexView.actionId("saveToWriter")); lpexView.setSaveWriter(null); |
Example of using saveToWriter to save to a String:
StringWriter writer = new StringWriter(); lpexView.setSaveWriter(writer); lpexView.doAction(lpexView.actionId("saveToWriter")); lpexView.setSaveWriter(null); String savedDocument = writer.toString(); |
public void trimDocument()
public int notifyTruncateDocument(LpexDocumentListener listener, int textLimit)
During a save operation, text elements saved to the file are truncated to the text-limit value in effect, under these conditions:
public void notifyTruncateDocumentRestore(LpexDocumentListener listener, int textLimit, int firstTruncatedElement)
public LpexCommand defineCommand(String commandString, LpexCommand lpexCommand)
public LpexCommand command(String commandString)
LpexCommand myInsertTextCommand = lpexView.command("myInsertText"); |
public boolean doDefaultCommand(String commandString)
lpexView.doDefaultCommand("insertText xyz"); |
public boolean doDefaultCommand(LpexDocumentLocation documentLocation, String commandString)
public boolean doCommand(String commandString)
A user-defined command modifies the editor command set available in an LPEX view by overriding or extending a default editor command, or by adding an entirely new command. If there is no user-defined command for the specified command string, this method will run the default editor command, if any.
public boolean doCommand(LpexDocumentLocation documentLocation, String commandString)
A user-defined command modifies the editor command set available in an LPEX view by overriding or extending a default editor command, or by adding an entirely new command. If there is no user-defined command for the specified command string, this method will run the default editor command, if any.
public static boolean doGlobalCommand(String commandString)
LpexView.doGlobalCommand("updateProfile all"); LpexView.doGlobalCommand("set default.print.footer %p"); |
public LpexAction defineAction(String actionString, LpexAction lpexAction)
public int actionId(String actionString)
public LpexAction action(String actionString)
public void doDefaultAction(int actionId)
public boolean defaultActionAvailable(int actionId)
public void doAction(int actionId)
Note that the LPEX built-in action ids defined in LpexActionConstants (for example, LpexActionConstants.ACTION_BLOCK_COPY) are reserved for the internal use of the editor, and change between releases. You must query, and eventually cache, the id of a built-in action before using it, for example:
int blockCopyId = lpexView.actionId("blockCopy"); lpexView.triggerAction(blockCopyId); |
public void triggerAction(int actionId)
Note that the LPEX built-in action ids defined in LpexActionConstants (for example, LpexActionConstants.ACTION_BLOCK_COPY) are reserved for the internal use of the editor, and change between releases. You must query, and eventually cache, the id of a built-in action before using it, for example:
int blockCopyId = lpexView.actionId("blockCopy"); lpexView.triggerAction(blockCopyId); |
public void triggerAction(int actionId, boolean record)
public boolean actionAvailable(int actionId)
public String actionKey(int actionId)
public String actionKeyText(int actionId)
public static String keyText(String keyString)
public boolean keyAssigned(String keyString)
keyAssigned("c-o.t"); |
public int elements()
Note: the elements editor parameter always returns the number of elements in the complete document.
public void jump(int element, int position)
Note: the locate editor command always applies to elements or lines in the complete document.
public void jump(LpexDocumentLocation documentLocation)
Note: the locate editor command always applies to elements or lines in the complete document.
public LpexParser parser()
public int parsePending(int element)
public void elementParsed(int element)
public String elementText(int element)
Note: the text editor parameter applies to the current element.
public String elementFullText(int element)
public String lineFullText(int line)
public void setElementText(int element, String text)
Note: the text editor parameter applies to the current element.
public boolean show(int element)
Note: the show editor parameter applies to the current element.
public boolean otherShow(int element)
public String elementStyle(int element)
Note: the style editor parameter applies to the current element.
public void setElementStyle(int element, String style)
Note: the style editor parameter applies to the current element.
public long elementClasses(int element)
Note: the elementClasses editor parameter applies to the current element.
public void setElementClasses(int element, long classes)
Note: the elementClasses editor parameter applies to the current element.
public long registerClass(String className)
public long classMask(String classNames)
public int currentElement()
Note: the element editor parameter returns the ordinal number of the (current) element in the complete document.
public int currentPosition()
lpexView.queryInt("position"); |
public LpexDocumentLocation documentLocation()
Note: the element editor parameter returns the ordinal number of the (current) element in the complete document.
public LpexDocumentLocation documentLocation(int charOffset, int eolLength)
This method assumes that a consistent line separator is used throughout the underlying file (section).
public int charOffset(LpexDocumentLocation documentLocation, int eolLength)
This method assumes that a consistent line separator is used throughout the underlying file (section).
public LpexView lpexView(String documentName)
public LpexView blockView()
public String query(String parameter)
public int queryInt(String parameter)
String value = query(parameter); return (value != null)? Integer.parseInt(value) : -1; |
public boolean queryOn(String parameter)
String value = query(parameter); return value != null && value.equals("on"); |
public String query(String parameter, LpexDocumentLocation documentLocation)
public int queryInt(String parameter, LpexDocumentLocation documentLocation)
String value = query(parameter, documentLocation); return (value != null)? Integer.parseInt(value) : -1; |
public boolean queryOn(String parameter, LpexDocumentLocation documentLocation)
String value = query(parameter, documentLocation); return value != null && value.equals("on"); |
public int elementOfRow(int row)
public int elementOfLine(int line)
Note: the element editor parameter returns the ordinal number of the (current) element in the complete document.
public int lineOfElement(int element)
If the element is a show element, the first document line above it is returned. If the element does not exist, or if there is no document line corresponding to the given element (for example, one or more show elements at the top of the document), this method returns 0.
Note: the line editor parameter returns the ordinal number of the (current) line in the complete document.
public String deletedMarkName(int markId)
public static String globalQuery(String parameter)
LpexView.globalQuery("version"); |
public boolean setLinesOutsideDocumentSection(int linesBeforeStart, int linesAfterEnd)
This feature is only provided for certain specific applications. Normally, the editor loads and operates on a complete document (file).
A call to this method may fail under certain circumstances. For example, you cannot use the document section feature when several views have been opened on the same document. In such a case false will be returned.
public int linesBeforeStart()
public int linesAfterEnd()
public void addLpexViewListener(LpexViewListener viewListener)
public void removeLpexViewListener(LpexViewListener viewListener)
public void addLpexCursorListener(LpexCursorListener cursorListener)
public void removeLpexCursorListener(LpexCursorListener cursorListener)
public void addLpexMarkListener(int markId, LpexMarkListener markListener)
public void removeLpexMarkListener(int markId, LpexMarkListener markListener)
public void removeLpexMarkListener(LpexMarkListener markListener)
public void addLpexDocumentListener(LpexDocumentListener documentListener)
A listener is only registered once, subsequent calls to add the same listener have no effect.
public void removeLpexDocumentListener(LpexDocumentListener documentListener)
public void addLpexDocumentAdjustListener(LpexDocumentListener documentAdjustListener)
Examples of text being further adjusted when set in the editor: padding of the text up to (the end of) the sequence-numbers area; reinterpretation of document text as sequence numbers; resequencing; MBCS bytes vs. Unicode characters inconsistencies in sequence-numbers columns; MBCS adjustment with spaces added prior to the sequence-numbers area.
A listener is only registered once, subsequent calls to add the same listener have no effect.
public void removeLpexDocumentAdjustListener(LpexDocumentListener documentAdjustListener)
public void addLpexDocumentSectionListener(LpexDocumentSectionListener sectionListener)
public void removeLpexDocumentSectionListener(LpexDocumentSectionListener sectionListener)
public static void setClassLoader(ClassLoader classLoader)
Class loaders registered through this method are only used when a class cannot be loaded by the current LPEX loader. Used for loading the user profile, user-defined commands and actions, and document parsers.
public static void extendInstallProfile(Properties extension)
This method should be called before any document views are created. Any of the editor parameters that are available with the install parameter can have installation settings specified in the install profile. Only new "install." values should be set in this manner.
Here is the Install.properties file shipped with LPEX.
Example:
Properties sabreTalkProperties = new Properties(); sabreTalkProperties.setProperty("install.updateProfile.parserClass.sabreTalk", "com.ibm.etools.tpf.sbt.SabreTalkParser"); sabreTalkProperties.setProperty("install.updateProfile.parserAssociation.sbt", "sabreTalk"); sabreTalkProperties.setProperty("install.updateProfile.parserAssociation.SBT", "sabreTalk"); LpexView.extendInstallProfile(sabreTalkProperties); |
public static String getLpexHelpPage(String lpexItem)
For example, getLpexHelpPage("tabs"); will return "ref/rlptabs.htm".
An application using LPEX must redefine the help command (by implementing the LpexCommand interface) to use its own help-delivery mechanism.
public void setFrame(org.eclipse.swt.widgets.Shell frame)
public org.eclipse.swt.widgets.Shell frame()
public org.eclipse.swt.widgets.Widget commandLineFocusWidget()
public void addLpexKeyListener(LpexKeyListener keyListener)
A listener is only registered once, subsequent calls to add the same listener have no effect.
public void removeLpexKeyListener(LpexKeyListener keyListener)
public void setFont(org.eclipse.swt.graphics.Font swtFont)
public org.eclipse.swt.graphics.Font getFont()
|
SWT LPEX v3.0.0 | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |