Bug 567241 - Text field does not refresh on failure
Summary: Text field does not refresh on failure
Status: UNCONFIRMED
Alias: None
Product: Sirius
Classification: Modeling
Component: Properties (show other bugs)
Version: 6.3.4   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2020-09-22 06:16 EDT by Nicolas PERANSIN CLA
Modified: 2021-05-05 09:31 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas PERANSIN CLA 2020-09-22 06:16:02 EDT
When in a text widget, the update fails (service throwing exception or transaction rollback), then the text of widget is not restored to model content.

This also cause refresh issues aterward when another fiel is edited.

This come from the chain of interpretation when the widget triggers a model update.

Update is ordered by following method:
org.eclipse.eef.ide.ui.internal.widgets.EEFTextLifecycleManager#updateValue(boolean)
This method expected a IStatus != OK on error which is not provided by Sirius interpretation.

When enable such error, following method must be changed:
- in org.eclipse.sirius.properties.core.internal.SiriusToolServices #executeOperation(SiriusInputDescriptor, EObject, String):

  instead of creating and running a SiriusCommand (useless as we are already in a transaction) perform,

```java
   List<ICommandTask> toPerform = Collections.singletonList(task);
   if (TaskExecutor.canExecute(toPerform)) {
     TaskExecutor.execute(toPerform);
   }
```

- in org.eclipse.sirius.ui.properties.internal.TransactionalEditingDomainContextAdapter #performModelChange(Runnable)

change the log listener into a transaction call back like this:

```java
  ted.getCommandStack().execute(new RecordingCommand(ted) {
    @Override
    protected void doExecute() {
      InternalTransaction transaction = ((InternalTransactionalEditingDomain) ted).getActiveTransaction();
      resultProvider.set(() -> transaction.getStatus());
      effect.run();
    }
        });

  return resultProvider.get() == null
    ? new Status(IStatus.ERROR, "org.eclipse.sirius.ui.properties",
                "Transaction fails for properties command")
    : resultProvider.get().get();

```

User using Sirius 6.3.x can achieve the same behavior by:
- creating a custom TextDescriptionConverter
-- change the call to SiriusToolServices into a custom service.
-- registered in org.eclipse.sirius.properties.core.descriptionConverter extension point
-- declaring custom service in odesign.
- extending TransactionalEditingDomainContextAdapter
-- change how perfomChange(...) behaves
-- registered in org.eclipse.sirius.ui.properties.contextAdapterProvider extension point
Comment 1 Nicolas PERANSIN CLA 2020-09-22 06:18:34 EDT
amend on TransactionalEditingDomainContextAdapter

full code is:

```

        AtomicReference<Supplier<IStatus>> resultProvider = new AtomicReference<>();

        ted.getCommandStack().execute(new RecordingCommand(ted) {
            @Override
            protected void doExecute() {
                InternalTransaction transaction = ((InternalTransactionalEditingDomain) ted)
                    .getActiveTransaction();
                resultProvider.set(() -> transaction.getStatus());
                effect.run();
                
            }
        });

        return resultProvider.get() == null
            ? new Status(IStatus.ERROR, "org.eclipse.sirius.ui.properties",
                "Transaction fails for properties command")
            : resultProvider.get().get();

```