implements PR-10f bank composition apply through packer and snapshot refresh
This commit is contained in:
+37
-14
@@ -1,8 +1,10 @@
|
||||
package p.studio.workspaces.assets.details.bank;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.packer.messages.ApplyBankCompositionRequest;
|
||||
import p.studio.Container;
|
||||
import p.studio.controls.banks.StudioAssetCapacityMeter;
|
||||
import p.studio.controls.forms.StudioFormActionBar;
|
||||
@@ -18,12 +20,14 @@ import p.studio.workspaces.assets.messages.events.StudioAssetBankCompositionAppl
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetBankCompositionApplyRequestedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetBankCompositionCapacityChangedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetBankCompositionDraftChangedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsRefreshRequestedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.workspaces.framework.StudioSubscriptionBag;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AssetDetailsBankCompositionControl extends VBox implements StudioControlLifecycle {
|
||||
private final ProjectReference projectReference;
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioSubscriptionBag subscriptions = new StudioSubscriptionBag();
|
||||
private final StudioFormActionBar actionBar = new StudioFormActionBar(
|
||||
@@ -39,7 +43,7 @@ public final class AssetDetailsBankCompositionControl extends VBox implements St
|
||||
|
||||
public AssetDetailsBankCompositionControl(ProjectReference projectReference, StudioWorkspaceEventBus workspaceBus) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
}
|
||||
|
||||
@@ -126,21 +130,40 @@ public final class AssetDetailsBankCompositionControl extends VBox implements St
|
||||
}
|
||||
|
||||
private void applyDraft() {
|
||||
if (viewState == null || viewState.selectedAssetReference() == null) {
|
||||
if (viewState == null || viewState.selectedAssetReference() == null || !coordinator.ready()) {
|
||||
return;
|
||||
}
|
||||
workspaceBus.publish(new StudioAssetBankCompositionApplyRequestedEvent(viewState.selectedAssetReference()));
|
||||
try {
|
||||
coordinator.apply();
|
||||
render();
|
||||
publishStateNotifications();
|
||||
workspaceBus.publish(new StudioAssetBankCompositionAppliedEvent(viewState.selectedAssetReference()));
|
||||
} catch (RuntimeException exception) {
|
||||
workspaceBus.publish(new StudioAssetBankCompositionApplyFailedEvent(
|
||||
viewState.selectedAssetReference(),
|
||||
exception.getMessage()));
|
||||
throw exception;
|
||||
}
|
||||
final var assetReference = viewState.selectedAssetReference();
|
||||
final var selectedPaths = coordinator.viewModel().selectedFiles().stream()
|
||||
.map(file -> file.path())
|
||||
.toList();
|
||||
workspaceBus.publish(new StudioAssetBankCompositionApplyRequestedEvent(assetReference));
|
||||
Container.backgroundTasks().submit(() -> {
|
||||
final var request = new ApplyBankCompositionRequest(
|
||||
projectReference.toPackerProjectContext(),
|
||||
assetReference,
|
||||
selectedPaths);
|
||||
try {
|
||||
final var response = Container.packer().workspaceService().applyBankComposition(request);
|
||||
Platform.runLater(() -> {
|
||||
if (response.success()) {
|
||||
coordinator.apply();
|
||||
render();
|
||||
publishStateNotifications();
|
||||
workspaceBus.publish(new StudioAssetBankCompositionAppliedEvent(assetReference));
|
||||
workspaceBus.publish(new StudioAssetsRefreshRequestedEvent(assetReference));
|
||||
} else {
|
||||
workspaceBus.publish(new StudioAssetBankCompositionApplyFailedEvent(
|
||||
assetReference,
|
||||
response.errorMessage()));
|
||||
}
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetBankCompositionApplyFailedEvent(
|
||||
assetReference,
|
||||
exception.getMessage())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void resetDraft() {
|
||||
|
||||
Reference in New Issue
Block a user