46 **************************************************************************/
47
48 private boolean itemCountDirty;
49
50 /**
51 * The virtualized container which handles the layout and scrolling of
52 * all the cells.
53 */
54 private final VirtualFlow<I> flow;
55
56
57
58 /***************************************************************************
59 * *
60 * Constructors *
61 * *
62 **************************************************************************/
63
64 /**
65 *
66 * @param control
67 */
68 public VirtualContainerBase(final C control) {
69 super(control);
70 flow = createVirtualFlow();
71
72 control.addEventHandler(ScrollToEvent.scrollToTopIndex(), event -> {
73 // Fix for RT-24630: The row count in VirtualFlow was incorrect
74 // (normally zero), so the scrollTo call was misbehaving.
75 if (itemCountDirty) {
76 // update row count before we do a scroll
77 updateItemCount();
78 itemCountDirty = false;
79 }
80 flow.scrollToTop(event.getScrollTarget());
81 });
82 }
83
84
85
86 /***************************************************************************
87 * *
88 * Abstract API *
89 * *
90 **************************************************************************/
91
92 /**
93 * Returns the total number of items in this container, including those
94 * that are currently hidden because they are out of view.
95 */
96 protected abstract int getItemCount();
97
98 /**
99 * This method is called when it is possible that the item count has changed (i.e. scrolling has occurred,
100 * the control has resized, etc). This method should recalculate the item count and store that for future
101 * use by the {@link #getItemCount} method.
102 */
103 protected abstract void updateItemCount();
104
105
106
107 /***************************************************************************
108 * *
109 * Public API *
110 * *
111 **************************************************************************/
112
113 /**
114 * Call this method to indicate that the item count should be updated on the next pulse.
|
46 **************************************************************************/
47
48 private boolean itemCountDirty;
49
50 /**
51 * The virtualized container which handles the layout and scrolling of
52 * all the cells.
53 */
54 private final VirtualFlow<I> flow;
55
56
57
58 /***************************************************************************
59 * *
60 * Constructors *
61 * *
62 **************************************************************************/
63
64 /**
65 *
66 * @param control the control
67 */
68 public VirtualContainerBase(final C control) {
69 super(control);
70 flow = createVirtualFlow();
71
72 control.addEventHandler(ScrollToEvent.scrollToTopIndex(), event -> {
73 // Fix for RT-24630: The row count in VirtualFlow was incorrect
74 // (normally zero), so the scrollTo call was misbehaving.
75 if (itemCountDirty) {
76 // update row count before we do a scroll
77 updateItemCount();
78 itemCountDirty = false;
79 }
80 flow.scrollToTop(event.getScrollTarget());
81 });
82 }
83
84
85
86 /***************************************************************************
87 * *
88 * Abstract API *
89 * *
90 **************************************************************************/
91
92 /**
93 * Returns the total number of items in this container, including those
94 * that are currently hidden because they are out of view.
95 * @return the total number of items in this container
96 */
97 protected abstract int getItemCount();
98
99 /**
100 * This method is called when it is possible that the item count has changed (i.e. scrolling has occurred,
101 * the control has resized, etc). This method should recalculate the item count and store that for future
102 * use by the {@link #getItemCount} method.
103 */
104 protected abstract void updateItemCount();
105
106
107
108 /***************************************************************************
109 * *
110 * Public API *
111 * *
112 **************************************************************************/
113
114 /**
115 * Call this method to indicate that the item count should be updated on the next pulse.
|