Skip to content

Commit 6d746b5

Browse files
committed
fix #1088 refactor menu component
1 parent b412530 commit 6d746b5

39 files changed

+3961
-1852
lines changed

domino-ui/src/main/java/org/dominokit/domino/ui/config/MenuConfig.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,64 @@
1717

1818
import org.dominokit.domino.ui.menu.SingleSelectionMode;
1919

20+
/**
21+
* Configuration contract for menu components in Domino UI.
22+
*
23+
* <p>This interface centralizes menu-related text and behavior defaults used by menu widgets, such
24+
* as labels/messages for search results and the default selection mode. Framework users may provide
25+
* their own implementation to customize messages (for localization or branding) and behavior while
26+
* leveraging the defaults provided here.
27+
*
28+
* <p>Note: Some returned strings include basic HTML markup (e.g., <b> tags) intended for rendering
29+
* in components that accept HTML content. If you override these methods, ensure the formatting is
30+
* appropriate for the target component and sanitized if necessary.
31+
*
32+
* <p>Extends {@link ZIndexConfig} to inherit z-index related configuration that affects menu popup
33+
* layering and stacking context.
34+
*/
2035
public interface MenuConfig extends ZIndexConfig {
36+
/**
37+
* Returns the message displayed when no search results match the provided token.
38+
*
39+
* @param token the user-entered search token that produced no results
40+
* @return a user-facing message, potentially containing simple HTML emphasizing the token
41+
*/
2142
default String getNoResultMatchMessage(String token) {
2243
return "No results matched " + " <b>" + token + "</b>";
2344
}
2445

46+
/**
47+
* Returns the label prefix used when suggesting the creation of a missing item.
48+
*
49+
* <p>For example, when the user types a value that doesn't exist, the UI may show a suggestion
50+
* like "Create <b>token</b>". This method provides the "Create " part, allowing consistent
51+
* localization/branding.
52+
*
53+
* @return the label prefix for the create-missing-item suggestion
54+
*/
2555
default String getMissingItemCreateLabel() {
2656
return "Create ";
2757
}
2858

59+
/**
60+
* Returns the full message used when suggesting the creation of a missing item.
61+
*
62+
* @param token the user-entered value that is missing
63+
* @return a suggestion message combining {@link #getMissingItemCreateLabel()} and the token,
64+
* often with simple HTML emphasis
65+
*/
2966
default String getMissingItemCreateMessage(String token) {
3067
return getMissingItemCreateLabel() + " <b>" + token + "</b>";
3168
}
3269

70+
/**
71+
* Returns the default selection mode for menu components.
72+
*
73+
* <p>The default is {@link SingleSelectionMode#RESELECT} which allows selecting an already
74+
* selected item to trigger its action again.
75+
*
76+
* @return the default {@link SingleSelectionMode}
77+
*/
3378
default SingleSelectionMode getDefaultSelectionMode() {
3479
return SingleSelectionMode.RESELECT;
3580
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.dominokit.domino.ui.data;
18+
19+
import java.util.List;
20+
import java.util.Optional;
21+
import org.dominokit.domino.ui.datatable.plugins.pagination.SortDirection;
22+
23+
/**
24+
* The {@code DataChangedEvent} class represents an event that is triggered when data in a data
25+
* store changes, such as when records are loaded or sorted.
26+
*
27+
* @param <T> The type of data representing the records in the data table.
28+
*/
29+
public class DataChangedEvent<T> {
30+
private final List<T> newData;
31+
private final boolean append;
32+
private final int totalCount;
33+
private final Optional<SortDirection> sortDir;
34+
private final Optional<String> sortColumn;
35+
36+
/**
37+
* Constructs a new {@code DataChangedEvent} with the provided data and total count.
38+
*
39+
* @param newData The list of new data records.
40+
* @param totalCount The total count of records.
41+
*/
42+
public DataChangedEvent(List<T> newData, int totalCount) {
43+
this.newData = newData;
44+
this.totalCount = totalCount;
45+
this.append = false;
46+
this.sortDir = Optional.empty();
47+
this.sortColumn = Optional.empty();
48+
}
49+
50+
/**
51+
* Constructs a new {@code DataChangedEvent} with the provided data, total count, sort direction,
52+
* and sort column.
53+
*
54+
* @param newData The list of new data records.
55+
* @param totalCount The total count of records.
56+
* @param sortDirection The sorting direction.
57+
* @param sortColumn The column used for sorting.
58+
*/
59+
public DataChangedEvent(
60+
List<T> newData, int totalCount, SortDirection sortDirection, String sortColumn) {
61+
this.newData = newData;
62+
this.totalCount = totalCount;
63+
this.append = false;
64+
this.sortDir = Optional.of(sortDirection);
65+
this.sortColumn = Optional.of(sortColumn);
66+
}
67+
68+
/**
69+
* Constructs a new {@code DataChangedEvent} with the provided data, append flag, and total count.
70+
*
71+
* @param newData The list of new data records.
72+
* @param append {@code true} if the data is being appended to the existing data; {@code false}
73+
* otherwise.
74+
* @param totalCount The total count of records.
75+
*/
76+
public DataChangedEvent(List<T> newData, boolean append, int totalCount) {
77+
this.newData = newData;
78+
this.append = append;
79+
this.totalCount = totalCount;
80+
this.sortDir = Optional.empty();
81+
this.sortColumn = Optional.empty();
82+
}
83+
84+
/**
85+
* Constructs a new {@code DataChangedEvent} with the provided data, append flag, total count,
86+
* sort direction, and sort column.
87+
*
88+
* @param newData The list of new data records.
89+
* @param append {@code true} if the data is being appended to the existing data; {@code false}
90+
* otherwise.
91+
* @param totalCount The total count of records.
92+
* @param sortDirection The sorting direction.
93+
* @param sortColumn The column used for sorting.
94+
*/
95+
public DataChangedEvent(
96+
List<T> newData,
97+
boolean append,
98+
int totalCount,
99+
SortDirection sortDirection,
100+
String sortColumn) {
101+
this.newData = newData;
102+
this.append = append;
103+
this.totalCount = totalCount;
104+
this.sortDir = Optional.of(sortDirection);
105+
this.sortColumn = Optional.of(sortColumn);
106+
}
107+
108+
/**
109+
* Gets the list of new data records.
110+
*
111+
* @return A list of new data records.
112+
*/
113+
public List<T> getNewData() {
114+
return newData;
115+
}
116+
117+
/**
118+
* Checks if the data is being appended to the existing data.
119+
*
120+
* @return {@code true} if the data is being appended; {@code false} otherwise.
121+
*/
122+
public boolean isAppend() {
123+
return append;
124+
}
125+
126+
/**
127+
* Gets the total count of records.
128+
*
129+
* @return The total count of records.
130+
*/
131+
public int getTotalCount() {
132+
return totalCount;
133+
}
134+
135+
/**
136+
* Gets the sorting direction, if available.
137+
*
138+
* @return An {@code Optional} containing the sorting direction, or empty if not available.
139+
*/
140+
public Optional<SortDirection> getSortDir() {
141+
return sortDir;
142+
}
143+
144+
/**
145+
* Gets the column used for sorting, if available.
146+
*
147+
* @return An {@code Optional} containing the sort column, or empty if not available.
148+
*/
149+
public Optional<String> getSortColumn() {
150+
return sortColumn;
151+
}
152+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.data;
17+
18+
public interface DataFilter<T> {
19+
boolean filter(T item);
20+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.dominokit.domino.ui.data;
18+
19+
import org.dominokit.domino.ui.utils.DominoEventListener;
20+
21+
/**
22+
* The {@code DataStore} interface defines a contract for managing and retrieving data for a data
23+
* table.
24+
*
25+
* @param <T> The type of data representing the records in the data table.
26+
*/
27+
public interface DataStore<T> extends DominoEventListener {
28+
29+
/**
30+
* Registers a data change listener to be notified when the data in the store changes.
31+
*
32+
* @param dataChangeListener The data change listener to register.
33+
*/
34+
void onDataChanged(StoreDataChangeListener<T> dataChangeListener);
35+
36+
/**
37+
* Removes a previously registered data change listener.
38+
*
39+
* @param dataChangeListener The data change listener to remove.
40+
*/
41+
void removeDataChangeListener(StoreDataChangeListener<T> dataChangeListener);
42+
43+
/** Loads or refreshes the data in the data store. */
44+
void load();
45+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.data;
17+
18+
import java.util.ArrayList;
19+
import java.util.Collection;
20+
import java.util.List;
21+
22+
public interface FilterMode<T> {
23+
24+
List<T> apply(Collection<T> data, Collection<? extends DataFilter<? super T>> filters);
25+
26+
static <T> FilterMode<T> denial() {
27+
return (data, filters) -> {
28+
if (data == null || data.isEmpty()) return new ArrayList<>();
29+
if (filters == null || filters.isEmpty()) return new ArrayList<>(data);
30+
List<T> out = new ArrayList<>(data.size());
31+
outer:
32+
for (T item : data) {
33+
for (DataFilter<? super T> f : filters) {
34+
if (!f.filter(item)) continue outer;
35+
}
36+
out.add(item);
37+
}
38+
return out;
39+
};
40+
}
41+
42+
static <T> FilterMode<T> acceptance() {
43+
return (data, filters) -> {
44+
if (data == null || data.isEmpty()) return new ArrayList<>();
45+
if (filters == null || filters.isEmpty()) return new ArrayList<>(data);
46+
List<T> out = new ArrayList<>();
47+
outer:
48+
for (T item : data) {
49+
for (DataFilter<? super T> f : filters) {
50+
if (f.filter(item)) {
51+
out.add(item);
52+
continue outer;
53+
}
54+
}
55+
}
56+
return out;
57+
};
58+
}
59+
60+
/** Ignore filters and accept all items */
61+
static <T> FilterMode<T> acceptAll() {
62+
return (data, filters) -> new ArrayList<>(data);
63+
}
64+
65+
/** Ignore filters and deny all items */
66+
static <T> FilterMode<T> denyAll() {
67+
return (data, filters) -> new ArrayList<>();
68+
}
69+
}

0 commit comments

Comments
 (0)