Skip to content

Commit

Permalink
Implement stock set moves.
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Feb 1, 2025
1 parent a4a3db1 commit 80b0cf6
Show file tree
Hide file tree
Showing 33 changed files with 1,171 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
import com.io7m.cardant_gui.ui.internal.CAGStatusService;
import com.io7m.cardant_gui.ui.internal.CAGStockAddDialogs;
import com.io7m.cardant_gui.ui.internal.CAGStockSearchView;
import com.io7m.cardant_gui.ui.internal.CAGStockSelectDialogs;
import com.io7m.cardant_gui.ui.internal.CAGStockSerialAddDialogs;
import com.io7m.cardant_gui.ui.internal.CAGStockSetMoveDialogs;
import com.io7m.cardant_gui.ui.internal.CAGStockTableView;
import com.io7m.cardant_gui.ui.internal.CAGStringConstants;
import com.io7m.cardant_gui.ui.internal.CAGStrings;
Expand Down Expand Up @@ -172,6 +174,14 @@ public void start(
CAGStockAddDialogs.class,
new CAGStockAddDialogs(services)
);
services.register(
CAGStockSelectDialogs.class,
new CAGStockSelectDialogs(services)
);
services.register(
CAGStockSetMoveDialogs.class,
new CAGStockSetMoveDialogs(services)
);
services.register(
CAGStockSerialAddDialogs.class,
new CAGStockSerialAddDialogs(services)
Expand Down Expand Up @@ -227,6 +237,7 @@ public void start(

final var controllers =
CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGMainView.class,
() -> new CAGMainView(services)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,22 @@ public final class CAGControllerFactoryMapped<T>
LoggerFactory.getLogger(CAGControllerFactoryMapped.class);

private final Map<Class<? extends T>, Supplier<? extends T>> controllers;
private final Class<?> owner;

private CAGControllerFactoryMapped(
final Class<?> inOwner,
final Map<Class<? extends T>, Supplier<? extends T>> inControllers)
{
this.owner =
Objects.requireNonNull(inOwner, "owner");
this.controllers =
Objects.requireNonNull(inControllers, "controllers");
}

/**
* A controller factory based on an immutable map of controllers.
*
* @param owner The owner, for error messages
* @param <T> The base type of controllers.
* @param constructors The constructors
*
Expand All @@ -57,11 +62,13 @@ private CAGControllerFactoryMapped(

@SafeVarargs
public static <T> CAGControllerFactoryType<T> create(
final Class<?> owner,
final Map.Entry<Class<? extends T>, Supplier<? extends T>>... constructors)
{
Objects.requireNonNull(constructors, "constructors");

return new CAGControllerFactoryMapped<>(
owner,
Map.ofEntries(constructors)
);
}
Expand All @@ -70,12 +77,12 @@ public static <T> CAGControllerFactoryType<T> create(
public T call(
final Class<? extends T> clazz)
{
LOG.debug("Resolving controller: {}", clazz);
LOG.debug("{}: Resolving controller: {}", this.owner, clazz);

final var supplier = this.controllers.get(clazz);
if (supplier == null) {
throw new IllegalStateException(
"No controller available for %s".formatted(clazz)
"%s: No controller available for %s".formatted(this.owner, clazz)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
final Stage stage)
{
return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGFileSelectView.class,
() -> new CAGFileSelectView(stage, arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
Objects.requireNonNull(stage, "stage");

return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGFileCreateView.class,
() -> new CAGFileCreateView(this.services(), stage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
Objects.requireNonNull(stage, "stage");

return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGItemAttachmentAddView.class,
() -> new CAGItemAttachmentAddView(stage, this.services(), arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
final Stage stage)
{
return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGItemCreateView.class,
() -> new CAGItemCreateView(arguments, stage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
Objects.requireNonNull(stage, "stage");

return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGItemNameSetView.class,
() -> new CAGItemNameSetView(stage, arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
final Stage stage)
{
return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGItemSearchView.class,
() -> new CAGItemSearchView(this.services())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
Objects.requireNonNull(stage, "stage");

return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGLocationAttachmentAddView.class,
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
Objects.requireNonNull(stage, "stage");

return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGLocationReparentView.class,
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
final Stage stage)
{
return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGLocationTreeView.class,
() -> new CAGLocationTreeView(this.services())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
Objects.requireNonNull(stage, "stage");

return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGMetadataAddView.class,
() -> new CAGMetadataAddView(stage, this.services(), arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected CAGControllerFactoryType<CAGViewType> controllerFactory(
Objects.requireNonNull(stage, "stage");

return CAGControllerFactoryMapped.create(
this.getClass(),
Map.entry(
CAGStockAddView.class,
() -> new CAGStockAddView(stage, this.services(), arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@
import com.io7m.cardant.model.CAStockInstanceID;
import com.io7m.cardant.model.CAStockOccurrenceSerial;
import com.io7m.cardant.model.CAStockOccurrenceType;
import com.io7m.cardant.model.CAStockRepositRemove;
import com.io7m.cardant.model.CAStockRepositSerialIntroduce;
import com.io7m.cardant.model.CAStockRepositSerialMove;
import com.io7m.cardant.model.CAStockRepositSerialNumberAdd;
import com.io7m.cardant.model.CAStockRepositSerialNumberRemove;
import com.io7m.cardant.model.CAStockRepositSetIntroduce;
import com.io7m.cardant.model.CAStockRepositSetMove;
import com.io7m.cardant.model.CAStockSearchParameters;
import com.io7m.cardant.protocol.inventory.CAICommandStockReposit;
import com.io7m.cardant.protocol.inventory.CAICommandStockSearchBegin;
import com.io7m.cardant.protocol.inventory.CAIResponseStockReposit;
import javafx.application.Platform;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.SortedList;
Expand All @@ -42,6 +45,7 @@

import java.util.ArrayList;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

/**
Expand All @@ -59,6 +63,7 @@ public final class CAGStockSearchController
private final ObservableList<CAStockOccurrenceType> stock;
private final SimpleObjectProperty<CAGPageRange> stockPages;
private final CAGClientServiceType client;
private final SimpleObjectProperty<Optional<CAStockOccurrenceType>> stockSelected;

private CAGStockSearchController(
final CAGClientServiceType inClient)
Expand All @@ -75,6 +80,8 @@ private CAGStockSearchController(

this.stockPages =
new SimpleObjectProperty<>(CAGPageRange.zero());
this.stockSelected =
new SimpleObjectProperty<>(Optional.empty());
}

/**
Expand All @@ -99,6 +106,25 @@ private void onClientStatusChanged()
this.stockPages.set(CAGPageRange.zero());
}

@Override
public ObservableValue<Optional<CAStockOccurrenceType>> stockSelected()
{
return this.stockSelected;
}

@Override
public void stockSelect(
final CAStockOccurrenceType item)
{
this.stockSelected.set(Optional.of(item));
}

@Override
public void stockSelectNone()
{
this.stockSelected.set(Optional.empty());
}

@Override
public ObservableList<CAStockOccurrenceType> stockView()
{
Expand Down Expand Up @@ -141,7 +167,7 @@ public void stockSearchBegin(
}

@Override
public void stockSerialMove(
public CompletableFuture<CAGUnit> stockSerialMove(
final CAStockOccurrenceSerial serial,
final CALocationID location)
{
Expand All @@ -156,8 +182,30 @@ public void stockSerialMove(
);

future.thenAccept(response -> {
Platform.runLater(() -> this.updateStockOccurrence(response.data()));
Platform.runLater(() -> {
response.data().ifPresent(this::updateStockOccurrence);
});
});

return future.thenApply(_ -> CAGUnit.UNIT);
}

@Override
public CompletableFuture<CAGUnit> stockSetMove(
final CAStockRepositSetMove move)
{
Objects.requireNonNull(move, "move");

final var future =
this.client.execute(new CAICommandStockReposit(move));

future.thenAccept(response -> {
Platform.runLater(() -> {
response.data().ifPresent(this::updateStockOccurrence);
});
});

return future.thenApply(_ -> CAGUnit.UNIT);
}

private void updateStockOccurrence(
Expand Down Expand Up @@ -219,7 +267,7 @@ public CompletableFuture<CAGUnit> stockSerialIntroduce(
}

@Override
public CompletableFuture<CAStockOccurrenceType> stockSerialAdd(
public CompletableFuture<Optional<CAStockOccurrenceType>> stockSerialAdd(
final CAStockInstanceID instance,
final CAItemSerial serial)
{
Expand All @@ -237,14 +285,16 @@ public CompletableFuture<CAStockOccurrenceType> stockSerialAdd(
);

future.thenAccept(response -> {
Platform.runLater(() -> this.updateStockOccurrence(response.data()));
Platform.runLater(() -> {
response.data().ifPresent(this::updateStockOccurrence);
});
});

return future.thenApply(CAIResponseStockReposit::data);
}

@Override
public CompletableFuture<CAStockOccurrenceType> stockSerialRemove(
public CompletableFuture<Optional<CAStockOccurrenceType>> stockSerialRemove(
final CAStockInstanceID instance,
final CAItemSerial serial)
{
Expand All @@ -262,9 +312,33 @@ public CompletableFuture<CAStockOccurrenceType> stockSerialRemove(
);

future.thenAccept(response -> {
Platform.runLater(() -> this.updateStockOccurrence(response.data()));
Platform.runLater(() -> {
response.data().ifPresent(this::updateStockOccurrence);
});
});

return future.thenApply(CAIResponseStockReposit::data);
}

@Override
public CompletableFuture<CAGUnit> stockRemoveAll(
final CAStockInstanceID instance)
{
Objects.requireNonNull(instance, "instance");

final var future =
this.client.execute(
new CAICommandStockReposit(new CAStockRepositRemove(instance))
);

future.thenAccept(_ -> {
Platform.runLater(() -> {
this.stock.removeIf(
existing -> Objects.equals(existing.instance(), instance)
);
});
});

return future.thenApply(_ -> CAGUnit.UNIT);
}
}
Loading

0 comments on commit 80b0cf6

Please sign in to comment.