POC: Rework workspace API #765
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims at reworking the workspace API, moving from a generic map of strings to a dedicated class that manages both reads and writes in a safe and typed way.
Details:
WorkspaceControllerloads a workspace JSON file and keeps a reference to the current loaded workspace, which is a dedicated class:WorkspaceData.LoadWorkspaceResponsehas been changed to carry theWorkspaceDatainstead of the file and the "plain" data.WorkspaceDatawhich is:ToolData. This class wraps the workspace file and the specific tool data as aMap<String, String>. A tool can retrieve its state from the workspace data by callingworkspaceData.getToolData(this). I preferred this way rather than having a genericgetToolData(String toolId)method which may be error prone, less secure.BaseToolPanel, theonLoadWorkspace(...)method has been changed to accept theWorkspaceDatainstance. Each tool panel retrieves the tool data via the aforementioned method and callsrestoreStateFrom(...)on its subcomponents (theAlternateMixToolPanelbeing an exception since it also manipulates the data for backwards compatibility)restoreStateFrom(...)method fromRestorableViewhas also been changed to acceptToolDatarather than a generic mapFlow
WorkspaceController->LoadWorkspaceResponse(WorkspaceData)->BaseToolPanel(WorkspaceData -> ToolData)->RestorableView(ToolData)Summary
All in all,
WorkspaceDataandToolDataare just wrappers for plain, generic maps. In fact, the goal of the first commit was to preserve as much as possible of the existing code, while just moving the logic to a single place so that it can more easily be tested, managed, changed.Three more things to note:
WorkspaceDataalready implements an enhancement for issue Relative paths in .json files #710, and as requested it's not a fallback system, but expects arelative.pathsproperty to be set totruein the workspace file. SinceToolDatais responsible for resolving the paths (because it's the class carrying the data to the specific tool), the wrapped workspace file determines if the relative path resolution is enabled. If the file is null, then it's disabled.