Skip to content

Commit 36a270f

Browse files
committed
Added helper classes to build internal data easily
1 parent cd234a2 commit 36a270f

File tree

6 files changed

+74
-12
lines changed

6 files changed

+74
-12
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package gwt.material.design.amcore.client.data;
2+
3+
import com.google.gwt.core.client.JavaScriptObject;
4+
import com.google.gwt.json.client.JSONArray;
5+
import com.google.gwt.json.client.JSONObject;
6+
import com.google.gwt.json.client.JSONValue;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
public class ChartData<T> {
12+
13+
private List<DataProvider<T>> providers = new ArrayList<>();
14+
private List<T> data = new ArrayList<>();
15+
16+
public ChartData() {
17+
}
18+
19+
public ChartData(List<T> data) {
20+
this.data = data;
21+
}
22+
23+
public ChartData add(DataProvider<T> providers) {
24+
this.providers.add(providers);
25+
return this;
26+
}
27+
28+
public JavaScriptObject get() {
29+
JSONArray array = new JSONArray();
30+
data.forEach(t -> {
31+
if (t != null) {
32+
JSONObject object = new JSONObject();
33+
providers.forEach(provider -> {
34+
String property = provider.getProperty();
35+
JSONValue value = provider.getValue(t);
36+
37+
if (property != null && value != null) {
38+
object.put(property, value);
39+
}
40+
});
41+
array.set(data.indexOf(t), object);
42+
}
43+
});
44+
return array.getJavaScriptObject();
45+
}
46+
47+
48+
public List<T> getData() {
49+
return data;
50+
}
51+
52+
public void setData(List<T> data) {
53+
this.data = data;
54+
}
55+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package gwt.material.design.amcore.client.data;
2+
3+
import com.google.gwt.json.client.JSONValue;
4+
5+
public interface DataProvider<T> {
6+
7+
String getProperty();
8+
9+
JSONValue getValue(T object);
10+
}

src/main/java/gwt/material/design/amcore/client/data/DataSource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,7 +31,7 @@
3131
import jsinterop.annotations.JsType;
3232

3333
@JsType(isNative = true)
34-
public class DataSource extends BaseObjectsEvents {
34+
public class DataSource extends BaseObjectsEvents {
3535

3636
@JsProperty
3737
public Component component;

src/main/java/gwt/material/design/amcore/client/data/parser/CSVOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

src/main/java/gwt/material/design/amcore/client/data/parser/CSVParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

src/main/java/gwt/material/design/amcore/client/data/parser/DataParser.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,9 +19,6 @@
1919
*/
2020
package gwt.material.design.amcore.client.data.parser;
2121

22-
import gwt.material.design.amcore.client.events.EventTarget;
23-
import gwt.material.design.jquery.client.api.Functions;
24-
import jsinterop.annotations.JsMethod;
2522
import jsinterop.annotations.JsProperty;
2623
import jsinterop.annotations.JsType;
2724

0 commit comments

Comments
 (0)