Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWojtek Polcwiartek2016-07-22 08:08:06 +0000
committerGerrit Code Review @ Eclipse.org2016-10-11 08:41:15 +0000
commit415dc4f3a393b149c33c88ecae3b0a3faeb48e6f (patch)
tree86f6767a95259ab28dfb25d4ca4fbaa199b8f1cf /bundles
parent3ee1dbdd122ecfd47fc00f0a4ab120fa2a963474 (diff)
downloadorg.eclipse.rap-415dc4f3a393b149c33c88ecae3b0a3faeb48e6f.tar.gz
org.eclipse.rap-415dc4f3a393b149c33c88ecae3b0a3faeb48e6f.tar.xz
org.eclipse.rap-415dc4f3a393b149c33c88ecae3b0a3faeb48e6f.zip
[497957] Toolbar language of CKEditor is configurable
A feature, that allows to configure the toollbars language of CKEditor via ToolbarConfiguration class. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=497957 Change-Id: Ib5038017e8496add014db961f361ebdf0fe565d8 Signed-off-by: Wojtek Polcwiartek <wojciech.polcwiartek@tolina.de>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/RichTextEditor.java125
-rw-r--r--bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/RichTextEditorConfiguration.java363
-rw-r--r--bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/toolbar/ToolbarConfiguration.java44
-rw-r--r--bundles/org.eclipse.rap.nebula.widgets.richtext/src/resources/RichTextEditor.js2
-rw-r--r--bundles/org.eclipse.rap.nebula.widgets.richtext/src/resources/config.js6
5 files changed, 495 insertions, 45 deletions
diff --git a/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/RichTextEditor.java b/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/RichTextEditor.java
index 78d965ee05..61186c5619 100644
--- a/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/RichTextEditor.java
+++ b/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/RichTextEditor.java
@@ -40,6 +40,7 @@ import org.eclipse.swt.widgets.Layout;
*
* @since 3.1
*/
+@SuppressWarnings( "deprecation" )
public class RichTextEditor extends Composite {
private static final String RESOURCES_PATH = "resources/";
@@ -50,8 +51,6 @@ public class RichTextEditor extends Composite {
"config.js",
"styles.js",
"contents.css",
- "lang/id.js",
- "lang/en.js",
"skins/moono/editor.css",
"skins/moono/editor_ie.css",
"skins/moono/editor_gecko.css",
@@ -76,7 +75,6 @@ public class RichTextEditor extends Composite {
private String text = "";
private boolean editable = true;
private final RemoteObject remoteObject;
-
private final OperationHandler operationHandler = new AbstractOperationHandler() {
@Override
public void handleSet( JsonObject properties ) {
@@ -86,12 +84,12 @@ public class RichTextEditor extends Composite {
}
}
};
+ private final RichTextEditorConfiguration config;
/**
* Constructs a new instance of this class given its parent.
*
* @param parent a composite control which will be the parent of the new instance (cannot be null)
- *
* @exception IllegalArgumentException
* <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
@@ -103,16 +101,14 @@ public class RichTextEditor extends Composite {
* </ul>
*/
public RichTextEditor( Composite parent ) {
- this( parent, null, SWT.NONE );
+ this( parent, SWT.NONE );
}
/**
* Constructs a new instance of this class given its parent.
*
* @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param config the {@link ToolbarConfiguration} to use or <code>null</code> for using the
- * default {@link ToolbarConfiguration}
- *
+ * @param style the style of control to construct
* @exception IllegalArgumentException
* <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
@@ -123,15 +119,44 @@ public class RichTextEditor extends Composite {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
- public RichTextEditor( Composite parent, ToolbarConfiguration config ) {
- this( parent, config, SWT.NONE );
+ public RichTextEditor( Composite parent, int style ) {
+ this( parent, (RichTextEditorConfiguration) null, style );
}
/**
* Constructs a new instance of this class given its parent.
*
* @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param toolbarConfig the
+ * {@link org.eclipse.nebula.widgets.richtext.toolbar.ToolbarConfiguration} to use or
+ * <code>null</code> for using the default
+ * {@link org.eclipse.nebula.widgets.richtext.toolbar.ToolbarConfiguration}
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
+ * </ul>
+ * @deprecated use constructors that take a {@link RichTextEditorConfiguration}
+ */
+ @Deprecated
+ public RichTextEditor( Composite parent, ToolbarConfiguration toolbarConfig ) {
+ this( parent, toolbarConfig, SWT.NONE );
+ }
+
+ /**
+ * Constructs a new instance of this class given its parent, the given
+ * {@link ToolbarConfiguration} and a style value describing its behavior and appearance.
*
+ * @param parent the parent composite where this rich text editor should be added to
+ * @param toolbarConfig the
+ * {@link org.eclipse.nebula.widgets.richtext.toolbar.ToolbarConfiguration} to use or
+ * <code>null</code> for using the default
+ * {@link org.eclipse.nebula.widgets.richtext.toolbar.ToolbarConfiguration}
+ * @param style the style of widget to construct
* @exception IllegalArgumentException
* <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
@@ -141,9 +166,11 @@ public class RichTextEditor extends Composite {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
+ * @deprecated use constructors that take a {@link RichTextEditorConfiguration}
*/
- public RichTextEditor( Composite parent, int style ) {
- this( parent, null, style );
+ @Deprecated
+ public RichTextEditor( Composite parent, ToolbarConfiguration toolbarConfig, int style ) {
+ this( parent, toolbarConfig != null ? new RichTextEditorConfiguration( toolbarConfig ) : null, style );
}
/**
@@ -151,10 +178,32 @@ public class RichTextEditor extends Composite {
* {@link ToolbarConfiguration} and a style value describing its behavior and appearance.
*
* @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param config the {@link ToolbarConfiguration} to use or <code>null</code> for using the
- * default {@link ToolbarConfiguration}
- * @param style the style of control to construct
+ * @param editorConfig the {@link RichTextEditorConfiguration} to use or <code>null</code> for
+ * using the default {@link RichTextEditorConfiguration}
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
+ * </ul>
+ *
+ * @since 3.2
+ */
+ public RichTextEditor( Composite parent, RichTextEditorConfiguration editorConfig ) {
+ this( parent, editorConfig, SWT.NONE );
+ }
+
+ /**
+ * Constructs a new instance of this class given its parent, the given
+ * {@link ToolbarConfiguration} and a style value describing its behavior and appearance.
*
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param editorConfig the {@link RichTextEditorConfiguration} to use or <code>null</code> for
+ * using the default {@link RichTextEditorConfiguration}
+ * @param style the style of control to construct
* @exception IllegalArgumentException
* <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
@@ -164,26 +213,42 @@ public class RichTextEditor extends Composite {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
+ *
+ * @since 3.2
*/
- public RichTextEditor( Composite parent, ToolbarConfiguration config, int style ) {
+ public RichTextEditor( Composite parent, RichTextEditorConfiguration editorConfig, int style ) {
super( parent, style );
+ // init editor configuration
+ if( editorConfig == null ) {
+ config = new RichTextEditorConfiguration();
+ } else {
+ config = editorConfig;
+ }
registerResources();
loadJavaScript();
Connection connection = RWT.getUISession().getConnection();
remoteObject = connection.createRemoteObject( REMOTE_TYPE );
remoteObject.setHandler( operationHandler );
remoteObject.set( "parent", getId( this ) );
- remoteObject.set( "config", getConfiguration( config ) );
+ remoteObject.set( "config", config.toJson() );
}
- private static void registerResources() {
+ private void registerResources() {
ResourceManager resourceManager = RWT.getResourceManager();
- boolean isRegistered = resourceManager.isRegistered( REGISTER_PATH + RESOURCE_FILES[ 0 ] );
+ for( String fileName : RESOURCE_FILES ) {
+ registerFileIfNeeded( resourceManager, fileName );
+ }
+ String lang = ( String )config.getOption( RichTextEditorConfiguration.LANGUAGE );
+ String defaultLang = ( String )config.getOption( RichTextEditorConfiguration.DEFAULT_LANGUAGE );
+ registerFileIfNeeded( resourceManager, "lang/" + lang + ".js" );
+ registerFileIfNeeded( resourceManager, "lang/" + defaultLang + ".js" );
+ }
+
+ private static void registerFileIfNeeded( ResourceManager resourceManager, String fileName ) {
+ boolean isRegistered = resourceManager.isRegistered( REGISTER_PATH + fileName );
if( !isRegistered ) {
try {
- for( String fileName : RESOURCE_FILES ) {
- register( resourceManager, fileName );
- }
+ register( resourceManager, fileName );
} catch( IOException ioe ) {
throw new IllegalArgumentException( "Failed to load resources", ioe );
}
@@ -209,13 +274,15 @@ public class RichTextEditor extends Composite {
}
}
- private static JsonValue getConfiguration( ToolbarConfiguration config ) {
- ToolbarConfiguration toolbarConfig = config == null ? new ToolbarConfiguration() : config;
- try {
- return JsonValue.readFrom( toolbarConfig.toString() );
- } catch( Exception ex ) {
- throw new IllegalArgumentException( "Invalid toolbar configuration", ex );
- }
+ /**
+ * This method returns the {@link RichTextEditorConfiguration} that is used to configure this
+ * {@link RichTextEditor}. It can be used to change some configurations at runtime.
+ *
+ * @return The {@link RichTextEditorConfiguration} used to configure this {@link RichTextEditor}.
+ * @since 3.2
+ */
+ public RichTextEditorConfiguration getEditorConfiguration() {
+ return config;
}
@Override
diff --git a/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/RichTextEditorConfiguration.java b/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/RichTextEditorConfiguration.java
new file mode 100644
index 0000000000..08ddd57027
--- /dev/null
+++ b/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/RichTextEditorConfiguration.java
@@ -0,0 +1,363 @@
+/*****************************************************************************
+ * Copyright (c) 2016 Dirk Fauth.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dirk Fauth <dirk.fauth@googlemail.com> - Initial API and implementation
+ * Wojtek Polcwiartek <wojciech.polcwiartek@tolina.de> - RAP implementation
+ *
+ *****************************************************************************/
+package org.eclipse.nebula.widgets.richtext;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.rap.json.JsonObject;
+import org.eclipse.rap.json.JsonValue;
+
+/**
+ * Configuration class that is used for general configurations of the CKEditor instance.
+ *
+ * @since 3.2
+ */
+public class RichTextEditorConfiguration {
+
+ /**
+ * Key for the default language configuration.
+ */
+ public static final String DEFAULT_LANGUAGE = "defaultLanguage";
+
+ /**
+ * Key for the language configuration.
+ */
+ public static final String LANGUAGE = "language";
+
+ /**
+ * Key for toolbar groups configuration.
+ */
+ public static final String TOOLBAR_GROUPS = "toolbarGroups";
+
+ /**
+ * Key for toolbar buttons that should not be rendered.
+ */
+ public static final String REMOVE_BUTTONS = "removeButtons";
+ /**
+ *
+ * Key to configure whether the toolbar can be collapsed by the user.
+ */
+ public static final String TOOLBAR_CAN_COLLAPSE = "toolbarCanCollapse";
+
+ /**
+ * Key to configure whether the toolbar must start expanded when the editor is loaded.
+ */
+ public static final String TOOLBAR_STARTUP_EXPANDED = "toolbarStartupExpanded";
+ private static final String DEFAULT_TOOLBAR_GROUPS = createDefaultToolbarGroups();
+
+ /**
+ * Configure whether to remove the <i>paste text</i> button from the toolbar. Default is
+ * <code>true</code>.
+ */
+ private boolean removePasteText = true;
+ /**
+ * Configure whether to remove the <i>paste from word</i> button from the toolbar. Default is
+ * <code>true</code>.
+ */
+ private boolean removePasteFromWord = true;
+ /**
+ * Configure whether to remove the <i>styles</i> combo box from the toolbar. Default is
+ * <code>true</code>.
+ */
+ private boolean removeStyles = true;
+ /**
+ * Configure whether to remove <i>format</i> combo box from the toolbar. Default is
+ * <code>true</code>.
+ */
+ private boolean removeFormat = true;
+
+ private final Map<String, Object> options = new HashMap<>();
+ private final Set<String> removedButtons = new HashSet<>();
+
+
+ /**
+ * Creates a new instance for general configurations that are added to the created CKEditor
+ * instance at initialization.
+ */
+ public RichTextEditorConfiguration() {
+ options.put( DEFAULT_LANGUAGE, Locale.ENGLISH.getLanguage() );
+ options.put( LANGUAGE, Locale.getDefault().getLanguage() );
+ setToolbarCollapsible( false );
+ setToolbarInitialExpanded( true );
+ options.put( TOOLBAR_GROUPS, DEFAULT_TOOLBAR_GROUPS );
+ options.put( REMOVE_BUTTONS, getRemoveButtonConfiguration() );
+ }
+
+ @SuppressWarnings( "deprecation" )
+ RichTextEditorConfiguration( org.eclipse.nebula.widgets.richtext.toolbar.ToolbarConfiguration config ) {
+ this();
+ removePasteText = config.removePasteText;
+ removePasteFromWord = config.removePasteFromWord;
+ removeStyles = config.removeStyles;
+ removeFormat = config.removeFormat;
+ removedButtons.addAll( config.getRemovedButtons() );
+ setToolbarCollapsible( config.toolbarCollapsible );
+ setToolbarInitialExpanded( config.toolbarInitialExpanded );
+ JsonObject jsonConfig = JsonObject.readFrom( config.toString() );
+ // set the option like this in case the method itself was overridden by subclassing
+ options.put( TOOLBAR_GROUPS, jsonConfig.get( TOOLBAR_GROUPS ).toString() );
+ // set the option like this in case the method itself was overridden by subclassing
+ options.put( REMOVE_BUTTONS, jsonConfig.get( REMOVE_BUTTONS ).asString() );
+ }
+
+ private static String createDefaultToolbarGroups() {
+ StringBuilder builder = new StringBuilder();
+ builder.append( "[" );
+ builder.append( "{\"name\":\"basicstyles\",\"groups\":[\"basicstyles\",\"cleanup\"]}," );
+ builder.append( "{\"name\":\"paragraph\",\"groups\":[\"list\",\"indent\",\"align\"]}," );
+ builder.append( "\"/\"," );
+ builder.append( "{\"name\":\"styles\"}," );
+ builder.append( "{\"name\":\"colors\" }" );
+ builder.append( "]" );
+ return builder.toString();
+ }
+
+ /**
+ * Adds a new option to the configuration.
+ *
+ * @param key The configuration option key.
+ * @param value The configuration option value.
+ * @see <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config">CKEDITOR.config</a>
+ */
+ public void setOption( String key, Object value ) {
+ options.put( key, value );
+ }
+
+ /**
+ * Returns a configuration option set in this {@link RichTextEditorConfiguration}.
+ *
+ * @param key The configuration option key for which the value is requested.
+ * @return The configuration option value for the given key or <code>null</code> in case there is
+ * nothing configured for that key.
+ */
+ public Object getOption( String key ) {
+ return options.get( key );
+ }
+
+ /**
+ * @return An unmodifiable map that contains all configuration option values.
+ */
+ public Map<String, Object> getAllOptions() {
+ return Collections.unmodifiableMap( options );
+ }
+
+ // convenience methods
+ /**
+ * @param lang The user interface language localization to use. If left empty, the editor will
+ * automatically be localized to the user language. If the user language is not
+ * supported, the language specified in the <i>defaultLanguage</i> configuration setting
+ * is used.
+ */
+ public void setLanguage( String lang ) {
+ options.put( LANGUAGE, lang );
+ }
+
+ /**
+ * @param locale The user interface language localization to use. If left empty, the editor will
+ * automatically be localized to the user language. If the user language is not
+ * supported, the language specified in the <i>defaultLanguage</i> configuration setting
+ * is used.
+ */
+ public void setLanguage( Locale locale ) {
+ setLanguage( locale.getLanguage() );
+ }
+
+ /**
+ * @param lang The language to be used if the language setting is left empty and it is not
+ * possible to localize the editor to the user language.
+ */
+ public void setDefaultLanguage( String lang ) {
+ options.put( DEFAULT_LANGUAGE, lang );
+ }
+
+ /**
+ * @param locale The language to be used if the language setting is left empty and it is not
+ * possible to localize the editor to the user language.
+ */
+ public void setDefaultLanguage( Locale locale ) {
+ setDefaultLanguage( locale.getLanguage() );
+ }
+
+ /**
+ * @param removePasteText <code>true</code> to remove the <i>paste text</i> button from the
+ * toolbar.
+ */
+ public void setRemovePasteText( boolean removePasteText ) {
+ this.removePasteText = removePasteText;
+ options.put( REMOVE_BUTTONS, getRemoveButtonConfiguration() );
+ }
+
+ /**
+ * @param removePasteFromWord <code>true</code> to remove the <i>paste from word</i> button from
+ * the toolbar.
+ */
+ public void setRemovePasteFromWord( boolean removePasteFromWord ) {
+ this.removePasteFromWord = removePasteFromWord;
+ options.put( REMOVE_BUTTONS, getRemoveButtonConfiguration() );
+ }
+
+ /**
+ * @param removeStyles <code>true</code> to remove the <i>styles</i> combo box from the toolbar.
+ */
+ public void setRemoveStyles( boolean removeStyles ) {
+ this.removeStyles = removeStyles;
+ options.put( REMOVE_BUTTONS, getRemoveButtonConfiguration() );
+ }
+
+ /**
+ * @param removeFormat <code>true</code> to remove <i>format</i> combo box from the toolbar.
+ */
+ public void setRemoveFormat( boolean removeFormat ) {
+ this.removeFormat = removeFormat;
+ options.put( REMOVE_BUTTONS, getRemoveButtonConfiguration() );
+ }
+
+ /**
+ * Adds the CKEditor default button for the given name to the toolbar.
+ * <p>
+ * <i>Note: This works only for buttons that have been removed using
+ * {@link #removeDefaultToolbarButton(String[])}</i>
+ * </p>
+ *
+ * @param buttonNames The names of the CKEditor default button to add.
+ */
+ public void addDefaultToolbarButton( String... buttonNames ) {
+ for( String buttonName : buttonNames ) {
+ removedButtons.remove( buttonName );
+ }
+ options.put( REMOVE_BUTTONS, getRemoveButtonConfiguration() );
+ }
+
+ /**
+ * Removes the CKEditor default button for the given name from the toolbar.
+ *
+ * @param buttonNames The names of the CKEditor default button to remove.
+ */
+ public void removeDefaultToolbarButton( String... buttonNames ) {
+ // remember the button that should be removed
+ for( String buttonName : buttonNames ) {
+ removedButtons.add( buttonName );
+ }
+ options.put( REMOVE_BUTTONS, getRemoveButtonConfiguration() );
+ }
+
+ /**
+ * @return The configuration which default buttons should be removed from the toolbar.
+ */
+ private String getRemoveButtonConfiguration() {
+ // Subscript and Superscript are not supported styling options for the
+ // Rich Text Viewer
+ StringBuilder builder = new StringBuilder();
+ if( removePasteText ) {
+ builder.append( ",PasteText" );
+ }
+ if( removePasteFromWord ) {
+ builder.append( ",PasteFromWord" );
+ }
+ if( removeStyles ) {
+ builder.append( ",Styles" );
+ }
+ if( removeFormat ) {
+ builder.append( ",Format" );
+ }
+ for( String removed : this.removedButtons ) {
+ builder.append( "," ).append( removed );
+ }
+ String removeButtons = builder.toString();
+ if( removeButtons.startsWith( "," ) ) {
+ return removeButtons.substring( 1 );
+ }
+ return removeButtons;
+ }
+
+ /**
+ * Configure if the toolbar should be collapsible. Default is <code>false</code>.
+ *
+ * @param toolbarCollapsible <code>true</code> if the toolbar should be collapsible,
+ * <code>false</code> if not.
+ */
+ public void setToolbarCollapsible( boolean toolbarCollapsible ) {
+ this.options.put( TOOLBAR_CAN_COLLAPSE, Boolean.valueOf( toolbarCollapsible ) );
+ }
+
+ /**
+ * Configure if the toolbar should be initially expanded. Default is <code>true</code>.
+ *
+ * @param toolbarInitialExpanded <code>true</code> if the toolbar should be initially expanded,
+ * <code>false</code> if not.
+ */
+ public void setToolbarInitialExpanded( boolean toolbarInitialExpanded ) {
+ this.options.put( TOOLBAR_STARTUP_EXPANDED, Boolean.valueOf( toolbarInitialExpanded ) );
+ }
+
+ JsonObject toJson() {
+ JsonObject jsonObject = new JsonObject();
+ Map<String, Object> allOptions = getAllOptions();
+ for( Entry<String, Object> entry : allOptions.entrySet() ) {
+ String optionName = entry.getKey();
+ Object optionValue = entry.getValue();
+ JsonValue jsonValue = createJsonValue( optionValue );
+ jsonObject.add( optionName, jsonValue );
+ }
+ return jsonObject;
+ }
+
+ private static JsonValue createJsonValue( Object value ) {
+ if( value instanceof Boolean ) {
+ Boolean bool = ( Boolean )value;
+ return JsonValue.valueOf( bool.booleanValue() );
+ }
+ if( value instanceof String ) {
+ String str = ( String )value;
+ return processString( str );
+ }
+ if( value instanceof Integer ) {
+ Integer num = ( Integer )value;
+ return JsonValue.valueOf( num.intValue() );
+ }
+ if( value instanceof Long ) {
+ Long num = ( Long )value;
+ return JsonValue.valueOf( num.longValue() );
+ }
+ if( value instanceof Float ) {
+ Float num = ( Float )value;
+ return JsonValue.valueOf( num.floatValue() );
+ }
+ if( value instanceof Double ) {
+ Double num = ( Double )value;
+ return JsonValue.valueOf( num.doubleValue() );
+ }
+ System.out.println( value );
+ String message = "Only a RichTextEditorConfiguration with Boolean, String, Integer, Long, "
+ + "Float and Double values is currently supported";
+ throw new IllegalArgumentException( message );
+ }
+
+ private static JsonValue processString( String str ) {
+ if( str == null || str.length() < 1 ) {
+ return JsonValue.valueOf( "" );
+ }
+ if( str.charAt( 0 ) == '[' || str.charAt( 0 ) == '{' ) {
+ return JsonValue.readFrom( str );
+ }
+ return JsonValue.valueOf( str );
+ }
+
+}
diff --git a/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/toolbar/ToolbarConfiguration.java b/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/toolbar/ToolbarConfiguration.java
index d4bfb5901c..bfb8966516 100644
--- a/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/toolbar/ToolbarConfiguration.java
+++ b/bundles/org.eclipse.rap.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/toolbar/ToolbarConfiguration.java
@@ -12,9 +12,12 @@
*****************************************************************************/
package org.eclipse.nebula.widgets.richtext.toolbar;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.nebula.widgets.richtext.RichTextEditorConfiguration;
+
/**
* The toolbar configuration of the CKEditor toolbar. Contains the default toolbar configuration via
@@ -24,8 +27,10 @@ import java.util.Set;
* {@link #getToolbarGroupConfiguration()} and {@link #getRemoveButtonConfiguration()}
* </p>
*
+ * @deprecated Use the more general {@link RichTextEditorConfiguration}
* @since 3.1
*/
+@Deprecated
public class ToolbarConfiguration {
private static final String CKEDITOR_CONFIG_TOOLBAR_GROUPS = "CKEDITOR.config.toolbarGroups";
@@ -37,13 +42,13 @@ public class ToolbarConfiguration {
* Configure whether to remove the <i>paste text</i> button from the toolbar. Default is
* <code>true</code>.
*/
- /*public*/ private final boolean removePasteText = true;
+ public boolean removePasteText = true;
/**
* Configure whether to remove the <i>paste from word</i> button from the toolbar. Default is
* <code>true</code>.
*/
- /*public*/ private final boolean removePasteFromWord = true;
+ public boolean removePasteFromWord = true;
/**
* Configure whether to remove the <i>styles</i> combo box from the toolbar. Default is
@@ -68,6 +73,7 @@ public class ToolbarConfiguration {
*/
public boolean toolbarInitialExpanded = true;
+
private final Set<String> removedButtons = new HashSet<>();
/**
@@ -131,9 +137,10 @@ public class ToolbarConfiguration {
* @see <a href="http://docs.ckeditor.com/#!/guide/dev_toolbar">CKEditor Toolbar Configuration</a>
*/
protected String getRemoveButtonConfiguration() {
- StringBuilder builder = new StringBuilder( "CKEDITOR.config.removeButtons = \"" );
+ StringBuilder builder = new StringBuilder( CKEDITOR_CONFIG_REMOVE_BUTTONS );
+ builder.append( " = \"" );
if( removePasteText ) {
- builder.append( ",PasteText" );
+ builder.append( "PasteText" );
}
if( removePasteFromWord ) {
builder.append( ",PasteFromWord" );
@@ -161,7 +168,7 @@ public class ToolbarConfiguration {
* @param buttonName The name of the CKEditor default button to add.
*/
public void addDefaultToolbarButton( String buttonName ) {
- this.removedButtons.remove( buttonName );
+ removedButtons.remove( buttonName );
}
/**
@@ -170,21 +177,21 @@ public class ToolbarConfiguration {
* @param buttonName The name of the CKEditor default button to remove.
*/
public void removeDefaultToolbarButton( String buttonName ) {
- this.removedButtons.add( buttonName );
+ removedButtons.add( buttonName );
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder( "{" );
- builder.append( "\"toolbarGroups\":" ).append( extractToolbarGroupConfiguration() ).append( "," );
- builder.append( "\"removeButtons\":" ).append( extractRemoveButtonConfiguration() ).append( "," );
+ builder.append( "\"toolbarGroups\":" ).append( getExtractedToolbarGroupConfiguration() ).append( "," );
+ builder.append( "\"removeButtons\":" ).append( getExtractedRemoveButtonConfiguration() ).append( "," );
builder.append( "\"toolbarCanCollapse\":" ).append( toolbarCollapsible ).append( "," );
builder.append( "\"toolbarStartupExpanded\":" ).append( toolbarInitialExpanded );
builder.append( "}" );
return builder.toString();
}
- private String extractToolbarGroupConfiguration() {
+ private String getExtractedToolbarGroupConfiguration() {
String toolbarGroupConfiguration = getToolbarGroupConfiguration().trim();
if( !toolbarGroupConfiguration.startsWith( CKEDITOR_CONFIG_TOOLBAR_GROUPS )
|| !toolbarGroupConfiguration.endsWith( ";" ) ) {
@@ -195,7 +202,7 @@ public class ToolbarConfiguration {
return toolbarGroupConfiguration.substring( equalSignIndex + 1, lastSemicolonIndex ).trim();
}
- private String extractRemoveButtonConfiguration() {
+ private String getExtractedRemoveButtonConfiguration() {
String removeButtonConfiguration = getRemoveButtonConfiguration().trim();
if( !removeButtonConfiguration.startsWith( CKEDITOR_CONFIG_REMOVE_BUTTONS )
|| !removeButtonConfiguration.endsWith( ";" ) ) {
@@ -206,4 +213,21 @@ public class ToolbarConfiguration {
return removeButtonConfiguration.substring( equalSignIndex + 1, lastSemicolonIndex ).trim();
}
+ /**
+ * @since 3.2
+ */
+ public String[] getToolbarButtonConfigurations() {
+ return new String[] {
+ getToolbarGroupConfiguration(),
+ getRemoveButtonConfiguration()
+ };
+ }
+
+ /**
+ * @since 3.2
+ */
+ public Set<String> getRemovedButtons() {
+ return Collections.unmodifiableSet(removedButtons);
+ }
+
}
diff --git a/bundles/org.eclipse.rap.nebula.widgets.richtext/src/resources/RichTextEditor.js b/bundles/org.eclipse.rap.nebula.widgets.richtext/src/resources/RichTextEditor.js
index 92ebd87722..123e0bbf50 100644
--- a/bundles/org.eclipse.rap.nebula.widgets.richtext/src/resources/RichTextEditor.js
+++ b/bundles/org.eclipse.rap.nebula.widgets.richtext/src/resources/RichTextEditor.js
@@ -68,6 +68,8 @@ var CKEDITOR_BASEPATH = "rwt-resources/ckeditor/";
CKEDITOR.config.removeButtons = config.removeButtons;
CKEDITOR.config.toolbarCanCollapse = config.toolbarCanCollapse;
CKEDITOR.config.toolbarStartupExpanded = config.toolbarStartupExpanded;
+ CKEDITOR.config.language = config.language;
+ CKEDITOR.config.defaultlanguage = config.defaultLanguage;
},
setText : function( text ) {
diff --git a/bundles/org.eclipse.rap.nebula.widgets.richtext/src/resources/config.js b/bundles/org.eclipse.rap.nebula.widgets.richtext/src/resources/config.js
index cbb4006460..94b03f190d 100644
--- a/bundles/org.eclipse.rap.nebula.widgets.richtext/src/resources/config.js
+++ b/bundles/org.eclipse.rap.nebula.widgets.richtext/src/resources/config.js
@@ -1,12 +1,6 @@
CKEDITOR.editorConfig = function( config ) {
/**
- * If you change the language, remember to also change CKEditor#RESOURCE_FILES to
- * load the corresponding "/lang/xxx.js" file.
- */
- config.language = 'en';
-
- /**
* Defines the colors to be displayed in the color selectors. This is a string
* containing hexadecimal notation for HTML colors, without the "#" prefix.
* A color name may optionally be defined by prefixing the entries with

Back to the top