1 | |
package org.kuali.student.common.ui.client.widgets.table.summary; |
2 | |
|
3 | |
import java.util.HashMap; |
4 | |
|
5 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrPanel; |
6 | |
|
7 | |
import com.google.gwt.user.client.Element; |
8 | |
import com.google.gwt.user.client.ui.Anchor; |
9 | |
import com.google.gwt.user.client.ui.FlexTable; |
10 | |
import com.google.gwt.user.client.ui.HasVerticalAlignment; |
11 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
12 | |
import com.google.gwt.user.client.ui.Label; |
13 | |
|
14 | |
public class SummaryTable extends FlexTable{ |
15 | 0 | private SummaryTableModel model = new SummaryTableModel(); |
16 | 0 | private int rowIndex = 0; |
17 | 0 | private HashMap<String, Integer> rowMap = new HashMap<String, Integer>(); |
18 | 0 | public SummaryTable(){ |
19 | 0 | setStyleName("summaryTable"); |
20 | |
|
21 | 0 | getColumnFormatter().setStyleName(0, "rowTitleColunm"); |
22 | 0 | getColumnFormatter().setStyleName(1, "cell1Colunm"); |
23 | 0 | getColumnFormatter().setStyleName(2, "cell2Colunm"); |
24 | 0 | } |
25 | |
public SummaryTableModel getModel() { |
26 | 0 | return model; |
27 | |
} |
28 | |
public void setModel(SummaryTableModel model) { |
29 | 0 | this.model = model; |
30 | 0 | doLayout(); |
31 | 0 | } |
32 | |
public void doLayout(){ |
33 | 0 | rowIndex = 0; |
34 | 0 | this.removeAllRows(); |
35 | 0 | if(model.getContentColumnHeader1() != null && model.getContentColumnHeader2() != null){ |
36 | 0 | super.setText(rowIndex, 1, model.getContentColumnHeader1()); |
37 | 0 | super.setText(rowIndex, 2, model.getContentColumnHeader2()); |
38 | 0 | getFlexCellFormatter().setStyleName(rowIndex,1, "columnTitle"); |
39 | 0 | getFlexCellFormatter().setStyleName(rowIndex,2, "columnTitle"); |
40 | |
|
41 | 0 | rowIndex++; |
42 | |
} |
43 | 0 | for(SummaryTableBlock section: model.getSectionList()){ |
44 | 0 | addSection(section); |
45 | |
} |
46 | |
|
47 | 0 | } |
48 | |
|
49 | |
public void markDiffs(String style){ |
50 | |
|
51 | 0 | for(int i = 1; i < rowIndex; i++){ |
52 | 0 | if(getFlexCellFormatter().getColSpan(i, 0) == 1 && getFlexCellFormatter().getColSpan(i, 1) == 1 |
53 | |
&& getFlexCellFormatter().getColSpan(i, 2) == 1){ |
54 | 0 | Element cell1 = this.getCellFormatter().getElement(i, 1); |
55 | 0 | Element cell2 = this.getCellFormatter().getElement(i, 2); |
56 | 0 | if(!cell1.getInnerText().equals(cell2.getInnerText())){ |
57 | 0 | this.getRowFormatter().addStyleName(i, style); |
58 | |
} |
59 | |
else{ |
60 | 0 | this.getRowFormatter().removeStyleName(i, style); |
61 | |
} |
62 | |
} |
63 | |
} |
64 | 0 | } |
65 | |
|
66 | |
public boolean containsKey(String key){ |
67 | 0 | return rowMap.containsKey(key); |
68 | |
} |
69 | |
|
70 | |
public void highlightRow(String rowKey, String style){ |
71 | 0 | if(rowMap.containsKey(rowKey)){ |
72 | 0 | this.getRowFormatter().setStyleName(rowMap.get(rowKey).intValue(), style); |
73 | |
} |
74 | 0 | } |
75 | |
|
76 | |
public void clearHighlightRow(String rowKey, String removeThisStyle){ |
77 | 0 | if(rowMap.containsKey(rowKey)){ |
78 | 0 | this.getRowFormatter().removeStyleName(rowMap.get(rowKey).intValue(), removeThisStyle); |
79 | |
} |
80 | 0 | } |
81 | |
|
82 | |
public void clearHighlightedRows(String removeThisStyle){ |
83 | 0 | for(int i = 0; i < rowIndex; i++){ |
84 | 0 | this.getRowFormatter().removeStyleName(i, removeThisStyle); |
85 | |
} |
86 | 0 | } |
87 | |
|
88 | |
public void highlightCell(String rowKey, int cellIndex, String style){ |
89 | 0 | if(rowMap.containsKey(rowKey)){ |
90 | 0 | this.getCellFormatter().setStyleName(rowMap.get(rowKey).intValue(),cellIndex, style); |
91 | |
} |
92 | 0 | } |
93 | |
|
94 | |
public void clearHighlightCell(String rowKey, int cellIndex){ |
95 | 0 | if(rowMap.containsKey(rowKey)){ |
96 | 0 | this.getCellFormatter().setStyleName(rowMap.get(rowKey).intValue(),cellIndex,""); |
97 | |
} |
98 | |
|
99 | 0 | } |
100 | |
private void addSection(SummaryTableBlock section){ |
101 | 0 | int topRowIndex = -1; |
102 | 0 | if(section.getTitle() != null && !section.getTitle().isEmpty()){ |
103 | 0 | getFlexCellFormatter().setStyleName(rowIndex,0, "sectionTitleRow"); |
104 | 0 | getFlexCellFormatter().setColSpan(rowIndex, 0, 3); |
105 | 0 | getFlexCellFormatter().setVerticalAlignment(rowIndex, 0, HasVerticalAlignment.ALIGN_BOTTOM); |
106 | 0 | HorizontalPanel sectionTitlePanel = new HorizontalPanel(); |
107 | 0 | Label sectionTitle = new Label(section.getTitle()); |
108 | 0 | sectionTitlePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM); |
109 | 0 | sectionTitle.setStyleName("sectionTitle"); |
110 | 0 | sectionTitlePanel.add(sectionTitle); |
111 | |
|
112 | 0 | if(model.isEditable()){ |
113 | 0 | Anchor sectionEditLink = new Anchor("Edit"); |
114 | 0 | sectionEditLink.setStyleName("sectionEditLink"); |
115 | 0 | if(section.getEditingHandler() != null){ |
116 | 0 | sectionEditLink.addClickHandler(section.getEditingHandler()); |
117 | |
} |
118 | 0 | sectionTitlePanel.add(sectionEditLink); |
119 | |
|
120 | |
} |
121 | 0 | setWidget(rowIndex,0, sectionTitlePanel); |
122 | 0 | rowIndex++; |
123 | 0 | } |
124 | |
else{ |
125 | 0 | topRowIndex = rowIndex; |
126 | |
} |
127 | |
|
128 | 0 | for(SummaryTableRow row: section.getSectionRowList()){ |
129 | 0 | addSectionRow(row); |
130 | |
} |
131 | |
|
132 | 0 | if(topRowIndex != -1){ |
133 | 0 | this.getRowFormatter().addStyleName(topRowIndex, "firstRowInUnnamedBlock"); |
134 | |
} |
135 | |
|
136 | 0 | } |
137 | |
private void addSectionRow(SummaryTableRow row){ |
138 | 0 | if(row.isShown()){ |
139 | 0 | if(row.isRequired()){ |
140 | 0 | AbbrPanel required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
141 | 0 | setHTML(rowIndex,0, row.getTitle() + required.toString()); |
142 | 0 | } |
143 | |
else{ |
144 | 0 | setText(rowIndex,0, row.getTitle()); |
145 | |
} |
146 | 0 | getFlexCellFormatter().setStyleName(rowIndex,0, "rowTitle"); |
147 | 0 | if(row.getTitleCellStyleName() != null){ |
148 | 0 | getFlexCellFormatter().addStyleName(rowIndex,0, row.getTitleCellStyleName()); |
149 | |
} |
150 | 0 | if(row.getContentCellCount() == 1){ |
151 | 0 | setWidget(rowIndex,1, row.getCell1()); |
152 | 0 | getFlexCellFormatter().setStyleName(rowIndex,1, "cell1"); |
153 | 0 | getFlexCellFormatter().setColSpan(rowIndex, 1,2); |
154 | 0 | if(row.getContentCellStyleName() != null){ |
155 | 0 | getFlexCellFormatter().addStyleName(rowIndex,1, row.getContentCellStyleName()); |
156 | |
} |
157 | 0 | }else if(row.getContentCellCount() == 2){ |
158 | 0 | setWidget(rowIndex,1, row.getCell1()); |
159 | 0 | setWidget(rowIndex,2,row.getCell2()); |
160 | 0 | getFlexCellFormatter().setColSpan(rowIndex, 1,1); |
161 | 0 | getFlexCellFormatter().setColSpan(rowIndex, 2,1); |
162 | 0 | getFlexCellFormatter().setStyleName(rowIndex,1, "cell1"); |
163 | 0 | getFlexCellFormatter().setStyleName(rowIndex,2, "cell2"); |
164 | 0 | if(row.getContentCellStyleName() != null){ |
165 | 0 | getFlexCellFormatter().addStyleName(rowIndex,1, row.getContentCellStyleName()); |
166 | 0 | getFlexCellFormatter().addStyleName(rowIndex,2, row.getContentCellStyleName()); |
167 | |
} |
168 | |
} |
169 | 0 | rowMap.put(row.getKey(), rowIndex); |
170 | 0 | rowIndex++; |
171 | |
} |
172 | 0 | } |
173 | |
|
174 | |
} |