1 package org.kuali.student.common.ui.client.widgets.table.summary;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.kuali.student.common.assembly.data.Data;
7 import org.kuali.student.common.assembly.data.Metadata;
8 import org.kuali.student.common.assembly.data.QueryPath;
9 import org.kuali.student.common.assembly.data.Data.DataType;
10 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
11 import org.kuali.student.common.ui.client.mvc.DataModel;
12 import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
13 import org.kuali.student.common.ui.client.util.PrintUtils;
14 import org.kuali.student.common.ui.client.widgets.KSButton;
15 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
16
17 import com.google.gwt.event.dom.client.ClickEvent;
18 import com.google.gwt.event.dom.client.ClickHandler;
19 import com.google.gwt.user.client.ui.Button;
20 import com.google.gwt.user.client.ui.Composite;
21 import com.google.gwt.user.client.ui.Label;
22 import com.google.gwt.user.client.ui.VerticalPanel;
23 import com.google.gwt.user.client.ui.Widget;
24
25 public class SummaryTableDemo extends Composite {
26 public SummaryTableDemo() {
27 super.initWidget(createDemoPage());
28
29 }
30 private Widget createSummaryTableFromDataModel(){
31 VerticalPanel p = new VerticalPanel();
32 p.setPixelSize(800, 800);
33
34
35 Metadata meta = new Metadata();
36 meta.setCanView(true);
37 meta.setDataType(DataType.DATA);
38
39 Map<String, Metadata> metadatas = new HashMap<String,Metadata>();
40 Metadata fieldMeta = new Metadata();
41 fieldMeta.setCanView(true);
42 fieldMeta.setDataType(DataType.STRING);
43 metadatas.put("field1", fieldMeta);
44
45 meta.setProperties(metadatas);
46
47 final DataModel datamodel = new DataModel();
48 DataModelDefinition definition = new DataModelDefinition();
49 definition.setMetadata(meta);
50
51 datamodel.setDefinition(definition);
52 datamodel.setRoot(new Data());
53 datamodel.set(QueryPath.parse("/field1"), "value");
54
55 final SummaryTableSection tableSection = new SummaryTableSection(null);
56 tableSection.setContentColumnHeader1("Title 1");
57
58 String fieldKey = "/field1";
59 MessageKeyInfo messageKey = new MessageKeyInfo("/field1");
60
61
62
63 FieldDescriptor fd = new FieldDescriptor(fieldKey, messageKey,fieldMeta);
64 FieldDescriptor fd2 = new FieldDescriptor(fieldKey, messageKey,fieldMeta);
65
66 SummaryTableFieldRow fieldRow = new SummaryTableFieldRow(fd,fd2);
67 SummaryTableFieldBlock block = new SummaryTableFieldBlock();
68 block.addSummaryTableFieldRow(fieldRow);
69 block.setTitle("sectionTitle");
70 tableSection.addSummaryTableFieldBlock(block);
71 tableSection.updateWidgetData(datamodel);
72 p.add(tableSection);
73
74
75
76
77 Button button = new Button("Change Data");
78 button.addClickHandler(new ClickHandler(){
79
80 @Override
81 public void onClick(ClickEvent event) {
82 datamodel.set(QueryPath.parse("/field1"), "new value");
83 tableSection.updateWidgetData(datamodel);
84 }
85
86 });
87 p.add(button);
88 return p;
89 }
90
91 private Widget createDemoPage(){
92 VerticalPanel p = new VerticalPanel();
93 p.setPixelSize(800, 800);
94 final SummaryTable summaryTable = new SummaryTable();
95 SummaryTableModel model = new SummaryTableModel();
96 model.setEditable(true);
97 model.setContentColumnHeader1("Title 1");
98 model.setContentColumnHeader2("Title 2");
99
100 SummaryTableBlock section = new SummaryTableBlock();
101 section.setTitle("section 1");
102
103
104 section.add(createRow1());
105 section.add(createRow2());
106 model.addSection(section);
107
108 section = new SummaryTableBlock();
109 section.setTitle("section 2");
110
111
112 section.add(createRow1());
113 section.add(createRow2());
114
115 model.addSection(section);
116 summaryTable.setModel(model);
117
118 summaryTable.highlightCell("key1",1, "cellHighlight");
119 p.add(summaryTable);
120 p.add(new KSButton("Print", new ClickHandler(){
121
122 @Override
123 public void onClick(ClickEvent event) {
124 PrintUtils.print(summaryTable);
125
126 }
127 }));
128 return p;
129 }
130 private SummaryTableRow createRow2(){
131 SummaryTableRow row = new SummaryTableRow();
132 row.setKey("key1");
133 row.setTitle("Row 2");
134 row.setCell1(new Label("content 2"));
135 return row;
136 }
137 private SummaryTableRow createRow1(){
138 SummaryTableRow row = new SummaryTableRow();
139 row.setTitle("Row 1");
140 row.setContentCellCount(2);
141 row.setCell1(new Label("content 1"));
142
143 row.setCell2(new Label("content 1"));
144 return row;
145 }
146 }