Skip to content

Commit 6f5e47d

Browse files
committed
fix #844 TreeGridPlugin fire event when row is expanded but no event is fired on before row expand
1 parent 43fed20 commit 6f5e47d

File tree

3 files changed

+129
-5
lines changed

3 files changed

+129
-5
lines changed

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/tree/TreeGridPlugin.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.dominokit.domino.ui.datatable.plugins.HasPluginConfig;
2929
import org.dominokit.domino.ui.datatable.plugins.tree.events.TreeRowCollapsedEvent;
3030
import org.dominokit.domino.ui.datatable.plugins.tree.events.TreeRowExpandedEvent;
31+
import org.dominokit.domino.ui.datatable.plugins.tree.events.TreeRowOnBeforeCollapseEvent;
32+
import org.dominokit.domino.ui.datatable.plugins.tree.events.TreeRowOnBeforeExpandEvent;
3133
import org.dominokit.domino.ui.elements.DivElement;
3234
import org.dominokit.domino.ui.icons.Icon;
3335
import org.dominokit.domino.ui.icons.ToggleIcon;
@@ -80,7 +82,8 @@ public boolean requiresUtilityColumn() {
8082
* @param row {@link org.dominokit.domino.ui.datatable.TableRow} to be expanded
8183
* @param recursive boolean, if true will recursively expand the row children
8284
*/
83-
public final void expandRow(TableRow<T> row, boolean recursive) {
85+
public void expandRow(TableRow<T> row, boolean recursive) {
86+
this.dataTable.fireTableEvent(new TreeRowOnBeforeExpandEvent<>(row));
8487
if (config.isLazy()) {
8588
TreeGridRowSubItemsMeta.get(row)
8689
.ifPresent(
@@ -119,6 +122,7 @@ public final void expandRow(TableRow<T> row, boolean recursive) {
119122
if (row.isRoot()) {
120123
increment();
121124
}
125+
this.dataTable.fireTableEvent(new TreeRowExpandedEvent<>(row));
122126
}
123127
}
124128

@@ -221,7 +225,7 @@ private void applyIndent(TableRow<T> tableRow) {
221225
*
222226
* @param row {@link org.dominokit.domino.ui.datatable.TableRow} to be expanded
223227
*/
224-
public final void expandRow(TableRow<T> row) {
228+
public void expandRow(TableRow<T> row) {
225229
expandRow(row, true);
226230
}
227231

@@ -231,7 +235,7 @@ public final void expandRow(TableRow<T> row) {
231235
*
232236
* @param recursive boolean, if true will recursively expand the row children
233237
*/
234-
public final void expandAllRows(boolean recursive) {
238+
public void expandAllRows(boolean recursive) {
235239
dataTable.getRows().forEach(tableRow -> expandRow(tableRow, recursive));
236240
}
237241

@@ -240,12 +244,12 @@ public final void expandAllRows(boolean recursive) {
240244
*
241245
* @param row {@link org.dominokit.domino.ui.datatable.TableRow} to be collapsed
242246
*/
243-
public final void collapseRow(TableRow<T> row) {
247+
public void collapseRow(TableRow<T> row) {
244248
collapse(row);
245249
}
246250

247251
/** Collapse all table row */
248-
public final void collapseAllRows() {
252+
public void collapseAllRows() {
249253
dataTable.getRows().forEach(this::collapseRow);
250254
}
251255

@@ -273,6 +277,7 @@ private void showRow(TableRow<T> row) {
273277
}
274278

275279
private void collapse(TableRow<T> row) {
280+
this.dataTable.fireTableEvent(new TreeRowOnBeforeCollapseEvent<>(row));
276281
Optional<TreeGridRowToggleIcon> iconMeta = row.getMeta(TREE_GRID_ROW_TOGGLE_ICON);
277282
iconMeta.ifPresent(
278283
meta -> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.datatable.plugins.tree.events;
17+
18+
import org.dominokit.domino.ui.datatable.TableRow;
19+
import org.dominokit.domino.ui.datatable.events.TableEvent;
20+
21+
/**
22+
* This event will be fired by the {@link
23+
* org.dominokit.domino.ui.datatable.plugins.row.RecordDetailsPlugin} when a record is expanded
24+
*
25+
* @param <T> the type of the record.
26+
*/
27+
public class TreeRowOnBeforeCollapseEvent<T> implements TableEvent {
28+
29+
/** A constant string to define a unique type for this event */
30+
public static final String TREE_ROW_ON_BEFORE_COLLAPSE_EVENT =
31+
"tree-row-on-before-collapse-event";
32+
33+
private final TableRow<T> tableRow;
34+
35+
/** @param tableRow the {@link TableRow} being expanded */
36+
/**
37+
* Constructor for TreeRowCollapsedEvent.
38+
*
39+
* @param tableRow a {@link TableRow} object
40+
*/
41+
public TreeRowOnBeforeCollapseEvent(TableRow<T> tableRow) {
42+
this.tableRow = tableRow;
43+
}
44+
45+
/** {@inheritDoc} */
46+
@Override
47+
public String getType() {
48+
return TREE_ROW_ON_BEFORE_COLLAPSE_EVENT;
49+
}
50+
51+
/** @return the {@link TableRow} being expanded */
52+
/**
53+
* Getter for the field <code>tableRow</code>.
54+
*
55+
* @return a {@link TableRow} object
56+
*/
57+
public TableRow<T> getTableRow() {
58+
return tableRow;
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.datatable.plugins.tree.events;
17+
18+
import org.dominokit.domino.ui.datatable.TableRow;
19+
import org.dominokit.domino.ui.datatable.events.TableEvent;
20+
21+
/**
22+
* This event will be fired by the {@link
23+
* org.dominokit.domino.ui.datatable.plugins.row.RecordDetailsPlugin} when a record is expanded
24+
*
25+
* @param <T> the type of the record.
26+
*/
27+
public class TreeRowOnBeforeExpandEvent<T> implements TableEvent {
28+
29+
/** A constant string to define a unique type for this event */
30+
public static final String TREE_ROW_ON_BEFORE_EXPAND_EVENT = "tree-row-on-before-expand-event";
31+
32+
private final TableRow<T> tableRow;
33+
34+
/** @param tableRow the {@link TableRow} being expanded */
35+
/**
36+
* Constructor for TreeRowExpandedEvent.
37+
*
38+
* @param tableRow a {@link TableRow} object
39+
*/
40+
public TreeRowOnBeforeExpandEvent(TableRow<T> tableRow) {
41+
this.tableRow = tableRow;
42+
}
43+
44+
/** {@inheritDoc} */
45+
@Override
46+
public String getType() {
47+
return TREE_ROW_ON_BEFORE_EXPAND_EVENT;
48+
}
49+
50+
/** @return the {@link TableRow} being expanded */
51+
/**
52+
* Getter for the field <code>tableRow</code>.
53+
*
54+
* @return a {@link TableRow} object
55+
*/
56+
public TableRow<T> getTableRow() {
57+
return tableRow;
58+
}
59+
}

0 commit comments

Comments
 (0)