Wysiwyg HTML editor in form plugin

Started by Hervé, April 08, 2018, 23:01:05 PM

Previous topic - Next topic

Hervé

Dear all,

I'd like to implement an wysiwyg HTML editor in my form plugin. I'm working with the nebula RichTextEditor (https://www.eclipse.org/nebula/widgets/richtext/richtext.php) thats works pretty well.

I declared the RichText class as a dependency and it works well when I lanch Arhci in Eclipse.

But, when I try to generate the plugin JAR file, I experience an error message "cannot export external class folder".

I already spent too much time on this issue and need some help. So, does anyone have a clue on what can happen and what I should do to fix it ?

Thanks in advance
Hervé

Phil Beauvoir

Depends how you set up your project with paths, dependencies etc. Need more info.

Phil
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Hervé

Hi Phil,

Thanks for your answer.

Basically, I cloned your project and set the target platform. Then, I created my plugin, defining the required plugins in the MANIFEST.MF file (using the Eclipse GUI):
Require-Bundle: com.archimatetool.editor,
com.archimatetool.canvas,
org.eclipse.core.runtime,
com.archimatetool.model,
org.eclipse.core.expressions,
org.eclipse.emf.common,
org.eclipse.help,
org.eclipse.swt


When I started working with the Nebula RichTextEditor, I did the following steps:

  • I installed the "Eclipse Nebula Stable Widgets" bundle from the Eclipse marketplace
  • I added the org.eclipse.nebula.widgets.richtext package to the required plugins in the MANIFEST.MF file
  • I added the richtext library in the plugin dependency of the Eclipse Application

All my testing goes well when I launch Archi in Eclipse but I fail to export my plugin as a JAR file.

Please do not hesitate to ask if you require more information.

Thanks and regards
Hervé

Phil Beauvoir

But where is the nebula jar physically? It seems that the export will expect to find it
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Hervé

In fact, there is no JAR file, but a D:\--- archi\eclipse-oxygen-4.7\workspace\.metadata\.plugins\org.eclipse.pde.core\.bundle_pool\plugins\org.eclipse.nebula.widgets.richtext_1.2.0.201804011600 folder with .class files ...

And that's the folder that Eclipse refuses to copy to my JAR file.


I downloaded the ZIP file containing the richtext jar file, and I copy it to my project. I then got a runtime exception "org.eclipse.swt.SWTException: 'CKEDITOR' is undefined".

I found a post https://bugs.eclipse.org/bugs/show_bug.cgi?id=520025 related to this runtime Exception, which states that I need to find a bundle and not include the single jar file.

But until now, I failed to find such bundle.

Best regards
Hervé

Phil Beauvoir

Hervé,

take a look at the com.archimatetool.widgets plug-in. Here, I've packaged up a few Nebula widgets in a bundle.

BTW - I never use the Eclipse Market Place, I have no idea what or where it is installing.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Hervé


Hervé

After analyzing the Nebula RichTextEditor.java source code, here is what I've found ...

For reference  :D

The Nebula widget is based under CKEditor, which is a JavaScript HTML editor that will be ran into a browser.

Therefore, to work, the browser needs to find the requested JavaScript files in the file system. So, Nebula developed a procedure that dynamically extracts those JavaScript from the JAR archive ... except if it is ran inside Eclipse as they already are extracted by Eclipse.

Their code is not checking if the widget is used inside Eclipse, but if it is ran as an OSGi plugin:
// if we are in an OSGi context, we need to convert the bundle URL to a file URL
Bundle bundle = FrameworkUtil.getBundle(RichTextEditor.class);
if (bundle != null) {
try {
templateURL = FileLocator.toFileURL(templateURL);
} catch (IOException e) {
e.printStackTrace();
}
}
else if (templateURL.toString().startsWith("jar")) {
                   .
                   .
                   .


Unfortunately, as an Archi plugin, I also run the widget in the OSGI framework, even if I'm not inside Eclipse. So the widget is not extracting the files it needs.



What I've done is create my own class that extends the Nebula RichTextEditor class, I extract the JavaScript files myself, then I use Reflection to update the parent class variable that holds the folder name (I know Reflection is bad, but the variable is private, so I haven't got the choice, have I).



Best regards
Hervé

Phil Beauvoir

These kinds of things are real pain in the butt when you just want to get on with it. I think I've spent too much of my life on this type of workaround. But well done for finding a solution. Sometimes reflection is OK.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

Once thing I learnt in the last 20 years about cross-platform WYSIWYG HTML Editors in Java (also known as the "Golden Unicorn") is that if you don't deploy one in your app you might get one or two feature requests, but if you do deploy one you then get hundreds of improvement requests and bug reports against it and you end up doing nothing else.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Hervé

You may be right  ;D

But my final aim is to generate wiki pages (mainly Wikimedia) using Archi and I did not find any wiki SWT editors. Instead I've found some converters from HTML to Wikimedia. That's why I implemented an HTML editor  ::)