Archi Forum

Archi => Archi Development => Topic started by: Hervé on April 08, 2018, 22:01:05 PM

Title: Wysiwyg HTML editor in form plugin
Post by: Hervé on April 08, 2018, 22:01:05 PM
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 (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é
Title: Re: Wysiwyg HTML editor in form plugin
Post by: Phil Beauvoir on April 08, 2018, 22:15:48 PM
Depends how you set up your project with paths, dependencies etc. Need more info.

Phil
Title: Re: Wysiwyg HTML editor in form plugin
Post by: Hervé on April 09, 2018, 08:53:50 AM
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:

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é
Title: Re: Wysiwyg HTML editor in form plugin
Post by: Phil Beauvoir on April 09, 2018, 10:12:35 AM
But where is the nebula jar physically? It seems that the export will expect to find it
Title: Re: Wysiwyg HTML editor in form plugin
Post by: Hervé on April 09, 2018, 11:56:20 AM
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 (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é
Title: Re: Wysiwyg HTML editor in form plugin
Post by: Phil Beauvoir on April 09, 2018, 13:12:08 PM
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.
Title: Re: Wysiwyg HTML editor in form plugin
Post by: Hervé on April 09, 2018, 15:04:49 PM
Thanks a lot Phil. I will do :)
Title: Re: Wysiwyg HTML editor in form plugin
Post by: Hervé on April 09, 2018, 22:02:25 PM
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é
Title: Re: Wysiwyg HTML editor in form plugin
Post by: Phil Beauvoir on April 09, 2018, 22:10:27 PM
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.
Title: Re: Wysiwyg HTML editor in form plugin
Post by: Phil Beauvoir on April 10, 2018, 09:37:55 AM
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.
Title: Re: Wysiwyg HTML editor in form plugin
Post by: Hervé on April 10, 2018, 11:42:09 AM
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  ::)