Skip to content

Commit

Permalink
Initial locations screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed May 26, 2024
1 parent 97ba8b9 commit 145cac6
Show file tree
Hide file tree
Showing 55 changed files with 2,812 additions and 602 deletions.
Binary file modified com.io7m.cardant_gui.ui/src/main/images/images.xcf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.io7m.cardant_gui.ui;

import com.io7m.cardant.client.preferences.api.CAPreferencesServiceType;
import com.io7m.cardant_gui.ui.internal.CAGAttachmentAddDialogs;
import com.io7m.cardant_gui.ui.internal.CAGCSS;
import com.io7m.cardant_gui.ui.internal.CAGClientService;
import com.io7m.cardant_gui.ui.internal.CAGClientServiceType;
Expand All @@ -27,13 +26,18 @@
import com.io7m.cardant_gui.ui.internal.CAGFileChoosers;
import com.io7m.cardant_gui.ui.internal.CAGFileChoosersType;
import com.io7m.cardant_gui.ui.internal.CAGFileViewDialogs;
import com.io7m.cardant_gui.ui.internal.CAGItemAttachmentAddDialogs;
import com.io7m.cardant_gui.ui.internal.CAGLocationAttachmentAddDialogs;
import com.io7m.cardant_gui.ui.internal.CAGMainAuditSearchView;
import com.io7m.cardant_gui.ui.internal.CAGMainAuditTableView;
import com.io7m.cardant_gui.ui.internal.CAGMainFileListView;
import com.io7m.cardant_gui.ui.internal.CAGMainFileSearchView;
import com.io7m.cardant_gui.ui.internal.CAGMainItemDetailsView;
import com.io7m.cardant_gui.ui.internal.CAGMainItemSearchView;
import com.io7m.cardant_gui.ui.internal.CAGMainItemTableView;
import com.io7m.cardant_gui.ui.internal.CAGMainLocationDetailsView;
import com.io7m.cardant_gui.ui.internal.CAGMainLocationSearchView;
import com.io7m.cardant_gui.ui.internal.CAGMainLocationTableView;
import com.io7m.cardant_gui.ui.internal.CAGMainTypePackageDetailsView;
import com.io7m.cardant_gui.ui.internal.CAGMainTypePackageSearchView;
import com.io7m.cardant_gui.ui.internal.CAGMainTypePackageTableView;
Expand Down Expand Up @@ -100,8 +104,13 @@ public void start(
new CAGFileViewDialogs(services));

services.register(
CAGAttachmentAddDialogs.class,
new CAGAttachmentAddDialogs(services)
CAGItemAttachmentAddDialogs.class,
new CAGItemAttachmentAddDialogs(services)
);

services.register(
CAGLocationAttachmentAddDialogs.class,
new CAGLocationAttachmentAddDialogs(services)
);

