package foundation.menu;
|
|
import foundation.dao.preload.Node;
|
import foundation.data.entity.Entity;
|
import foundation.json.IJSONProvider;
|
import foundation.json.IJSONWriter;
|
|
public class Menu extends Node implements IJSONProvider {
|
|
private String id;
|
private String parentId;
|
private int orderNo;
|
private Entity entity;
|
|
public Menu() {
|
|
}
|
|
public void load(Entity entity) {
|
this.entity = entity;
|
id = entity.getString("id");
|
parentId = entity.getString("parent_id");
|
orderNo = entity.getInteger("order_no", 0);
|
}
|
|
public void copyFrom(Menu menu) {
|
this.id = menu.id;
|
this.parentId = menu.parentId;
|
this.orderNo = menu.orderNo;
|
this.entity = menu.entity;
|
}
|
|
public void addOneChild(Menu child) {
|
child.parent = this;
|
children.add(child.getId(), child);
|
}
|
|
public Entity getEntity() {
|
return entity;
|
}
|
|
public String getId() {
|
return id;
|
}
|
|
public String getParentId() {
|
return parentId;
|
}
|
|
public int getOrderNo() {
|
return orderNo;
|
}
|
|
@Override
|
public void writeJSON(IJSONWriter writer) {
|
writer.beginObject();
|
writeJSONBody(writer);
|
writer.endObject();
|
}
|
|
public void writeJSONBody(IJSONWriter writer) {
|
entity.writeJSONBody(writer);
|
|
if (!children.isEmpty()) {
|
writer.beginArray("children");
|
|
for (Node child: children) {
|
child.writeJSON(writer);
|
}
|
|
writer.endArray();
|
}
|
}
|
|
}
|