/
Grid.java
7426 lines (6636 loc) · 254 KB
/
Grid.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* 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 com.vaadin.v7.ui;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.vaadin.data.sort.Sort;
import com.vaadin.data.sort.SortOrder;
import com.vaadin.event.ContextClickEvent;
import com.vaadin.event.SortEvent;
import com.vaadin.event.SortEvent.SortListener;
import com.vaadin.event.SortEvent.SortNotifier;
import com.vaadin.server.AbstractClientConnector;
import com.vaadin.server.AbstractExtension;
import com.vaadin.server.EncodeResult;
import com.vaadin.server.ErrorMessage;
import com.vaadin.server.Extension;
import com.vaadin.server.JsonCodec;
import com.vaadin.server.KeyMapper;
import com.vaadin.server.VaadinSession;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.util.SharedUtil;
import com.vaadin.ui.AbstractFocusable;
import com.vaadin.ui.Component;
import com.vaadin.ui.ConnectorTracker;
import com.vaadin.ui.SelectiveRenderer;
import com.vaadin.ui.UI;
import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;
import com.vaadin.ui.declarative.DesignException;
import com.vaadin.ui.declarative.DesignFormatter;
import com.vaadin.util.ReflectTools;
import com.vaadin.v7.data.Container;
import com.vaadin.v7.data.Container.Indexed;
import com.vaadin.v7.data.Container.ItemSetChangeEvent;
import com.vaadin.v7.data.Container.ItemSetChangeListener;
import com.vaadin.v7.data.Container.ItemSetChangeNotifier;
import com.vaadin.v7.data.Container.PropertySetChangeEvent;
import com.vaadin.v7.data.Container.PropertySetChangeListener;
import com.vaadin.v7.data.Container.PropertySetChangeNotifier;
import com.vaadin.v7.data.Container.Sortable;
import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.Property;
import com.vaadin.v7.data.Validator.InvalidValueException;
import com.vaadin.v7.data.fieldgroup.DefaultFieldGroupFieldFactory;
import com.vaadin.v7.data.fieldgroup.FieldGroup;
import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException;
import com.vaadin.v7.data.fieldgroup.FieldGroupFieldFactory;
import com.vaadin.v7.data.util.IndexedContainer;
import com.vaadin.v7.data.util.converter.Converter;
import com.vaadin.v7.data.util.converter.ConverterUtil;
import com.vaadin.v7.event.ItemClickEvent;
import com.vaadin.v7.event.SelectionEvent;
import com.vaadin.v7.event.ItemClickEvent.ItemClickListener;
import com.vaadin.v7.event.ItemClickEvent.ItemClickNotifier;
import com.vaadin.v7.event.SelectionEvent.SelectionListener;
import com.vaadin.v7.event.SelectionEvent.SelectionNotifier;
import com.vaadin.v7.server.communication.data.DataGenerator;
import com.vaadin.v7.server.communication.data.RpcDataProviderExtension;
import com.vaadin.v7.shared.ui.grid.EditorClientRpc;
import com.vaadin.v7.shared.ui.grid.EditorServerRpc;
import com.vaadin.v7.shared.ui.grid.GridClientRpc;
import com.vaadin.v7.shared.ui.grid.GridColumnState;
import com.vaadin.v7.shared.ui.grid.GridConstants;
import com.vaadin.v7.shared.ui.grid.GridConstants.Section;
import com.vaadin.v7.shared.ui.grid.GridServerRpc;
import com.vaadin.v7.shared.ui.grid.GridState;
import com.vaadin.v7.shared.ui.grid.GridStaticCellType;
import com.vaadin.v7.shared.ui.grid.GridStaticSectionState;
import com.vaadin.v7.shared.ui.grid.GridStaticSectionState.CellState;
import com.vaadin.v7.shared.ui.grid.GridStaticSectionState.RowState;
import com.vaadin.v7.shared.ui.grid.HeightMode;
import com.vaadin.v7.shared.ui.grid.ScrollDestination;
import com.vaadin.v7.shared.ui.grid.selection.MultiSelectionModelServerRpc;
import com.vaadin.v7.shared.ui.grid.selection.MultiSelectionModelState;
import com.vaadin.v7.shared.ui.grid.selection.SingleSelectionModelServerRpc;
import com.vaadin.v7.shared.ui.grid.selection.SingleSelectionModelState;
import com.vaadin.v7.ui.renderers.HtmlRenderer;
import com.vaadin.v7.ui.renderers.Renderer;
import com.vaadin.v7.ui.renderers.TextRenderer;
import elemental.json.Json;
import elemental.json.JsonObject;
import elemental.json.JsonValue;
/**
* A grid component for displaying tabular data.
* <p>
* Grid is always bound to a {@link Container.Indexed}, but is not a
* {@code Container} of any kind in of itself. The contents of the given
* Container is displayed with the help of {@link Renderer Renderers}.
*
* <h3 id="grid-headers-and-footers">Headers and Footers</h3>
* <p>
*
*
* <h3 id="grid-converters-and-renderers">Converters and Renderers</h3>
* <p>
* Each column has its own {@link Renderer} that displays data into something
* that can be displayed in the browser. That data is first converted with a
* {@link com.vaadin.v7.data.util.converter.Converter Converter} into something
* that the Renderer can process. This can also be an implicit step - if a
* column has a simple data type, like a String, no explicit assignment is
* needed.
* <p>
* Usually a renderer takes some kind of object, and converts it into a
* HTML-formatted string.
* <p>
* <code><pre>
* Grid grid = new Grid(myContainer);
* Column column = grid.getColumn(STRING_DATE_PROPERTY);
* column.setConverter(new StringToDateConverter());
* column.setRenderer(new MyColorfulDateRenderer());
* </pre></code>
*
* <h3 id="grid-lazyloading">Lazy Loading</h3>
* <p>
* The data is accessed as it is needed by Grid and not any sooner. In other
* words, if the given Container is huge, but only the first few rows are
* displayed to the user, only those (and a few more, for caching purposes) are
* accessed.
*
* <h3 id="grid-selection-modes-and-models">Selection Modes and Models</h3>
* <p>
* Grid supports three selection <em>{@link SelectionMode modes}</em> (single,
* multi, none), and comes bundled with one <em>{@link SelectionModel
* model}</em> for each of the modes. The distinction between a selection mode
* and selection model is as follows: a <em>mode</em> essentially says whether
* you can have one, many or no rows selected. The model, however, has the
* behavioral details of each. A single selection model may require that the
* user deselects one row before selecting another one. A variant of a
* multiselect might have a configurable maximum of rows that may be selected.
* And so on.
* <p>
* <code><pre>
* Grid grid = new Grid(myContainer);
*
* // uses the bundled SingleSelectionModel class
* grid.setSelectionMode(SelectionMode.SINGLE);
*
* // changes the behavior to a custom selection model
* grid.setSelectionModel(new MyTwoSelectionModel());
* </pre></code>
*
* @since 7.4
* @author Vaadin Ltd
*/
@Deprecated
public class Grid extends AbstractFocusable implements SelectionNotifier,
SortNotifier, SelectiveRenderer, ItemClickNotifier {
/**
* An event listener for column visibility change events in the Grid.
*
* @since 7.5.0
*/
@Deprecated
public interface ColumnVisibilityChangeListener extends Serializable {
/**
* Called when a column has become hidden or unhidden.
*
* @param event
*/
void columnVisibilityChanged(ColumnVisibilityChangeEvent event);
}
/**
* An event that is fired when a column's visibility changes.
*
* @since 7.5.0
*/
@Deprecated
public static class ColumnVisibilityChangeEvent extends Component.Event {
private final Column column;
private final boolean userOriginated;
private final boolean hidden;
/**
* Constructor for a column visibility change event.
*
* @param source
* the grid from which this event originates
* @param column
* the column that changed its visibility
* @param hidden
* <code>true</code> if the column was hidden,
* <code>false</code> if it became visible
* @param isUserOriginated
* <code>true</code> iff the event was triggered by an UI
* interaction
*/
public ColumnVisibilityChangeEvent(Grid source, Column column,
boolean hidden, boolean isUserOriginated) {
super(source);
this.column = column;
this.hidden = hidden;
userOriginated = isUserOriginated;
}
/**
* Gets the column that became hidden or visible.
*
* @return the column that became hidden or visible.
* @see Column#isHidden()
*/
public Column getColumn() {
return column;
}
/**
* Was the column set hidden or visible.
*
* @return <code>true</code> if the column was hidden <code>false</code>
* if it was set visible
*/
public boolean isHidden() {
return hidden;
}
/**
* Returns <code>true</code> if the column reorder was done by the user,
* <code>false</code> if not and it was triggered by server side code.
*
* @return <code>true</code> if event is a result of user interaction
*/
public boolean isUserOriginated() {
return userOriginated;
}
}
/**
* A callback interface for generating details for a particular row in Grid.
*
* @since 7.5.0
* @author Vaadin Ltd
* @see DetailsGenerator#NULL
*/
@Deprecated
public interface DetailsGenerator extends Serializable {
/** A details generator that provides no details */
public DetailsGenerator NULL = new DetailsGenerator() {
@Override
public Component getDetails(RowReference rowReference) {
return null;
}
};
/**
* This method is called for whenever a details row needs to be shown on
* the client. Grid removes all of its references to details components
* when they are no longer displayed on the client-side and will
* re-request once needed again.
* <p>
* <em>Note:</em> If a component gets generated, it may not be manually
* attached anywhere. The same details component can not be displayed
* for multiple different rows.
*
* @param rowReference
* the reference for the row for which to generate details
* @return the details for the given row, or <code>null</code> to leave
* the details empty.
*/
Component getDetails(RowReference rowReference);
}
/**
* A class that manages details components by calling
* {@link DetailsGenerator} as needed. Details components are attached by
* this class when the {@link RpcDataProviderExtension} is sending data to
* the client. Details components are detached and forgotten when client
* informs that it has dropped the corresponding item.
*
* @since 7.6.1
*/
@Deprecated
public final static class DetailComponentManager
extends AbstractGridExtension implements DataGenerator {
/**
* The user-defined details generator.
*
* @see #setDetailsGenerator(DetailsGenerator)
*/
private DetailsGenerator detailsGenerator;
/**
* This map represents all details that are currently visible on the
* client. Details components get destroyed once they scroll out of
* view.
*/
private final Map<Object, Component> itemIdToDetailsComponent = new HashMap<>();
/**
* Set of item ids that got <code>null</code> from DetailsGenerator when
* {@link DetailsGenerator#getDetails(RowReference)} was called.
*/
private final Set<Object> emptyDetails = new HashSet<>();
/**
* Set of item IDs for all open details rows. Contains even the ones
* that are not currently visible on the client.
*/
private final Set<Object> openDetails = new HashSet<>();
public DetailComponentManager(Grid grid) {
this(grid, DetailsGenerator.NULL);
}
public DetailComponentManager(Grid grid,
DetailsGenerator detailsGenerator) {
super(grid);
setDetailsGenerator(detailsGenerator);
}
/**
* Creates a details component with the help of the user-defined
* {@link DetailsGenerator}.
* <p>
* This method attaches created components to the parent {@link Grid}.
*
* @param itemId
* the item id for which to create the details component.
* @throws IllegalStateException
* if the current details generator provides a component
* that was manually attached.
*/
private void createDetails(Object itemId) throws IllegalStateException {
assert itemId != null : "itemId was null";
if (itemIdToDetailsComponent.containsKey(itemId)
|| emptyDetails.contains(itemId)) {
// Don't overwrite existing components
return;
}
RowReference rowReference = new RowReference(getParentGrid());
rowReference.set(itemId);
DetailsGenerator detailsGenerator = getParentGrid()
.getDetailsGenerator();
Component details = detailsGenerator.getDetails(rowReference);
if (details != null) {
if (details.getParent() != null) {
String name = detailsGenerator.getClass().getName();
throw new IllegalStateException(
name + " generated a details component that already "
+ "was attached. (itemId: " + itemId
+ ", component: " + details + ")");
}
itemIdToDetailsComponent.put(itemId, details);
addComponentToGrid(details);
assert !emptyDetails.contains(itemId) : "Bookeeping thinks "
+ "itemId is empty even though we just created a "
+ "component for it (" + itemId + ")";
} else {
emptyDetails.add(itemId);
}
}
/**
* Destroys a details component correctly.
* <p>
* This method will detach the component from parent {@link Grid}.
*
* @param itemId
* the item id for which to destroy the details component
*/
private void destroyDetails(Object itemId) {
emptyDetails.remove(itemId);
Component removedComponent = itemIdToDetailsComponent
.remove(itemId);
if (removedComponent == null) {
return;
}
removeComponentFromGrid(removedComponent);
}
/**
* Recreates all visible details components.
*/
public void refreshDetails() {
Set<Object> visibleItemIds = new HashSet<>(
itemIdToDetailsComponent.keySet());
for (Object itemId : visibleItemIds) {
destroyDetails(itemId);
createDetails(itemId);
refreshRow(itemId);
}
}
/**
* Sets details visiblity status of given item id.
*
* @param itemId
* item id to set
* @param visible
* <code>true</code> if visible; <code>false</code> if not
*/
public void setDetailsVisible(Object itemId, boolean visible) {
if ((visible && openDetails.contains(itemId))
|| (!visible && !openDetails.contains(itemId))) {
return;
}
if (visible) {
openDetails.add(itemId);
refreshRow(itemId);
} else {
openDetails.remove(itemId);
destroyDetails(itemId);
refreshRow(itemId);
}
}
@Override
public void generateData(Object itemId, Item item, JsonObject rowData) {
// DetailComponentManager should not send anything if details
// generator is the default null version.
if (openDetails.contains(itemId)
&& !detailsGenerator.equals(DetailsGenerator.NULL)) {
// Double check to be sure details component exists.
createDetails(itemId);
Component detailsComponent = itemIdToDetailsComponent
.get(itemId);
rowData.put(GridState.JSONKEY_DETAILS_VISIBLE,
(detailsComponent != null
? detailsComponent.getConnectorId() : ""));
}
}
@Override
public void destroyData(Object itemId) {
if (openDetails.contains(itemId)) {
destroyDetails(itemId);
}
}
/**
* Sets a new details generator for row details.
* <p>
* The currently opened row details will be re-rendered.
*
* @param detailsGenerator
* the details generator to set
* @throws IllegalArgumentException
* if detailsGenerator is <code>null</code>;
*/
public void setDetailsGenerator(DetailsGenerator detailsGenerator)
throws IllegalArgumentException {
if (detailsGenerator == null) {
throw new IllegalArgumentException(
"Details generator may not be null");
} else if (detailsGenerator == this.detailsGenerator) {
return;
}
this.detailsGenerator = detailsGenerator;
refreshDetails();
}
/**
* Gets the current details generator for row details.
*
* @return the detailsGenerator the current details generator
*/
public DetailsGenerator getDetailsGenerator() {
return detailsGenerator;
}
/**
* Checks whether details are visible for the given item.
*
* @param itemId
* the id of the item for which to check details visibility
* @return <code>true</code> iff the details are visible
*/
public boolean isDetailsVisible(Object itemId) {
return openDetails.contains(itemId);
}
}
/**
* Custom field group that allows finding property types before an item has
* been bound.
*/
private final class CustomFieldGroup extends FieldGroup {
public CustomFieldGroup() {
setFieldFactory(EditorFieldFactory.get());
}
@Override
protected Class<?> getPropertyType(Object propertyId)
throws BindException {
if (getItemDataSource() == null) {
return datasource.getType(propertyId);
} else {
return super.getPropertyType(propertyId);
}
}
@Override
protected <T extends Field> T build(String caption, Class<?> dataType,
Class<T> fieldType) throws BindException {
T field = super.build(caption, dataType, fieldType);
if (field instanceof CheckBox) {
field.setCaption(null);
}
return field;
}
}
/**
* Field factory used by default in the editor.
*
* Aims to fields of suitable type and with suitable size for use in the
* editor row.
*/
@Deprecated
public static class EditorFieldFactory
extends DefaultFieldGroupFieldFactory {
private static final EditorFieldFactory INSTANCE = new EditorFieldFactory();
protected EditorFieldFactory() {
}
/**
* Returns the singleton instance
*
* @return the singleton instance
*/
public static EditorFieldFactory get() {
return INSTANCE;
}
@Override
public <T extends Field> T createField(Class<?> type,
Class<T> fieldType) {
T f = super.createField(type, fieldType);
if (f != null) {
f.setWidth("100%");
}
return f;
}
@Override
protected AbstractSelect createCompatibleSelect(
Class<? extends AbstractSelect> fieldType) {
if (anySelect(fieldType)) {
return super.createCompatibleSelect(ComboBox.class);
}
return super.createCompatibleSelect(fieldType);
}
@Override
protected void populateWithEnumData(AbstractSelect select,
Class<? extends Enum> enumClass) {
// Use enums directly and the EnumToStringConverter to be consistent
// with what is shown in the Grid
@SuppressWarnings("unchecked")
EnumSet<?> enumSet = EnumSet.allOf(enumClass);
for (Object r : enumSet) {
select.addItem(r);
}
}
}
/**
* Error handler for the editor
*/
@Deprecated
public interface EditorErrorHandler extends Serializable {
/**
* Called when an exception occurs while the editor row is being saved
*
* @param event
* An event providing more information about the error
*/
void commitError(CommitErrorEvent event);
}
/**
* ContextClickEvent for the Grid Component.
*
* @since 7.6
*/
@Deprecated
public static class GridContextClickEvent extends ContextClickEvent {
private final Object itemId;
private final int rowIndex;
private final Object propertyId;
private final Section section;
public GridContextClickEvent(Grid source,
MouseEventDetails mouseEventDetails, Section section,
int rowIndex, Object itemId, Object propertyId) {
super(source, mouseEventDetails);
this.itemId = itemId;
this.propertyId = propertyId;
this.section = section;
this.rowIndex = rowIndex;
}
/**
* Returns the item id of context clicked row.
*
* @return item id of clicked row; <code>null</code> if header or footer
*/
public Object getItemId() {
return itemId;
}
/**
* Returns property id of clicked column.
*
* @return property id
*/
public Object getPropertyId() {
return propertyId;
}
/**
* Return the clicked section of Grid.
*
* @return section of grid
*/
public Section getSection() {
return section;
}
/**
* Returns the clicked row index relative to Grid section. In the body
* of the Grid the index is the item index in the Container. Header and
* Footer rows for index can be fetched with
* {@link Grid#getHeaderRow(int)} and {@link Grid#getFooterRow(int)}.
*
* @return row index in section
*/
public int getRowIndex() {
return rowIndex;
}
@Override
public Grid getComponent() {
return (Grid) super.getComponent();
}
}
/**
* An event which is fired when saving the editor fails
*/
@Deprecated
public static class CommitErrorEvent extends Component.Event {
private CommitException cause;
private Set<Column> errorColumns = new HashSet<>();
private String userErrorMessage;
public CommitErrorEvent(Grid grid, CommitException cause) {
super(grid);
this.cause = cause;
userErrorMessage = cause.getLocalizedMessage();
}
/**
* Retrieves the cause of the failure
*
* @return the cause of the failure
*/
public CommitException getCause() {
return cause;
}
@Override
public Grid getComponent() {
return (Grid) super.getComponent();
}
/**
* Checks if validation exceptions caused this error
*
* @return true if the problem was caused by a validation error
*/
public boolean isValidationFailure() {
return cause.getCause() instanceof InvalidValueException;
}
/**
* Marks that an error indicator should be shown for the editor of a
* column.
*
* @param column
* the column to show an error for
*/
public void addErrorColumn(Column column) {
errorColumns.add(column);
}
/**
* Gets all the columns that have been marked as erroneous.
*
* @return an umodifiable collection of erroneous columns
*/
public Collection<Column> getErrorColumns() {
return Collections.unmodifiableCollection(errorColumns);
}
/**
* Gets the error message to show to the user.
*
* @return error message to show
*/
public String getUserErrorMessage() {
return userErrorMessage;
}
/**
* Sets the error message to show to the user.
*
* @param userErrorMessage
* the user error message to set
*/
public void setUserErrorMessage(String userErrorMessage) {
this.userErrorMessage = userErrorMessage;
}
}
/**
* An event listener for column reorder events in the Grid.
*
* @since 7.5.0
*/
@Deprecated
public interface ColumnReorderListener extends Serializable {
/**
* Called when the columns of the grid have been reordered.
*
* @param event
* An event providing more information
*/
void columnReorder(ColumnReorderEvent event);
}
/**
* An event that is fired when the columns are reordered.
*
* @since 7.5.0
*/
@Deprecated
public static class ColumnReorderEvent extends Component.Event {
private final boolean userOriginated;
/**
*
* @param source
* the grid where the event originated from
* @param userOriginated
* <code>true</code> if event is a result of user
* interaction, <code>false</code> if from API call
*/
public ColumnReorderEvent(Grid source, boolean userOriginated) {
super(source);
this.userOriginated = userOriginated;
}
/**
* Returns <code>true</code> if the column reorder was done by the user,
* <code>false</code> if not and it was triggered by server side code.
*
* @return <code>true</code> if event is a result of user interaction
*/
public boolean isUserOriginated() {
return userOriginated;
}
}
/**
* An event listener for column resize events in the Grid.
*
* @since 7.6
*/
@Deprecated
public interface ColumnResizeListener extends Serializable {
/**
* Called when the columns of the grid have been resized.
*
* @param event
* An event providing more information
*/
void columnResize(ColumnResizeEvent event);
}
/**
* An event that is fired when a column is resized, either programmatically
* or by the user.
*
* @since 7.6
*/
@Deprecated
public static class ColumnResizeEvent extends Component.Event {
private final Column column;
private final boolean userOriginated;
/**
*
* @param source
* the grid where the event originated from
* @param userOriginated
* <code>true</code> if event is a result of user
* interaction, <code>false</code> if from API call
*/
public ColumnResizeEvent(Grid source, Column column,
boolean userOriginated) {
super(source);
this.column = column;
this.userOriginated = userOriginated;
}
/**
* Returns the column that was resized.
*
* @return the resized column.
*/
public Column getColumn() {
return column;
}
/**
* Returns <code>true</code> if the column resize was done by the user,
* <code>false</code> if not and it was triggered by server side code.
*
* @return <code>true</code> if event is a result of user interaction
*/
public boolean isUserOriginated() {
return userOriginated;
}
}
/**
* Interface for an editor event listener
*/
@Deprecated
public interface EditorListener extends Serializable {
public static final Method EDITOR_OPEN_METHOD = ReflectTools.findMethod(
EditorListener.class, "editorOpened", EditorOpenEvent.class);
public static final Method EDITOR_MOVE_METHOD = ReflectTools.findMethod(
EditorListener.class, "editorMoved", EditorMoveEvent.class);
public static final Method EDITOR_CLOSE_METHOD = ReflectTools
.findMethod(EditorListener.class, "editorClosed",
EditorCloseEvent.class);
/**
* Called when an editor is opened
*
* @param e
* an editor open event object
*/
public void editorOpened(EditorOpenEvent e);
/**
* Called when an editor is reopened without closing it first
*
* @param e
* an editor move event object
*/
public void editorMoved(EditorMoveEvent e);
/**
* Called when an editor is closed
*
* @param e
* an editor close event object
*/
public void editorClosed(EditorCloseEvent e);
}
/**
* Base class for editor related events
*/
@Deprecated
public static abstract class EditorEvent extends Component.Event {
private Object itemID;
protected EditorEvent(Grid source, Object itemID) {
super(source);
this.itemID = itemID;
}
/**
* Get the item (row) for which this editor was opened
*/
public Object getItem() {
return itemID;
}
}
/**
* This event gets fired when an editor is opened
*/
@Deprecated
public static class EditorOpenEvent extends EditorEvent {
public EditorOpenEvent(Grid source, Object itemID) {
super(source, itemID);
}
}
/**
* This event gets fired when an editor is opened while another row is being
* edited (i.e. editor focus moves elsewhere)
*/
@Deprecated
public static class EditorMoveEvent extends EditorEvent {
public EditorMoveEvent(Grid source, Object itemID) {
super(source, itemID);
}
}
/**
* This event gets fired when an editor is dismissed or closed by other
* means.
*/
@Deprecated
public static class EditorCloseEvent extends EditorEvent {
public EditorCloseEvent(Grid source, Object itemID) {
super(source, itemID);
}
}
/**
* Default error handler for the editor
*
*/
@Deprecated