org.eclipse.epf.richtext
Class RichTextEditor

java.lang.Object
  extended byorg.eclipse.epf.richtext.RichTextEditor
All Implemented Interfaces:
IRichText, IRichTextEditor
Direct Known Subclasses:
MethodRichTextEditor

public class RichTextEditor
extends java.lang.Object
implements IRichTextEditor

The default rich text editor implementation.

The default rich text editor uses XHTML as the underlying markup language for the rich text content. It is implemented using a ViewForm control with a tool bar at the top, a tab folder that contains a RichText control for entering the rich text content, and a tab foler that contains a StyleText control for viewing and modifying the XHTML representation of the rich text content.

Since:
1.0
Author:
Kelvin Low

Field Summary
 
Fields inherited from interface org.eclipse.epf.richtext.IRichText
PROPERTY_NAME
 
Constructor Summary
RichTextEditor(org.eclipse.swt.widgets.Composite parent, int style)
          Creates a new instance.
RichTextEditor(org.eclipse.swt.widgets.Composite parent, int style, java.lang.String basePath)
          Creates a new instance.
 
Method Summary
 void addDisposeListener(org.eclipse.swt.events.DisposeListener listener)
          Adds the listener to the collection of listeners who will be notifed when this editor is disposed.
 void addHelpListener(org.eclipse.swt.events.HelpListener listener)
          Adds a listener to the collection of listeners who will be notified when help events are generated for this editor.
 void addHTML(java.lang.String text)
          Inserts text at the selection (overwriting the selection).
 void addKeyListener(org.eclipse.swt.events.KeyListener listener)
          Adds a listener to the collection of listeners who will be notified when keys are pressed and released within this editor.
 void addListener(int eventType, org.eclipse.swt.widgets.Listener listener)
          Adds the listener to the collection of listeners who will be notifed when an event of the given type occurs within this editor.
 void addModifyListener(org.eclipse.swt.events.ModifyListener listener)
          Adds a listener to the collection of listeners who will be notified when the content of this editor is modified.
 void dispose()
          Disposes the operating system resources allocated by this editor.
 int executeCommand(java.lang.String command)
          Executes the given rich text command.
 int executeCommand(java.lang.String command, java.lang.String param)
          Executes the given rich text command with a single parameter.
 int executeCommand(java.lang.String command, java.lang.String[] params)
          Executes the given rich text command with an array of parameters.
 void fillToolBar(IRichTextToolBar toolBar)
          Fills the tool bar with action items.
 java.lang.String getBasePath()
          Returns the base path used for resolving text and image links.
 org.eclipse.swt.widgets.Control getControl()
          Returns the form control.
 java.lang.Object getData(java.lang.String key)
          Returns an application specific property value.
 boolean getEditable()
          Returns the editable state.
 java.lang.Object getLayoutData()
          Returns the layout data.
 java.util.Iterator getListeners()
          Returns the event listeners attached to this editor.
 boolean getModified()
          Checks whether the content has been modified.
 java.util.Iterator getModifyListeners()
          Returns the modify listeners attached to this editor.
 IRichText getRichTextControl()
          Returns the rich text control embedded within this editor.
 java.lang.String getSelectedText()
          Returns the currently selected text.
 org.eclipse.swt.custom.StyledText getSourceEdit()
          Returns the HTML source edit control.
 java.lang.String getText()
          Returns the rich text content.
 boolean hasFocus()
          Checks whether this editor has focus.
 boolean isDisposed()
          Checks whether this control has been disposed.
 boolean isHTMLTabSelected()
          Checks whether the HTML tab is selected.
 void removeDisposeListener(org.eclipse.swt.events.DisposeListener listener)
          Removes a listener from the collection of listeners who will be notified when this editor is disposed.
 void removeHelpListener(org.eclipse.swt.events.HelpListener listener)
          Removes a listener from the collection of listeners who will be notified when help events are generated for this editor.
 void removeKeyListener(org.eclipse.swt.events.KeyListener listener)
          Removes a listener from the collection of listeners who will be notified when keys are pressed and released within this editor.
 void removeListener(int eventType, org.eclipse.swt.widgets.Listener listener)
          Removes the listener from the collection of listeners who will be notifed when an event of the given type occurs within this editor.
 void removeModifyListener(org.eclipse.swt.events.ModifyListener listener)
          Removes a listener from the collection of listeners who will be notified when the content of this editor is modified.
 void restoreText()
          Restores the rich text content back to the initial value.
 void setData(java.lang.String key, java.lang.Object value)
          Sets an application specific property name and value.
 void setEditable(boolean editable)
          Sets the editable state.
 void setFocus()
          Sets focus to this editor.
 void setLayoutData(java.lang.Object layoutData)
          Sets the layout data.
 void setModified(boolean modified)
          Sets the modified state.
 void setSelection(int index)
          Selects the Rich Text or HTML tab.
 void setText(java.lang.String text)
          Sets the rich text content.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RichTextEditor

