Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Jan 30, 2024
2 parents ba8b160 + dc43a26 commit 919ba14
Show file tree
Hide file tree
Showing 22 changed files with 627 additions and 127 deletions.
2 changes: 1 addition & 1 deletion domino-ui-shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>domino-ui-parent</artifactId>
<groupId>org.dominokit</groupId>
<version>2.0.0-RC5</version>
<version>2.0.0</version>
</parent>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Boolean> 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<Boolean> 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<Boolean> 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<Boolean> 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<Boolean> 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<Boolean> 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<Boolean> 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();
}
}
2 changes: 1 addition & 1 deletion domino-ui-tools/mdi-icons-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>domino-ui-tools</artifactId>
<groupId>org.dominokit</groupId>
<version>2.0.0-RC5</version>
<version>2.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion domino-ui-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>domino-ui-parent</artifactId>
<groupId>org.dominokit</groupId>
<version>2.0.0-RC5</version>
<version>2.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion domino-ui-webjar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>domino-ui-parent</artifactId>
<groupId>org.dominokit</groupId>
<version>2.0.0-RC5</version>
<version>2.0.0</version>
</parent>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion domino-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.dominokit</groupId>
<artifactId>domino-ui-parent</artifactId>
<version>2.0.0-RC5</version>
<version>2.0.0</version>
</parent>

<artifactId>domino-ui</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> newData = new ArrayList<>(original);
setData(newData);
}

/**
* Removes a single record from the data store, updating both the original and filtered lists.
*
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class LocalListScrollingDataSource<T> implements DataStore<T> {
private final List<T> original;
private List<T> filtered = new ArrayList<>();
private final int pageSize;
private int initialLoadedPages = 1;
private int pageIndex = 0;
private List<StoreDataChangeListener<T>> listeners = new ArrayList<>();
private SearchFilter<T> searchFilter;
Expand All @@ -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.
Expand All @@ -72,6 +85,21 @@ public LocalListScrollingDataSource(List<T> 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<T> 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.
*
Expand Down Expand Up @@ -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 ->
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -391,7 +391,7 @@ private void doClose() {
}
this.open = false;
getConfig().getZindexManager().onPopupClose(this);
triggerCollapseListeners((T) this);
triggerCloseListeners((T) this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -371,7 +371,7 @@ public Window setWindowTop(double windowTop) {
}

private void initPosition() {
addExpandListener(component -> updatePosition());
addOpenListener(component -> updatePosition());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public AbstractSelect() {
.ifPresent(
meta ->
onOptionDeselected(meta.getOption(), isChangeListenersPaused())))
.addCollapseListener((menu) -> focus());
.addOpenListener((menu) -> focus());

onAttached(
mutationRecord -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public AbstractSuggestBox(SuggestionsStore<T, E, O> store) {
.setAutoOpen(false)
.setFitToTargetWidth(true)
.setDropDirection(DropDirection.BEST_MIDDLE_UP_DOWN)
.addCollapseListener(component -> focus())
.addCloseListener(component -> focus())
.addSelectionListener(
(source, selection) -> {
source
Expand Down
Loading

0 comments on commit 919ba14

Please sign in to comment.