Skip to content

Commit 114f771

Browse files
committed
feat: add public getters for left/right grids
Deprecate the protected final leftGrid/rightGrid fields. Deprecate all the methods that just delegate into an equivalent call on the left/right grid. Close #31 Close #68
1 parent 568d991 commit 114f771

File tree

1 file changed

+57
-27
lines changed

1 file changed

+57
-27
lines changed

src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ Collection<T> getItems() {
8585

8686
private final TwinColModel<T> right;
8787

88-
protected final Grid<T> leftGrid;
88+
/** @deprecated Use getLeftGrid() */
89+
@Deprecated protected final Grid<T> leftGrid;
8990

90-
protected final Grid<T> rightGrid;
91+
/** @deprecated Use getRightGrid() */
92+
@Deprecated protected final Grid<T> rightGrid;
9193

92-
/** @deprecated Use leftGrid.getDataProvider() */
94+
/** @deprecated Use getLeftGrid().getDataProvider() */
9395
@Deprecated protected ListDataProvider<T> leftGridDataProvider;
9496

95-
/** @deprecated Use rightGrid.getDataProvider() */
97+
/** @deprecated Use getRightGrid().getDataProvider() */
9698
@Deprecated protected ListDataProvider<T> rightGridDataProvider;
9799

98100
private final Button addAllButton = new Button();
@@ -135,7 +137,7 @@ public TwinColGrid(final ListDataProvider<T> dataProvider, String caption) {
135137
setDataProvider(dataProvider);
136138

137139
rightGridDataProvider = DataProvider.ofCollection(new LinkedHashSet<>());
138-
rightGrid.setDataProvider(rightGridDataProvider);
140+
getRightGrid().setDataProvider(rightGridDataProvider);
139141

140142
addButton.setIcon(VaadinIcon.ANGLE_RIGHT.create());
141143
addButton.setWidth("3em");
@@ -155,25 +157,27 @@ public TwinColGrid(final ListDataProvider<T> dataProvider, String caption) {
155157
buttonContainer.setSpacing(false);
156158
buttonContainer.setSizeUndefined();
157159

158-
leftGrid.setWidth("100%");
159-
rightGrid.setWidth("100%");
160+
getLeftGrid().setWidth("100%");
161+
getRightGrid().setWidth("100%");
160162

161163
addAllButton.addClickListener(
162164
e -> {
163-
left.getItems().stream().forEach(leftGrid.getSelectionModel()::select);
164-
updateSelection(new LinkedHashSet<>(leftGrid.getSelectedItems()), new HashSet<>());
165+
left.getItems().stream().forEach(getLeftGrid().getSelectionModel()::select);
166+
updateSelection(new LinkedHashSet<>(getLeftGrid().getSelectedItems()), new HashSet<>());
165167
});
166168

167169
addButton.addClickListener(
168-
e -> updateSelection(new LinkedHashSet<>(leftGrid.getSelectedItems()), new HashSet<>()));
170+
e ->
171+
updateSelection(
172+
new LinkedHashSet<>(getLeftGrid().getSelectedItems()), new HashSet<>()));
169173

170174
removeButton.addClickListener(
171-
e -> updateSelection(new HashSet<>(), rightGrid.getSelectedItems()));
175+
e -> updateSelection(new HashSet<>(), getRightGrid().getSelectedItems()));
172176

173177
removeAllButton.addClickListener(
174178
e -> {
175-
right.getItems().stream().forEach(rightGrid.getSelectionModel()::select);
176-
updateSelection(new HashSet<>(), rightGrid.getSelectedItems());
179+
right.getItems().stream().forEach(getRightGrid().getSelectionModel()::select);
180+
updateSelection(new HashSet<>(), getRightGrid().getSelectedItems());
177181
});
178182

179183
getElement().getStyle().set("display", "flex");
@@ -197,6 +201,16 @@ public TwinColGrid(final ListDataProvider<T> dataProvider, String caption) {
197201
setSizeUndefined();
198202
}
199203

204+
/** Return the left grid component */
205+
public Grid<T> getLeftGrid() {
206+
return leftGrid;
207+
}
208+
209+
/** Return the right grid component */
210+
public Grid<T> getRightGrid() {
211+
return rightGrid;
212+
}
213+
200214
private void forEachSide(Consumer<TwinColModel<T>> consumer) {
201215
consumer.accept(left);
202216
consumer.accept(right);
@@ -210,33 +224,45 @@ public void setItems(Stream<T> items) {
210224
setDataProvider(DataProvider.fromStream(items));
211225
}
212226

227+
/** @deprecated Use {@code getLeftGrid.getDataProvider()} */
228+
@Deprecated
213229
public void setLeftGridClassName(String classname) {
214-
leftGrid.setClassName(classname);
230+
getLeftGrid().setClassName(classname);
215231
}
216232

233+
/** @deprecated Use {@code getLeftGrid().addClassName(classname)} */
234+
@Deprecated
217235
public void addLeftGridClassName(String classname) {
218-
leftGrid.addClassName(classname);
236+
getLeftGrid().addClassName(classname);
219237
}
220238

239+
/** @deprecated Use {@code getLeftGrid().removeClassName(classname)} */
240+
@Deprecated
221241
public void removeLeftGridClassName(String classname) {
222-
leftGrid.removeClassName(classname);
242+
getLeftGrid().removeClassName(classname);
223243
}
224244

245+
/** @deprecated Use {@code getRightGrid().setClassName(classname)} */
246+
@Deprecated
225247
public void setRightGridClassName(String classname) {
226-
rightGrid.setClassName(classname);
248+
getRightGrid().setClassName(classname);
227249
}
228250

251+
/** @deprecated Use {@code getRightGrid().addClassName(classname)} */
252+
@Deprecated
229253
public void addRightGridClassName(String classname) {
230-
rightGrid.addClassName(classname);
254+
getRightGrid().addClassName(classname);
231255
}
232256

257+
/** @deprecated Use {@code getRightGrid().removeClassName(classname)} */
258+
@Deprecated
233259
public void removeRightGridClassName(String classname) {
234-
rightGrid.removeClassName(classname);
260+
getRightGrid().removeClassName(classname);
235261
}
236262

237263
private void setDataProvider(ListDataProvider<T> dataProvider) {
238264
leftGridDataProvider = dataProvider;
239-
leftGrid.setDataProvider(dataProvider);
265+
getLeftGrid().setDataProvider(dataProvider);
240266
if (right.getDataProvider() != null) {
241267
right.getItems().clear();
242268
right.getDataProvider().refreshAll();
@@ -299,8 +325,8 @@ public TwinColGrid<T> withLeftColumnCaption(final String leftColumnCaption) {
299325
*/
300326
public TwinColGrid<T> addColumn(
301327
final ItemLabelGenerator<T> itemLabelGenerator, final String header) {
302-
leftGrid.addColumn(new TextRenderer<>(itemLabelGenerator)).setHeader(header);
303-
rightGrid.addColumn(new TextRenderer<>(itemLabelGenerator)).setHeader(header);
328+
getLeftGrid().addColumn(new TextRenderer<>(itemLabelGenerator)).setHeader(header);
329+
getRightGrid().addColumn(new TextRenderer<>(itemLabelGenerator)).setHeader(header);
304330
return this;
305331
}
306332

@@ -434,7 +460,7 @@ public void setValue(final Set<T> value) {
434460
value.stream()
435461
.map(Objects::requireNonNull)
436462
.collect(Collectors.toCollection(LinkedHashSet::new));
437-
updateSelection(newValues, new LinkedHashSet<>(leftGrid.getSelectedItems()));
463+
updateSelection(newValues, new LinkedHashSet<>(getLeftGrid().getSelectedItems()));
438464
}
439465

440466
/**
@@ -473,8 +499,8 @@ public boolean isRequiredIndicatorVisible() {
473499

474500
@Override
475501
public void setReadOnly(final boolean readOnly) {
476-
leftGrid.setSelectionMode(readOnly ? SelectionMode.NONE : SelectionMode.MULTI);
477-
rightGrid.setSelectionMode(readOnly ? SelectionMode.NONE : SelectionMode.MULTI);
502+
getLeftGrid().setSelectionMode(readOnly ? SelectionMode.NONE : SelectionMode.MULTI);
503+
getRightGrid().setSelectionMode(readOnly ? SelectionMode.NONE : SelectionMode.MULTI);
478504
addButton.setEnabled(!readOnly);
479505
removeButton.setEnabled(!readOnly);
480506
addAllButton.setEnabled(!readOnly);
@@ -551,12 +577,16 @@ private void configDragAndDrop(
551577
});
552578
}
553579

580+
/** @deprecated Use {@code getLeftGrid().addSelectionListener(listener);} */
581+
@Deprecated
554582
public void addLeftGridSelectionListener(SelectionListener<Grid<T>, T> listener) {
555-
leftGrid.addSelectionListener(listener);
583+
getLeftGrid().addSelectionListener(listener);
556584
}
557585

586+
/** @deprecated Use {@code getRightGrid().addSelectionListener(listener);} */
587+
@Deprecated
558588
public void addRightGridSelectionListener(SelectionListener<Grid<T>, T> listener) {
559-
rightGrid.addSelectionListener(listener);
589+
getRightGrid().addSelectionListener(listener);
560590
}
561591

562592
public TwinColGrid<T> addFilterableColumn(

0 commit comments

Comments
 (0)