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