P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
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
package foundation.page;
 
import foundation.data.entity.Entity;
import foundation.json.IJSONProvider;
import foundation.json.IJSONWriter;
import foundation.util.MapList;
 
public class Page implements IJSONProvider {
 
    private String id;
    private String code;
    private String title;
    private String url;
    private boolean active;
    private MapList<String, Tab> tabs;
    private MapList<String, Button> buttons;
    
    
    public Page() {
        tabs = new MapList<String, Tab>();
        buttons = new MapList<String, Button>();
    }
 
    public void load(Entity entity) {
        id = entity.getString("id");
        code = entity.getString("code");
        title = entity.getString("title");
        url = entity.getString("url");
        active = entity.getBoolean("active", true);
    }
    
    public void loadOneTab(Tab tab) {
        tabs.add(tab.getId(), tab);
    }
    
    public Tab getTab(String tabId) {
        return tabs.get(tabId);
    }
    
    public void loadOneButton(Button button) {
        buttons.add(button.getId(), button);
    }
 
    public Button getButton(String buttonId) {
        return buttons.get(buttonId);
    }
 
    public String getId() {
        return id;
    }
    
    public String getCode() {
        return code;
    }
 
    public String getTitle() {
        return title;
    }
 
    public String getUrl() {
        return url;
    }
 
    public boolean isActive() {
        return active;
    }
 
    @Override
    public void writeJSON(IJSONWriter writer) {
        writer.beginObject("page");
        writeJSONBody(writer);
        writer.endObject();
    }
 
    public void writeJSONPageBody(IJSONWriter writer) {
        writer.write("id", id);
        writer.write("code", code);
        writer.write("title", title);
        writer.write("url", url);
        writer.write("active", active);
    }
    public void writeJSONBody(IJSONWriter writer) {
        //1. write page
        writeJSONPageBody(writer);
        
        //2. write tabs
        writer.beginArray("tabs");
        
        for (Tab tab: tabs) {
            writeOneTab(writer, tab);
        }
        
        writer.endArray();
        
        //3. write buttons
        writer.beginArray("buttons");
        
        for (Button button: buttons) {
            writeOneButton(writer, button);
        }
        
        writer.endArray();
    }
 
    private void writeOneTab(IJSONWriter writer, Tab tab) {
        writer.beginObject();
        writer.write("name", tab.getName());
        writer.endObject();    
    }
    
    private void writeOneButton(IJSONWriter writer, Button button) {
        writer.beginObject();
        writer.write("code", button.getCode());
        writer.write("title", button.getTitle());
        writer.write("visible", true);
        writer.write("active", true);
        writer.endObject();        
    }
 
}