public RichTextEditor(org.eclipse.swt.widgets.Composite parent,
                      int style)
Creates a new instance.

Parameters:
parent - the parent composite
style - the editor style

RichTextEditor

public RichTextEditor(org.eclipse.swt.widgets.Composite parent,
                      int style,
                      java.lang.String basePath)
Creates a new instance.

Parameters:
parent - the parent composite
style - the editor style
basePath - the base path used for resolving links
Method Detail

getControl

public org.eclipse.swt.widgets.Control getControl()
Returns the form control.

Specified by:
getControl in interface IRichText
Returns:
the form control

getRichTextControl

public IRichText getRichTextControl()
Returns the rich text control embedded within this editor.


setLayoutData

public void setLayoutData(java.lang.Object layoutData)
Sets the layout data.

Specified by:
setLayoutData in interface IRichText
Parameters:
layoutData - the layout data to set

getLayoutData

public java.lang.Object getLayoutData()
Returns the layout data.

Specified by:
getLayoutData in interface IRichText
Returns:
the editor's layout data

setFocus

public void setFocus()
Sets focus to this editor.

Specified by:
setFocus in interface IRichText

hasFocus

public boolean hasFocus()
Checks whether this editor has focus.

Specified by:
hasFocus in interface IRichText
Returns:
true if this editor has the user-interface focus

setSelection

public void setSelection(int index)
Selects the Rich Text or HTML tab.

Specified by:
setSelection in interface IRichTextEditor
Parameters:
index - 0 for the Rich Text tab, 1 for the HTML tab.

getBasePath

public java.lang.String getBasePath()
Returns the base path used for resolving text and image links.

Specified by:
getBasePath in interface IRichText
Returns:
the base path used for resolving links specified with , , etc.

getEditable

public boolean getEditable()
Returns the editable state.

Specified by:
getEditable in interface IRichText
Returns:
true if the content can be edited

setEditable

public void setEditable(boolean editable)
Sets the editable state.

Specified by:
setEditable in interface IRichText
Parameters:
editable - the editable state

getModified

public boolean getModified()
Checks whether the content has been modified.

Specified by:
getModified in interface IRichText
Returns:
true if the content has been modified

setModified

public void setModified(boolean modified)
Sets the modified state.

Specified by:
setModified in interface IRichText
Parameters:
modified - the modified state

getText

public java.lang.String getText()
Returns the rich text content.

Specified by:
getText in interface IRichText
Returns:
the rich text content formatted in XHTML

setText

public void setText(java.lang.String text)
Sets the rich text content.

Specified by:
setText in interface IRichText
Parameters:
text - the rich text content in XHTML format

restoreText

public void restoreText()
Restores the rich text content back to the initial value.

Specified by:
restoreText in interface IRichText

getSelectedText

public java.lang.String getSelectedText()
Returns the currently selected text.

Specified by:
getSelectedText in interface IRichText
Returns:
the selected text or "" if there is no selection

getData

public java.lang.Object getData(java.lang.String key)
Returns an application specific property value.

Specified by:
getData in interface IRichText
Parameters:
key - the name of the property
Returns:
the value of the property or null if it has not been set

setData

public void setData(java.lang.String key,
                    java.lang.Object value)
Sets an application specific property name and value.

Specified by:
setData in interface IRichText
Parameters:
key - the name of the property
value - the new value for the property

executeCommand

public int executeCommand(java.lang.String command)
Executes the given rich text command. The supported command strings are defined in RichTextCommand.

Specified by:
executeCommand in interface IRichText
Parameters:
command - a rich text command string
Returns:
a status code returned by the executed command

executeCommand

public int executeCommand(java.lang.String command,
                          java.lang.String param)
Executes the given rich text command with a single parameter. The supported command strings are defined in RichTextCommand.

Specified by:
executeCommand in interface IRichText
Parameters:
command - a rich text command string
param - a parameter for the command or null
Returns:
a status code returned by the executed command

executeCommand

public int executeCommand(java.lang.String command,
                          java.lang.String[] params)
