From 9aa6a584e71381dcbd6476189784048b018e177b Mon Sep 17 00:00:00 2001 From: Philippe DUL Date: Tue, 26 May 2020 09:27:54 +0200 Subject: [PATCH] [561365] Richtext can lost the last modification when switching tab (#194) * [561365] Richtext can lose the last modification when switching tab - Fix the Issue Bug: 561365 Change-Id: I3139f3b9add7b981cb3d8fa5a5192c6bb973ac86 Signed-off-by: Philippe DUL Co-authored-by: Sandu Postaru Conflicts: core/plugins/org.polarsys.capella.core.ui.properties.richtext/src/org/polarsys/capella/core/ui/properties/richtext/sections/CapellaDescriptionPropertySection.java releng/plugins/org.polarsys.capella.targets/full/capella.target-definition.targetplatform Change-Id: I52ce6d622a30b4645f481ea800801e634da5900b --- .../fields/ElementDescriptionGroup.java | 32 +++++++++++++++++-- .../CapellaDescriptionPropertySection.java | 7 ++-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/core/plugins/org.polarsys.capella.core.ui.properties.richtext/src/org/polarsys/capella/core/ui/properties/richtext/fields/ElementDescriptionGroup.java b/core/plugins/org.polarsys.capella.core.ui.properties.richtext/src/org/polarsys/capella/core/ui/properties/richtext/fields/ElementDescriptionGroup.java index afd21a686b..a67a5a8abf 100644 --- a/core/plugins/org.polarsys.capella.core.ui.properties.richtext/src/org/polarsys/capella/core/ui/properties/richtext/fields/ElementDescriptionGroup.java +++ b/core/plugins/org.polarsys.capella.core.ui.properties.richtext/src/org/polarsys/capella/core/ui/properties/richtext/fields/ElementDescriptionGroup.java @@ -86,6 +86,13 @@ private class SavingStrategy implements SaveStrategy { EStructuralFeature feature; + // Does the saveStrategy has to perform the last save before its disposal. + // If null, the last save is not yet there. + // If true, the last save has to be done + // If false, the last save has been done and another save is not welcome as the given owner may have changed + Boolean lastSave = null; + + public SavingStrategy() { } @@ -99,11 +106,30 @@ public void save(final String editorText, final EObject owner, final EStructural // Due to async 'lost focus' event, the given owner in parameter can be the next one and not the intended one // Usecase: - // On ProjectExplorer, select an element. Change its description, then choose another element in explorer. + // On ProjectExplorer, select an element. Change its description, keep edition focus, then choose another element + // in explorer. // Save is called twice, one in loadData/within bind method with previous element, then another one in lostFocus // with new one but with old text. - if (this.owner == owner && this.feature == feature) { + if (lastSave == null && this.owner == owner && this.feature == feature) { + setDataValue(owner, feature, editorText); + + } else if (Boolean.TRUE.equals(lastSave)) { + // Usecase: + // On two opened diagrams with description tab opened, Change description of element, keep edition focus, then + // switch tab to other diagram. + // Last save may be lost by the previous if. + setDataValue(owner, feature, editorText); + lastSave = Boolean.FALSE; + } + } + + /** + * Mark the save strategy to ensure that last save of the editor will be performed + */ + public void ensureLastSave() { + if (lastSave == null) { + lastSave = Boolean.TRUE; } } } @@ -154,6 +180,7 @@ public void aboutToBeShown() { if (updateDescriptionEditability(semanticElement, semanticFeature)) { try { if (semanticElement != null && semanticFeature != null) { + ((SavingStrategy) descriptionTextField.getSaveStrategy()).ensureLastSave(); descriptionTextField.bind(semanticElement, semanticFeature); descriptionTextField.setSaveStrategy(new SavingStrategy(semanticElement, semanticFeature)); } @@ -305,6 +332,7 @@ public void loadData(EObject element, EStructuralFeature feature) { } // We setSaveStrategy after the bind, as bind also do a saveContent on previous element. + ((SavingStrategy) descriptionTextField.getSaveStrategy()).ensureLastSave(); descriptionTextField.bind(semanticElement, semanticFeature); descriptionTextField.setSaveStrategy(new SavingStrategy(semanticElement, semanticFeature)); diff --git a/core/plugins/org.polarsys.capella.core.ui.properties.richtext/src/org/polarsys/capella/core/ui/properties/richtext/sections/CapellaDescriptionPropertySection.java b/core/plugins/org.polarsys.capella.core.ui.properties.richtext/src/org/polarsys/capella/core/ui/properties/richtext/sections/CapellaDescriptionPropertySection.java index 23e5511d31..12c3ae168f 100644 --- a/core/plugins/org.polarsys.capella.core.ui.properties.richtext/src/org/polarsys/capella/core/ui/properties/richtext/sections/CapellaDescriptionPropertySection.java +++ b/core/plugins/org.polarsys.capella.core.ui.properties.richtext/src/org/polarsys/capella/core/ui/properties/richtext/sections/CapellaDescriptionPropertySection.java @@ -86,7 +86,7 @@ public DelayedSetDescription(String name) { @Override public boolean belongsTo(Object family) { - return family == DelayedSetDescription.class.getSimpleName(); + return DelayedSetDescription.class.getSimpleName().equals(family); }; @Override @@ -126,10 +126,7 @@ public void setInput(IWorkbenchPart part, ISelection selection) { EObject elt = CapellaAdapterHelper .resolveRepresentationOrBusinessObject(((StructuredSelection) selection).getFirstElement()); - if (elt instanceof CapellaElement) { - loadData(elt); - - } else if (elt instanceof DRepresentation) { + if (elt instanceof CapellaElement || elt instanceof DRepresentation) { loadData(elt); } }