41
41
import com .vaadin .flow .component .grid .Grid ;
42
42
import com .vaadin .flow .component .grid .GridArrayUpdater ;
43
43
import com .vaadin .flow .component .grid .GridArrayUpdater .UpdateQueueData ;
44
+ import com .vaadin .flow .component .grid .dataview .GridDataView ;
45
+ import com .vaadin .flow .component .grid .dataview .GridLazyDataView ;
46
+ import com .vaadin .flow .component .grid .dataview .GridListDataView ;
44
47
import com .vaadin .flow .component .treegrid .CollapseEvent ;
45
48
import com .vaadin .flow .component .treegrid .ExpandEvent ;
46
49
import com .vaadin .flow .component .treegrid .HierarchyColumnComponentRenderer ;
47
50
import com .vaadin .flow .component .treegrid .TreeGrid ;
48
51
import com .vaadin .flow .component .treegrid .TreeGridArrayUpdater ;
49
52
import com .vaadin .flow .data .binder .PropertyDefinition ;
53
+ import com .vaadin .flow .data .provider .BackEndDataProvider ;
54
+ import com .vaadin .flow .data .provider .CallbackDataProvider ;
50
55
import com .vaadin .flow .data .provider .CompositeDataGenerator ;
51
56
import com .vaadin .flow .data .provider .DataChangeEvent ;
52
57
import com .vaadin .flow .data .provider .DataCommunicator ;
53
58
import com .vaadin .flow .data .provider .DataProvider ;
59
+ import com .vaadin .flow .data .provider .ListDataProvider ;
54
60
import com .vaadin .flow .data .provider .hierarchy .HasHierarchicalDataProvider ;
55
61
import com .vaadin .flow .data .provider .hierarchy .HierarchicalArrayUpdater .HierarchicalUpdate ;
56
62
import com .vaadin .flow .data .provider .hierarchy .HierarchicalConfigurableFilterDataProvider ;
57
63
import com .vaadin .flow .data .provider .hierarchy .HierarchicalDataCommunicator ;
58
64
import com .vaadin .flow .data .provider .hierarchy .HierarchicalDataProvider ;
59
65
import com .vaadin .flow .data .provider .hierarchy .HierarchicalQuery ;
66
+ import com .vaadin .flow .data .provider .hierarchy .TreeData ;
60
67
import com .vaadin .flow .data .provider .hierarchy .TreeDataProvider ;
61
68
import com .vaadin .flow .data .renderer .ComponentRenderer ;
62
69
import com .vaadin .flow .data .renderer .Renderer ;
@@ -286,24 +293,190 @@ public Registration addCollapseListener(
286
293
}
287
294
288
295
@ Override
289
- public void setDataProvider (DataProvider <T , ?> dataProvider ) {
290
- if (!(dataProvider instanceof HierarchicalDataProvider )) {
291
- throw new IllegalArgumentException (
292
- "TreeGrid only accepts hierarchical data providers. "
293
- + "An example of interface to be used: HierarchicalDataProvider" );
294
- }
295
- if (dataProviderRegistration != null ) {
296
- dataProviderRegistration .remove ();
297
- }
298
- dataProviderRegistration = dataProvider .addDataProviderListener (e -> {
299
- if (!(e instanceof DataChangeEvent .DataRefreshEvent )) {
300
- // refreshAll was called
301
- getElement ().callJsFunction ("$connector.reset" );
302
- }
303
- });
304
- super .setDataProvider (dataProvider );
305
- }
306
-
296
+ public void setDataProvider (DataProvider <T , ?> dataProvider ) {
297
+ if (dataProvider instanceof HierarchicalDataProvider ) {
298
+ this .setDataProvider ((HierarchicalDataProvider ) dataProvider );
299
+ } else {
300
+ throw new IllegalArgumentException (
301
+ "TreeGrid only accepts hierarchical data providers. "
302
+ + "An example of interface to be used: HierarchicalDataProvider" );
303
+ }
304
+ }
305
+
306
+ @ Override
307
+ public void setDataProvider (
308
+ HierarchicalDataProvider <T , ?> hierarchicalDataProvider ) {
309
+ if (dataProviderRegistration != null ) {
310
+ dataProviderRegistration .remove ();
311
+ }
312
+ dataProviderRegistration = hierarchicalDataProvider
313
+ .addDataProviderListener (e -> {
314
+ if (!(e instanceof DataChangeEvent .DataRefreshEvent )) {
315
+ // refreshAll was called
316
+ getElement ().executeJs (
317
+ "$0.$connector && $0.$connector.reset()" ,
318
+ getElement ());
319
+ }
320
+ });
321
+ super .setDataProvider (hierarchicalDataProvider );
322
+ }
323
+
324
+ /**
325
+ * Tree grid does not support data views. Use
326
+ * {@link #setDataProvider(HierarchicalDataProvider)} instead. This method
327
+ * is inherited from Grid and it will throw an
328
+ * {@link UnsupportedOperationException}.
329
+ *
330
+ * @param dataProvider
331
+ * the data provider
332
+ * @return the data view
333
+ * @deprecated use {@link #setDataProvider(HierarchicalDataProvider)},
334
+ * {@link #setItems(Collection, ValueProvider)},
335
+ * {@link #setItems(Stream, ValueProvider)} or
336
+ * {@link #setTreeData(TreeData)} instead.
337
+ */
338
+ @ Deprecated
339
+ @ Override
340
+ public GridLazyDataView <T > setItems (
341
+ BackEndDataProvider <T , Void > dataProvider ) {
342
+ throw new UnsupportedOperationException (
343
+ "TreeGrid only accepts hierarchical data providers. "
344
+ + "Use another setDataProvider/setItems method instead with hierarchical data."
345
+ + "An example of interface to be used: HierarchicalDataProvider" );
346
+ }
347
+
348
+ /**
349
+ * Tree grid supports only hierarchical data so use another method instead.
350
+ * This method is inherited from Grid and it will throw an
351
+ * {@link UnsupportedOperationException}.
352
+ *
353
+ * @param fetchCallback
354
+ * the fetch callback
355
+ * @return the data view
356
+ * @deprecated use {@link #setDataProvider(HierarchicalDataProvider)},
357
+ * {@link #setItems(Collection, ValueProvider)},
358
+ * {@link #setItems(Stream, ValueProvider)} or
359
+ * {@link #setTreeData(TreeData)} instead.
360
+ */
361
+ @ Deprecated
362
+ @ Override
363
+ public GridLazyDataView <T > setItems (
364
+ CallbackDataProvider .FetchCallback <T , Void > fetchCallback ) {
365
+ throw new UnsupportedOperationException (
366
+ "TreeGrid only accepts hierarchical data providers. "
367
+ + "Use another setDataProvider/setItems method instead with hierarchical data."
368
+ + "An example of interface to be used: HierarchicalDataProvider" );
369
+ }
370
+
371
+ /**
372
+ * Tree grid supports only hierarchical data providers so use another method
373
+ * instead. This method is inherited from Grid and it will throw an
374
+ * {@link UnsupportedOperationException}.
375
+ *
376
+ * @param dataProvider
377
+ * the data provider
378
+ * @return the data view
379
+ * @deprecated use {@link #setDataProvider(HierarchicalDataProvider)},
380
+ * {@link #setItems(Collection, ValueProvider)},
381
+ * {@link #setItems(Stream, ValueProvider)} or
382
+ * {@link #setTreeData(TreeData)} instead.
383
+ */
384
+ @ Deprecated
385
+ @ Override
386
+ public GridListDataView <T > setItems (ListDataProvider <T > dataProvider ) {
387
+ throw new UnsupportedOperationException (
388
+ "TreeGrid only accepts hierarchical data providers. "
389
+ + "Use another setDataProvider/setItems method instead with hierarchical data."
390
+ + "An example of interface to be used: HierarchicalDataProvider" );
391
+ }
392
+
393
+ /**
394
+ * Tree grid supports only hierarchical data so use another method instead.
395
+ * This method is inherited from Grid and it will throw an
396
+ * {@link UnsupportedOperationException}.
397
+ *
398
+ * @param items
399
+ * the items to display, not {@code null}
400
+ * @return the data view
401
+ * @deprecated use {@link #setDataProvider(HierarchicalDataProvider)},
402
+ * {@link #setItems(Collection, ValueProvider)},
403
+ * {@link #setItems(Stream, ValueProvider)} or
404
+ * {@link #setTreeData(TreeData)} instead.
405
+ */
406
+ @ Deprecated
407
+ @ Override
408
+ public GridListDataView <T > setItems (T ... items ) {
409
+ throw new UnsupportedOperationException (
410
+ "TreeGrid only accepts hierarchical data providers. "
411
+ + "Use another setDataProvider/setItems method instead with hierarchical data."
412
+ + "An example of interface to be used: HierarchicalDataProvider" );
413
+ }
414
+
415
+ /**
416
+ * Tree grid supports only hierarchical data, so use another method instead.
417
+ * This method is inherited from Grid and it will throw an
418
+ * {@link UnsupportedOperationException}.
419
+ *
420
+ * @param items
421
+ * the items to display, not {@code null}
422
+ * @return the data view
423
+ * @deprecated use {@link #setDataProvider(HierarchicalDataProvider)},
424
+ * {@link #setItems(Collection, ValueProvider)},
425
+ * {@link #setItems(Stream, ValueProvider)} or
426
+ * {@link #setTreeData(TreeData)} instead.
427
+ */
428
+ @ Deprecated
429
+ @ Override
430
+ public GridListDataView <T > setItems (Collection <T > items ) {
431
+ throw new UnsupportedOperationException (
432
+ "TreeGrid only accepts hierarchical data providers. "
433
+ + "Use another setDataProvider/setItems method instead with hierarchical data."
434
+ + "An example of interface to be used: HierarchicalDataProvider" );
435
+ }
436
+
437
+ /**
438
+ * Tree grid does not support list data view, this will throw an
439
+ * {@link UnsupportedOperationException}.
440
+ *
441
+ * @return exception is thrown
442
+ * @deprecated not supported
443
+ */
444
+ @ Deprecated
445
+ @ Override
446
+ public GridListDataView <T > getListDataView () {
447
+ throw new UnsupportedOperationException (
448
+ "TreeGrid does not support list data view." );
449
+ }
450
+
451
+ /**
452
+ * Tree grid does not support list data view, this will throw an
453
+ * {@link UnsupportedOperationException}.
454
+ *
455
+ * @return exception is thrown
456
+ * @deprecated not supported
457
+ */
458
+ @ Deprecated
459
+ @ Override
460
+ public GridLazyDataView <T > getLazyDataView () {
461
+ throw new UnsupportedOperationException (
462
+ "TreeGrid does not support lazy data view." );
463
+ }
464
+
465
+ /**
466
+ * Tree grid does not support list data view, this will throw an
467
+ * {@link UnsupportedOperationException}.
468
+ *
469
+ * @return exception is thrown
470
+ * @deprecated not supported
471
+ */
472
+ @ Deprecated
473
+ @ Override
474
+ public GridDataView <T > getGenericDataView () {
475
+ throw new UnsupportedOperationException (
476
+ "TreeGrid does not support generic data view." );
477
+ }
478
+
479
+
307
480
/**
308
481
* Adds a new Hierarchy column to this {@link Grid} with a value provider.
309
482
* The value is converted to String when sent to the client by using
@@ -779,6 +952,22 @@ public HierarchicalDataProvider<T, SerializablePredicate<T>> getDataProvider() {
779
952
return (HierarchicalDataProvider <T , SerializablePredicate <T >>) super .getDataProvider ();
780
953
}
781
954
955
+ /**
956
+ * The effective index of an item depends on the complete hierarchy of the
957
+ * tree. {@link TreeGrid} uses lazy loading for performance reasons and does
958
+ * not know about the complete hierarchy. Without the knowledge of the
959
+ * complete hierarchy, {@link TreeGrid} can’t reliably calculate an exact
960
+ * scroll position. <b>This uncertainty makes this method unreliable and so
961
+ * should be avoided.</b>
962
+ *
963
+ * @param rowIndex
964
+ * zero based index of the item to scroll to in the current view.
965
+ */
966
+ @ Override
967
+ public void scrollToIndex (int rowIndex ) {
968
+ super .scrollToIndex (rowIndex );
969
+ }
970
+
782
971
@ Override
783
972
protected void applyFilterPredicate (SerializablePredicate <T > finalPredicate ) {
784
973
DataProvider <T , ?> dataProvider = getDataProvider ();
@@ -788,4 +977,5 @@ protected void applyFilterPredicate(SerializablePredicate<T> finalPredicate) {
788
977
((HierarchicalConfigurableFilterDataProvider <T , Void , Filter >)dataProvider ).setFilter (new Filter <T >(finalPredicate ));
789
978
}
790
979
}
980
+
791
981
}
0 commit comments