Skip to content

Commit

Permalink
[561365] Richtext can lost the last modification when switching tab
Browse files Browse the repository at this point in the history
(#194)

* [561365] Richtext can lose the last modification when switching tab

- Fix the Issue

Bug: 561365
Change-Id: I3139f3b9add7b981cb3d8fa5a5192c6bb973ac86
Signed-off-by: Philippe DUL <[email protected]>

Co-authored-by: Sandu Postaru <[email protected]>

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
  • Loading branch information
pdulth committed Jul 20, 2020
1 parent 15051cd commit 9aa6a58
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}

Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 9aa6a58

Please sign in to comment.