Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate CKEditor in GWT

Tags:

gwt

ckeditor

I'm looking for a way to integrate CKEditor in my GWT project.

I've made some googling and found this project: https://code.google.com/p/gwt-ckeditor/ which has been abandoned for years. So the CKEditor is completely outdated.

I've also seen the CKEditor being loaded outside of GWT into a textarea created in GWT. I'm not sure if that's a good way.

If someone could give me some advises, it would be highly appreciated. Thanks by advance

like image 898
gryter Avatar asked Jan 12 '23 07:01

gryter


1 Answers

You can use JSNI for activate the CKEditor. For loadning the javascript file, either you load this in the html page, or by using ScriptInjector and StyleInjector.

In GWT, create a componant :

package com.google.editor;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.TakesValue;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextArea;

public class CKeditor extends Composite implements TakesValue<String> {
  TextArea text = new TextArea();
  protected JavaScriptObject editor;

  public CKeditor() {
    initWidget(text);
  }

  @Override
  protected void onAttach() {
    super.onAttach();
    initCKEditor(text.getElement().getId());
  }

  private native void initCKEditor(String id) /*-{
    [email protected]::editor =  CKEDITOR.replace( id );
  }-*/;

  @Override
  public native void setValue(String value) /*-{
    [email protected]::editor.setData(value);
  }-*/;

  @Override
  public native String getValue() /*-{
    [email protected]::editor.setData(value);
  }-*/;
}

It's a sample, add all config you want to set in CKEditor

like image 94
Patrice De Saint Steban Avatar answered Mar 11 '23 08:03

Patrice De Saint Steban