1 | |
package org.kuali.student.common.ui.client.widgets.field.layout.layouts; |
2 | |
|
3 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
4 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.ValidationMessagePanel; |
5 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonLayout; |
6 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement; |
7 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel; |
8 | |
|
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.Widget; |
12 | |
|
13 | |
public class HorizontalLayout extends FieldLayout{ |
14 | 0 | private FlexTable horizontalArea = new FlexTable(); |
15 | 0 | private ValidationMessagePanel validationPanel = new ValidationMessagePanel(); |
16 | 0 | private SpanPanel fieldArea = new SpanPanel(); |
17 | |
private SpanPanel buttonArea; |
18 | 0 | private int currentRow = 0; |
19 | 0 | private int currentColumn = 0; |
20 | |
|
21 | |
public HorizontalLayout(){ |
22 | 0 | super(); |
23 | 0 | hasValidation = true; |
24 | 0 | init(); |
25 | 0 | } |
26 | |
|
27 | |
public HorizontalLayout(boolean hasValidation){ |
28 | 0 | super(); |
29 | 0 | this.hasValidation = hasValidation; |
30 | 0 | init(); |
31 | 0 | } |
32 | |
|
33 | |
public HorizontalLayout(SectionTitle title){ |
34 | 0 | super(); |
35 | 0 | this.setLayoutTitle(title); |
36 | 0 | hasValidation = true; |
37 | 0 | init(); |
38 | 0 | } |
39 | |
|
40 | |
public HorizontalLayout(SectionTitle title, boolean hasValidation){ |
41 | 0 | super(); |
42 | 0 | this.setLayoutTitle(title); |
43 | 0 | this.hasValidation = hasValidation; |
44 | 0 | init(); |
45 | |
|
46 | 0 | } |
47 | |
|
48 | |
private void init(){ |
49 | 0 | instructions.setVisible(false); |
50 | 0 | this.add(instructions); |
51 | 0 | this.add(message); |
52 | 0 | if(hasValidation){ |
53 | 0 | this.add(validationPanel); |
54 | |
} |
55 | 0 | this.add(horizontalArea); |
56 | 0 | } |
57 | |
|
58 | |
@Override |
59 | |
public void addButtonLayoutToLayout(ButtonLayout buttonLayout) { |
60 | 0 | if(buttonArea == null){ |
61 | 0 | buttonArea = new SpanPanel(); |
62 | 0 | this.add(buttonArea); |
63 | |
} |
64 | 0 | buttonArea.add(buttonLayout); |
65 | 0 | } |
66 | |
|
67 | |
@Override |
68 | |
public void addFieldToLayout(FieldElement field) { |
69 | 0 | horizontalArea.setWidget(currentRow, currentColumn, field); |
70 | 0 | horizontalArea.getFlexCellFormatter().setVerticalAlignment(currentRow, currentColumn, HasVerticalAlignment.ALIGN_TOP); |
71 | |
|
72 | 0 | if(hasValidation){ |
73 | 0 | field.setValidationPanel(validationPanel); |
74 | |
} |
75 | 0 | currentColumn++; |
76 | 0 | } |
77 | |
|
78 | |
@Override |
79 | |
public void addLayoutToLayout(FieldLayout layout) { |
80 | 0 | horizontalArea.setWidget(currentRow, currentColumn, layout); |
81 | 0 | horizontalArea.getFlexCellFormatter().setVerticalAlignment(currentRow, currentColumn, HasVerticalAlignment.ALIGN_TOP); |
82 | 0 | currentColumn++; |
83 | 0 | } |
84 | |
|
85 | |
@Override |
86 | |
public void addWidgetToLayout(Widget widget) { |
87 | 0 | horizontalArea.setWidget(currentRow, currentColumn, widget); |
88 | 0 | horizontalArea.getFlexCellFormatter().setVerticalAlignment(currentRow, currentColumn, HasVerticalAlignment.ALIGN_TOP); |
89 | 0 | currentColumn++; |
90 | 0 | } |
91 | |
|
92 | |
public void nextRow(){ |
93 | 0 | currentRow++; |
94 | 0 | currentColumn = 0; |
95 | 0 | } |
96 | |
|
97 | |
@Override |
98 | |
public void removeFieldLayoutComponentFromLayout( |
99 | |
FieldLayoutComponent component) { |
100 | 0 | if(component instanceof FieldElement){ |
101 | 0 | horizontalArea.remove((FieldElement)component); |
102 | |
} |
103 | 0 | else if(component instanceof FieldLayout){ |
104 | 0 | horizontalArea.remove((FieldLayout)component); |
105 | |
} |
106 | |
|
107 | 0 | } |
108 | |
|
109 | |
@Override |
110 | |
public void removeWidgetFromLayout(Widget widget) { |
111 | 0 | horizontalArea.remove(widget); |
112 | 0 | } |
113 | |
|
114 | |
@Override |
115 | |
public void setLayoutTitle(SectionTitle layoutTitle) { |
116 | 0 | if(this.layoutTitle != null){ |
117 | 0 | this.remove(this.layoutTitle); |
118 | |
} |
119 | 0 | if(layoutTitle != null){ |
120 | 0 | this.layoutTitle = layoutTitle; |
121 | 0 | this.insert(layoutTitle, 0); |
122 | 0 | layoutTitle.addStyleName("ks-layout-header"); |
123 | |
} |
124 | |
|
125 | 0 | } |
126 | |
|
127 | |
} |