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