|
@@ -1,15 +1,9 @@ |
1 |
1 |
|
package com.temp.client.foundation.widget.table.cell; |
2 |
2 |
|
|
3 |
|
- |
import com.google.gwt.cell.client.AbstractEditableCell; |
4 |
|
- |
import com.google.gwt.cell.client.Cell; |
5 |
|
- |
import com.google.gwt.cell.client.ValueUpdater; |
6 |
|
- |
import com.google.gwt.dom.client.Element; |
7 |
|
- |
import com.google.gwt.dom.client.InputElement; |
8 |
|
- |
import com.google.gwt.dom.client.NativeEvent; |
9 |
|
- |
import com.google.gwt.event.dom.client.KeyCodes; |
10 |
|
- |
import com.google.gwt.safehtml.shared.SafeHtml; |
11 |
|
- |
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
12 |
|
- |
import com.google.gwt.safehtml.shared.SafeHtmlUtils; |
|
3 |
+ |
import com.google.gwt.cell.client.*; |
|
4 |
+ |
import com.google.gwt.dom.client.*; |
|
5 |
+ |
import com.google.gwt.event.dom.client.*; |
|
6 |
+ |
import com.google.gwt.safehtml.shared.*; |
13 |
7 |
|
|
14 |
8 |
|
/** |
15 |
9 |
|
* A {@link Cell} used to render a radio button. The value of the radio button |
|
@@ -29,8 +23,8 @@ |
29 |
23 |
|
* Constructs a new {@link RadioButtonCell} that does not depend on |
30 |
24 |
|
* selection and does not handle selection. |
31 |
25 |
|
*/ |
32 |
|
- |
public RadioButtonCell(boolean enabled, String name) { |
33 |
|
- |
super("change", "keydown"); |
|
26 |
+ |
public RadioButtonCell( boolean enabled, String name ) { |
|
27 |
+ |
super( "change", "keydown" ); |
34 |
28 |
|
this.enabled = enabled; |
35 |
29 |
|
this.name = name; |
36 |
30 |
|
} |
|
@@ -39,20 +33,16 @@ |
39 |
33 |
|
* Constructs a new {@link RadioButtonCell} that can be configured to depend |
40 |
34 |
|
* and/or handle selection |
41 |
35 |
|
* |
42 |
|
- |
* @param groupName |
43 |
|
- |
* HTML name attribute of the radiobutton |
44 |
|
- |
* @param dependsOnSelection |
45 |
|
- |
* true if the cell depends on the selection state |
46 |
|
- |
* @param handlesSelection |
47 |
|
- |
* true if the cell modifies the selection state |
|
36 |
+ |
* @param groupName HTML name attribute of the radiobutton |
|
37 |
+ |
* @param dependsOnSelection true if the cell depends on the selection state |
|
38 |
+ |
* @param handlesSelection true if the cell modifies the selection state |
48 |
39 |
|
*/ |
49 |
|
- |
public RadioButtonCell(boolean dependsOnSelection, boolean handlesSelection, boolean enabled, String name) { |
50 |
|
- |
this(enabled,name); |
|
40 |
+ |
public RadioButtonCell( boolean dependsOnSelection, boolean handlesSelection, boolean enabled, String name ) { |
|
41 |
+ |
this( enabled, name ); |
51 |
42 |
|
this.dependsOnSelection = dependsOnSelection; |
52 |
43 |
|
this.handlesSelection = handlesSelection; |
53 |
44 |
|
} |
54 |
45 |
|
|
55 |
|
- |
|
56 |
46 |
|
@Override |
57 |
47 |
|
public boolean dependsOnSelection() { |
58 |
48 |
|
return dependsOnSelection; |
|
@@ -64,13 +54,13 @@ |
64 |
54 |
|
} |
65 |
55 |
|
|
66 |
56 |
|
@Override |
67 |
|
- |
public void onBrowserEvent(Context context, Element parent, Boolean value, |
68 |
|
- |
NativeEvent event, ValueUpdater<Boolean> valueUpdater) { |
|
57 |
+ |
public void onBrowserEvent( Context context, Element parent, Boolean value, |
|
58 |
+ |
NativeEvent event, ValueUpdater<Boolean> valueUpdater ) { |
69 |
59 |
|
String type = event.getType(); |
70 |
60 |
|
|
71 |
|
- |
boolean enterPressed = "keydown".equals(type) |
72 |
|
- |
&& event.getKeyCode() == KeyCodes.KEY_ENTER; |
73 |
|
- |
if ("change".equals(type) || enterPressed) { |
|
61 |
+ |
boolean enterPressed = "keydown".equals( type ) |
|
62 |
+ |
&& event.getKeyCode() == KeyCodes.KEY_ENTER; |
|
63 |
+ |
if ( "change".equals( type ) || enterPressed ) { |
74 |
64 |
|
InputElement input = parent.getFirstChild().cast(); |
75 |
65 |
|
Boolean isChecked = input.isChecked(); |
76 |
66 |
|
|
|
@@ -81,9 +71,9 @@ |
81 |
71 |
|
* let the SelectionEventManager determine which keys will trigger a |
82 |
72 |
|
* change. |
83 |
73 |
|
*/ |
84 |
|
- |
if (enterPressed && (handlesSelection() || !dependsOnSelection())) { |
|
74 |
+ |
if ( enterPressed && (handlesSelection() || !dependsOnSelection()) ) { |
85 |
75 |
|
isChecked = true; |
86 |
|
- |
input.setChecked(isChecked); |
|
76 |
+ |
input.setChecked( isChecked ); |
87 |
77 |
|
} |
88 |
78 |
|
|
89 |
79 |
|
/** |
|
@@ -91,65 +81,65 @@ |
91 |
81 |
|
* do not save the value because we can get into an inconsistent state. |
92 |
82 |
|
*/ |
93 |
83 |
|
Object key = context.getKey(); |
94 |
|
- |
if (value != isChecked && !dependsOnSelection()) { |
95 |
|
- |
setViewData(key, isChecked); |
|
84 |
+ |
if ( value != isChecked && !dependsOnSelection() ) { |
|
85 |
+ |
setViewData( key, isChecked ); |
96 |
86 |
|
} else { |
97 |
|
- |
clearViewData(key); |
|
87 |
+ |
clearViewData( key ); |
98 |
88 |
|
} |
99 |
89 |
|
|
100 |
|
- |
if (valueUpdater != null) { |
101 |
|
- |
valueUpdater.update(isChecked); |
|
90 |
+ |
if ( valueUpdater != null ) { |
|
91 |
+ |
valueUpdater.update( isChecked ); |
102 |
92 |
|
} |
103 |
93 |
|
} |
104 |
94 |
|
} |
105 |
95 |
|
|
106 |
96 |
|
@Override |
107 |
|
- |
public boolean isEditing(com.google.gwt.cell.client.Cell.Context context, |
108 |
|
- |
Element parent, Boolean value) { |
|
97 |
+ |
public boolean isEditing( com.google.gwt.cell.client.Cell.Context context, |
|
98 |
+ |
Element parent, Boolean value ) { |
109 |
99 |
|
// A radio button is never in "edit mode". There is no intermediate state |
110 |
100 |
|
// between checked and unchecked. |
111 |
101 |
|
return false; |
112 |
102 |
|
} |
113 |
103 |
|
|
114 |
104 |
|
@Override |
115 |
|
- |
public void render(com.google.gwt.cell.client.Cell.Context context, |
116 |
|
- |
Boolean value, SafeHtmlBuilder sb) { |
|
105 |
+ |
public void render( com.google.gwt.cell.client.Cell.Context context, |
|
106 |
+ |
Boolean value, SafeHtmlBuilder sb ) { |
117 |
107 |
|
Object key = context.getKey(); |
118 |
|
- |
Boolean viewData = getViewData(key); |
119 |
|
- |
if (viewData != null && viewData.equals(value)) { |
120 |
|
- |
clearViewData(key); |
|
108 |
+ |
Boolean viewData = getViewData( key ); |
|
109 |
+ |
if ( viewData != null && viewData.equals( value ) ) { |
|
110 |
+ |
clearViewData( key ); |
121 |
111 |
|
viewData = null; |
122 |
112 |
|
} |
123 |
113 |
|
|
124 |
|
- |
if (value != null && ((viewData != null) ? viewData : value)) { |
125 |
|
- |
sb.append(this.getRadioButtonInput(true)); |
|
114 |
+ |
if ( value != null && ((viewData != null) ? viewData : value) ) { |
|
115 |
+ |
sb.append( this.getRadioButtonInput( true ) ); |
126 |
116 |
|
} else { |
127 |
|
- |
sb.append(this.getRadioButtonInput(false)); |
|
117 |
+ |
sb.append( this.getRadioButtonInput( false ) ); |
128 |
118 |
|
} |
129 |
119 |
|
} |
130 |
120 |
|
|
131 |
121 |
|
/** |
132 |
122 |
|
* Provides an HTML string representation of a radio button |
|
123 |
+ |
* |
133 |
124 |
|
* @param selected |
134 |
125 |
|
*/ |
135 |
|
- |
private SafeHtml getRadioButtonInput(boolean selected) { |
136 |
|
- |
StringBuffer sb = new StringBuffer(RADIO_INPUT_TEMPLATE_START); |
|
126 |
+ |
private SafeHtml getRadioButtonInput( boolean selected ) { |
|
127 |
+ |
StringBuffer sb = new StringBuffer( RADIO_INPUT_TEMPLATE_START ); |
137 |
128 |
|
|
138 |
|
- |
String safeName = SafeHtmlUtils.htmlEscape(this.name); |
|
129 |
+ |
String safeName = SafeHtmlUtils.htmlEscape( this.name ); |
139 |
130 |
|
|
140 |
131 |
|
sb.append( (null == this.name) ? "" : safeName ); |
141 |
|
- |
sb.append("\" "); |
|
132 |
+ |
sb.append( "\" " ); |
142 |
133 |
|
|
143 |
|
- |
if(selected) { |
144 |
|
- |
sb.append(RADIO_INPUT_SELECTED_TOKEN); |
|
134 |
+ |
if ( selected ) { |
|
135 |
+ |
sb.append( RADIO_INPUT_SELECTED_TOKEN ); |
145 |
136 |
|
} |
146 |
137 |
|
|
147 |
|
- |
if(!this.enabled) { |
148 |
|
- |
sb.append(RADIO_INPUT_DISABLED_TOKEN); |
|
138 |
+ |
if ( !this.enabled ) { |
|
139 |
+ |
sb.append( RADIO_INPUT_DISABLED_TOKEN ); |
149 |
140 |
|
} |
150 |
141 |
|
|
151 |
|
- |
sb.append(RADIO_INPUT_TEMPLATE_END); |
152 |
|
- |
return SafeHtmlUtils.fromSafeConstant(sb.toString()); |
|
142 |
+ |
sb.append( RADIO_INPUT_TEMPLATE_END ); |
|
143 |
+ |
return SafeHtmlUtils.fromSafeConstant( sb.toString() ); |
153 |
144 |
|
} |
154 |
|
- |
|
155 |
145 |
|
} |