|
@@ -1,15 +1,9 @@ |
1 |
1 |
|
package com.temp.client.foundation.widget.table.cell; |
2 |
2 |
|
|
3 |
|
- |
|
4 |
|
- |
import com.google.gwt.cell.client.AbstractEditableCell; |
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 |
|
public abstract class AbstractDisableableBooleanEditableCell extends AbstractEditableCell<Boolean, Boolean> { |
15 |
9 |
|
public static class CellHtmlProvider { |
|
@@ -18,11 +12,11 @@ |
18 |
12 |
|
private final SafeHtml disabledSelected; |
19 |
13 |
|
private final SafeHtml disabledNotSelected; |
20 |
14 |
|
|
21 |
|
- |
public CellHtmlProvider(String enabledSelected, String enabledNotSelected, String disabledSelected, String disabledNotSelected) { |
22 |
|
- |
this.enabledSelected = SafeHtmlUtils.fromTrustedString(enabledSelected); |
23 |
|
- |
this.enabledNotSelected = SafeHtmlUtils.fromTrustedString(enabledNotSelected); |
24 |
|
- |
this.disabledSelected = SafeHtmlUtils.fromTrustedString(disabledSelected); |
25 |
|
- |
this.disabledNotSelected = SafeHtmlUtils.fromTrustedString(disabledNotSelected); |
|
15 |
+ |
public CellHtmlProvider( String enabledSelected, String enabledNotSelected, String disabledSelected, String disabledNotSelected ) { |
|
16 |
+ |
this.enabledSelected = SafeHtmlUtils.fromTrustedString( enabledSelected ); |
|
17 |
+ |
this.enabledNotSelected = SafeHtmlUtils.fromTrustedString( enabledNotSelected ); |
|
18 |
+ |
this.disabledSelected = SafeHtmlUtils.fromTrustedString( disabledSelected ); |
|
19 |
+ |
this.disabledNotSelected = SafeHtmlUtils.fromTrustedString( disabledNotSelected ); |
26 |
20 |
|
} |
27 |
21 |
|
|
28 |
22 |
|
public SafeHtml htmlEnabledSelected() { |
|
@@ -50,10 +44,10 @@ |
50 |
44 |
|
* Construct a new AbstractDisableableBooleanEditableCell that optionally controls selection. |
51 |
45 |
|
* |
52 |
46 |
|
* @param dependsOnSelection true if the cell depends on the selection state |
53 |
|
- |
* @param handlesSelection true if the cell modifies the selection state |
|
47 |
+ |
* @param handlesSelection true if the cell modifies the selection state |
54 |
48 |
|
*/ |
55 |
|
- |
protected AbstractDisableableBooleanEditableCell(boolean dependsOnSelection, boolean handlesSelection, CellHtmlProvider htmlProvider) { |
56 |
|
- |
super("change", "keydown"); |
|
49 |
+ |
protected AbstractDisableableBooleanEditableCell( boolean dependsOnSelection, boolean handlesSelection, CellHtmlProvider htmlProvider ) { |
|
50 |
+ |
super( "change", "keydown" ); |
57 |
51 |
|
this.htmlProvider = htmlProvider; |
58 |
52 |
|
this.dependsOnSelection = dependsOnSelection; |
59 |
53 |
|
this.handlesSelection = handlesSelection; |
|
@@ -64,15 +58,15 @@ |
64 |
58 |
|
* |
65 |
59 |
|
* @param isSelectBox true if the cell controls the selection state |
66 |
60 |
|
*/ |
67 |
|
- |
protected AbstractDisableableBooleanEditableCell(boolean isSelectBox, CellHtmlProvider htmlProvider) { |
68 |
|
- |
this(isSelectBox, isSelectBox, htmlProvider); |
|
61 |
+ |
protected AbstractDisableableBooleanEditableCell( boolean isSelectBox, CellHtmlProvider htmlProvider ) { |
|
62 |
+ |
this( isSelectBox, isSelectBox, htmlProvider ); |
69 |
63 |
|
} |
70 |
64 |
|
|
71 |
65 |
|
/** |
72 |
66 |
|
* Construct a new AbstractDisableableBooleanEditableCell. |
73 |
67 |
|
*/ |
74 |
|
- |
protected AbstractDisableableBooleanEditableCell(CellHtmlProvider htmlProvider) { |
75 |
|
- |
this(false, htmlProvider); |
|
68 |
+ |
protected AbstractDisableableBooleanEditableCell( CellHtmlProvider htmlProvider ) { |
|
69 |
+ |
this( false, htmlProvider ); |
76 |
70 |
|
} |
77 |
71 |
|
|
78 |
72 |
|
@Override |
|
@@ -86,19 +80,19 @@ |
86 |
80 |
|
} |
87 |
81 |
|
|
88 |
82 |
|
@Override |
89 |
|
- |
public boolean isEditing(Context context, Element parent, Boolean value) { |
|
83 |
+ |
public boolean isEditing( Context context, Element parent, Boolean value ) { |
90 |
84 |
|
// A 'Boolean' is never in "edit mode". There is no intermediate state |
91 |
85 |
|
// between Selected and Not Selected. |
92 |
86 |
|
return false; |
93 |
87 |
|
} |
94 |
88 |
|
|
95 |
89 |
|
@Override |
96 |
|
- |
public void onBrowserEvent(Context context, Element parent, Boolean value, |
97 |
|
- |
NativeEvent event, ValueUpdater<Boolean> valueUpdater) { |
|
90 |
+ |
public void onBrowserEvent( Context context, Element parent, Boolean value, |
|
91 |
+ |
NativeEvent event, ValueUpdater<Boolean> valueUpdater ) { |
98 |
92 |
|
String type = event.getType(); |
99 |
93 |
|
|
100 |
|
- |
boolean enterPressed = "keydown".equals(type) && event.getKeyCode() == KeyCodes.KEY_ENTER; |
101 |
|
- |
if ("change".equals(type) || enterPressed) { |
|
94 |
+ |
boolean enterPressed = "keydown".equals( type ) && event.getKeyCode() == KeyCodes.KEY_ENTER; |
|
95 |
+ |
if ( "change".equals( type ) || enterPressed ) { |
102 |
96 |
|
InputElement input = parent.getFirstChild().cast(); |
103 |
97 |
|
Boolean isChecked = input.isChecked(); |
104 |
98 |
|
|
|
@@ -109,41 +103,41 @@ |
109 |
103 |
|
* let the SelectionEventManager determine which keys will trigger a |
110 |
104 |
|
* change. |
111 |
105 |
|
*/ |
112 |
|
- |
if (enterPressed && (handlesSelection() || !dependsOnSelection())) { |
|
106 |
+ |
if ( enterPressed && (handlesSelection() || !dependsOnSelection()) ) { |
113 |
107 |
|
isChecked = !isChecked; |
114 |
|
- |
input.setChecked(isChecked); |
|
108 |
+ |
input.setChecked( isChecked ); |
115 |
109 |
|
} |
116 |
110 |
|
|
117 |
111 |
|
/* |
118 |
112 |
|
* Save the new value. However, if the cell depends on the selection, then |
119 |
113 |
|
* do not save the value because we can get into an inconsistent state. |
120 |
114 |
|
*/ |
121 |
|
- |
if (value != isChecked && !dependsOnSelection()) { |
122 |
|
- |
setViewData(context.getKey(), isChecked); |
|
115 |
+ |
if ( value != isChecked && !dependsOnSelection() ) { |
|
116 |
+ |
setViewData( context.getKey(), isChecked ); |
123 |
117 |
|
} else { |
124 |
|
- |
clearViewData(context.getKey()); |
|
118 |
+ |
clearViewData( context.getKey() ); |
125 |
119 |
|
} |
126 |
120 |
|
|
127 |
|
- |
if (valueUpdater != null) { |
128 |
|
- |
valueUpdater.update(isChecked); |
|
121 |
+ |
if ( valueUpdater != null ) { |
|
122 |
+ |
valueUpdater.update( isChecked ); |
129 |
123 |
|
} |
130 |
124 |
|
} |
131 |
125 |
|
} |
132 |
126 |
|
|
133 |
127 |
|
@Override |
134 |
|
- |
public void render(Context context, Boolean value, SafeHtmlBuilder sb) { |
|
128 |
+ |
public void render( Context context, Boolean value, SafeHtmlBuilder sb ) { |
135 |
129 |
|
// Get the view data. |
136 |
130 |
|
Object key = context.getKey(); |
137 |
|
- |
Boolean viewData = getViewData(key); |
138 |
|
- |
if (viewData != null && viewData.equals(value)) { |
139 |
|
- |
clearViewData(key); |
|
131 |
+ |
Boolean viewData = getViewData( key ); |
|
132 |
+ |
if ( viewData != null && viewData.equals( value ) ) { |
|
133 |
+ |
clearViewData( key ); |
140 |
134 |
|
viewData = null; |
141 |
135 |
|
} |
142 |
136 |
|
|
143 |
|
- |
if (value != null && ((viewData != null) ? viewData : value)) { |
144 |
|
- |
sb.append(isEnabled() ? htmlProvider.htmlEnabledSelected() : htmlProvider.htmlDisabledSelected()); |
|
137 |
+ |
if ( value != null && ((viewData != null) ? viewData : value) ) { |
|
138 |
+ |
sb.append( isEnabled() ? htmlProvider.htmlEnabledSelected() : htmlProvider.htmlDisabledSelected() ); |
145 |
139 |
|
} else { |
146 |
|
- |
sb.append(isEnabled() ? htmlProvider.htmlEnabledNotSelected() : htmlProvider.htmlDisabledNotSelected()); |
|
140 |
+ |
sb.append( isEnabled() ? htmlProvider.htmlEnabledNotSelected() : htmlProvider.htmlDisabledNotSelected() ); |
147 |
141 |
|
} |
148 |
142 |
|
} |
149 |
143 |
|
|