Skip to content

Commit

Permalink
[2179] Provide a system property to disable nebula richtext widget
Browse files Browse the repository at this point in the history
Bug 2179

Change-Id: Icfd00fa512daf41d77991bbb81c3f19d294a38a7
Signed-off-by: Ali AKAR <ali.akar82@gmail.com>
  • Loading branch information
aliakar82 committed Sep 12, 2018
1 parent d5444ff commit b6f0c02
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 22 deletions.
Expand Up @@ -82,4 +82,17 @@ public void addWidget(Composite parent) {
}
}

/**
* Returns whether the nebula rich text is enable or disabled by the end-user.
* It's provided as a fallback solution is case of issues with richtext.
* By default richtext is enabled.
* @return
*/
public boolean isRichTextEnabled() {
String property = System.getProperty("disable.nebula.richtext");
if(property != null) {
return !Boolean.valueOf(property);
}
return true;
}
}
Expand Up @@ -28,13 +28,16 @@
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.polarsys.capella.common.data.modellingcore.AbstractType;
import org.polarsys.capella.core.data.capellacore.CapellaElement;
import org.polarsys.capella.core.data.capellacore.CapellacorePackage;
import org.polarsys.capella.core.data.cs.CsPackage;
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.epbs.ConfigurationItem;
import org.polarsys.capella.core.model.handler.helpers.CapellaAdapterHelper;
import org.polarsys.capella.core.model.handler.helpers.CapellaProjectHelper;
import org.polarsys.capella.core.model.handler.helpers.CapellaProjectHelper.TriStateBoolean;
import org.polarsys.capella.core.ui.properties.fields.AbstractSemanticField;
import org.polarsys.capella.core.ui.properties.fields.TextAreaValueGroup;
import org.polarsys.capella.core.ui.properties.richtext.RichtextManager;
import org.polarsys.capella.core.ui.properties.richtext.fields.CapellaElementDescriptionGroup;
import org.polarsys.capella.core.ui.properties.sections.AbstractSection;

