Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuai Li2016-05-23 14:37:10 +0000
committerGerrit Code Review @ Eclipse.org2016-05-24 07:52:06 +0000
commitac233284410bf2a2fb8257fbecfb4e6718395e3b (patch)
treec6be82b2dfea8415af68ddc09314e43e1ac4896f /plugins/uml
parent67a5513c1d746dff3551d9c3bf25e86219464df3 (diff)
downloadorg.eclipse.papyrus-ac233284410bf2a2fb8257fbecfb4e6718395e3b.tar.gz
org.eclipse.papyrus-ac233284410bf2a2fb8257fbecfb4e6718395e3b.tar.xz
org.eclipse.papyrus-ac233284410bf2a2fb8257fbecfb4e6718395e3b.zip
Bug 494318 - [Rich Text] Preferences
- Add preference to choose renderer and editor (by we use the simple renderer and editor) - Comment body wrapper editor - Fix some potential NPEs Change-Id: I78153204d554f59b21ef7ecd2725a3dfe2d2a870 Signed-off-by: Shuai Li <shuai.li@cea.fr>
Diffstat (limited to 'plugins/uml')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml9
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/HTMLCornerBentFigure.java102
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/preferences/RichtextPreferenceInitializer.java40
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/preferences/RichtextPreferencePage.java53
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/Model/UML/ui/SingleComment.xwt4
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/CommentBodyWrapperEditor.java245
6 files changed, 413 insertions, 40 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
index 23d60395449..db854aac9a2 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
@@ -524,12 +524,21 @@
id="org.eclipse.papyrus.uml.diagram.common.StereotypePasteStrategyPreferencePage"
name="Stereotype Strategy">
</page>
+ <page
+ category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
+ class="org.eclipse.papyrus.uml.diagram.common.preferences.RichtextPreferencePage"
+ id="org.eclipse.papyrus.uml.diagram.common.RichtextPreferencePage"
+ name="Rich text">
+ </page>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="org.eclipse.papyrus.uml.diagram.common.preferences.StereotypePasteStrategyPreferenceInitializer">
</initializer>
+ <initializer
+ class="org.eclipse.papyrus.uml.diagram.common.preferences.RichtextPreferenceInitializer">
+ </initializer>
</extension>
<extension
point="org.eclipse.papyrus.infra.gmfdiag.canonical.strategies">
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/HTMLCornerBentFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/HTMLCornerBentFigure.java
index 56e1809de3a..e67f2db0d44 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/HTMLCornerBentFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/HTMLCornerBentFigure.java
@@ -32,10 +32,12 @@ import org.eclipse.draw2d.text.FlowPage;
import org.eclipse.draw2d.text.TextFlow;
import org.eclipse.gmf.runtime.draw2d.ui.internal.figures.AnimatableScrollPane;
import org.eclipse.gmf.runtime.draw2d.ui.text.TextFlowEx;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.FontDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.parser.HTMLCleaner;
+import org.eclipse.papyrus.uml.diagram.common.preferences.RichtextPreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
@@ -93,6 +95,10 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
protected HTMLRenderer htmlRenderer;
/**
+ * Preference boolean
+ */
+ protected Boolean useHtmlRenderer = null;
+ /**
* Body size to remember so layout changes are not fired infinitely
*
* @since 2.0
@@ -138,31 +144,35 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
* Generates the basic contents for this figure
*/
protected void createContents() {
- if (htmlRenderer == null) {
- IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
-
- for (IConfigurationElement e : config) {
- if (!"contributor".equals(e.getName())) {
- continue;
- }
- try {
- Object instance = e.createExecutableExtension("contributor");
- if (instance instanceof HTMLRenderer) {
- htmlRenderer = (HTMLRenderer) instance;
- break;
- }
- } catch (Exception ex) {
- Activator.log.warn("Invalid html renderer contribution from: " + e.getContributor());
- }
- }
- }
-
- if (htmlRenderer == null) {
+ if (!useHtmlRenderer()) {
page = new FlowPage();
page.setForegroundColor(getForegroundColor());
this.add(page);
} else {
- IFigure htmlContent = htmlRenderer.getFigure();
+ if (htmlRenderer == null) {
+ IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
+
+ for (IConfigurationElement e : config) {
+ if (!"contributor".equals(e.getName())) {
+ continue;
+ }
+ try {
+ Object instance = e.createExecutableExtension("contributor");
+ if (instance instanceof HTMLRenderer) {
+ htmlRenderer = (HTMLRenderer) instance;
+ break;
+ }
+ } catch (Exception ex) {
+ Activator.log.warn("Invalid html renderer contribution from: " + e.getContributor());
+ }
+ }
+ }
+
+ IFigure htmlContent = null;
+
+ if (htmlRenderer != null) {
+ htmlContent = htmlRenderer.getFigure();
+ }
if (htmlContent != null) {
this.add(htmlContent);
@@ -196,19 +206,21 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
}
private void paintHTML() {
- try {
- if (this.isVisible()) {
- if (Display.getDefault() != null) {
- int width = getClientArea().width;
- int height = getClientArea().height;
-
- if (width > 0 && height > 0) { // width and height can be nil before figures are displayed
- htmlRenderer.paintHTML(text, width, height, 0, 0);
+ if (htmlRenderer != null) {
+ try {
+ if (this.isVisible()) {
+ if (Display.getDefault() != null) {
+ int width = getClientArea().width;
+ int height = getClientArea().height;
+
+ if (width > 0 && height > 0) { // width and height can be nil before figures are displayed
+ htmlRenderer.paintHTML(text, width, height, 0, 0);
+ }
}
}
+ } catch (Exception e) {
+ Activator.log.error(e);
}
- } catch (Exception e) {
- Activator.log.error(e);
}
}
@@ -279,15 +291,17 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
this.text = text;
- if (htmlRenderer == null) {
- // remove all children from page.
- page.removeAll();
+ if (!useHtmlRenderer() || htmlRenderer == null) {
+ if (page != null) {
+ // remove all children from page.
+ page.removeAll();
- // init the first font data
- currentFontData = new FontData("Wingdings", 8, SWT.NORMAL);
+ // init the first font data
+ currentFontData = new FontData("Wingdings", 8, SWT.NORMAL);
- // generates new ones
- generateBlockForText(text, page);
+ // generates new ones
+ generateBlockForText(text, page);
+ }
} else {
paintHTML();
}
@@ -909,4 +923,16 @@ public class HTMLCornerBentFigure extends CornerBentFigure implements ILabelFigu
public Point getEditionLocation() {
return getBounds().getTopLeft();
}
+
+ private boolean useHtmlRenderer() {
+ if (useHtmlRenderer == null) {
+ useHtmlRenderer = false;
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ if (store != null) {
+ useHtmlRenderer = store.getBoolean(RichtextPreferencePage.USE_HTML_RENDERER);
+ }
+ }
+
+ return useHtmlRenderer;
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/preferences/RichtextPreferenceInitializer.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/preferences/RichtextPreferenceInitializer.java
new file mode 100644
index 00000000000..7336eb29190
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/preferences/RichtextPreferenceInitializer.java
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST.
+ *
+ * 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:
+ * Shuai Li (CEA LIST) shuai.li@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+
+
+/**
+ * This preference initializer initializes Stereotype strategy preferences
+ */
+public class RichtextPreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /**
+ * Initialize default preferences
+ */
+ @Override
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = getPreferenceStore();
+ store.setDefault(RichtextPreferencePage.USE_HTML_RENDERER, false);
+ store.setDefault(RichtextPreferencePage.USE_CK_EDITOR, false);
+ }
+
+ /**
+ * Get the preference store
+ */
+ protected IPreferenceStore getPreferenceStore() {
+ return Activator.getDefault().getPreferenceStore();
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/preferences/RichtextPreferencePage.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/preferences/RichtextPreferencePage.java
new file mode 100644
index 00000000000..a833c30806b
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/preferences/RichtextPreferencePage.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2010 CEA List.
+ * 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:
+ * Shuai Li (CEA List) <shuai.li@cea.fr> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.preferences;
+
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * Rich text preferences page to choose basic or advanced renderer
+ */
+
+public class RichtextPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ public static final String USE_HTML_RENDERER = "useHtmlRenderer";
+ public static final String USE_CK_EDITOR = "useCkEditor";
+
+ public RichtextPreferencePage() {
+ super(GRID);
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ setDescription("Rich Text Preferences");
+ }
+
+ /**
+ * Creates the field editors.
+ */
+ @Override
+ public void createFieldEditors() {
+ addField(new BooleanFieldEditor(USE_HTML_RENDERER, "Use advanced rich text renderer (needs a reload of opened diagrams). Warning: may raise stability issues.", getFieldEditorParent()));
+ addField(new BooleanFieldEditor(USE_CK_EDITOR, "Use advanced rich text editor", getFieldEditorParent()));
+ }
+
+ /**
+ * Init.
+ *
+ * @param workbench
+ * the workbench
+ */
+ @Override
+ public void init(IWorkbench workbench) {
+ }
+
+}
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/Model/UML/ui/SingleComment.xwt b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/Model/UML/ui/SingleComment.xwt
index 40337e578e5..74ef1a70cc8 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/Model/UML/ui/SingleComment.xwt
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/Model/UML/ui/SingleComment.xwt
@@ -6,8 +6,8 @@
<Composite.layout>
<ppel:PropertiesLayout></ppel:PropertiesLayout>
</Composite.layout>
- <uml:CommentBodyRichTextEditor input="{Binding}"
- property="UML:Comment:body"></uml:CommentBodyRichTextEditor>
+ <uml:CommentBodyWrapperEditor input="{Binding}"
+ property="UML:Comment:body"></uml:CommentBodyWrapperEditor>
<ppe:MultiReference input="{Binding}"
property="UML:Comment:annotatedElement"></ppe:MultiReference>
</Composite>
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/CommentBodyWrapperEditor.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/CommentBodyWrapperEditor.java
new file mode 100644
index 00000000000..2000d979b70
--- /dev/null
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/CommentBodyWrapperEditor.java
@@ -0,0 +1,245 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * 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:
+ * Shuai Li (CEA LIST) <shuai.li@cea.fr> - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.properties.widgets;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.properties.ui.modelelement.DataSource;
+import org.eclipse.papyrus.infra.properties.ui.widgets.AbstractPropertyEditor;
+import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
+import org.eclipse.papyrus.uml.diagram.common.preferences.RichtextPreferencePage;
+import org.eclipse.papyrus.uml.properties.Activator;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * Wraps the simple comment editor and the rich text comment editor
+ *
+ */
+public class CommentBodyWrapperEditor extends AbstractPropertyEditor {
+ private CommentBodyEditor normalEditor;
+ private CommentBodyRichTextEditor richTextEditor;
+
+ /**
+ * Instantiates a new comment body wrapper editor.
+ *
+ * @param parent
+ * the parent
+ * @param style
+ * the style
+ */
+ public CommentBodyWrapperEditor(Composite parent, int style) {
+ if (Platform.getPreferencesService().getBoolean("org.eclipse.papyrus.uml.diagram.common", RichtextPreferencePage.USE_CK_EDITOR, false, null)) {
+ richTextEditor = new CommentBodyRichTextEditor(parent, style);
+ normalEditor = null;
+ } else {
+ normalEditor = new CommentBodyEditor(parent, style);
+ richTextEditor = null;
+ }
+
+ if (richTextEditor == null && normalEditor == null) {
+ normalEditor = new CommentBodyEditor(parent, style);
+ }
+ }
+
+ @Override
+ protected void doBinding() {
+ if (normalEditor != null) {
+ normalEditor.doBinding();
+ } else if (richTextEditor != null) {
+ richTextEditor.doBinding();
+ } else {
+ super.doBinding();
+ }
+ }
+
+ @Override
+ public void setProperty(String path) {
+ if (normalEditor != null) {
+ normalEditor.setProperty(path);
+ } else if (richTextEditor != null) {
+ richTextEditor.setProperty(path);
+ } else {
+ super.setProperty(path);
+ }
+ }
+
+ @Override
+ public void updateLabel() {
+ if (normalEditor != null) {
+ normalEditor.updateLabel();
+ } else if (richTextEditor != null) {
+ richTextEditor.updateLabel();
+ } else {
+ super.updateLabel();
+ }
+ }
+
+ @Override
+ public void updateLabel(String label) {
+ if (normalEditor != null) {
+ normalEditor.updateLabel(label);
+ } else if (richTextEditor != null) {
+ richTextEditor.updateLabel(label);
+ } else {
+ super.updateLabel(label);
+ }
+ }
+
+ @Override
+ public String getProperty() {
+ if (normalEditor != null) {
+ return normalEditor.getProperty();
+ } else if (richTextEditor != null) {
+ return richTextEditor.getProperty();
+ }
+ return super.getProperty();
+ }
+
+ @Override
+ public void setInput(DataSource input) {
+ if (normalEditor != null) {
+ normalEditor.setInput(input);
+ } else if (richTextEditor != null) {
+ richTextEditor.setInput(input);
+ } else {
+ super.setInput(input);
+ }
+ }
+
+ @Override
+ public DataSource getInput() {
+ if (normalEditor != null) {
+ return normalEditor.getInput();
+ } else if (richTextEditor != null) {
+ return richTextEditor.getInput();
+ }
+ return super.getInput();
+ }
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ if (normalEditor != null) {
+ normalEditor.setReadOnly(readOnly);
+ } else if (richTextEditor != null) {
+ richTextEditor.setReadOnly(readOnly);
+ } else {
+ super.setReadOnly(readOnly);
+ }
+ }
+
+ @Override
+ public AbstractEditor getEditor() {
+ if (normalEditor != null) {
+ return normalEditor.getEditor();
+ } else if (richTextEditor != null) {
+ return richTextEditor.getEditor();
+ }
+ return super.getEditor();
+ }
+
+ @Override
+ public boolean getReadOnly() {
+ if (normalEditor != null) {
+ return normalEditor.getReadOnly();
+ } else if (richTextEditor != null) {
+ return richTextEditor.getReadOnly();
+ }
+ return super.getReadOnly();
+ }
+
+ @Override
+ public void setLayoutData(Object data) {
+ if (normalEditor != null) {
+ normalEditor.setLayoutData(data);
+ } else if (richTextEditor != null) {
+ richTextEditor.setLayoutData(data);
+ } else {
+ super.setLayoutData(data);
+ }
+ }
+
+ @Override
+ public Object getLayoutData() {
+ if (normalEditor != null) {
+ return normalEditor.getLayoutData();
+ } else if (richTextEditor != null) {
+ return richTextEditor.getLayoutData();
+ }
+ return super.getLayoutData();
+ }
+
+ @Override
+ public void setShowLabel(boolean showLabel) {
+ if (normalEditor != null) {
+ normalEditor.setShowLabel(showLabel);
+ } else if (richTextEditor != null) {
+ richTextEditor.setShowLabel(showLabel);
+ } else {
+ super.setShowLabel(showLabel);
+ }
+ }
+
+ @Override
+ public boolean getShowLabel() {
+ if (normalEditor != null) {
+ return normalEditor.getShowLabel();
+ } else if (richTextEditor != null) {
+ return richTextEditor.getShowLabel();
+ }
+ return super.getShowLabel();
+ }
+
+ @Override
+ public void setCustomLabel(String customLabel) {
+ if (normalEditor != null) {
+ normalEditor.setCustomLabel(customLabel);
+ } else if (richTextEditor != null) {
+ richTextEditor.setCustomLabel(customLabel);
+ } else {
+ super.setCustomLabel(customLabel);
+ }
+ }
+
+ @Override
+ public String getCustomLabel() {
+ if (normalEditor != null) {
+ return normalEditor.getCustomLabel();
+ } else if (richTextEditor != null) {
+ return richTextEditor.getCustomLabel();
+ }
+ return super.getCustomLabel();
+ }
+
+ @Override
+ public Control getControl() {
+ if (normalEditor != null) {
+ return normalEditor.getControl();
+ } else if (richTextEditor != null) {
+ return richTextEditor.getControl();
+ }
+ return super.getControl();
+ }
+
+ @Override
+ public IValidator getValidator() {
+ if (normalEditor != null) {
+ return normalEditor.getValidator();
+ } else if (richTextEditor != null) {
+ return richTextEditor.getValidator();
+ }
+ return super.getValidator();
+ }
+}

Back to the top