Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#197 #196 Improve dirty state handling #101

Merged
merged 3 commits into from
Mar 23, 2021
Merged

Conversation

tortmayr
Copy link
Contributor

The SetDirtyStateAction now also declares the action/operation which caused the dirty state change.
Ensure that the SetDirtyStateAction is only sent once during a model update
Ensure that layout engine is invoked after bounds have been computed (AutomaticServerLayout case)

Part of eclipse-glsp/glsp#197
Fixes eclipse-glsp/glsp#196

The `SetDirtyStateAction` now also declares the action/operation which caused the dirty state change. 
Ensure that the `SetDirtyStateAction` is only sent once during a model update

Part of eclipse-glsp/glsp#197
Fixes eclipse-glsp/glsp#196

public SetDirtyStateAction() {
super(ID);
}

public SetDirtyStateAction(final boolean isDirty) {
public SetDirtyStateAction(final boolean isDirty, final Action causedBy) {
Copy link
Member

@planger planger Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to make this a mandatory parameter? Afaik, VSCode just wants to know that for undo actions, right? I'm wondering whether this justifies making this a mandatory parameter for all other invocations caused by anything else than UndoAction. Also do you think it would be simpler to just have a string argument: reason = 'operation' | 'undo' | 'save'? I don't have a hard opinion on that, but enforcing to provide an actual action seems like a strong requirement for this rather specific use case of VSCode.

Minor knitpick, I think as a name I'd prefer reason rather than causedBy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for reason ;-)

Copy link
Contributor Author

@tortmayr tortmayr Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for 'reason' and making it optional. In any case it should be possible to determine wehter the dirty state change was triggered by an actual new edtit/operation, an undo/redo action or a save action. Now thinking about it, we also have a another case: the server could also update the model without an operation invocation (e.g. by receiving an update from the model server).
So maybe we should type reason as follows: "operation"|"undo"|"redo"|"save"|"externalUpdate".
What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Yes, sounds good! Maybe just external is good enough, e.g. also if the file got updated on the file system or whatever other external reason. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should be just String then and adopters can provide any reason they want and we just have a list of known String reasons but no strict typing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me as well. We could then just use the action.kind as default reason string as well

Copy link
Contributor

@martin-fleck-at martin-fleck-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tobi, in our example everything works fine and well but I am not sure this is true if we do not need a client layout. Maybe I am missing something and you can clarify that case for me (see comments inline).

if (diagramConfiguration.getLayoutKind() == ServerLayoutKind.AUTOMATIC) {
layoutEngine.layout(modelState);
}
Action modelAction = gModel.getRevision() == 0 ? new SetModelAction(gModel) : new UpdateModelAction(gModel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already had cases where I had to override this method only to change the animate flag in this method. Would it be possible to extract the new UpdateModelAction(gModel) into a separate method or provide a method that returns the animate boolean that is then used in the creation of this action? I know it is not strictly part of this change but with this change the method just became more complicated and overriding more cumbersome ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this is something that we could store in the DiagramConfiguration (similar to the needsClientLayout flag). This way the user doesn't have to subclass the ModelSubmissionHandler and can configure it directly in the DiagramConfiguration.

return Arrays.asList(action, new SetDirtyStateAction(modelState.isDirty()));
List<Action> result = new ArrayList<>();
result.add(modelAction);
Optional.ofNullable(causedBy).ifPresent(result::add);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why we would need to add the 'cause' to the result? The method comment mentions that the result of this call should be dispatched through the ActionDispatcher (either directly or not), would that lead not to an infinite loop in case we do not need a client layout or do I miss something here?

}
}
return submitModelDirectly(modelState);
return submitModelDirectly(modelState, needsClientLayout ? null : causedBy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it should not be possible for needsClientLayout to be true here. If it were, we would already have returned.

Copy link
Contributor

@martin-fleck-at martin-fleck-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me and as far as I can tell, everything still works as expected, thank you very much Tobias! I just have one minor request to update an outdated Javadoc.

…atures/core/model/ModelSubmissionHandler.java

Co-authored-by: Martin Fleck <mfleck@eclipsesource.com>
Copy link
Contributor

@martin-fleck-at martin-fleck-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, everything looks good to me now!

@martin-fleck-at martin-fleck-at merged commit 38004fd into master Mar 23, 2021
@tortmayr tortmayr deleted the tortmayr/197 branch March 23, 2021 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic layout is applied to early
3 participants