diff --git a/domino-ui-shared/pom.xml b/domino-ui-shared/pom.xml index 0be9789e9..bdf04d0dd 100644 --- a/domino-ui-shared/pom.xml +++ b/domino-ui-shared/pom.xml @@ -5,7 +5,7 @@ domino-ui-parent org.dominokit - 2.0.0-RC5 + 2.0.0 jar 4.0.0 diff --git a/domino-ui-shared/src/main/java/org/dominokit/domino/ui/style/ConditionalCssClass.java b/domino-ui-shared/src/main/java/org/dominokit/domino/ui/style/ConditionalCssClass.java new file mode 100644 index 000000000..24e23a2e1 --- /dev/null +++ b/domino-ui-shared/src/main/java/org/dominokit/domino/ui/style/ConditionalCssClass.java @@ -0,0 +1,177 @@ +/* + * Copyright © 2019 Dominokit + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dominokit.domino.ui.style; + +import elemental2.dom.Element; +import java.util.function.Supplier; +import org.dominokit.domino.ui.IsElement; + +/** + * A utility class to facilitate the conditional application or removal of CSS classes based on + * boolean conditions. This class acts as a wrapper around the {@link CssClass} interface, with the + * provision for conditional application or removal of styles. + * + * @see CssClass + * @author [Your Name or Organization] + */ +public class ConditionalCssClass implements CssClass { + + private CssClass cssClass; + private Supplier condition; + + /** + * Creates an instance with a specified {@link CssClass} and a condition flag. + * + * @param cssClass The CSS class to be conditionally applied or removed. + * @param condition Condition flag to determine if the class should be applied (true) or removed + * (false). + * @return A new instance of {@code ConditionalCssClass}. + */ + public static ConditionalCssClass of(CssClass cssClass, Supplier condition) { + return new ConditionalCssClass(cssClass, condition); + } + + /** + * Creates an instance with a specified {@link HasCssClass} and a condition flag. This method + * extracts the {@link CssClass} from the provided {@link HasCssClass}. + * + * @param cssClass The object implementing {@link HasCssClass} whose CSS class will be extracted. + * @param condition Condition flag to determine if the class should be applied (true) or removed + * (false). + * @return A new instance of {@code ConditionalCssClass}. + */ + public static ConditionalCssClass of(HasCssClass cssClass, Supplier condition) { + return new ConditionalCssClass(cssClass.getCssClass(), condition); + } + + /** + * Creates an instance with a specified CSS class string and a condition flag. + * + * @param cssClass The string representation of the CSS class to be conditionally applied or + * removed. + * @param condition Condition flag to determine if the class should be applied (true) or removed + * (false). + * @return A new instance of {@code ConditionalCssClass}. + */ + public static ConditionalCssClass of(String cssClass, Supplier condition) { + return new ConditionalCssClass(() -> cssClass, condition); + } + + /** + * Initializes the {@code ConditionalCssClass} with a provided {@link CssClass} and a condition + * flag. + * + * @param cssClass The CSS class to be managed. + * @param condition Condition flag to determine if the class should be applied (true) or removed + * (false). + */ + public ConditionalCssClass(CssClass cssClass, Supplier condition) { + this.cssClass = cssClass; + this.condition = condition; + } + + /** + * Applies or removes the CSS class on the provided element based on the condition flag. + * + * @param element The DOM element to which the CSS class will be applied or removed. + */ + @Override + public void apply(Element element) { + apply(element, condition); + } + + /** + * Applies or removes the CSS class on the provided element based on the given condition flag. + * + * @param element The DOM element to which the CSS class will be applied or removed. + * @param condition Condition flag to determine if the class should be applied (true) or removed + * (false). + */ + public void apply(Element element, Supplier condition) { + if (condition.get()) { + cssClass.apply(element); + } else { + remove(element); + } + } + + /** + * Applies or removes the CSS class on the provided {@link IsElement} based on the specified + * condition. + * + * @param element The UI element (implementing {@link IsElement}) on which the CSS class will be + * conditionally applied or removed. + * @param condition Condition flag to determine if the class should be applied (true) or removed + * (false). + */ + public void apply(IsElement element, Supplier condition) { + apply(element.element(), condition); + } + + /** + * Checks if the CSS class is applied to the specified DOM {@link Element}. + * + * @param element The DOM element to check. + * @return {@code true} if the CSS class is applied to the element, {@code false} otherwise. + */ + @Override + public boolean isAppliedTo(Element element) { + return cssClass.isAppliedTo(element); + } + + /** + * Checks if the CSS class is applied to the specified {@link IsElement}. + * + * @param element The UI element (implementing {@link IsElement}) to check. + * @return {@code true} if the CSS class is applied to the element, {@code false} otherwise. + */ + @Override + public boolean isAppliedTo(IsElement element) { + return cssClass.isAppliedTo(element); + } + + /** + * Removes the CSS class from the specified DOM {@link Element}. + * + * @param element The DOM element from which the CSS class will be removed. + */ + @Override + public void remove(Element element) { + cssClass.remove(element); + } + + /** + * Removes the CSS class from the specified {@link IsElement}. + * + * @param element The UI element (implementing {@link IsElement}) from which the CSS class will be + * removed. + */ + @Override + public void remove(IsElement element) { + cssClass.remove(element); + } + + /** + * Retrieves the CSS class string associated with this instance. + * + * @return The string representation of the associated CSS class. + */ + @Override + public String getCssClass() { + return cssClass.getCssClass(); + } +} diff --git a/domino-ui-tools/mdi-icons-processor/pom.xml b/domino-ui-tools/mdi-icons-processor/pom.xml index d82797bbf..8b5ecf7e9 100644 --- a/domino-ui-tools/mdi-icons-processor/pom.xml +++ b/domino-ui-tools/mdi-icons-processor/pom.xml @@ -5,7 +5,7 @@ domino-ui-tools org.dominokit - 2.0.0-RC5 + 2.0.0 4.0.0 diff --git a/domino-ui-tools/pom.xml b/domino-ui-tools/pom.xml index d947b6bd5..3846ae6db 100644 --- a/domino-ui-tools/pom.xml +++ b/domino-ui-tools/pom.xml @@ -5,7 +5,7 @@ domino-ui-parent org.dominokit - 2.0.0-RC5 + 2.0.0 4.0.0 diff --git a/domino-ui-webjar/pom.xml b/domino-ui-webjar/pom.xml index e99ed88c8..ee41dbeb0 100644 --- a/domino-ui-webjar/pom.xml +++ b/domino-ui-webjar/pom.xml @@ -5,7 +5,7 @@ domino-ui-parent org.dominokit - 2.0.0-RC5 + 2.0.0 jar 4.0.0 diff --git a/domino-ui/pom.xml b/domino-ui/pom.xml index 496268166..efb92fdf7 100644 --- a/domino-ui/pom.xml +++ b/domino-ui/pom.xml @@ -6,7 +6,7 @@ org.dominokit domino-ui-parent - 2.0.0-RC5 + 2.0.0 domino-ui diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/store/LocalListDataStore.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/store/LocalListDataStore.java index 39129e4fd..94d8a1b75 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/store/LocalListDataStore.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/store/LocalListDataStore.java @@ -553,6 +553,19 @@ public void addRecord(T record) { setData(newData); } + /** + * Inserts a single record to the data store at the specified index, updating both the original + * and filtered lists. + * + * @param index The insertion index. + * @param record The record to be added. + */ + public void insertRecord(int index, T record) { + original.add(index, record); + List newData = new ArrayList<>(original); + setData(newData); + } + /** * Removes a single record from the data store, updating both the original and filtered lists. * @@ -566,6 +579,16 @@ public void removeRecord(T record) { } } + /** + * Removes a single record from the data store from the specified index, updating both the + * original and filtered lists. + * + * @param index The index of the record to be removed + */ + public void removeRecord(int index) { + removeRecord(original.get(index)); + } + /** * Updates a single record in the data store by replacing it with a new record, updating both the * original and filtered lists. diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/store/LocalListScrollingDataSource.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/store/LocalListScrollingDataSource.java index faad4b74a..11f636e21 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/store/LocalListScrollingDataSource.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/store/LocalListScrollingDataSource.java @@ -43,6 +43,7 @@ public class LocalListScrollingDataSource implements DataStore { private final List original; private List filtered = new ArrayList<>(); private final int pageSize; + private int initialLoadedPages = 1; private int pageIndex = 0; private List> listeners = new ArrayList<>(); private SearchFilter searchFilter; @@ -59,6 +60,18 @@ public LocalListScrollingDataSource(int pageSize) { this.pageSize = pageSize; } + /** + * Creates a new instance of {@link LocalListScrollingDataSource} with the specified page size. + * + * @param pageSize The number of records to load per page. + * @param initialLoadedPages The number of pages to load in the initial load - page index 0 -. + */ + public LocalListScrollingDataSource(int pageSize, int initialLoadedPages) { + this.original = new ArrayList<>(); + this.pageSize = pageSize; + this.initialLoadedPages = initialLoadedPages; + } + /** * Creates a new instance of {@link LocalListScrollingDataSource} with the specified page size and * initial data. @@ -72,6 +85,21 @@ public LocalListScrollingDataSource(List data, int pageSize) { this.filtered.addAll(data); } + /** + * Creates a new instance of {@link LocalListScrollingDataSource} with the specified page size and + * initial data. + * + * @param data The initial data to populate the data source. + * @param pageSize The number of records to load per page. + * @param initialLoadedPages The number of pages to load in the initial load - page index 0 -. + */ + public LocalListScrollingDataSource(List data, int pageSize, int initialLoadedPages) { + this.original = data; + this.pageSize = pageSize; + this.initialLoadedPages = initialLoadedPages; + this.filtered.addAll(data); + } + /** * Retrieves a copy of records stored in the data store. * @@ -162,7 +190,7 @@ public void load() { private void fireUpdate(boolean append) { int fromIndex = pageSize * pageIndex; - int toIndex = Math.min(fromIndex + pageSize, filtered.size()); + int toIndex = Math.min(getToIndex(fromIndex), filtered.size()); listeners.forEach( dataChangeListener -> @@ -173,6 +201,15 @@ private void fireUpdate(boolean append) { filtered.size()))); } + private int getToIndex(int fromIndex) { + if (pageIndex == 0 && initialLoadedPages > 1) { + int toIndex = fromIndex + (initialLoadedPages * pageSize); + pageIndex = initialLoadedPages - 1; + return toIndex; + } + return fromIndex + pageSize; + } + /** * Handles various table-related events and delegates to specific event handling methods based on * the event type. diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/AbstractDialog.java b/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/AbstractDialog.java index 462037490..b8c2c7b4c 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/AbstractDialog.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/AbstractDialog.java @@ -318,7 +318,7 @@ private void doOpen() { getConfig().getZindexManager().onPopupOpen(this); element.removeCss(dui_hidden); updateFocus(); - triggerExpandListeners((T) this); + triggerOpenListeners((T) this); this.open = true; } @@ -391,7 +391,7 @@ private void doClose() { } this.open = false; getConfig().getZindexManager().onPopupClose(this); - triggerCollapseListeners((T) this); + triggerCloseListeners((T) this); } /** diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/AlertMessageDialog.java b/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/AlertMessageDialog.java index 8d06e3c05..cfec5c493 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/AlertMessageDialog.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/AlertMessageDialog.java @@ -99,7 +99,7 @@ public AlertMessageDialog() { setStretchHeight(DialogSize.VERY_SMALL); setAutoClose(false); contentHeader.get().addCss(dui_justify_around); - addExpandListener( + addOpenListener( (component) -> { if (alertIcon.isInitialized()) { Animation.create(getAlertIcon()) diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/Window.java b/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/Window.java index 5d30e42b1..5a7d1db54 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/Window.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/Window.java @@ -129,8 +129,8 @@ public Window(String title) { } }; - addExpandListener(component -> addMoveListeners()); - addCollapseListener(component -> removeMoveListeners()); + addOpenListener(component -> addMoveListeners()); + addCloseListener(component -> removeMoveListeners()); updatePosition(); onResize((element1, observer, entries) -> updatePosition()); @@ -371,7 +371,7 @@ public Window setWindowTop(double windowTop) { } private void initPosition() { - addExpandListener(component -> updatePosition()); + addOpenListener(component -> updatePosition()); } /** diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSelect.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSelect.java index 9ed020c2a..ae89b97c4 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSelect.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSelect.java @@ -164,7 +164,7 @@ public AbstractSelect() { .ifPresent( meta -> onOptionDeselected(meta.getOption(), isChangeListenersPaused()))) - .addCollapseListener((menu) -> focus()); + .addOpenListener((menu) -> focus()); onAttached( mutationRecord -> { diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSuggestBox.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSuggestBox.java index b0900d110..a08f26129 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSuggestBox.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSuggestBox.java @@ -138,7 +138,7 @@ public AbstractSuggestBox(SuggestionsStore store) { .setAutoOpen(false) .setFitToTargetWidth(true) .setDropDirection(DropDirection.BEST_MIDDLE_UP_DOWN) - .addCollapseListener(component -> focus()) + .addCloseListener(component -> focus()) .addSelectionListener( (source, selection) -> { source diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/menu/AbstractMenuItem.java b/domino-ui/src/main/java/org/dominokit/domino/ui/menu/AbstractMenuItem.java index f0f2de8ca..9e1ce2aa8 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/menu/AbstractMenuItem.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/menu/AbstractMenuItem.java @@ -33,6 +33,7 @@ import org.dominokit.domino.ui.events.EventType; import org.dominokit.domino.ui.icons.lib.Icons; import org.dominokit.domino.ui.menu.direction.BestFitSideDropDirection; +import org.dominokit.domino.ui.style.ConditionalCssClass; import org.dominokit.domino.ui.utils.*; import org.gwtproject.editor.client.TakesValue; @@ -234,7 +235,8 @@ public AbstractMenuItem deselect() { */ public > T select(boolean silent) { if (!isDisabled() && isSelectable()) { - addCss(dui_menu_item_selected); + addCss( + ConditionalCssClass.of(dui_menu_item_selected, () -> parent.isPreserveSelectionStyles())); setAttribute("selected", true); if (!silent) { selectionHandlers.forEach(handler -> handler.onSelection(this)); diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/menu/Menu.java b/domino-ui/src/main/java/org/dominokit/domino/ui/menu/Menu.java index 3a5707950..25cff8e98 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/menu/Menu.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/menu/Menu.java @@ -119,6 +119,7 @@ public class Menu extends BaseDominoElement> private boolean selectionListenersPaused = false; private boolean multiSelect = false; private boolean autoOpen = true; + private boolean preserveSelectionStyles = true; private EventListener repositionListener = evt -> { if (isOpened()) { @@ -1358,7 +1359,7 @@ private void doOpen(boolean focus) { if (isSearchable()) { searchBox.get().clearSearch(); } - triggerExpandListeners(this); + triggerOpenListeners(this); onAttached( mutationRecord -> { position(); @@ -1571,7 +1572,7 @@ public Menu close() { searchBox.get().clearSearch(); } menuItems.forEach(AbstractMenuItem::onParentClosed); - triggerCollapseListeners(this); + triggerCloseListeners(this); if (smallScreen && nonNull(parent) && parent.isDropDown()) { parent.expand(); } @@ -1898,32 +1899,24 @@ public Menu setCloseOnBlur(boolean closeOnBlur) { return this; } - /** Represents a handler called when the menu is closed. */ - @FunctionalInterface - public interface CloseHandler { - - /** Method to be executed when the menu is closed. */ - void onClose(); - } - - /** Represents a handler called when the menu is opened. */ - @FunctionalInterface - public interface OpenHandler { - - /** Method to be executed when the menu is opened. */ - void onOpen(); + /** + * @return boolean true if the selection style should be preserved after the menu item loses the + * selection focus, otherwise false. + */ + public boolean isPreserveSelectionStyles() { + return preserveSelectionStyles; } - /** Handles changes in the selection status of a menu item. */ - public interface MenuItemSelectionHandler { - - /** - * Called when a menu item's selection status changes. - * - * @param menuItem The menu item whose selection status changed. - * @param selected {@code true} if the item is now selected, {@code false} otherwise. - */ - void onItemSelectionChange(AbstractMenuItem menuItem, boolean selected); + /** + * if true selecting an Item in the menu will preserve the selection style when the menu loses the + * focus. + * + * @param preserveSelectionStyles boolean, true to preserve the style, false to remove the style. + * @return same Menu instance. + */ + public Menu setPreserveSelectionStyles(boolean preserveSelectionStyles) { + this.preserveSelectionStyles = preserveSelectionStyles; + return this; } /** Represents a handler for a group of menu items. */ diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/popover/BasePopover.java b/domino-ui/src/main/java/org/dominokit/domino/ui/popover/BasePopover.java index 36e97a604..0b0326a87 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/popover/BasePopover.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/popover/BasePopover.java @@ -168,7 +168,7 @@ public T expand() { } doOpen(); getConfig().getZindexManager().onPopupOpen(this); - triggerExpandListeners((T) this); + triggerOpenListeners((T) this); } return (T) this; } @@ -237,7 +237,7 @@ protected void doClose() { element().remove(); body().removeEventListener(EventType.keydown.getName(), closeListener); getConfig().getZindexManager().onPopupClose(this); - triggerCollapseListeners((T) this); + triggerCloseListeners((T) this); } /** diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BaseDominoElement.java b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BaseDominoElement.java index 1c8c8d1c9..d3ead7fe6 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BaseDominoElement.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BaseDominoElement.java @@ -135,13 +135,13 @@ public abstract class BaseDominoElement> collapseListeners = new LinkedHashSet<>(); + protected Set> closeListeners = new LinkedHashSet<>(); /** Set of expand listeners for this DOM element. */ - protected Set> expandListeners = new LinkedHashSet<>(); + protected Set> openListeners = new LinkedHashSet<>(); private LambdaFunction dominoUuidInitializer; @@ -440,88 +440,88 @@ public T setCollapseStrategy(CollapseStrategy strategy) { * @return The modified DOM element. */ @Override - public T pauseCollapseListeners() { - this.collapseListenersPaused = true; + public T pauseCloseListeners() { + this.closeListenersPaused = true; return (T) this; } /** - * Resumes the collapse listeners for this element. + * Resumes the close listeners for this element. * * @return The modified DOM element. */ @Override - public T resumeCollapseListeners() { - this.collapseListenersPaused = false; + public T resumeCloseListeners() { + this.closeListenersPaused = false; return (T) this; } /** - * Toggles whether the collapse listeners for this element are paused. + * Toggles whether the close listeners for this element are paused. * * @param toggle {@code true} to pause, {@code false} to resume. * @return The modified DOM element. */ @Override - public T togglePauseCollapseListeners(boolean toggle) { - this.collapseListenersPaused = toggle; + public T togglePauseCloseListeners(boolean toggle) { + this.closeListenersPaused = toggle; return (T) this; } /** - * Retrieves the set of {@link CollapseListener}s registered for this element. + * Retrieves the set of {@link CloseListener}s registered for this element. * - * @return A set of {@link CollapseListener} instances. + * @return A set of {@link CloseListener} instances. */ @Override - public Set> getCollapseListeners() { - return collapseListeners; + public Set> getCloseListeners() { + return closeListeners; } /** - * Retrieves the set of {@link ExpandListener}s registered for this element. + * Retrieves the set of {@link OpenListener}s registered for this element. * - * @return A set of {@link ExpandListener} instances. + * @return A set of {@link OpenListener} instances. */ @Override - public Set> getExpandListeners() { - return expandListeners; + public Set> getOpenListeners() { + return openListeners; } /** - * Checks if the collapse listeners are currently paused. + * Checks if the close listeners are currently paused. * - * @return {@code true} if collapse listeners are paused, {@code false} otherwise. + * @return {@code true} if close listeners are paused, {@code false} otherwise. */ @Override - public boolean isCollapseListenersPaused() { - return this.collapseListenersPaused; + public boolean isCloseListenersPaused() { + return this.closeListenersPaused; } /** - * Triggers collapse listeners for this element. + * Triggers close listeners for this element. * * @param component The component that triggered the event. * @return The modified DOM element. */ @Override - public T triggerCollapseListeners(T component) { - if (!this.collapseListenersPaused) { - getCollapseListeners().forEach(collapseListener -> collapseListener.onCollapsed((T) this)); + public T triggerCloseListeners(T component) { + if (!this.closeListenersPaused) { + getCloseListeners().forEach(closeListener -> closeListener.onClosed((T) this)); } return (T) this; } /** - * Triggers expand listeners for this element. + * Triggers open listeners for this element. * * @param component The component that triggered the event. * @return The modified DOM element. */ @Override - public T triggerExpandListeners(T component) { - if (!this.collapseListenersPaused) { - getExpandListeners().forEach(expandListener -> expandListener.onExpanded((T) this)); + public T triggerOpenListeners(T component) { + if (!this.closeListenersPaused) { + getOpenListeners().forEach(openListener -> openListener.onOpened((T) this)); } return (T) this; } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasCollapseListeners.java b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasCollapseListeners.java index 2664684da..28b3c2a01 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasCollapseListeners.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasCollapseListeners.java @@ -23,18 +23,21 @@ * expand event listeners to an element. * * @param The type of the element that can have collapse and expand event listeners. + * @deprecated use {@link HasOpenCloseListeners} */ -public interface HasCollapseListeners { +@Deprecated +public interface HasCollapseListeners extends HasOpenCloseListeners { /** * Adds a collapse event listener to the element. * * @param collapseListener The collapse event listener to be added. * @return The element with the collapse event listener added. + * @deprecated use {@link #addCloseListener} */ + @Deprecated default T addCollapseListener(CollapseListener collapseListener) { - getCollapseListeners().add(collapseListener); - return (T) this; + return addCloseListener(collapseListener); } /** @@ -42,10 +45,11 @@ default T addCollapseListener(CollapseListener collapseListener) { * * @param expandListener The expand event listener to be added. * @return The element with the expand event listener added. + * @deprecated use {@link #addOpenListener} */ + @Deprecated default T addExpandListener(ExpandListener expandListener) { - getExpandListeners().add(expandListener); - return (T) this; + return addOpenListener(expandListener); } /** @@ -53,10 +57,11 @@ default T addExpandListener(ExpandListener expandListener) { * * @param collapseListener The collapse event listener to be removed. * @return The element with the collapse event listener removed. + * @deprecated use {@link #removeCloseListener} */ + @Deprecated default T removeCollapseListener(CollapseListener collapseListener) { - getCollapseListeners().remove(collapseListener); - return (T) this; + return removeCloseListener(collapseListener); } /** @@ -64,10 +69,11 @@ default T removeCollapseListener(CollapseListener collapseListener) { * * @param expandListener The expand event listener to be removed. * @return The element with the expand event listener removed. + * @deprecated use {@link #removeOpenListener} */ + @Deprecated default T removeExpandListener(ExpandListener expandListener) { - getExpandListeners().remove(expandListener); - return (T) this; + return removeOpenListener(expandListener); } /** @@ -76,9 +82,11 @@ default T removeExpandListener(ExpandListener expandListener) { * @param collapseListener The collapse event listener to be checked. * @return {@code true} if the element has the specified collapse event listener, {@code false} * otherwise. + * @deprecated use {@link #hasCloseListener} */ + @Deprecated default boolean hasCollapseListener(CollapseListener collapseListener) { - return getCollapseListeners().contains(collapseListener); + return hasCloseListener(collapseListener); } /** @@ -87,24 +95,34 @@ default boolean hasCollapseListener(CollapseListener collapseListener * @param expandListener The expand event listener to be checked. * @return {@code true} if the element has the specified expand event listener, {@code false} * otherwise. + * @deprecated use {@link #hasOpenListener} */ + @Deprecated default boolean hasExpandListener(ExpandListener expandListener) { - return getExpandListeners().contains(expandListener); + return hasOpenListener(expandListener); } /** * Pauses all collapse event listeners associated with the element. * * @return The element with its collapse event listeners paused. + * @deprecated use {@link #pauseCloseListeners} */ - T pauseCollapseListeners(); + @Deprecated + default T pauseCollapseListeners() { + return pauseCloseListeners(); + } /** * Resumes all pause collapse event listeners associated with the element. * * @return The element with its collapse event listeners resumed. + * @deprecated use {@link #resumeCloseListeners} */ - T resumeCollapseListeners(); + @Deprecated + default T resumeCollapseListeners() { + return resumeCloseListeners(); + } /** * Toggles the pause state of collapse event listeners associated with the element. @@ -112,8 +130,12 @@ default boolean hasExpandListener(ExpandListener expandListener) { * @param toggle {@code true} to pause the listeners, {@code false} to resume them. * @return The element with its collapse event listeners paused or resumed based on the toggle * parameter. + * @deprecated use {@link #togglePauseCloseListeners} */ - T togglePauseCollapseListeners(boolean toggle); + @Deprecated + default T togglePauseCollapseListeners(boolean toggle) { + return togglePauseCloseListeners(toggle); + } /** * Executes a given action while temporarily pausing the collapse event listeners, then resumes @@ -124,16 +146,11 @@ default boolean hasExpandListener(ExpandListener expandListener) { * @param handler The action to execute. * @return The element with its collapse event listeners paused during the action and resumed * afterward. + * @deprecated use {@link #withPauseCloseListenersToggle} */ + @Deprecated default T withPauseCollapseListenersToggle(boolean toggle, Handler handler) { - boolean oldState = isCollapseListenersPaused(); - togglePauseCollapseListeners(toggle); - try { - handler.apply((T) this); - } finally { - togglePauseCollapseListeners(oldState); - } - return (T) this; + return withPauseCloseListenersToggle(toggle, handler); } /** @@ -145,85 +162,107 @@ default T withPauseCollapseListenersToggle(boolean toggle, Handler handler) { * @param handler The asynchronous action to execute. * @return The element with its collapse event listeners paused during the action and resumed * afterward. + * @deprecated use {@link #withPauseCloseListenersToggle} */ + @Deprecated default T withPauseCollapseListenersToggle(boolean toggle, AsyncHandler handler) { - boolean oldState = isCollapseListenersPaused(); - togglePauseCollapseListeners(toggle); - try { - handler.apply((T) this, () -> togglePauseCollapseListeners(oldState)); - } catch (Exception e) { - togglePauseCollapseListeners(oldState); - throw e; - } - return (T) this; + return withPauseCloseListenersToggle(toggle, handler); } /** * Gets a set of all collapse event listeners associated with the element. * * @return A set of collapse event listeners. + * @deprecated use {@link #getCloseListeners} */ - Set> getCollapseListeners(); + @Deprecated + default Set> getCollapseListeners() { + return getCloseListeners(); + } /** * Gets a set of all expand event listeners associated with the element. * * @return A set of expand event listeners. + * @deprecated use {@link #getOpenListeners} */ - Set> getExpandListeners(); + @Deprecated + default Set> getExpandListeners() { + return getOpenListeners(); + } /** * Checks if the collapse event listeners are currently paused. * * @return {@code true} if the collapse event listeners are paused, {@code false} otherwise. + * @deprecated use {@link #isCloseListenersPaused} */ - boolean isCollapseListenersPaused(); + @Deprecated + default boolean isCollapseListenersPaused() { + return isCloseListenersPaused(); + } /** * Triggers all collapse event listeners associated with the element. * * @param component The component that triggered the listeners. * @return The element with its collapse event listeners triggered. + * @deprecated use {@link #triggerCloseListeners} */ - T triggerCollapseListeners(T component); + @Deprecated + default T triggerCollapseListeners(T component) { + return triggerCloseListeners(component); + } /** * Triggers all expand event listeners associated with the element. * * @param component The component that triggered the listeners. * @return The element with its expand event listeners triggered. + * @deprecated use {@link #triggerOpenListeners} */ - T triggerExpandListeners(T component); + @Deprecated + default T triggerExpandListeners(T component) { + return triggerOpenListeners(component); + } /** * Functional interface for handling collapse events. * * @param The type of the component that triggered the event. + * @deprecated use {@link CloseListener} */ + @Deprecated @FunctionalInterface - interface CollapseListener { + interface CollapseListener extends HasOpenCloseListeners.CloseListener { /** * Called when a collapse event occurs on the associated element. * * @param component The component that triggered the event. */ - void onCollapsed(T component); + default void onCollapsed(T component) { + onClosed(component); + }; } /** * Functional interface for handling expand events. * * @param The type of the component that triggered the event. + * @deprecated use {@link OpenListener} */ + @Deprecated @FunctionalInterface - interface ExpandListener { + interface ExpandListener extends HasOpenCloseListeners.OpenListener { /** * Called when an expand event occurs on the associated element. * * @param component The component that triggered the event. */ - void onExpanded(T component); + default void onExpanded(T component) { + onOpened(component); + } } } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasOpenCloseListeners.java b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasOpenCloseListeners.java new file mode 100644 index 000000000..cfecb3248 --- /dev/null +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasOpenCloseListeners.java @@ -0,0 +1,229 @@ +/* + * Copyright © 2019 Dominokit + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dominokit.domino.ui.utils; + +import java.util.Set; + +/** + * The {@code HasOpenCloseListeners} interface defines methods for adding and managing close and + * open event listeners to an element. + * + * @param The type of the element that can have close and open event listeners. + */ +public interface HasOpenCloseListeners { + + /** + * Adds a close event listener to the element. + * + * @param closeListener The close event listener to be added. + * @return The element with the close event listener added. + */ + default T addCloseListener(CloseListener closeListener) { + getCloseListeners().add(closeListener); + return (T) this; + } + + /** + * Adds an open event listener to the element. + * + * @param openListener The open event listener to be added. + * @return The element with the open event listener added. + */ + default T addOpenListener(OpenListener openListener) { + getOpenListeners().add(openListener); + return (T) this; + } + + /** + * Removes a close event listener from the element. + * + * @param closeListener The close event listener to be removed. + * @return The element with the close event listener removed. + */ + default T removeCloseListener(CloseListener closeListener) { + getCloseListeners().remove(closeListener); + return (T) this; + } + + /** + * Removes an open event listener from the element. + * + * @param openListener The open event listener to be removed. + * @return The element with the open event listener removed. + */ + default T removeOpenListener(OpenListener openListener) { + getOpenListeners().remove(openListener); + return (T) this; + } + + /** + * Checks if the element has a close event listener. + * + * @param closeListener The close event listener to be checked. + * @return {@code true} if the element has the specified close event listener, {@code false} + * otherwise. + */ + default boolean hasCloseListener(CloseListener closeListener) { + return getCloseListeners().contains(closeListener); + } + + /** + * Checks if the element has an open event listener. + * + * @param openListener The open event listener to be checked. + * @return {@code true} if the element has the specified open event listener, {@code false} + * otherwise. + */ + default boolean hasOpenListener(OpenListener openListener) { + return getOpenListeners().contains(openListener); + } + + /** + * Pauses all close event listeners associated with the element. + * + * @return The element with its close event listeners paused. + */ + T pauseCloseListeners(); + + /** + * Resumes all pause close event listeners associated with the element. + * + * @return The element with its close event listeners resumed. + */ + T resumeCloseListeners(); + + /** + * Toggles the pause state of close event listeners associated with the element. + * + * @param toggle {@code true} to pause the listeners, {@code false} to resume them. + * @return The element with its close event listeners paused or resumed based on the toggle + * parameter. + */ + T togglePauseCloseListeners(boolean toggle); + + /** + * Executes a given action while temporarily pausing the close event listeners, then resumes their + * state. + * + * @param toggle {@code true} to pause the listeners during the action, {@code false} to resume + * them afterward. + * @param handler The action to execute. + * @return The element with its close event listeners paused during the action and resumed + * afterward. + */ + default T withPauseCloseListenersToggle(boolean toggle, Handler handler) { + boolean oldState = isCloseListenersPaused(); + togglePauseCloseListeners(toggle); + try { + handler.apply((T) this); + } finally { + togglePauseCloseListeners(oldState); + } + return (T) this; + } + + /** + * Executes a given asynchronous action while temporarily pausing the close event listeners, then + * resumes their state. + * + * @param toggle {@code true} to pause the listeners during the action, {@code false} to resume + * them afterward. + * @param handler The asynchronous action to execute. + * @return The element with its close event listeners paused during the action and resumed + * afterward. + */ + default T withPauseCloseListenersToggle(boolean toggle, AsyncHandler handler) { + boolean oldState = isCloseListenersPaused(); + togglePauseCloseListeners(toggle); + try { + handler.apply((T) this, () -> togglePauseCloseListeners(oldState)); + } catch (Exception e) { + togglePauseCloseListeners(oldState); + throw e; + } + return (T) this; + } + + /** + * Gets a set of all close event listeners associated with the element. + * + * @return A set of close event listeners. + */ + Set> getCloseListeners(); + + /** + * Gets a set of all open event listeners associated with the element. + * + * @return A set of open event listeners. + */ + Set> getOpenListeners(); + + /** + * Checks if the close event listeners are currently paused. + * + * @return {@code true} if the close event listeners are paused, {@code false} otherwise. + */ + boolean isCloseListenersPaused(); + + /** + * Triggers all close event listeners associated with the element. + * + * @param component The component that triggered the listeners. + * @return The element with its close event listeners triggered. + */ + T triggerCloseListeners(T component); + + /** + * Triggers all open event listeners associated with the element. + * + * @param component The component that triggered the listeners. + * @return The element with its open event listeners triggered. + */ + T triggerOpenListeners(T component); + + /** + * Functional interface for handling close events. + * + * @param The type of the component that triggered the event. + */ + @FunctionalInterface + interface CloseListener { + + /** + * Called when a close event occurs on the associated element. + * + * @param component The component that triggered the event. + */ + void onClosed(T component); + } + + /** + * Functional interface for handling open events. + * + * @param The type of the component that triggered the event. + */ + @FunctionalInterface + interface OpenListener { + + /** + * Called when an open event occurs on the associated element. + * + * @param component The component that triggered the event. + */ + void onOpened(T component); + } +} diff --git a/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-dark.css b/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-dark.css index 500e88af6..8010d8fdc 100644 --- a/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-dark.css +++ b/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-dark.css @@ -419,7 +419,7 @@ --dui-datatable-border-color: var(--dui-accent-d-4); --dui-datatable-column-resizer-color: var(--dui-accent-d-2); --dui-datatable-pin-column-border-color: var(--dui-accent-d-2); - --dui-nav-bar-description-color: var(--dui-clr-white); + --dui-nav-bar-description-color: inherit; --dui-datatable-tfoot-bg-color: var(--dui-accent-d-4); } diff --git a/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-light.css b/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-light.css index d981f1a78..2ef8c3bc5 100644 --- a/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-light.css +++ b/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-light.css @@ -407,6 +407,6 @@ --dui-datatable-border-color: var(--dui-accent-l-4); --dui-datatable-column-resizer-color: var(--dui-accent-l-4); --dui-datatable-pin-column-border-color: var(--dui-accent-l-2); - --dui-nav-bar-description-color: var(--dui-clr-white); + --dui-nav-bar-description-color: inherit; --dui-datatable-tfoot-bg-color: var(--dui-accent-l-5); } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 23b667079..0e10ebc6f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.dominokit domino-ui-parent - 2.0.0-RC5 + 2.0.0 pom domino-ui-parent @@ -68,19 +68,19 @@ HEAD-SNAPSHOT - 2.0.0-RC5 + 2.0.0 11 11 - 3.11.0 - 3.0.1 + 3.12.1 + 3.3.0 3.6.2 2.9 3.0 - 3.0.0-M1 + 3.1.1 1.1.0 - 1.6.8 - 1.6 + 1.6.13 + 3.1.0 UTF-8 UTF-8 1.2.1 @@ -158,7 +158,7 @@ com.google.guava guava - 32.0.1-jre + 33.0.0-jre org.dominokit @@ -168,13 +168,13 @@ com.google.auto.service auto-service - 1.0-rc6 + 1.1.1 provided com.squareup javapoet - 1.9.0 + 1.13.0 org.dominokit @@ -190,7 +190,7 @@ junit junit - 4.13.1 + 4.13.2 test