Skip to content

Commit

Permalink
Merge pull request #4416 from mP1/feature/SpreadsheetFormatterTableCo…
Browse files Browse the repository at this point in the history
…mponent-implements-Value

SpreadsheetFormatterTableComponent implements Value
  • Loading branch information
mP1 authored Jan 15, 2025
2 parents 135da5e + 852444b commit b4c62c6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import walkingkooka.spreadsheet.dominokit.selector.RemoveOrReplacePluginSelectorTokenComponent;
import walkingkooka.spreadsheet.engine.SpreadsheetDelta;
import walkingkooka.spreadsheet.format.SpreadsheetFormatterName;
import walkingkooka.spreadsheet.format.SpreadsheetFormatterSample;
import walkingkooka.spreadsheet.format.SpreadsheetFormatterSelector;
import walkingkooka.spreadsheet.format.SpreadsheetFormatterSelectorToken;
import walkingkooka.spreadsheet.format.SpreadsheetFormatterSelectorTokenAlternative;
Expand All @@ -50,6 +51,7 @@
import walkingkooka.spreadsheet.server.formatter.SpreadsheetFormatterSelectorMenuList;
import walkingkooka.text.CharSequences;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -264,11 +266,17 @@ private void onSpreadsheetFormatterSelectorEdit(final SpreadsheetFormatterSelect
this.formatterName = edit.selector()
.map(SpreadsheetFormatterSelector::name);

this.table.refresh(
edit.samples(),
context
final List<SpreadsheetFormatterSample> samples = edit.samples();
this.table.setValue(
Optional.ofNullable(
samples.isEmpty() ?
null :
samples
)
);

this.table.refresh(context);

final SpreadsheetFormatterSelectorAppendComponentPluginSelectorTokenComponentContextRemoveOrReplacePluginSelectorTokenComponentContext appenderRemoveOrReplaceContext =
SpreadsheetFormatterSelectorAppendComponentPluginSelectorTokenComponentContextRemoveOrReplacePluginSelectorTokenComponentContext.with(
edit.selector()
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.Value;
import walkingkooka.collect.list.Lists;
import walkingkooka.spreadsheet.dominokit.card.SpreadsheetCard;
import walkingkooka.spreadsheet.dominokit.datatable.SpreadsheetDataTableComponent;
Expand All @@ -36,7 +37,8 @@
/**
* A table that displays {@link walkingkooka.spreadsheet.format.SpreadsheetFormatterSample} with one per row.
*/
public final class SpreadsheetFormatterTableComponent implements TableComponent<SpreadsheetFormatterTableComponent> {
public final class SpreadsheetFormatterTableComponent implements TableComponent<SpreadsheetFormatterTableComponent>,
Value<Optional<List<SpreadsheetFormatterSample>>> {

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

public void refresh(final List<SpreadsheetFormatterSample> samples,
final SpreadsheetFormatterTableComponentContext context) {
Objects.requireNonNull(samples, "samples");
@Override
public Optional<List<SpreadsheetFormatterSample>> value() {
return this.samples;
}

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

private Optional<List<SpreadsheetFormatterSample>> samples;

public void refresh(final SpreadsheetFormatterTableComponentContext context) {
this.cellRenderer.context = Objects.requireNonNull(context, "context");
this.dataTable.setValue(
Optional.of(samples)
);
this.dataTable.setValue(this.samples);

// manually show/hide depending on samples. Card will never be empty because SpreadsheetDataTableComponent is never empty
if (samples.isEmpty()) {
if (this.samples.isEmpty()) {
this.card.hide();
} else {
this.card.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import walkingkooka.spreadsheet.dominokit.selector.AppendPluginSelectorTokenComponent;
import walkingkooka.spreadsheet.dominokit.selector.RemoveOrReplacePluginSelectorTokenComponent;
import walkingkooka.spreadsheet.engine.SpreadsheetDelta;
import walkingkooka.spreadsheet.format.SpreadsheetFormatterSample;
import walkingkooka.spreadsheet.format.pattern.SpreadsheetPatternKind;
import walkingkooka.spreadsheet.meta.SpreadsheetMetadata;
import walkingkooka.spreadsheet.parser.SpreadsheetParserName;
Expand All @@ -50,6 +51,7 @@
import walkingkooka.spreadsheet.server.parser.SpreadsheetParserSelectorEdit;
import walkingkooka.text.CharSequences;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -260,8 +262,15 @@ private void onSpreadsheetParserSelectorEdit(final SpreadsheetParserSelectorEdit
this.parserName = edit.selector()
.map(SpreadsheetParserSelector::name);

final List<SpreadsheetFormatterSample> samples = edit.samples();
this.table.setValue(
Optional.ofNullable(
samples.isEmpty() ?
null :
samples
)
);
this.table.refresh(
edit.samples(),
SpreadsheetParserSelectorDialogComponentSpreadsheetFormatterTableComponentContext.with(
edit.selector()
.orElse(null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import walkingkooka.tree.text.TextNode;

import java.util.List;
import java.util.Optional;

public final class SpreadsheetFormatterTableComponentTest implements TableComponentTesting<SpreadsheetFormatterTableComponent>,
SpreadsheetMetadataTesting {
Expand Down Expand Up @@ -102,8 +103,16 @@ private void refreshAndCheck(final List<SpreadsheetFormatterSample> samples,
final SpreadsheetFormatterTableComponent component = SpreadsheetFormatterTableComponent.empty(
"id123-"
);

component.setValue(
Optional.ofNullable(
samples.isEmpty() ?
null :
samples
)
);

component.refresh(
samples,
new FakeSpreadsheetFormatterTableComponentContext() {
@Override
public HistoryToken historyToken() {
Expand Down

0 comments on commit b4c62c6

Please sign in to comment.