Executes the given rich text command with an array of parameters. The supported command strings are defined in RichTextCommand.

Specified by:
executeCommand in interface IRichText
Parameters:
command - a rich text command string
params - an array of parameters for the command or null
Returns:
a status code returned by the executed command

dispose

public void dispose()
Disposes the operating system resources allocated by this editor.

Specified by:
dispose in interface IRichText

isDisposed

public boolean isDisposed()
Checks whether this control has been disposed.

Specified by:
isDisposed in interface IRichText
Returns:
true if this control is disposed successfully

getModifyListeners

public java.util.Iterator getModifyListeners()
Returns the modify listeners attached to this editor.

Specified by:
getModifyListeners in interface IRichText
Returns:
an iterator for retrieving the modify listeners

addKeyListener

public void addKeyListener(org.eclipse.swt.events.KeyListener listener)
Adds a listener to the collection of listeners who will be notified when keys are pressed and released within this editor.

Specified by:
addKeyListener in interface IRichText
Parameters:
listener - the listener which should be notified

removeKeyListener

public void removeKeyListener(org.eclipse.swt.events.KeyListener listener)
Removes a listener from the collection of listeners who will be notified when keys are pressed and released within this editor.

Specified by:
removeKeyListener in interface IRichText
Parameters:
listener - the listener which should no longer be notified

addModifyListener

public void addModifyListener(org.eclipse.swt.events.ModifyListener listener)
Adds a listener to the collection of listeners who will be notified when the content of this editor is modified.

Specified by:
addModifyListener in interface IRichText
Parameters:
listener - the listener which should be notified

removeModifyListener

public void removeModifyListener(org.eclipse.swt.events.ModifyListener listener)
Removes a listener from the collection of listeners who will be notified when the content of this editor is modified.

Specified by:
removeModifyListener in interface IRichText
Parameters:
listener - the listener which should no longer be notified

addDisposeListener

public void addDisposeListener(org.eclipse.swt.events.DisposeListener listener)
Adds the listener to the collection of listeners who will be notifed when this editor is disposed.

Specified by:
addDisposeListener in interface IRichText
Parameters:
listener - the listener which should be notified

removeDisposeListener

public void removeDisposeListener(org.eclipse.swt.events.DisposeListener listener)
Removes a listener from the collection of listeners who will be notified when this editor is disposed.

Specified by:
removeDisposeListener in interface IRichText
Parameters:
listener - the listener which should no longer be notified

addHelpListener

public void addHelpListener(org.eclipse.swt.events.HelpListener listener)
Adds a listener to the collection of listeners who will be notified when help events are generated for this editor.

Specified by:
addHelpListener in interface IRichText
Parameters:
listener - the listener which should be notified

removeHelpListener

public void removeHelpListener(org.eclipse.swt.events.HelpListener listener)
Removes a listener from the collection of listeners who will be notified when help events are generated for this editor.

Specified by:
removeHelpListener in interface IRichText
Parameters:
listener - the listener which should no longer be notified

addListener

public void addListener(int eventType,
                        org.eclipse.swt.widgets.Listener listener)
Adds the listener to the collection of listeners who will be notifed when an event of the given type occurs within this editor.

Specified by:
addListener in interface IRichText
Parameters:
eventType - the type of event to listen for
listener - the listener which should be notified when the event occurs

removeListener

public void removeListener(int eventType,
                           org.eclipse.swt.widgets.Listener listener)
Removes the listener from the collection of listeners who will be notifed when an event of the given type occurs within this editor.

Specified by:
removeListener in interface IRichText
Parameters:
eventType - the type of event to listen for
listener - the listener which should no longer be notified when the event occurs

getListeners

public java.util.Iterator getListeners()
Returns the event listeners attached to this editor.

Specified by:
getListeners in interface IRichText
Returns:
an iterator for retrieving the event listeners attached to this editor

fillToolBar

public void fillToolBar(IRichTextToolBar toolBar)
Fills the tool bar with action items.

Specified by:
fillToolBar in interface IRichTextEditor
Parameters:
toolBar - a tool bar contain rich text actions

getSourceEdit

public org.eclipse.swt.custom.StyledText getSourceEdit()
Returns the HTML source edit control.

Returns:
a StyleText object.

addHTML

public void addHTML(java.lang.String text)
Inserts text at the selection (overwriting the selection).


isHTMLTabSelected

public boolean isHTMLTabSelected()
Checks whether the HTML tab is selected.

Returns:
true if the HTML tab is selected.