94 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
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 |
|
|
|
16 |
import java.util.List;
|
|
|
17 |
|
|
|
18 |
import org.openconcerto.utils.io.JSONConverter;
|
|
|
19 |
import net.minidev.json.JSONObject;
|
|
|
20 |
|
|
|
21 |
public class LightUITable extends LightUIElement {
|
|
|
22 |
private Boolean verticallyScrollable = false;
|
|
|
23 |
private TableSpec tableSpec = null;
|
|
|
24 |
|
|
|
25 |
// Init from json constructor
|
|
|
26 |
public LightUITable(final JSONObject json) {
|
|
|
27 |
this.fromJSON(json);
|
|
|
28 |
}
|
|
|
29 |
// Clone constructor
|
|
|
30 |
public LightUITable(final LightUITable tableElement) {
|
|
|
31 |
super(tableElement);
|
|
|
32 |
this.verticallyScrollable = tableElement.verticallyScrollable;
|
|
|
33 |
this.tableSpec = tableElement.tableSpec;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
public LightUITable(final String id) {
|
|
|
37 |
this.setId(id);
|
|
|
38 |
this.setType(LightUIElement.TYPE_TABLE);
|
|
|
39 |
this.setFillWidth(true);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public TableSpec getTableSpec() {
|
|
|
43 |
return this.tableSpec;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public void setTableSpec(final TableSpec tableSpec) {
|
|
|
47 |
this.tableSpec = tableSpec;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public Boolean isVerticallyScrollable() {
|
|
|
51 |
return this.verticallyScrollable;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
public void setVerticallyScrollable(final Boolean verticallyScrollable) {
|
|
|
55 |
this.verticallyScrollable = verticallyScrollable;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public LightUIElement getElementById(final String elementId) {
|
|
|
59 |
if(this.tableSpec != null) {
|
|
|
60 |
final TableContent content = this.tableSpec.getContent();
|
|
|
61 |
if(content != null) {
|
|
|
62 |
final List<Row> listRows = content.getRows();
|
|
|
63 |
if(listRows != null && listRows.size() > 0) {
|
|
|
64 |
for(final Row row : listRows) {
|
|
|
65 |
final List<Object> rowValues = row.getValues();
|
|
|
66 |
for(final Object value : rowValues) {
|
|
|
67 |
if(value instanceof LightUIElement) {
|
|
|
68 |
final LightUIElement element = (LightUIElement) value;
|
|
|
69 |
if(element.getId().equals(elementId)) {
|
|
|
70 |
return element;
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
} else {
|
|
|
76 |
System.out.println("LightUITable.getElementById() - No rows for table: " + this.getId());
|
|
|
77 |
}
|
|
|
78 |
} else {
|
|
|
79 |
System.out.println("LightUITable.getElementById() - Null TableContent for table: " + this.getId());
|
|
|
80 |
}
|
|
|
81 |
} else {
|
|
|
82 |
System.out.println("LightUITable.getElementById() - Null TableSpec for table: " + this.getId());
|
|
|
83 |
}
|
|
|
84 |
return null;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
@Override
|
|
|
88 |
public LightUIElement clone() {
|
|
|
89 |
return new LightUITable(this);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
@Override
|
|
|
93 |
public JSONObject toJSON() {
|
|
|
94 |
final JSONObject json = super.toJSON();
|
|
|
95 |
if(this.verticallyScrollable) {
|
|
|
96 |
json.put("vertically-scrollable", true);
|
|
|
97 |
}
|
|
|
98 |
if(this.tableSpec != null) {
|
|
|
99 |
json.put("table-spec", this.tableSpec.toJSON());
|
|
|
100 |
}
|
|
|
101 |
return json;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
@Override
|
|
|
105 |
public void fromJSON(final JSONObject json) {
|
|
|
106 |
super.fromJSON(json);
|
|
|
107 |
this.verticallyScrollable = (Boolean) JSONConverter.getParameterFromJSON(json, "vertically-scrollable", Boolean.class, false);
|
|
|
108 |
|
|
|
109 |
final JSONObject jsonRawContent = (JSONObject) JSONConverter.getParameterFromJSON(json, "table-spec", JSONObject.class);
|
|
|
110 |
if (jsonRawContent != null) {
|
|
|
111 |
this.tableSpec = new TableSpec(jsonRawContent);
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
}
|