event bus start: code, PRs e specs
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
package p.studio.events;
|
||||
|
||||
import p.studio.projects.ProjectReference;
|
||||
import p.studio.workspaces.assets.AssetWorkspaceAssetSummary;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetsAssetSummaryPatchedEvent(
|
||||
ProjectReference project,
|
||||
AssetWorkspaceAssetSummary summary) implements StudioEvent {
|
||||
public StudioAssetsAssetSummaryPatchedEvent {
|
||||
Objects.requireNonNull(project, "project");
|
||||
Objects.requireNonNull(summary, "summary");
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package p.studio.events;
|
||||
|
||||
import p.studio.projects.ProjectReference;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetsDetailsRedrawRequestedEvent(ProjectReference project) implements StudioEvent {
|
||||
public StudioAssetsDetailsRedrawRequestedEvent {
|
||||
Objects.requireNonNull(project, "project");
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package p.studio.events;
|
||||
|
||||
import p.studio.projects.ProjectReference;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetsNavigatorRedrawRequestedEvent(ProjectReference project) implements StudioEvent {
|
||||
public StudioAssetsNavigatorRedrawRequestedEvent {
|
||||
Objects.requireNonNull(project, "project");
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package p.studio.events;
|
||||
|
||||
import p.studio.projects.ProjectReference;
|
||||
import p.studio.workspaces.assets.AssetWorkspaceSelectionKey;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetsWorkspaceSelectionRequestedEvent(
|
||||
ProjectReference project,
|
||||
AssetWorkspaceSelectionKey selectionKey) implements StudioEvent {
|
||||
public StudioAssetsWorkspaceSelectionRequestedEvent {
|
||||
Objects.requireNonNull(project, "project");
|
||||
Objects.requireNonNull(selectionKey, "selectionKey");
|
||||
}
|
||||
}
|
||||
@@ -86,13 +86,6 @@ public final class AssetWorkspace implements Workspace {
|
||||
null);
|
||||
}
|
||||
|
||||
public AssetWorkspace(
|
||||
ProjectReference projectReference,
|
||||
AssetWorkspaceService assetWorkspaceService,
|
||||
AssetWorkspaceMutationService mutationService) {
|
||||
this(projectReference, assetWorkspaceService, defaultWorkspaceBus(), mutationService, null);
|
||||
}
|
||||
|
||||
private AssetWorkspace(
|
||||
ProjectReference projectReference,
|
||||
AssetWorkspaceService assetWorkspaceService,
|
||||
@@ -123,6 +116,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
packerEventAdapter);
|
||||
this.packService = new FileSystemPackerBuildService(new p.packer.building.PackerBuildPlanner(), packerEventAdapter);
|
||||
|
||||
subscribeLocalEvents();
|
||||
root.getStyleClass().add("assets-workspace");
|
||||
root.setCenter(buildLayout());
|
||||
root.setBottom(buildLogsPane());
|
||||
@@ -157,6 +151,33 @@ public final class AssetWorkspace implements Workspace {
|
||||
return new StudioWorkspaceEventBus(WorkspaceId.ASSETS, Container.events());
|
||||
}
|
||||
|
||||
private void subscribeLocalEvents() {
|
||||
workspaceBus.subscribe(StudioAssetsWorkspaceSelectionRequestedEvent.class, event -> {
|
||||
if (projectMatches(event.project())) {
|
||||
applySelectionRequest(event.selectionKey());
|
||||
}
|
||||
});
|
||||
workspaceBus.subscribe(StudioAssetsNavigatorRedrawRequestedEvent.class, event -> {
|
||||
if (projectMatches(event.project())) {
|
||||
renderNavigator();
|
||||
}
|
||||
});
|
||||
workspaceBus.subscribe(StudioAssetsDetailsRedrawRequestedEvent.class, event -> {
|
||||
if (projectMatches(event.project())) {
|
||||
renderDetails();
|
||||
}
|
||||
});
|
||||
workspaceBus.subscribe(StudioAssetsAssetSummaryPatchedEvent.class, event -> {
|
||||
if (projectMatches(event.project())) {
|
||||
applyAssetSummaryPatch(event.summary());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean projectMatches(ProjectReference project) {
|
||||
return projectReference.equals(project);
|
||||
}
|
||||
|
||||
private VBox buildLayout() {
|
||||
inlineProgressLabel.getStyleClass().add("assets-workspace-inline-progress-label");
|
||||
inlineProgressLabel.setText(Container.i18n().text(I18n.ASSETS_PROGRESS_IDLE));
|
||||
@@ -179,7 +200,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
final String current = newValue == null ? "" : newValue;
|
||||
if (!previous.equals(current)) {
|
||||
searchQuery = current;
|
||||
renderState();
|
||||
requestNavigatorRedraw();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -269,7 +290,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
} else {
|
||||
activeFilters.remove(filter);
|
||||
}
|
||||
renderState();
|
||||
requestNavigatorRedraw();
|
||||
});
|
||||
filterButtons.put(filter, button);
|
||||
filterBar.getChildren().add(button);
|
||||
@@ -285,7 +306,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
stagedMutationPreview = null;
|
||||
selectedPreviewInput = null;
|
||||
selectedPreviewZoom = 1;
|
||||
renderState();
|
||||
requestRedraw();
|
||||
}
|
||||
setInlineProgress(Container.i18n().text(I18n.ASSETS_PROGRESS_REFRESHING), ProgressBar.INDETERMINATE_PROGRESS, true);
|
||||
appendLog("Assets refresh started.");
|
||||
@@ -303,7 +324,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
}
|
||||
setInlineProgress(Container.i18n().text(I18n.ASSETS_PROGRESS_IDLE), 0, false);
|
||||
appendLog("Assets refresh failed: " + rootCauseMessage(throwable));
|
||||
renderState();
|
||||
requestRedraw();
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceRefreshFailedEvent(projectReference, rootCauseMessage(throwable)));
|
||||
return;
|
||||
}
|
||||
@@ -315,7 +336,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
pendingSelectionKey = null;
|
||||
setInlineProgress(Container.i18n().text(I18n.ASSETS_PROGRESS_IDLE), 0, false);
|
||||
appendLog("Assets refresh completed: " + state.assets().size() + " assets.");
|
||||
renderState();
|
||||
requestRedraw();
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceRefreshedEvent(projectReference, state.assets().size()));
|
||||
state.selectedAsset().ifPresent(asset -> {
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceSelectionChangedEvent(projectReference, asset.selectionKey()));
|
||||
@@ -339,7 +360,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
stagedMutationPreview = null;
|
||||
selectedPreviewInput = null;
|
||||
selectedPreviewZoom = 1;
|
||||
renderDetails();
|
||||
requestDetailsRedraw();
|
||||
}
|
||||
setInlineProgress(Container.i18n().text(I18n.ASSETS_PROGRESS_LOADING_DETAILS), ProgressBar.INDETERMINATE_PROGRESS, true);
|
||||
appendLog("Loading details for " + selectionKey.stableKey() + ".");
|
||||
@@ -359,7 +380,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
}
|
||||
setInlineProgress(Container.i18n().text(I18n.ASSETS_PROGRESS_IDLE), 0, false);
|
||||
appendLog("Asset details failed: " + message);
|
||||
renderDetails();
|
||||
requestDetailsRedraw();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -369,7 +390,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
selectedPreviewZoom = 1;
|
||||
setInlineProgress(Container.i18n().text(I18n.ASSETS_PROGRESS_IDLE), 0, false);
|
||||
appendLog("Asset details ready for " + details.summary().assetName() + ".");
|
||||
renderDetails();
|
||||
requestDetailsRedraw();
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -394,6 +415,19 @@ public final class AssetWorkspace implements Workspace {
|
||||
renderDetails();
|
||||
}
|
||||
|
||||
private void requestRedraw() {
|
||||
requestNavigatorRedraw();
|
||||
requestDetailsRedraw();
|
||||
}
|
||||
|
||||
private void requestNavigatorRedraw() {
|
||||
workspaceBus.publish(new StudioAssetsNavigatorRedrawRequestedEvent(projectReference));
|
||||
}
|
||||
|
||||
private void requestDetailsRedraw() {
|
||||
workspaceBus.publish(new StudioAssetsDetailsRedrawRequestedEvent(projectReference));
|
||||
}
|
||||
|
||||
private void renderNavigator() {
|
||||
assetRowsBySelectionKey.clear();
|
||||
switch (state.status()) {
|
||||
@@ -556,7 +590,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
inputButton.setOnAction(event -> {
|
||||
selectedPreviewInput = input;
|
||||
selectedPreviewZoom = 1;
|
||||
renderState();
|
||||
requestDetailsRedraw();
|
||||
});
|
||||
roleBox.getChildren().add(inputButton);
|
||||
}
|
||||
@@ -718,7 +752,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
button.setDisable(zoom > maxZoom);
|
||||
button.setOnAction(event -> {
|
||||
selectedPreviewZoom = zoom;
|
||||
renderState();
|
||||
requestDetailsRedraw();
|
||||
});
|
||||
zoomBar.getChildren().add(button);
|
||||
}
|
||||
@@ -824,17 +858,9 @@ public final class AssetWorkspace implements Workspace {
|
||||
}
|
||||
|
||||
final AssetWorkspaceAssetSummary updatedSummary = withPreload(details.summary(), preloadEnabled);
|
||||
selectedAssetDetails = new AssetWorkspaceAssetDetails(
|
||||
updatedSummary,
|
||||
details.outputFormat(),
|
||||
details.outputCodec(),
|
||||
details.inputsByRole(),
|
||||
details.diagnostics());
|
||||
state = AssetWorkspaceState.ready(replaceAssetSummary(updatedSummary), updatedSummary.selectionKey());
|
||||
setInlineProgress(Container.i18n().text(I18n.ASSETS_PROGRESS_IDLE), 0, false);
|
||||
appendLog("Preload updated for " + updatedSummary.assetName() + ".");
|
||||
renderNavigator();
|
||||
renderDetails();
|
||||
workspaceBus.publish(new StudioAssetsAssetSummaryPatchedEvent(projectReference, updatedSummary));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -869,12 +895,40 @@ public final class AssetWorkspace implements Workspace {
|
||||
summary.hasDiagnostics());
|
||||
}
|
||||
|
||||
private AssetWorkspaceAssetSummary withBuildParticipation(
|
||||
AssetWorkspaceAssetSummary summary,
|
||||
AssetWorkspaceBuildParticipation buildParticipation) {
|
||||
return new AssetWorkspaceAssetSummary(
|
||||
summary.selectionKey(),
|
||||
summary.assetName(),
|
||||
summary.state(),
|
||||
buildParticipation,
|
||||
summary.assetId(),
|
||||
summary.assetFamily(),
|
||||
summary.assetRoot(),
|
||||
summary.preload(),
|
||||
summary.hasDiagnostics());
|
||||
}
|
||||
|
||||
private List<AssetWorkspaceAssetSummary> replaceAssetSummary(AssetWorkspaceAssetSummary updatedSummary) {
|
||||
return state.assets().stream()
|
||||
.map(asset -> asset.selectionKey().equals(updatedSummary.selectionKey()) ? updatedSummary : asset)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private void applyAssetSummaryPatch(AssetWorkspaceAssetSummary updatedSummary) {
|
||||
state = AssetWorkspaceState.ready(replaceAssetSummary(updatedSummary), state.selectedKey());
|
||||
if (selectedAssetDetails != null && selectedAssetDetails.summary().selectionKey().equals(updatedSummary.selectionKey())) {
|
||||
selectedAssetDetails = new AssetWorkspaceAssetDetails(
|
||||
updatedSummary,
|
||||
selectedAssetDetails.outputFormat(),
|
||||
selectedAssetDetails.outputCodec(),
|
||||
selectedAssetDetails.inputsByRole(),
|
||||
selectedAssetDetails.diagnostics());
|
||||
}
|
||||
requestRedraw();
|
||||
}
|
||||
|
||||
private void renderNavigatorProjection(AssetNavigatorProjection projection) {
|
||||
navigatorContent.getChildren().clear();
|
||||
for (AssetNavigatorGroup group : projection.groups()) {
|
||||
@@ -983,11 +1037,15 @@ public final class AssetWorkspace implements Workspace {
|
||||
}
|
||||
|
||||
private void selectAsset(AssetWorkspaceSelectionKey selectionKey) {
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceSelectionRequestedEvent(projectReference, selectionKey));
|
||||
}
|
||||
|
||||
private void applySelectionRequest(AssetWorkspaceSelectionKey selectionKey) {
|
||||
state = state.withSelection(selectionKey);
|
||||
stagedMutationPreview = null;
|
||||
appendLog("Selected asset " + selectionKey.stableKey() + ".");
|
||||
updateNavigatorSelection();
|
||||
renderDetails();
|
||||
requestDetailsRedraw();
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceSelectionChangedEvent(projectReference, selectionKey));
|
||||
loadSelectedAssetDetails(selectionKey);
|
||||
}
|
||||
@@ -1043,7 +1101,6 @@ public final class AssetWorkspace implements Workspace {
|
||||
if (!result.diagnostics().isEmpty()) {
|
||||
appendLog("Doctor diagnostics: " + result.diagnostics().size() + ".");
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void handlePackResult(PackerBuildResult result) {
|
||||
@@ -1089,14 +1146,14 @@ public final class AssetWorkspace implements Workspace {
|
||||
try {
|
||||
stagedMutationPreview = mutationService.preview(projectReference, selectedAsset, action, null);
|
||||
appendLog("Preview ready for " + actionLabel(action) + ".");
|
||||
renderState();
|
||||
requestDetailsRedraw();
|
||||
Platform.runLater(() -> detailsScroll.setVvalue(0.0d));
|
||||
} catch (RuntimeException runtimeException) {
|
||||
final String message = rootCauseMessage(runtimeException);
|
||||
appendLog("Preview failed: " + message);
|
||||
workspaceBus.publish(new StudioAssetsMutationFailedEvent(projectReference, action, message));
|
||||
stagedMutationPreview = null;
|
||||
renderState();
|
||||
requestDetailsRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1111,19 +1168,21 @@ public final class AssetWorkspace implements Workspace {
|
||||
if (!preview.canApply()) {
|
||||
stagedMutationPreview = preview;
|
||||
appendLog(actionLabel(action) + " blocked.");
|
||||
renderState();
|
||||
requestDetailsRedraw();
|
||||
return;
|
||||
}
|
||||
mutationService.apply(projectReference, preview);
|
||||
appendLog("Applied " + actionLabel(preview.action()) + ".");
|
||||
stagedMutationPreview = null;
|
||||
refresh();
|
||||
if (!applyMutationSummaryPatch(preview)) {
|
||||
refresh();
|
||||
}
|
||||
} catch (RuntimeException runtimeException) {
|
||||
final String message = rootCauseMessage(runtimeException);
|
||||
appendLog("Mutation failed: " + message);
|
||||
workspaceBus.publish(new StudioAssetsMutationFailedEvent(projectReference, action, message));
|
||||
stagedMutationPreview = null;
|
||||
renderState();
|
||||
requestDetailsRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1148,16 +1207,31 @@ public final class AssetWorkspace implements Workspace {
|
||||
mutationService.apply(projectReference, preview);
|
||||
appendLog("Applied " + actionLabel(preview.action()) + ".");
|
||||
stagedMutationPreview = null;
|
||||
refresh();
|
||||
if (!applyMutationSummaryPatch(preview)) {
|
||||
refresh();
|
||||
}
|
||||
} catch (RuntimeException runtimeException) {
|
||||
final String message = rootCauseMessage(runtimeException);
|
||||
appendLog("Mutation failed: " + message);
|
||||
workspaceBus.publish(new StudioAssetsMutationFailedEvent(projectReference, action, message));
|
||||
stagedMutationPreview = null;
|
||||
renderState();
|
||||
requestDetailsRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean applyMutationSummaryPatch(AssetWorkspaceMutationPreview preview) {
|
||||
final AssetWorkspaceAssetSummary updatedSummary = switch (preview.action()) {
|
||||
case INCLUDE_IN_BUILD -> withBuildParticipation(preview.asset(), AssetWorkspaceBuildParticipation.INCLUDED);
|
||||
case EXCLUDE_FROM_BUILD -> withBuildParticipation(preview.asset(), AssetWorkspaceBuildParticipation.EXCLUDED);
|
||||
default -> null;
|
||||
};
|
||||
if (updatedSummary == null) {
|
||||
return false;
|
||||
}
|
||||
workspaceBus.publish(new StudioAssetsAssetSummaryPatchedEvent(projectReference, updatedSummary));
|
||||
return true;
|
||||
}
|
||||
|
||||
private Node createStagedMutationPanel(AssetWorkspaceMutationPreview preview) {
|
||||
final VBox panel = new VBox(10);
|
||||
panel.getStyleClass().add("assets-mutation-panel");
|
||||
@@ -1191,7 +1265,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
cancel.getStyleClass().addAll("studio-button", "studio-button-cancel");
|
||||
cancel.setOnAction(event -> {
|
||||
stagedMutationPreview = null;
|
||||
renderState();
|
||||
requestDetailsRedraw();
|
||||
});
|
||||
final Button apply = new Button(Container.i18n().text(I18n.ASSETS_MUTATION_APPLY));
|
||||
apply.getStyleClass().addAll("studio-button", "studio-button-primary");
|
||||
@@ -1310,7 +1384,7 @@ public final class AssetWorkspace implements Workspace {
|
||||
final String message = rootCauseMessage(runtimeException);
|
||||
appendLog("Mutation failed: " + message);
|
||||
stagedMutationPreview = preview;
|
||||
renderState();
|
||||
requestDetailsRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user