Why this post... because I 'm looking about a rich text editor in an eclipse RCP application... After few readings I saw that is not so obvious.
You could find more info at : git@github.com:franckys/TutorialSamples.git
In the tinymceTest folder.
This repo does not contain tinyMce so you have to download your own to make it work.
In the tinymceTest folder.
This repo does not contain tinyMce so you have to download your own to make it work.
At the end I found (and use) an interresting approach : Integrate a well known (In my case) javascript rich text editor, relying on SWT browser (http://www.vogella.com/blog/2009/12/21/javascript-swt/) capabilities.... The result :
As the integraton is not an "heavy one" I decided to do my own...
These are the steps required for this integration :
- I download the last Tinymce version. In my case the 3.5.2 (download here)
- Build an HTML page containing required :
- CSS
- Javascript
- textarea html element
- Use your favorite tools for debuging (In my case chrome + web developers tools) to customize tinymce contents (plugins, buttons, css...)
- Optional : Build a specific tinymce plugin to allow contextual floating menu content managment. For this I simply :
- take the example,
- follows Tinymce guide line
- remove all unecessary code
- add this code :
init : function(ed, url) { ed.onInit.add(function(ed, e){ ed.plugins.contextmenu.onContextMenu.add(function(th, menu, event) { menu.removeAll(); menu.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'}); menu.add({title : 'paste.paste_word_desc', icon : 'pasteword', cmd : 'mcePasteWord'}); ed.plugins.paste.pasteAsPlainText = 1; }); }); },
- write a java plugin :
- providing a composite Class containing (and presenting) "org.eclipse.swt.browser.Browser"
- initializing this browser with an URL ponting on the previous HTML page
- providing a setEditorContent (inject in textarea the desired and HTML/JS formated code) In java
- providing a getEditorContent using for example In java
public void setEditorContent(String htmlText) {
String jscript = " setEditorText('" + formatEditorText(htmlText) + "');";
if (!browser.execute(jscript)) {
throw new UnsupportedOperationException("JavaScript was not executed.");
}
}
In js
function setEditorText(editcontent) {
var textarea = document.getElementById('textarea');
textarea.value = editcontent;
}
public String getEditorContent() {
Object o = browser.evaluate("return getEditorText()");
return (String) o;
}}
in js
function getEditorText() {
var tmce = tinyMCE.get('textarea');
return tmce.getContent();
}
You could find more info at : git@github.com:franckys/TutorialSamples.git
In the tinymceTest folder.
This repo does not contain tinyMce so you have to download your own to make it work.
Rich editor in eclipse RCP (Part2)
In the tinymceTest folder.
This repo does not contain tinyMce so you have to download your own to make it work.
Rich editor in eclipse RCP (Part2)
Hi Francky! Thank you for a great little tutorial. Would it be possible to include a link to the project that you used to produce the image at the top of the post?
ReplyDeleteThat would be useful for us beginners to fill in some of the gaps in our knowledge :-)
Hi Mark,
ReplyDeleteI wrote this post after doing a proof of concepts and then delete the projet.
I'am looking to build another one and share it.
This comment has been removed by the author.
ReplyDeleteA link to git repository was add. It does not contain tinyMCE source so you have to download your own to make it work.
ReplyDeleteHi Franky,
ReplyDeleteI was pleased to see that you wrote a solution for my exact problem^^
But on implementing it, I encountered the problem, that setting the html content does not work. you seem to just inject it into a textarea. Why not over tinyMCE.get(textAreaID).setContent(htmlContent)?
Both ways do not work for me and I cannot see what is wrong.
Hope on your help
greetings
Hi,
Delete> Why just inject into a textArea.?
Because this is a solution found on tinyMce forum (http://www.tinymce.com/forum/viewtopic.php?id=9983, post 2) and as I don't encounter problem I don't really take much attention about it.
If you look in getEditorText() I use another way to locate content tinyMCE.get('textarea').So I'm surprise that you could not acheive this "setter". Maybe posting your html containing tinymce could help a lot.
Unable to access provided git url
ReplyDeleteI changed the url ... thanks
Delete