OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 182 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
94 ilm 5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.ui.light;
15
 
142 ilm 16
import org.openconcerto.utils.NumberUtils;
132 ilm 17
import org.openconcerto.utils.io.JSONConverter;
18
 
19
import java.awt.event.ActionEvent;
20
import java.awt.event.ActionListener;
21
import java.util.ArrayList;
94 ilm 22
import java.util.List;
23
 
142 ilm 24
import javax.xml.parsers.ParserConfigurationException;
25
 
26
import org.jdom2.Document;
27
import org.jdom2.Element;
28
 
132 ilm 29
import net.minidev.json.JSONArray;
94 ilm 30
import net.minidev.json.JSONObject;
31
 
174 ilm 32
public class LightUITable extends LightUserControlContainer {
142 ilm 33
 
34
    public static final int DEFAULT_LINE_HEIGHT = 40;
35
 
36
    private static final String LINE_PER_ROW = "line-per-row";
37
    private static final String TABLE_SPEC = "table-spec";
38
    private static final String ALLOW_SELECTION = "allow-selection";
39
    private static final String ALLOW_MULTI_SELECTION = "allow-multi-selection";
40
    private static final String DYNAMIC_LOAD = "dynamic-load";
41
    private static final String AUTO_SELECT_FIRST_LINE = "auto-select-first-line";
132 ilm 42
    private Boolean dynamicLoad = false;
43
    private Boolean allowSelection = false;
142 ilm 44
    private Boolean allowMultiSelection = false;
45
    private Boolean autoSelectFirstLine = true;
94 ilm 46
    private TableSpec tableSpec = null;
47
 
174 ilm 48
    private transient List<ActionListener> selectionListeners = new ArrayList<>();
132 ilm 49
 
50
    // Nombre de ligne à afficher par Row
51
    private int linePerRow = 1;
52
 
142 ilm 53
    private int lineHeight = DEFAULT_LINE_HEIGHT;
54
 
156 ilm 55
    public LightUITable() {
56
        // Serialization
57
    }
58
 
94 ilm 59
    // Init from json constructor
60
    public LightUITable(final JSONObject json) {
132 ilm 61
        super(json);
94 ilm 62
    }
132 ilm 63
 
94 ilm 64
    // Clone constructor
65
    public LightUITable(final LightUITable tableElement) {
66
        super(tableElement);
67
        this.tableSpec = tableElement.tableSpec;
132 ilm 68
        this.allowSelection = tableElement.allowSelection;
94 ilm 69
    }
132 ilm 70
 
94 ilm 71
    public LightUITable(final String id) {
132 ilm 72
        super(id);
94 ilm 73
        this.setType(LightUIElement.TYPE_TABLE);
132 ilm 74
 
75
        this.setWeightX(1);
94 ilm 76
        this.setFillWidth(true);
77
 
142 ilm 78
        final RowSelectionSpec selection = new RowSelectionSpec(this.getId());
79
        final ColumnsSpec columnsSpec = new ColumnsSpec(this.getId(), new ArrayList<ColumnSpec>(), new ArrayList<String>(), new ArrayList<String>());
174 ilm 80
        this.tableSpec = new TableSpec(this.getId(), selection, columnsSpec);
81
        this.tableSpec.setContent(new TableContent(this.getId()));
132 ilm 82
    }
83
 
84
    @Override
85
    public void setId(final String id) {
86
        super.setId(id);
87
 
142 ilm 88
        if (this.tableSpec != null) {
89
            this.tableSpec.setId(id);
132 ilm 90
 
142 ilm 91
            if (this.tableSpec.getSelection() != null) {
92
                this.tableSpec.getSelection().setTableId(id);
93
            }
94
 
95
            if (this.tableSpec.getContent() != null) {
96
                this.tableSpec.getContent().setTableId(id);
97
            }
98
        }
132 ilm 99
    }
100
 
142 ilm 101
    public final void setLinePerRow(int linePerRow) {
132 ilm 102
        this.linePerRow = linePerRow;
103
    }
104
 
142 ilm 105
    public final int getLinePerRow() {
132 ilm 106
        return this.linePerRow;
107
    }
108
 
142 ilm 109
    public final void setLineHeight(int lineHeight) {
110
        this.lineHeight = lineHeight;
111
    }
112
 
113
    public final int getLineHeight() {
114
        return this.lineHeight;
115
    }
116
 
117
    public final TableSpec getTableSpec() {
94 ilm 118
        return this.tableSpec;
119
    }
120
 
142 ilm 121
    public final void setTableSpec(final TableSpec tableSpec) {
94 ilm 122
        this.tableSpec = tableSpec;
123
    }
132 ilm 124
 
142 ilm 125
    public final Boolean isAllowSelection() {
132 ilm 126
        return this.allowSelection;
127
    }
128
 
142 ilm 129
    public final void setAllowSelection(final boolean allowSelection) {
132 ilm 130
        this.allowSelection = allowSelection;
131
    }
132
 
142 ilm 133
    public final Boolean isAllowMultiSelection() {
134
        return this.allowMultiSelection;
135
    }
136
 
137
    public final void setAllowMultiSelection(final boolean allowMultiSelection) {
138
        this.allowMultiSelection = allowMultiSelection;
139
    }
140
 
141
    public final Boolean isDynamicLoad() {
132 ilm 142
        return this.dynamicLoad;
143
    }
144
 
142 ilm 145
    public final void setDynamicLoad(final boolean dynamicLoad) {
132 ilm 146
        this.dynamicLoad = dynamicLoad;
147
    }
148
 
142 ilm 149
    public final Boolean isAutoSelectFirstLine() {
150
        return this.autoSelectFirstLine;
94 ilm 151
    }
132 ilm 152
 
142 ilm 153
    public final void setAutoSelectFirstLine(final boolean autoSelectFirstLine) {
154
        this.autoSelectFirstLine = autoSelectFirstLine;
94 ilm 155
    }
132 ilm 156
 
142 ilm 157
    public final Row removeRow(final int index) {
158
        return this.tableSpec.getContent().removeRow(index);
159
    }
160
 
161
    public final boolean removeRow(final Row row) {
162
        final TableContent content = this.getTableSpec().getContent();
163
        return content.removeRow(row);
164
    }
165
 
166
    public final boolean hasRow() {
167
        return (this.tableSpec != null && this.tableSpec.getContent() != null && this.tableSpec.getContent().getRowsCount() > 0);
168
    }
169
 
170
    public final Row getRow(final int index) {
171
        return this.getTableSpec().getContent().getRow(index);
172
    }
173
 
174
    public Row getRowById(final Number rowId) {
175
        final int size = this.getTableSpec().getContent().getRowsCount();
176
        for (int i = 0; i < size; i++) {
177
            final Row row = this.getRow(i);
178
            if (NumberUtils.areNumericallyEqual(row.getId(), rowId)) {
179
                return row;
180
            }
181
        }
182
        return null;
183
    }
184
 
185
    public final Row setRow(final int index, final Row row) {
186
        return this.getTableSpec().getContent().setRow(index, row);
187
    }
188
 
156 ilm 189
    public final void insertRow(final int index, final Row row) {
190
        this.getTableSpec().getContent().insertRow(index, row);
191
    }
192
 
142 ilm 193
    public final boolean addRow(final Row row) {
194
        return this.getTableSpec().getContent().addRow(row);
195
    }
196
 
197
    public final int getRowsCount() {
198
        return this.getTableSpec().getContent().getRowsCount();
199
    }
200
 
201
    public final void clearRows() {
202
        this.getTableSpec().getContent().clearRows();
203
    }
204
 
205
    /**
206
     * Get Ids of SQLRowAccessor store in selected rows
207
     *
208
     * @return The list of selected DB Ids
209
     */
210
    public final List<Number> getSelectedIds() {
211
        return this.getTableSpec().getSelection().getIds();
212
    }
213
 
214
    public final Number getFirstSelectedId() {
215
        final List<Number> selectedIds = this.getTableSpec().getSelection().getIds();
216
        if (selectedIds.isEmpty()) {
217
            return null;
218
        } else {
219
            return selectedIds.get(0);
220
        }
221
    }
222
 
223
    public final void setSelectedIds(final List<Number> selectedIds, final boolean fire) {
224
        this.getTableSpec().getSelection().setIds(selectedIds);
225
        if (fire) {
226
            this.fireSelectionChange();
227
        }
228
    }
229
 
230
    public final void clearSelection(final boolean fire) {
156 ilm 231
        this.getTableSpec().getSelection().clear();
142 ilm 232
        if (fire) {
233
            this.fireSelectionChange();
234
        }
235
    }
236
 
237
    public final List<Row> getSelectedRows() {
174 ilm 238
        final List<Row> selectedRows = new ArrayList<>();
142 ilm 239
 
240
        if (this.getTableSpec().getSelection() != null) {
241
            final List<Number> selectedIds = this.getSelectedIds();
242
            for (final Number selectedId : selectedIds) {
243
                final Row selectedRow = this.getRowById(selectedId);
244
                if (selectedRow != null) {
245
                    selectedRows.add(selectedRow);
246
                }
247
            }
248
        }
249
 
250
        return selectedRows;
251
    }
252
 
144 ilm 253
    @Override
142 ilm 254
    public final boolean replaceChild(final LightUIElement pChild) {
132 ilm 255
        pChild.setReadOnly(this.isReadOnly());
256
 
142 ilm 257
        for (int i = 0; i < this.getRowsCount(); i++) {
258
            final Row tableRow = this.getTableSpec().getContent().getRow(i);
132 ilm 259
            final List<Object> tableRowValues = tableRow.getValues();
260
            final int tableRowValuesCount = tableRowValues.size();
261
 
262
            for (int j = 0; j < tableRowValuesCount; j++) {
263
                final Object tableRowValue = tableRowValues.get(j);
264
                if (tableRowValue instanceof LightUIElement) {
265
                    final LightUIElement child = (LightUIElement) tableRowValue;
266
 
267
                    if (child.getId().equals(pChild.getId())) {
268
                        tableRowValues.set(i, pChild);
269
                        child.setParent(this);
270
                        return true;
271
                    }
272
                    if (child instanceof LightUIContainer) {
273
                        if (((LightUIContainer) child).replaceChild(pChild)) {
274
                            return true;
275
                        }
276
                    }
277
                    if (child instanceof LightUITable) {
278
                        if (((LightUITable) child).replaceChild(pChild)) {
279
                            return true;
280
                        }
281
                    }
282
                }
283
            }
284
        }
285
        return false;
286
    }
287
 
144 ilm 288
    public final <T extends LightUIElement> T findElementByID(final String searchParam, final Class<T> objectClass) {
289
        if (this.hasRow()) {
290
 
291
            for (int i = 0; i < this.getRowsCount(); i++) {
292
                final Row row = this.getRow(i);
293
                final List<Object> rowValues = row.getValues();
294
                for (final Object value : rowValues) {
295
                    if (value instanceof LightUIContainer) {
296
                        final LightUIContainer panel = (LightUIContainer) value;
297
                        final T element = panel.findChildByID(searchParam, objectClass);
298
                        if (element != null) {
299
                            return element;
300
                        }
301
                    } else if (value instanceof LightUIElement) {
302
                        final LightUIElement element = (LightUIElement) value;
303
 
304
                        if (element.getId().equals(searchParam)) {
305
                            if (objectClass.isAssignableFrom(element.getClass())) {
306
                                return objectClass.cast(element);
307
                            } else {
308
                                throw new IllegalArgumentException(
309
                                        "Element found at is not an instance of " + objectClass.getName() + ", element class: " + element.getClass().getName() + " element ID: " + element.getId());
310
                            }
311
                        }
312
 
313
                        if (element instanceof LightUITable) {
314
                            final T resultElement = ((LightUITable) element).findElementByID(searchParam, objectClass);
315
                            if (resultElement != null) {
316
                                return resultElement;
317
                            }
318
                        }
319
                    }
320
                }
321
            }
322
        } else {
323
            System.out.println("LightUITable.findElementByID() - No rows for table: " + this.getId());
324
        }
325
        return null;
132 ilm 326
    }
327
 
144 ilm 328
    public final <T extends LightUIElement> T findElementByUUID(final String searchParam, final Class<T> objectClass) {
142 ilm 329
        if (this.hasRow()) {
330
 
331
            for (int i = 0; i < this.getRowsCount(); i++) {
332
                final Row row = this.getRow(i);
333
                final List<Object> rowValues = row.getValues();
334
                for (final Object value : rowValues) {
335
                    if (value instanceof LightUIContainer) {
336
                        final LightUIContainer panel = (LightUIContainer) value;
144 ilm 337
                        final T element = panel.findChildByUUID(searchParam, objectClass);
142 ilm 338
                        if (element != null) {
339
                            return element;
340
                        }
341
                    } else if (value instanceof LightUIElement) {
342
                        final LightUIElement element = (LightUIElement) value;
144 ilm 343
 
344
                        if (element.getUUID().equals(searchParam)) {
345
                            if (objectClass.isAssignableFrom(element.getClass())) {
346
                                return objectClass.cast(element);
347
                            } else {
348
                                throw new IllegalArgumentException(
349
                                        "Element found at is not an instance of " + objectClass.getName() + ", element class: " + element.getClass().getName() + " element ID: " + element.getId());
142 ilm 350
                            }
351
                        }
132 ilm 352
 
142 ilm 353
                        if (element instanceof LightUITable) {
144 ilm 354
                            final T resultElement = ((LightUITable) element).findElementByUUID(searchParam, objectClass);
142 ilm 355
                            if (resultElement != null) {
356
                                return resultElement;
94 ilm 357
                            }
358
                        }
359
                    }
360
                }
361
            }
362
        } else {
144 ilm 363
            System.out.println("LightUITable.findElementByUUID() - No rows for table: " + this.getId());
94 ilm 364
        }
365
        return null;
366
    }
367
 
142 ilm 368
    public <T extends LightUIElement> List<T> findChildren(final Class<T> expectedClass, final boolean recursively) {
174 ilm 369
        final List<T> result = new ArrayList<>();
142 ilm 370
 
371
        if (this.hasRow()) {
372
            final int size = this.getRowsCount();
373
            for (int i = 0; i < size; i++) {
374
                final Row row = this.getRow(i);
375
                final List<Object> rowValues = row.getValues();
376
                for (final Object value : rowValues) {
174 ilm 377
                    if (value != null) {
378
                        if (recursively) {
379
                            if (value instanceof LightUIContainer) {
380
                                result.addAll(((LightUIContainer) value).findChildren(expectedClass, recursively));
381
                            } else if (value instanceof LightUITable) {
382
                                result.addAll(((LightUITable) value).findChildren(expectedClass, recursively));
383
                            }
142 ilm 384
                        }
174 ilm 385
                        if (expectedClass.isAssignableFrom(value.getClass())) {
386
                            result.add(expectedClass.cast(value));
387
                        }
142 ilm 388
                    }
389
                }
390
            }
391
        } else {
392
            System.out.println("LightUITable.getElementById() - No rows for table: " + this.getId());
393
        }
394
 
395
        return result;
396
    }
397
 
398
    public final void addSelectionListener(final ActionListener selectionListener) {
185 ilm 399
        this.setAllowSelection(true);
132 ilm 400
        this.selectionListeners.add(selectionListener);
401
    }
402
 
142 ilm 403
    public final void removeSelectionListeners() {
132 ilm 404
        this.selectionListeners.clear();
405
    }
406
 
142 ilm 407
    public final void fireSelectionChange() {
132 ilm 408
        for (final ActionListener listener : this.selectionListeners) {
409
            listener.actionPerformed(new ActionEvent(this, 1, "selection"));
410
        }
411
    }
412
 
142 ilm 413
    // TODO: garder l'ordre des colonnes invisibles
414
    /**
415
     * Create columns preferences with the current ColumnsSpec
416
     *
417
     * @return XML document with columns preferences
418
     */
419
    public final Document createXmlPreferences(final Document userPrefs, final ColumnsSpec columnsSpec) throws ParserConfigurationException {
420
 
421
        final Element rootElement = new Element("list");
422
        final Document xmlConf = new Document();
423
 
424
        final int columnSpecCount = columnsSpec.getColumnCount();
174 ilm 425
        final List<String> visibleIds = new ArrayList<>();
142 ilm 426
        for (int i = 0; i < columnSpecCount; i++) {
427
            final ColumnSpec columnSpec = columnsSpec.getColumn(i);
428
            final Element xmlColumn = this.createXmlColumn(columnSpec.getId(), columnSpec.getMaxWidth(), columnSpec.getMinWidth(), columnSpec.getWidth());
429
            rootElement.addContent(xmlColumn);
430
            visibleIds.add(columnSpec.getId());
431
        }
432
 
433
        final Element rootUserPrefs = userPrefs.getRootElement();
434
        final List<Element> xmlColumns = rootUserPrefs.getChildren();
435
        final int columnsSize = xmlColumns.size();
436
        for (int i = 0; i < columnsSize; i++) {
437
            final Element xmlColumn = xmlColumns.get(i);
438
            final String columnId = xmlColumn.getAttribute("id").getValue();
439
            if (!visibleIds.contains(columnId)) {
440
                final int maxWidth = Integer.parseInt(xmlColumn.getAttribute("max-width").getValue());
441
                final int minWidth = Integer.parseInt(xmlColumn.getAttribute("min-width").getValue());
442
                final int width = Integer.parseInt(xmlColumn.getAttribute("width").getValue());
443
                final Element newXmlColumn = this.createXmlColumn(columnId, maxWidth, minWidth, width);
444
                rootElement.addContent(newXmlColumn);
445
            }
446
        }
447
        xmlConf.setRootElement(rootElement);
448
        return xmlConf;
449
    }
450
 
451
    /**
452
     * Create default columns preferences from the SQLTableModelLinesSourceOnline
453
     *
454
     * @return XML document with columns preferences
455
     */
456
    public Document createDefaultXmlPreferences() {
457
        final Element rootElement = new Element("list");
458
 
459
        if (this.getTableSpec() != null && this.getTableSpec().getColumns() != null) {
460
            final int sqlColumnsCount = this.getTableSpec().getColumns().getColumnCount();
461
            for (int i = 0; i < sqlColumnsCount; i++) {
462
                final ColumnSpec column = this.getTableSpec().getColumns().getColumn(i);
463
                final String columnId = column.getId();
464
                final Element columnElement = this.createXmlColumn(columnId, column.getMaxWidth(), column.getMinWidth(), column.getWidth());
465
                rootElement.addContent(columnElement);
466
            }
467
        }
468
        final Document xmlConf = new Document(rootElement);
469
 
470
        return xmlConf;
471
    }
472
 
473
    protected final Element createXmlColumn(final String columnId, final double maxWidth, final double minWidth, final double width) {
474
        final Element columnElement = new Element("column");
475
        columnElement.setAttribute("id", columnId);
476
        columnElement.setAttribute("max-width", String.valueOf(maxWidth));
477
        columnElement.setAttribute("min-width", String.valueOf(minWidth));
478
        columnElement.setAttribute("width", String.valueOf(width));
479
        return columnElement;
480
    }
481
 
132 ilm 482
    @Override
483
    public void setReadOnly(final boolean readOnly) {
484
        super.setReadOnly(readOnly);
142 ilm 485
 
486
        if (this.hasRow()) {
487
            final int size = this.getRowsCount();
488
            for (int i = 0; i < size; i++) {
489
                final Row row = this.getRow(i);
132 ilm 490
                final List<Object> values = row.getValues();
491
                for (final Object value : values) {
174 ilm 492
                    if (value instanceof LightUIElement) {
132 ilm 493
                        ((LightUIElement) value).setReadOnly(readOnly);
494
                    }
495
                }
496
            }
497
        }
498
    }
499
 
500
    @Override
142 ilm 501
    public void _setValueFromContext(final Object value) {
132 ilm 502
        if (value != null) {
156 ilm 503
            final JSONArray jsonContext = JSONConverter.getObjectFromJSON(value, JSONArray.class);
132 ilm 504
            final ColumnsSpec columnsSpec = this.getTableSpec().getColumns();
505
            final int columnsCount = columnsSpec.getColumnCount();
506
 
156 ilm 507
            final List<Integer> editorsIndex = new ArrayList<>();
132 ilm 508
 
509
            for (int i = 0; i < columnsCount; i++) {
510
                final ColumnSpec columnSpec = columnsSpec.getColumn(i);
511
                if (columnSpec.getEditor() != null) {
512
                    editorsIndex.add(i);
513
                }
514
            }
515
 
142 ilm 516
            if (this.hasRow()) {
517
                final int size = this.getRowsCount();
518
                if (jsonContext.size() != size) {
180 ilm 519
                    throw new IllegalStateException("LightUITable.setValueFromContext() - Incorrect line count in JSON, row count:" + size + " context:" + jsonContext.size() + " (" + value + ")");
142 ilm 520
                } else {
521
 
522
                    for (int i = 0; i < size; i++) {
523
                        final Row row = this.getRow(i);
174 ilm 524
                        final JSONObject jsonLineContext = JSONConverter.getObjectFromJSON(jsonContext.get(i), JSONObject.class);
142 ilm 525
                        final Number rowId = JSONConverter.getParameterFromJSON(jsonLineContext, "row.id", Number.class);
174 ilm 526
                        final String rowExtendId = JSONConverter.getParameterFromJSON(jsonLineContext, "row.extend.id", String.class);
142 ilm 527
                        if (NumberUtils.areNumericallyEqual(rowId, row.getId()) && (row.getExtendId() == null || (row.getExtendId() != null && rowExtendId.equals(row.getExtendId())))) {
528
                            if (row.isFillWidth()) {
529
                                if (!row.getValues().isEmpty() && row.getValues().get(0) instanceof LightUserControl) {
530
                                    final LightUIElement element = (LightUIElement) row.getValues().get(0);
531
                                    if (element instanceof LightUserControl) {
532
                                        if (jsonLineContext.containsKey(element.getUUID())) {
533
                                            ((LightUserControl) element)._setValueFromContext(jsonLineContext.get(element.getUUID()));
534
                                        } else {
535
                                            System.out.println("LightUITable.setValueFromContext() - Unable to find element : id - " + element.getId() + " uuid - " + element.getUUID());
536
                                            System.out.println("LightUITable.setValueFromContext() - In JSON                : " + jsonLineContext.toJSONString());
537
                                        }
538
                                    }
539
                                }
540
                            } else {
541
                                for (int k = 0; k < editorsIndex.size(); k++) {
542
                                    final Object objEditor = row.getValues().get(editorsIndex.get(k));
543
                                    if (!(objEditor instanceof LightUserControl)) {
544
                                        throw new IllegalArgumentException("Impossible to find editor for row: " + rowId.toString() + " at position: " + String.valueOf(k));
545
                                    }
546
                                    final LightUIElement editor = (LightUIElement) objEditor;
547
 
548
                                    if (editor instanceof LightUserControl && jsonLineContext.containsKey(editor.getUUID())) {
549
                                        ((LightUserControl) editor)._setValueFromContext(jsonLineContext.get(editor.getUUID()));
132 ilm 550
                                    } else {
142 ilm 551
                                        throw new IllegalArgumentException(
552
                                                "Impossible to find value for editor: " + editor.getId() + " for row: " + rowId.toString() + " at position: " + String.valueOf(k));
132 ilm 553
                                    }
554
                                }
555
                            }
556
                        } else {
174 ilm 557
                            final List<Number> ids = new ArrayList<>(size);
144 ilm 558
                            for (int j = 0; j < size; j++) {
559
                                ids.add(this.getRow(j).getId());
560
                            }
561
                            throw new IllegalArgumentException("Impossible to find row: " + rowId.toString() + " known table row ids :" + ids);
132 ilm 562
                        }
563
                    }
564
                }
565
            }
566
        }
567
    }
568
 
569
    @Override
94 ilm 570
    public JSONObject toJSON() {
571
        final JSONObject json = super.toJSON();
132 ilm 572
        if (this.allowSelection) {
142 ilm 573
            json.put(ALLOW_SELECTION, true);
132 ilm 574
        }
142 ilm 575
        if (this.allowMultiSelection) {
576
            json.put(ALLOW_MULTI_SELECTION, true);
577
        }
132 ilm 578
        if (this.dynamicLoad) {
142 ilm 579
            json.put(DYNAMIC_LOAD, true);
132 ilm 580
        }
142 ilm 581
        if (!this.autoSelectFirstLine) {
582
            json.put(AUTO_SELECT_FIRST_LINE, false);
94 ilm 583
        }
132 ilm 584
        if (this.tableSpec != null) {
142 ilm 585
            json.put(TABLE_SPEC, this.tableSpec.toJSON());
94 ilm 586
        }
142 ilm 587
 
588
        json.put(LINE_PER_ROW, this.linePerRow);
94 ilm 589
        return json;
590
    }
591
 
592
    @Override
593
    public void fromJSON(final JSONObject json) {
594
        super.fromJSON(json);
142 ilm 595
        this.allowSelection = JSONConverter.getParameterFromJSON(json, ALLOW_SELECTION, Boolean.class, false);
596
        this.allowSelection = JSONConverter.getParameterFromJSON(json, ALLOW_MULTI_SELECTION, Boolean.class, false);
597
        this.dynamicLoad = JSONConverter.getParameterFromJSON(json, DYNAMIC_LOAD, Boolean.class, false);
598
        this.autoSelectFirstLine = JSONConverter.getParameterFromJSON(json, AUTO_SELECT_FIRST_LINE, Boolean.class, true);
599
        this.linePerRow = JSONConverter.getParameterFromJSON(json, LINE_PER_ROW, Integer.class);
132 ilm 600
 
144 ilm 601
        final JSONObject jsonRawContent = JSONConverter.getParameterFromJSON(json, TABLE_SPEC, JSONObject.class);
132 ilm 602
 
94 ilm 603
        if (jsonRawContent != null) {
604
            this.tableSpec = new TableSpec(jsonRawContent);
605
        }
606
    }
142 ilm 607
 
608
    @Override
609
    public void destroy() {
610
        super.destroy();
611
        this.selectionListeners.clear();
612
    }
94 ilm 613
}