Skip to content

Commit

Permalink
Merge pull request #4421 from mP1/feature/TableComponent-extends-Valu…
Browse files Browse the repository at this point in the history
…eComponent

TableComponent extends ValueComponent
  • Loading branch information
mP1 authored Jan 15, 2025
2 parents 168d751 + 9d12a40 commit 68d12bd
Show file tree
Hide file tree
Showing 18 changed files with 430 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import elemental2.dom.HTMLElement;
import org.dominokit.domino.ui.IsElement;
import walkingkooka.CanBeEmpty;
import walkingkooka.spreadsheet.dominokit.datatable.SpreadsheetDataTableComponent;
import walkingkooka.text.printer.IndentingPrinter;
import walkingkooka.text.printer.TreePrintable;

Expand Down Expand Up @@ -87,7 +88,7 @@ default boolean isEmptyIfChildrenAreEmpty() {
boolean hide = true;

for (final IsElement<?> child : this.children()) {
if (child instanceof CanBeEmpty) {
if (false == child instanceof SpreadsheetDataTableComponent && child instanceof CanBeEmpty) {
final CanBeEmpty canBeEmpty = (CanBeEmpty) child;
if (canBeEmpty.isEmpty()) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@

package walkingkooka.spreadsheet.dominokit.datatable;

import elemental2.dom.EventListener;
import elemental2.dom.HTMLDivElement;
import org.dominokit.domino.ui.IsElement;
import org.dominokit.domino.ui.datatable.ColumnConfig;
import org.dominokit.domino.ui.datatable.DataTable;
import org.dominokit.domino.ui.datatable.plugins.pagination.BodyScrollPlugin;
import org.dominokit.domino.ui.datatable.plugins.summary.EmptyStatePlugin;
import org.dominokit.domino.ui.icons.Icon;
import org.dominokit.domino.ui.utils.HasChangeListeners.ChangeListener;
import walkingkooka.spreadsheet.dominokit.ComponentWithChildren;
import walkingkooka.spreadsheet.dominokit.SpreadsheetElementIds;
import walkingkooka.spreadsheet.dominokit.SpreadsheetIcons;
import walkingkooka.spreadsheet.dominokit.history.HistoryToken;
import walkingkooka.spreadsheet.dominokit.history.HistoryTokenAnchorComponent;
import walkingkooka.spreadsheet.dominokit.value.FormValueComponent;
import walkingkooka.spreadsheet.dominokit.value.ValueComponent;
import walkingkooka.spreadsheet.dominokit.value.TableComponent;
import walkingkooka.text.CharSequences;
import walkingkooka.text.printer.IndentingPrinter;
import walkingkooka.text.printer.TreePrintable;
Expand All @@ -46,46 +44,13 @@
/**
* A {@link FormValueComponent} wrapper around a {@link DataTable}.
*/
public interface SpreadsheetDataTableComponentLike<T> extends ValueComponent<HTMLDivElement, List<T>, SpreadsheetDataTableComponent<T>>,
public interface SpreadsheetDataTableComponentLike<T> extends TableComponent<HTMLDivElement, List<T>, SpreadsheetDataTableComponent<T>>,
ComponentWithChildren<SpreadsheetDataTableComponent<T>, HTMLDivElement>,
TreePrintable {

@Override SpreadsheetDataTableComponent<T> setCssText(final String css);
// events...........................................................................................................

@Override
default SpreadsheetDataTableComponent<T> addChangeListener(final ChangeListener<Optional<List<T>>> listener) {
throw new UnsupportedOperationException();
}

@Override
default SpreadsheetDataTableComponent<T> addFocusListener(final EventListener listener) {
throw new UnsupportedOperationException();
}

@Override
default SpreadsheetDataTableComponent<T> addKeydownListener(final EventListener listener) {
throw new UnsupportedOperationException();
}

@Override
default SpreadsheetDataTableComponent<T> addKeyupListener(final EventListener listener) {
throw new UnsupportedOperationException();
}

@Override
default SpreadsheetDataTableComponent<T> hideMarginBottom() {
throw new UnsupportedOperationException();
}

@Override
default SpreadsheetDataTableComponent<T> removeBorders() {
throw new UnsupportedOperationException();
}

@Override
default SpreadsheetDataTableComponent<T> focus() {
throw new UnsupportedOperationException();
return (SpreadsheetDataTableComponent<T>)this;
}

// prev/next links..................................................................................................
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
import walkingkooka.text.CharSequences;
import walkingkooka.text.printer.IndentingPrinter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;

/**
* A table that displays matched cells in {@link SpreadsheetDelta} as a table
*/
public final class SpreadsheetDeltaMatchedCellsTableComponent implements TableComponent<SpreadsheetDeltaMatchedCellsTableComponent>,
public final class SpreadsheetDeltaMatchedCellsTableComponent implements TableComponent<HTMLDivElement, Set<SpreadsheetCell>, SpreadsheetDeltaMatchedCellsTableComponent>,
NopFetcherWatcher,
NopEmptyResponseFetcherWatcher,
SpreadsheetDeltaFetcherWatcher {
Expand Down Expand Up @@ -101,6 +104,31 @@ private static ColumnConfig<SpreadsheetCell> columnConfig(final String title,
).setTextAlign(cellTextAlign);
}

@Override
public SpreadsheetDeltaMatchedCellsTableComponent focus() {
this.dataTable.focus();
return this;
}

// value............................................................................................................

@Override
public Optional<Set<SpreadsheetCell>> value() {
return this.dataTable.value()
.map(TreeSet::new);
}

@Override
public SpreadsheetDeltaMatchedCellsTableComponent setValue(final Optional<Set<SpreadsheetCell>> value) {
Objects.requireNonNull(value, "value");

this.dataTable.setValue(
value.map(ArrayList::new)
);

return this;
}

// SpreadsheetDeltaWatcher.........................................................................................

/**
Expand All @@ -111,11 +139,10 @@ public void onSpreadsheetDelta(final HttpMethod method,
final AbsoluteOrRelativeUrl url,
final SpreadsheetDelta delta,
final AppContext context) {
final List<SpreadsheetCell> cells = Lists.array();
cells.addAll(delta.cells());

this.dataTable.setValue(
Optional.of(cells)
this.setValue(
Optional.of(
delta.cells()
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import elemental2.dom.HTMLDivElement;
import org.dominokit.domino.ui.datatable.CellTextAlign;
import org.dominokit.domino.ui.datatable.ColumnConfig;
import walkingkooka.Value;
import walkingkooka.collect.list.Lists;
import walkingkooka.spreadsheet.dominokit.card.SpreadsheetCard;
import walkingkooka.spreadsheet.dominokit.datatable.SpreadsheetDataTableComponent;
Expand All @@ -37,8 +36,7 @@
/**
* A table that displays {@link walkingkooka.spreadsheet.format.SpreadsheetFormatterSample} with one per row.
*/
public final class SpreadsheetFormatterTableComponent implements TableComponent<SpreadsheetFormatterTableComponent>,
Value<Optional<List<SpreadsheetFormatterSample>>> {
public final class SpreadsheetFormatterTableComponent implements TableComponent<HTMLDivElement, List<SpreadsheetFormatterSample>, SpreadsheetFormatterTableComponent> {

/**
* Creates an empty {@link SpreadsheetFormatterTableComponent}.
Expand Down Expand Up @@ -100,13 +98,21 @@ private static ColumnConfig<SpreadsheetFormatterSample> columnConfig(final Strin
);
}

@Override
public SpreadsheetFormatterTableComponent focus() {
this.dataTable.focus();
return this;
}

@Override
public Optional<List<SpreadsheetFormatterSample>> value() {
return this.samples;
}

public void setValue(final Optional<List<SpreadsheetFormatterSample>> samples) {
@Override
public SpreadsheetFormatterTableComponent setValue(final Optional<List<SpreadsheetFormatterSample>> samples) {
this.samples = Objects.requireNonNull(samples, "samples");
return this;
}

private Optional<List<SpreadsheetFormatterSample>> samples;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public boolean isMatch(final HistoryToken token) {
*/
@Override
public void dialogReset() {
this.table.setList(JarEntryInfoList.EMPTY);
this.table.clear();
this.pluginName = null;
this.list = JarEntryInfoList.EMPTY;
}
Expand All @@ -234,7 +234,9 @@ public void refresh(final RefreshContext context) {
.map(PluginName::value)
.orElse("Loading...")
);
this.table.setList(this.list);
this.table.setValue(
Optional.of(this.list)
);

this.refreshDelete();
this.refreshDownload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import elemental2.dom.HTMLDivElement;
import org.dominokit.domino.ui.datatable.CellTextAlign;
import org.dominokit.domino.ui.datatable.ColumnConfig;
import walkingkooka.Cast;
import walkingkooka.collect.list.Lists;
import walkingkooka.spreadsheet.dominokit.SpreadsheetIcons;
import walkingkooka.spreadsheet.dominokit.card.SpreadsheetCard;
Expand All @@ -38,7 +39,7 @@
* A table that lists all the entries from a {@link JarEntryInfoList}.
* No previous or next paging links are provided, it is assumed the table will scroll.
*/
final class JarEntryInfoListTableComponent implements TableComponent<JarEntryInfoListTableComponent> {
final class JarEntryInfoListTableComponent implements TableComponent<HTMLDivElement, JarEntryInfoList, JarEntryInfoListTableComponent> {

/**
* Creates an empty {@link JarEntryInfoListTableComponent}.
Expand Down Expand Up @@ -126,17 +127,28 @@ private static ColumnConfig<JarEntryInfo> columnConfig(final String title,
);
}

private final SpreadsheetDataTableComponent<JarEntryInfo> table;
@Override
public Optional<JarEntryInfoList> value() {
return this.table.value()
.map(JarEntryInfoList::with);
}

JarEntryInfoListTableComponent setList(final JarEntryInfoList list) {
@Override
public JarEntryInfoListTableComponent setValue(final Optional<JarEntryInfoList> list) {
this.table.setValue(
Optional.of(
list
)
Cast.to(list)
);
return this;
}

@Override
public JarEntryInfoListTableComponent focus() {
this.table.focus();
return this;
}

private final SpreadsheetDataTableComponent<JarEntryInfo> table;

// setCssText.......................................................................................................

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ public void onPlugin(final PluginName name,
@Override
public void onPluginSet(final PluginSet plugins,
final AppContext context) {
this.table.setSet(plugins);
this.table.setValue(
Optional.ofNullable(
plugins.isEmpty() ?
null :
plugins
)
);
this.refreshIfOpen(context);
}

Expand All @@ -186,7 +192,7 @@ public boolean isMatch(final HistoryToken token) {

@Override
public void dialogReset() {
this.table.setSet(PluginSet.EMPTY);
this.table.clearValue();
this.uploadAnchor.setDisabled(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.TreeSet;

/**
* A table that lists all the entries from a {@link PluginSet}.
*/
final class PluginSetTableComponent implements TableComponent<PluginSetTableComponent> {
final class PluginSetTableComponent implements TableComponent<HTMLDivElement, PluginSet, PluginSetTableComponent> {

/**
* Creates an empty {@link PluginSetTableComponent}.
Expand All @@ -56,7 +57,7 @@ private PluginSetTableComponent(final String id,
final PluginSetTableComponentContext context) {
this.card = SpreadsheetCard.empty();

this.table = SpreadsheetDataTableComponent.with(
this.dataTable = SpreadsheetDataTableComponent.with(
id,
columnConfigs(),
PluginSetTableComponentSpreadsheetDataTableComponentCellRenderer.with(
Expand All @@ -69,7 +70,7 @@ private PluginSetTableComponent(final String id,
);

this.card.appendChild(
this.table.previousNextLinks(id)
this.dataTable.previousNextLinks(id)
);
}

Expand Down Expand Up @@ -116,19 +117,31 @@ private static ColumnConfig<Plugin> columnConfig(final String title,
);
}

private final SpreadsheetDataTableComponent<Plugin> table;
private final SpreadsheetDataTableComponent<Plugin> dataTable;

PluginSetTableComponent setSet(final PluginSet set) {
this.table.setValue(
Optional.of(
new ArrayList<>(set)
)
@Override
public PluginSetTableComponent focus() {
this.dataTable.focus();
return this;
}


@Override
public Optional<PluginSet> value() {
return this.dataTable.value()
.map(v -> PluginSet.with(new TreeSet<>(v)));
}

@Override
public PluginSetTableComponent setValue(final Optional<PluginSet> set) {
this.dataTable.setValue(
set.map(ArrayList::new)
);
return this;
}

PluginSetTableComponent refresh(final PluginListHistoryToken historyToken) {
this.table.refreshPreviousNextLinks(
this.dataTable.refreshPreviousNextLinks(
historyToken,
DEFAULT_COUNT
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ public void onSpreadsheetMetadata(final SpreadsheetMetadata metadata,
public void onSpreadsheetMetadataSet(final Set<SpreadsheetMetadata> metadatas,
final AppContext context) {
if (this.isOpen()) {
this.table.setMetadata(
new ArrayList<>(metadatas)
this.table.setValue(
Optional.ofNullable(
metadatas.isEmpty() ?
null :
new ArrayList<>(metadatas)
)
);
this.table.refresh(
context.historyToken()
Expand Down
Loading

0 comments on commit 68d12bd

Please sign in to comment.