Expand All @@ -47,11 +50,16 @@ public class CapellaDescriptionPropertySection extends AbstractSection {
* We use here a static map to keep track of the instances of this class.
* The idea is: when a section in a wizard is disposed, the current opening section in the view properties could be notified to be refresh. (This is the bug we have with richtext editor)
*/
private static Map<CapellaDescriptionPropertySection, EObject> mapDescriptionSectionToEObject = new HashMap<CapellaDescriptionPropertySection, EObject>();
private static Map<CapellaDescriptionPropertySection, EObject> mapDescriptionSectionToEObject = new HashMap<>();
/**
*
*/
protected CapellaElementDescriptionGroup descriptionGroup;

/**
* In case Richtext is disabled, we replace Richtext widget by this text group.
*/
private TextAreaValueGroup descriptionFallbackGroup;

/**
* @see org.eclipse.ui.views.properties.tabbed.ISection#createControls(org.eclipse.swt.widgets.Composite,
Expand All @@ -64,7 +72,12 @@ public void createControls(Composite parent, TabbedPropertySheetPage aTabbedProp
rootParentComposite.setLayout(new GridLayout());
rootParentComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

descriptionGroup = new CapellaElementDescriptionGroup(rootParentComposite, (aTabbedPropertySheetPage != null) ? getWidgetFactory() : null, this);
if(RichtextManager.getInstance().isRichTextEnabled()) {
descriptionGroup = new CapellaElementDescriptionGroup(rootParentComposite, (aTabbedPropertySheetPage != null) ? getWidgetFactory() : null, this);
}else {
descriptionFallbackGroup = new TextAreaValueGroup(rootParentComposite, "", getWidgetFactory(), true);
descriptionFallbackGroup.setDisplayedInWizard(isDisplayedInWizard());
}
}

/**
Expand Down Expand Up @@ -125,6 +138,8 @@ public void loadData(EObject capellaElement) {
mapDescriptionSectionToEObject.put(this, capellaElement);
if (null != descriptionGroup) {
descriptionGroup.loadData(capellaElement);
}else if(descriptionFallbackGroup != null) {
descriptionFallbackGroup.loadData(capellaElement, CapellacorePackage.eINSTANCE.getCapellaElement_Description());
}
}

Expand All @@ -135,17 +150,17 @@ public void loadData(EObject capellaElement) {
@Override
public void setInput(IWorkbenchPart part, ISelection selection) {
if (selection instanceof StructuredSelection) {
EObject elt = CapellaAdapterHelper.resolveSemanticObject(((StructuredSelection) selection).getFirstElement());
if (elt instanceof CapellaElement) {
if (elt.eClass().equals(CsPackage.eINSTANCE.getPart())) {
boolean allowMultiplePart = TriStateBoolean.True.equals(CapellaProjectHelper.isReusableComponentsDriven((Part) elt));
if (!allowMultiplePart) {
AbstractType type = ((Part) elt).getAbstractType();
if ((type != null) && !(type instanceof ConfigurationItem)) {
super.setInput(part, new StructuredSelection(type));
loadData((CapellaElement) type);
return;
}
EObject elt = CapellaAdapterHelper
.resolveSemanticObject(((StructuredSelection) selection).getFirstElement());
if (elt instanceof CapellaElement && elt.eClass().equals(CsPackage.eINSTANCE.getPart())) {
boolean allowMultiplePart = TriStateBoolean.True
.equals(CapellaProjectHelper.isReusableComponentsDriven((Part) elt));
if (!allowMultiplePart) {
AbstractType type = ((Part) elt).getAbstractType();
if ((type != null) && !(type instanceof ConfigurationItem)) {
super.setInput(part, new StructuredSelection(type));
loadData((CapellaElement) type);
return;
}
}
loadData((CapellaElement) elt);
Expand All @@ -160,10 +175,7 @@ public void setInput(IWorkbenchPart part, ISelection selection) {
@Override
public boolean select(Object toTest) {
EObject eObj = CapellaAdapterHelper.resolveSemanticObject(toTest);
if (eObj instanceof CapellaElement) {
return true;
}
return false;
return eObj instanceof CapellaElement;
}

/**
Expand All @@ -183,6 +195,9 @@ public void setEnabled(boolean enabled) {
*/
@Override
public List<AbstractSemanticField> getSemanticFields() {
if(descriptionFallbackGroup != null) {
return Collections.singletonList(descriptionFallbackGroup);
}
return Collections.emptyList();
}

Expand Down
Expand Up @@ -34,6 +34,8 @@
import org.polarsys.capella.core.model.handler.provider.CapellaReadOnlyHelper;
import org.polarsys.capella.core.model.handler.provider.IReadOnlySectionHandler;
import org.polarsys.capella.core.ui.properties.fields.AbstractSemanticField;
import org.polarsys.capella.core.ui.properties.fields.TextAreaValueGroup;
import org.polarsys.capella.core.ui.properties.richtext.RichtextManager;
import org.polarsys.capella.core.ui.properties.richtext.fields.CapellaElementDescriptionGroup;
import org.polarsys.capella.core.ui.properties.sections.AbstractSection;

Expand All @@ -47,6 +49,11 @@ public class DiagramDescriptionPropertySection extends AbstractSection {
private WeakReference<DRepresentation> representation;

protected CapellaElementDescriptionGroup descriptionGroup;

/**
* In case Richtext is disabled, we replace Richtext widget by this text group.
*/
private TextAreaValueGroup descriptionFallbackGroup;

/**
* {@inheritDoc}
Expand All @@ -71,9 +78,14 @@ public void createControls(Composite parent, TabbedPropertySheetPage aTabbedProp
* @param widgetFactory
* @param textGroup
*/
protected void createDescriptionWidget(TabbedPropertySheetWidgetFactory widgetFactory, Composite parent) {
descriptionGroup = new CapellaElementDescriptionGroup(parent, widgetFactory, this);
protected void createDescriptionWidget(TabbedPropertySheetWidgetFactory widgetFactory, Composite parent) {
if (RichtextManager.getInstance().isRichTextEnabled()) {
descriptionGroup = new CapellaElementDescriptionGroup(parent, widgetFactory, this);
} else {
descriptionFallbackGroup = new TextAreaValueGroup(rootParentComposite, "", getWidgetFactory(), true);
descriptionFallbackGroup.setDisplayedInWizard(isDisplayedInWizard());
}
}

/**
* {@inheritDoc}
Expand Down Expand Up @@ -136,7 +148,9 @@ public void loadData() {

if (descriptionGroup != null) {
descriptionGroup.loadData(representation.get(), DescriptionPackage.Literals.DOCUMENTED_ELEMENT__DOCUMENTATION);
}
}else if(descriptionFallbackGroup != null) {
descriptionFallbackGroup.loadData(representation.get(), DescriptionPackage.Literals.DOCUMENTED_ELEMENT__DOCUMENTATION);
}
}

@Override
Expand Down Expand Up @@ -201,6 +215,9 @@ public void setEnabled(boolean enabled) {
*/
@Override
public List<AbstractSemanticField> getSemanticFields() {
if(descriptionFallbackGroup != null) {
return Collections.singletonList(descriptionFallbackGroup);
}
return Collections.emptyList();
}

Expand All @@ -217,5 +234,4 @@ public void aboutToBeShown() {
descriptionGroup.aboutToBeShown();
super.aboutToBeShown();
}

}

0 comments on commit b6f0c02

Please sign in to comment.