Class RichTextEditor
java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.nebula.widgets.richtext.RichTextEditor
- All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable
public class RichTextEditor
extends org.eclipse.swt.widgets.Composite
Rich Text Editor control that wraps a
Browser with enabled Javascript that shows a simple
HTML template containing a ckeditor as rich text editor.
The following style bits are supported:
SWT.RESIZE- specify if the resize function of ckeditor is enabled (mostly used for embedded usage)SWT.MIN- specify if the configured minimum dimensions should be applied to the resize function of ckeditorSWT.EMBEDDED- specify if the rich text editor is used in embedded mode (e.g. as a cell editor of a JFace viewer)
SWT.MOZILLA or SWT.WEBKIT can be set to
specify the native browser that should be used for rendering
- See Also:
- https://ckeditor.com/
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classRichTextEditor.FocusInFunctionCallback function that is called via Javascript if the editor gains focus.(package private) classRichTextEditor.FocusOutFunctionCallback function that is called via Javascript on blur in the editor part.(package private) classRichTextEditor.JavaExecutionFinishedFunctionCallback function that is called via Javascript after a java callback is triggered via custom toolbar button.(package private) classRichTextEditor.JavaExecutionStartedFunctionCallback function that is called via Javascript before a java callback is triggered via custom toolbar button.(package private) classRichTextEditor.KeyPressedFunctionCallback function that is called via Javascript if a keydown event occurs in the editor part.(package private) classRichTextEditor.KeyReleasedFunctionCallback function that is called via Javascript if a keyup event occurs in the editor part.(package private) classRichTextEditor.ModifyFunctionCallback function that is called via Javascript if a change event occurs in the editor part. -
Field Summary
Fields Modifier and Type Field Description static java.lang.StringJAR_UNPACK_LOCATION_PROPERTYKey of the system property to specify a fixed directory to unpack the ckeditor resources to.protected org.eclipse.swt.graphics.RectangleresizedBounds -
Constructor Summary
Constructors Constructor Description RichTextEditor(org.eclipse.swt.widgets.Composite parent)Creates aRichTextEditorthat wraps aBrowserusing the style bitSWT.NONEand the defaultRichTextEditorConfiguration.RichTextEditor(org.eclipse.swt.widgets.Composite parent, int style)Creates aRichTextEditorthat wraps aBrowserusing the given style bit and the defaultRichTextEditorConfiguration.RichTextEditor(org.eclipse.swt.widgets.Composite parent, RichTextEditorConfiguration editorConfig)Creates aRichTextEditorthat wraps aBrowserusing the style bitSWT.NONEand the givenRichTextEditorConfiguration.RichTextEditor(org.eclipse.swt.widgets.Composite parent, RichTextEditorConfiguration editorConfig, int style)Creates aRichTextEditorthat wraps aBrowserusing the given style bit and the givenRichTextEditorConfiguration.RichTextEditor(org.eclipse.swt.widgets.Composite parent, ToolbarConfiguration toolbarConfig)Deprecated.use constructors that take aRichTextEditorConfigurationRichTextEditor(org.eclipse.swt.widgets.Composite parent, ToolbarConfiguration toolbarConfig, int style)Deprecated.use constructors that take aRichTextEditorConfiguration -
Method Summary
Modifier and Type Method Description voidaddFocusListener(org.eclipse.swt.events.FocusListener listener)voidaddJavaCallbackListener(JavaCallbackListener listener)Add aJavaCallbackListenerthat is triggered on executing a Java callback via customToolbarButton.voidaddKeyListener(org.eclipse.swt.events.KeyListener listener)voidaddModifyListener(org.eclipse.swt.events.ModifyListener listener)Adds the listener to the collection of listeners who will be notified when the receiver's text is modified, by sending it one of the messages defined in theModifyListenerinterface.voidaddToolbarButton(ToolbarButton button)Adds the givenToolbarButtonto the toolbar of the editor.voidaddToolbarButton(ToolbarButton button, org.eclipse.swt.browser.BrowserFunction function)Adds the givenToolbarButtonto the toolbar of the editor.voiddispose()java.lang.ObjectevaluateJavascript(java.lang.String script)Evaluates the specified script in the internalBrowserand returns the result.booleanexecuteJavascript(java.lang.String script)Executes the specified script in the internalBrowser.booleanforceFocus()RichTextEditorConfigurationgetEditorConfiguration()This method returns theRichTextEditorConfigurationthat is used to configure thisRichTextEditor.protected intgetMinimumHeight()Returns the minimum height that should be used for initially open the editor in embedded mode.protected intgetMinimumWidth()Returns the minimum width that should be used for initially open the editor in embedded mode.java.lang.StringgetSelectedHTML()Returns the current selected text containing the markup tags for styling.java.lang.StringgetSelectedText()Returns the current selected text without any markup tags.java.lang.StringgetText()voidinsertHTML(java.lang.String html)Inserts HTML code into the currently selected position in the editor in WYSIWYG mode.voidinsertText(java.lang.String text)Insert text content into the currently selected position in the editor in WYSIWYG mode.booleanisEditable()Returns the editable state.booleanisFocusControl()booleanisHandleFocusChanges()voidnotifyFocusGained(org.eclipse.swt.events.FocusEvent event)Notify the registeredFocusListenerthat the editor gained focus.voidnotifyFocusLost(org.eclipse.swt.events.FocusEvent event)Notify the registeredFocusListenerthat the editor lost focus.voidnotifyKeyPressed(org.eclipse.swt.events.KeyEvent event)Notify the registeredKeyListenerthat a key was pressed.voidnotifyKeyReleased(org.eclipse.swt.events.KeyEvent event)Notify the registeredKeyListenerthat a key was released.voidnotifyModifyListeners(org.eclipse.swt.events.ModifyEvent event)Notifies all of the receiver's listeners when the receiver's text is modified.voidremoveFocusListener(org.eclipse.swt.events.FocusListener listener)voidremoveJavaCallbackListener(JavaCallbackListener listener)Remove aJavaCallbackListenerthat is triggered on executing a Java callback via customToolbarButton.voidremoveKeyListener(org.eclipse.swt.events.KeyListener listener)voidremoveModifyListener(org.eclipse.swt.events.ModifyListener listener)Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.voidremoveToolbarButton(ToolbarButton button)Removes the givenToolbarButtonfrom the toolbar of the editor.voidsetBounds(int x, int y, int width, int height)voidsetBounds(org.eclipse.swt.graphics.Rectangle rect)voidsetEditable(boolean editable)Sets the editable state.booleansetFocus()voidsetHandleFocusChanges(boolean handleFocusChanges)Configure whether focus changes should be handled or not.(package private) voidsetInlineContainerBounds(int x, int y, int width, int height)Used in embedded mode to support manual resizing of the editor.voidsetLanguage(java.lang.String language)Sets the user interface language localization to use.voidsetLanguage(java.lang.String language, boolean update)voidsetLanguage(java.util.Locale locale)Sets the user interface language localization to use.voidsetLanguage(java.util.Locale locale, boolean update)voidsetText(java.lang.String text)Set text to the editing area.voidsetVisible(boolean visible)voidupdateEditor()Update the editor.voidupdateToolbar()Update the toolbar.Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setLayout, setLayoutDeferred, setTabList, toStringMethods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBarMethods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addGestureListener, addHelpListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeGestureListener, removeHelpListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setCapture, setCursor, setDragDetect, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, updateMethods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData
-
Field Details
-
resizedBounds
protected org.eclipse.swt.graphics.Rectangle resizedBounds -
JAR_UNPACK_LOCATION_PROPERTY
public static final java.lang.String JAR_UNPACK_LOCATION_PROPERTYKey of the system property to specify a fixed directory to unpack the ckeditor resources to. If a system property for that key is registered and the rich text control is deployed within a JAR, the resources will be unpacked into the specified directory. If no value is registered for that key and the rich text control is deployed in a JAR, the resources will be unpacked into a temporary directory, that gets deleted when the runtime is shutdown. If the rich text control is not deployed within a JAR but as part of an Eclipse application, the bundle will be unpacked automatically. In this case this system property won't get interpreted.- See Also:
- Constant Field Values
-
-
Constructor Details
-
RichTextEditor
public RichTextEditor(org.eclipse.swt.widgets.Composite parent)Creates aRichTextEditorthat wraps aBrowserusing the style bitSWT.NONEand the defaultRichTextEditorConfiguration.- Parameters:
parent- the parent composite where this rich text editor should be added to
-
RichTextEditor
@Deprecated public RichTextEditor(org.eclipse.swt.widgets.Composite parent, ToolbarConfiguration toolbarConfig)Deprecated.use constructors that take aRichTextEditorConfigurationCreates aRichTextEditorthat wraps aBrowserusing the style bitSWT.NONEand creates aRichTextEditorConfigurationout of the givenToolbarConfiguration.- Parameters:
parent- the parent composite where this rich text editor should be added totoolbarConfig- theToolbarConfigurationto use ornullfor using the defaultToolbarConfiguration
-
RichTextEditor
public RichTextEditor(org.eclipse.swt.widgets.Composite parent, RichTextEditorConfiguration editorConfig)Creates aRichTextEditorthat wraps aBrowserusing the style bitSWT.NONEand the givenRichTextEditorConfiguration.- Parameters:
parent- the parent composite where this rich text editor should be added toeditorConfig- theRichTextEditorConfigurationto use ornullfor using the defaultRichTextEditorConfiguration
-
RichTextEditor
public RichTextEditor(org.eclipse.swt.widgets.Composite parent, int style)Creates aRichTextEditorthat wraps aBrowserusing the given style bit and the defaultRichTextEditorConfiguration.- Parameters:
parent- the parent composite where this rich text editor should be added tostyle- the style of widget to construct, seeBrowserfor further style bit information
-
RichTextEditor
@Deprecated public RichTextEditor(org.eclipse.swt.widgets.Composite parent, ToolbarConfiguration toolbarConfig, int style)Deprecated.use constructors that take aRichTextEditorConfigurationCreates aRichTextEditorthat wraps aBrowserusing the given style bit and creates aRichTextEditorConfigurationout of the givenToolbarConfiguration.- Parameters:
parent- the parent composite where this rich text editor should be added totoolbarConfig- theToolbarConfigurationto use ornullfor using the defaultToolbarConfigurationstyle- the style of widget to construct, seeBrowserfor further style bit information- See Also:
Browser
-
RichTextEditor
public RichTextEditor(org.eclipse.swt.widgets.Composite parent, RichTextEditorConfiguration editorConfig, int style)Creates aRichTextEditorthat wraps aBrowserusing the given style bit and the givenRichTextEditorConfiguration.- Parameters:
parent- the parent composite where this rich text editor should be added toeditorConfig- theRichTextEditorConfigurationto use ornullfor using the defaultRichTextEditorConfigurationstyle- the style of widget to construct, seeBrowserfor further style bit information- See Also:
Browser
-
-
Method Details
-
dispose
public void dispose()- Overrides:
disposein classorg.eclipse.swt.widgets.Widget
-
setVisible
public void setVisible(boolean visible)- Overrides:
setVisiblein classorg.eclipse.swt.widgets.Control
-
getText
public java.lang.String getText()- Returns:
- The text that is currently set in the editing area. Contains HTML tags for formatting.
-
setText
public void setText(java.lang.String text)Set text to the editing area. Can contain HTML tags for styling.- Parameters:
text- The text to set to the editing area.
-
insertText
public void insertText(java.lang.String text)Insert text content into the currently selected position in the editor in WYSIWYG mode. The styles of the selected element will be applied to the inserted text. Spaces around the text will be left untouched.- Parameters:
text- Text to be inserted into the editor.
-
insertHTML
public void insertHTML(java.lang.String html)Inserts HTML code into the currently selected position in the editor in WYSIWYG mode.- Parameters:
html- HTML code to be inserted into the editor.
-
getSelectedText
public java.lang.String getSelectedText()Returns the current selected text without any markup tags.- Returns:
- The current selected text without any markup tags.
-
getSelectedHTML
public java.lang.String getSelectedHTML()Returns the current selected text containing the markup tags for styling.Note: It will not contain the parent tag.
- Returns:
- The current selected text containing any markup styling tags.
-
isEditable
public boolean isEditable()Returns the editable state.- Returns:
- whether or not the receiver is editable
-
updateToolbar
public void updateToolbar()Update the toolbar. Typically used if buttons where added or removed at runtime. -
updateEditor
public void updateEditor()Update the editor. Basically it will destroy and recreate the CKEditor. Needed to be used if a basic configuration is changed, e.g. the language.- Since:
- 1.1
-
setEditable
public void setEditable(boolean editable)Sets the editable state.- Parameters:
editable- the new editable state
-
getEditorConfiguration
This method returns theRichTextEditorConfigurationthat is used to configure thisRichTextEditor. It can be used to change some configurations at runtime.Note: After configuration values have been changed it is necessary to call
updateEditor()so the configurations are applied.- Returns:
- The
RichTextEditorConfigurationused to configure thisRichTextEditor. - Since:
- 1.1
-
setLanguage
public void setLanguage(java.util.Locale locale)Sets the user interface language localization to use. Only the language part of theLocalewill be used. This method triggers an immediate update of the editor instance.- Parameters:
locale- The user interface language localization to use.- Since:
- 1.1
-
setLanguage
public void setLanguage(java.util.Locale locale, boolean update)- Parameters:
locale- The user interface language localization to use.update-trueif the editor should be updated immediately,falseif the update should not be executed. In that caseupdateEditor()needs to be executed explicitly.- Since:
- 1.1
-
setLanguage
public void setLanguage(java.lang.String language)Sets the user interface language localization to use. This method triggers an immediate update of the editor instance.- Parameters:
language- The user interface language localization to use.- Since:
- 1.1
-
setLanguage
public void setLanguage(java.lang.String language, boolean update)- Parameters:
language- The user interface language localization to use.update-trueif the editor should be updated immediately,falseif the update should not be executed. In that caseupdateEditor()needs to be executed explicitly.- Since:
- 1.1
-
addToolbarButton
Adds the givenToolbarButtonto the toolbar of the editor.- Parameters:
button- The button to add.- See Also:
RichTextEditorConfiguration.addToolbarButton(ToolbarButton)
-
addToolbarButton
public void addToolbarButton(ToolbarButton button, org.eclipse.swt.browser.BrowserFunction function)Adds the givenToolbarButtonto the toolbar of the editor. Uses the givenBrowserFunctionas callback for the button.- Parameters:
button- The button to add.function- The function to use as callback.- See Also:
RichTextEditorConfiguration.addToolbarButton(ToolbarButton, BrowserFunction)
-
removeToolbarButton
Removes the givenToolbarButtonfrom the toolbar of the editor.- Parameters:
button- The button to remove.- See Also:
RichTextEditorConfiguration.removeToolbarButton(ToolbarButton)
-
setFocus
public boolean setFocus()- Overrides:
setFocusin classorg.eclipse.swt.widgets.Composite
-
forceFocus
public boolean forceFocus()- Overrides:
forceFocusin classorg.eclipse.swt.widgets.Control
-
isFocusControl
public boolean isFocusControl()- Overrides:
isFocusControlin classorg.eclipse.swt.widgets.Control
-
addFocusListener
public void addFocusListener(org.eclipse.swt.events.FocusListener listener)- Overrides:
addFocusListenerin classorg.eclipse.swt.widgets.Control
-
removeFocusListener
public void removeFocusListener(org.eclipse.swt.events.FocusListener listener)- Overrides:
removeFocusListenerin classorg.eclipse.swt.widgets.Control
-
notifyFocusGained
public void notifyFocusGained(org.eclipse.swt.events.FocusEvent event)Notify the registeredFocusListenerthat the editor gained focus.- Parameters:
event- The event to fire.
-
notifyFocusLost
public void notifyFocusLost(org.eclipse.swt.events.FocusEvent event)Notify the registeredFocusListenerthat the editor lost focus.- Parameters:
event- The event to fire.
-
setBounds
public void setBounds(org.eclipse.swt.graphics.Rectangle rect)- Overrides:
setBoundsin classorg.eclipse.swt.widgets.Control
-
setBounds
public void setBounds(int x, int y, int width, int height)- Overrides:
setBoundsin classorg.eclipse.swt.widgets.Control
-
setInlineContainerBounds
void setInlineContainerBounds(int x, int y, int width, int height)Used in embedded mode to support manual resizing of the editor. Executed via callback on ckeditor resize.- Parameters:
x- the new x coordinate for the receivery- the new y coordinate for the receiverwidth- the new width for the receiverheight- the new height for the receiver
-
getMinimumHeight
protected int getMinimumHeight()Returns the minimum height that should be used for initially open the editor in embedded mode. It is also used to specify the resize minimum height if the editor was created using the style bitSWT.MIN. Using the defaultRichTextEditorConfigurationthis is 150 for the toolbar and 50 for showing one row in the editor area.- Returns:
- The minimum height to use for initially open the editor in embedded mode and for
editor resize minimum in case the editor was created with
SWT.MIN
-
getMinimumWidth
protected int getMinimumWidth()Returns the minimum width that should be used for initially open the editor in embedded mode. It is also used to specify the resize minimum width if the editor was created using the style bitSWT.MIN. Using the defaultRichTextEditorConfigurationthis is 370 for showing the default options in three lines of the toolbar.- Returns:
- The minimum width to use for initially open the editor in embedded mode and for
editor resize minimum in case the editor was created with
SWT.MIN
-
executeJavascript
public boolean executeJavascript(java.lang.String script)Executes the specified script in the internalBrowser. Can be used to execute Javascript directly in the browser from a listener if necessary.- Parameters:
script- the script with javascript commands- Returns:
trueif the operation was successful andfalseotherwise- See Also:
Browser.execute(String)
-
evaluateJavascript
public java.lang.Object evaluateJavascript(java.lang.String script)Evaluates the specified script in the internalBrowserand returns the result. Can be used to evaluate Javascript directly in the browser from a listener if necessary.- Parameters:
script- the script with javascript commands- Returns:
- the return value, if any, of executing the script
- See Also:
Browser.evaluate(String)
-
isHandleFocusChanges
public boolean isHandleFocusChanges()- Returns:
trueif focus changes are handled,falseif not
-
setHandleFocusChanges
public void setHandleFocusChanges(boolean handleFocusChanges)Configure whether focus changes should be handled or not. A typical use case for disabling the focus handling is for example to open a dialog from a Java callback via custom toolbar button.- Parameters:
handleFocusChanges-trueif focus changes should be handled,falseif not
-
addKeyListener
public void addKeyListener(org.eclipse.swt.events.KeyListener listener)- Overrides:
addKeyListenerin classorg.eclipse.swt.widgets.Control
-
removeKeyListener
public void removeKeyListener(org.eclipse.swt.events.KeyListener listener)- Overrides:
removeKeyListenerin classorg.eclipse.swt.widgets.Control
-
notifyKeyPressed
public void notifyKeyPressed(org.eclipse.swt.events.KeyEvent event)Notify the registeredKeyListenerthat a key was pressed.- Parameters:
event- The event to fire.
-
notifyKeyReleased
public void notifyKeyReleased(org.eclipse.swt.events.KeyEvent event)Notify the registeredKeyListenerthat a key was released.- Parameters:
event- The event to fire.
-
addModifyListener
public void addModifyListener(org.eclipse.swt.events.ModifyListener listener)Adds the listener to the collection of listeners who will be notified when the receiver's text is modified, by sending it one of the messages defined in theModifyListenerinterface.- Parameters:
listener- the listener which should be notified- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the listener is null
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
ModifyListener,removeModifyListener(org.eclipse.swt.events.ModifyListener)
-
removeModifyListener
public void removeModifyListener(org.eclipse.swt.events.ModifyListener listener)Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.- Parameters:
listener- the listener which should no longer be notified- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the listener is null
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
ModifyListener,addModifyListener(org.eclipse.swt.events.ModifyListener)
-
notifyModifyListeners
public void notifyModifyListeners(org.eclipse.swt.events.ModifyEvent event)Notifies all of the receiver's listeners when the receiver's text is modified.- Parameters:
eventType- the type of event which has occurredevent- the event data- Throws:
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
addModifyListener(ModifyListener),removeModifyListener(ModifyListener)
-
addJavaCallbackListener
Add aJavaCallbackListenerthat is triggered on executing a Java callback via customToolbarButton.- Parameters:
listener- TheJavaCallbackListenerto add.
-
removeJavaCallbackListener
Remove aJavaCallbackListenerthat is triggered on executing a Java callback via customToolbarButton.- Parameters:
listener- TheJavaCallbackListenerto remove.
-