services.register(CAPreferencesServiceType.class, this.preferences);
Expand Down Expand Up @@ -169,6 +178,18 @@ public void start(
Map.entry(
CAGMainTypePackageTableView.class,
() -> new CAGMainTypePackageTableView(services)
),
Map.entry(
CAGMainLocationDetailsView.class,
() -> new CAGMainLocationDetailsView(services)
),
Map.entry(
CAGMainLocationSearchView.class,
() -> new CAGMainLocationSearchView(services)
),
Map.entry(
CAGMainLocationTableView.class,
() -> new CAGMainLocationTableView(services)
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import java.util.Objects;

import static com.io7m.cardant_gui.ui.internal.CAGStringConstants.CARDANT_AUDITSEARCH_TYPE_ANY;
import static com.io7m.cardant_gui.ui.internal.CAGStringConstants.CARDANT_AUDITSEARCH_TYPE_EQUALTO;
import static com.io7m.cardant_gui.ui.internal.CAGStringConstants.CARDANT_AUDITSEARCH_TYPE_NOTEQUALTO;
import static com.io7m.cardant_gui.ui.internal.CAGStringConstants.CARDANT_EXACT_ANY;
import static com.io7m.cardant_gui.ui.internal.CAGStringConstants.CARDANT_EXACT_EQUALTO;
import static com.io7m.cardant_gui.ui.internal.CAGStringConstants.CARDANT_EXACT_NOTEQUALTO;

/**
* A string converter.
Expand Down Expand Up @@ -56,13 +56,13 @@ public String toString(

return switch (k) {
case ANY -> {
yield this.strings.format(CARDANT_AUDITSEARCH_TYPE_ANY);
yield this.strings.format(CARDANT_EXACT_ANY);
}
case EQUAL_TO -> {
yield this.strings.format(CARDANT_AUDITSEARCH_TYPE_EQUALTO);
yield this.strings.format(CARDANT_EXACT_EQUALTO);
}
case NOT_EQUAL_TO -> {
yield this.strings.format(CARDANT_AUDITSEARCH_TYPE_NOTEQUALTO);
yield this.strings.format(CARDANT_EXACT_NOTEQUALTO);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.io7m.cardant.model.CAItemID;
import com.io7m.cardant.model.CAItemSearchParameters;
import com.io7m.cardant.model.CAItemSummary;
import com.io7m.cardant.model.CALocationID;
import com.io7m.cardant.model.CALocationSummary;
import com.io7m.cardant.model.CAMetadataType;
import com.io7m.cardant.model.type_package.CATypePackageIdentifier;
import com.io7m.cardant.model.type_package.CATypePackageSearchParameters;
Expand All @@ -36,6 +38,9 @@
import com.io7m.cardant.protocol.inventory.CAICommandItemAttachmentAdd;
import com.io7m.cardant.protocol.inventory.CAICommandItemGet;
import com.io7m.cardant.protocol.inventory.CAICommandItemSearchBegin;
import com.io7m.cardant.protocol.inventory.CAICommandLocationAttachmentAdd;
import com.io7m.cardant.protocol.inventory.CAICommandLocationGet;
import com.io7m.cardant.protocol.inventory.CAICommandLocationList;
import com.io7m.cardant.protocol.inventory.CAICommandTypePackageGetText;
import com.io7m.cardant.protocol.inventory.CAICommandTypePackageInstall;
import com.io7m.cardant.protocol.inventory.CAICommandTypePackageSearchBegin;
Expand All @@ -46,6 +51,7 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.SortedList;
import javafx.scene.control.TreeItem;
import javafx.scene.image.Image;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -64,7 +70,9 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

Expand All @@ -80,25 +88,37 @@ public final class CAGController implements CAGControllerType
private static final Logger LOG =
LoggerFactory.getLogger(CAGController.class);

private final ObservableList<CAItemSummary> items;
private final SortedList<CAItemSummary> itemsSorted;
private final ObservableList<CAItemSummary> itemsRead;
private final SimpleObjectProperty<CAGPageRange> itemPages;
private static final CALocationID ROOT_LOCATION =
CALocationID.of("00000000-0000-0000-0000-000000000000");

private static final CALocationSummary ROOT_LOCATION_SUMMARY =
new CALocationSummary(ROOT_LOCATION, Optional.empty(), "Everywhere");

private final CAGClientServiceType clientService;
private final SimpleObjectProperty<CAItemSummary> itemSelected;
private final ObservableList<CAMetadataType> itemSelectedMeta;
private final SortedList<CAMetadataType> itemSelectedMetaSorted;
private final ObservableList<CAAttachment> itemSelectedAttachments;
private final ObservableList<CAAuditEvent> auditEvents;
private final ObservableList<CAFileType.CAFileWithoutData> files;
private final ObservableList<CAItemSummary> items;
private final ObservableList<CAItemSummary> itemsRead;
private final ObservableList<CAMetadataType> itemSelectedMeta;
private final ObservableList<CATypePackageSummary> typePackages;
private final SimpleObjectProperty<CAGPageRange> auditEventPages;
private final SimpleObjectProperty<CAGPageRange> filePages;
private final SimpleObjectProperty<CAGPageRange> itemPages;
private final SimpleObjectProperty<CAGPageRange> typePackagePages;
private final SimpleObjectProperty<CAGTransferStatusType> transferStatus;
private final SimpleObjectProperty<CAGPageRange> auditEventPages;
private final ObservableList<CAAuditEvent> auditEvents;
private final SimpleObjectProperty<CAItemSummary> itemSelected;
private final SimpleStringProperty typePackageTextSelected;
private final SortedList<CAAuditEvent> auditEventsSorted;
private final SimpleObjectProperty<CAGPageRange> typePackagePages;
private final ObservableList<CATypePackageSummary> typePackages;
private final SortedList<CAItemSummary> itemsSorted;
private final SortedList<CAMetadataType> itemSelectedMetaSorted;
private final SortedList<CATypePackageSummary> typePackagesSorted;
private final SimpleStringProperty typePackageTextSelected;
private final ObservableList<CAMetadataType> locationSelectedMeta;
private final SortedList<CAMetadataType> locationSelectedMetaSorted;
private final ObservableList<CAAttachment> locationSelectedAttachments;
private final SimpleObjectProperty<CAGPageRange> locationPages;
private final SimpleObjectProperty<CALocationSummary> locationSelected;
private final SimpleObjectProperty<TreeItem<CALocationSummary>> locationTree;

private CAGController(
final CAGClientServiceType inClientService)
Expand All @@ -122,7 +142,6 @@ private CAGController(
FXCollections.observableArrayList();
this.itemSelectedMetaSorted =
new SortedList<>(this.itemSelectedMeta);

this.itemSelectedAttachments =
FXCollections.observableArrayList();

Expand Down Expand Up @@ -150,6 +169,21 @@ private CAGController(

this.typePackageTextSelected =
new SimpleStringProperty();

this.locationSelectedMeta =
FXCollections.observableArrayList();
this.locationSelectedMetaSorted =
new SortedList<>(this.locationSelectedMeta);
this.locationSelectedAttachments =
FXCollections.observableArrayList();

this.locationPages =
new SimpleObjectProperty<>(new CAGPageRange(0L, 0L));
this.locationSelected =
new SimpleObjectProperty<>();

this.locationTree =
new SimpleObjectProperty<>();
}

/**
Expand Down Expand Up @@ -596,4 +630,148 @@ public String toString()
Integer.valueOf(this.hashCode())
);
}

@Override
public ObservableValue<TreeItem<CALocationSummary>> locationTree()
{
return this.locationTree;
}

@Override
public void locationSearchBegin()
{
final var future =
this.clientService.execute(new CAICommandLocationList());

future.thenAccept(response -> {
Platform.runLater(() -> {
final var data =
response.data();
final var summaries =
data.locations();

LOG.debug("Received {} locations", summaries.size());

final var treeItems =
new HashMap<CALocationID, TreeItem<CALocationSummary>>(summaries.size());
final var newRoot =
new TreeItem<>(ROOT_LOCATION_SUMMARY);

for (final var location : summaries.values()) {
final var item = new TreeItem<>(location);
treeItems.put(location.id(), item);
}

for (final var location : summaries.values()) {
final var locationItem =
treeItems.get(location.id());
final var parent =
location.parent();

if (parent.isEmpty()) {
newRoot.getChildren().add(locationItem);
continue;
}

final var parentId =
parent.get();
final var parentItem =
treeItems.get(parentId);

if (parentItem == null) {
LOG.warn("Location {} provided a nonexistent parent {}", location.id(), parentId);
continue;
}

parentItem.getChildren().add(locationItem);
}

this.locationTree.set(newRoot);
});
});
}

@Override
public void locationGet(
final CALocationID id)
{
if (Objects.equals(id, ROOT_LOCATION)) {
this.locationSelectNothing();
return;
}

final var future =
this.clientService.execute(new CAICommandLocationGet(id));

future.thenAccept(response -> {
Platform.runLater(() -> {
final var location = response.data();

this.locationSelected.set(location.summary());

this.locationSelectedMeta.setAll(
location.metadata()
.values()
.stream()
.toList()
);

this.locationSelectedAttachments.setAll(
location.attachments()
.values()
.stream()
.sorted(Comparator.comparing(o -> o.key().fileID()))
.collect(Collectors.toList())
);
});
});
}

@Override
public SortedList<CAMetadataType> locationSelectedMetadata()
{
return this.locationSelectedMetaSorted;
}

@Override
public void locationSelectNothing()
{
this.locationSelected.set(null);
}

@Override
public ObservableList<CAAttachment> locationSelectedAttachments()
{
return this.locationSelectedAttachments;
}

@Override
public void locationAttachmentAdd(
final CAICommandLocationAttachmentAdd command)
{

}

@Override
public ObservableValue<CAGPageRange> locationPages()
{
return this.locationPages;
}

@Override
public ObservableValue<CALocationSummary> locationSelected()
{
return this.locationSelected;
}

@Override
public void locationRemove()
{
final var location = this.locationSelected.get();
if (location == null) {
return;
}

throw new IllegalStateException("Unimplemented code!");
}
}
Loading

0 comments on commit 145cac6

Please sign in to comment.