|
@@ -1,79 +1,75 @@ |
1 |
1 |
|
package com.temp.client.foundation.widget.table.cell; |
2 |
2 |
|
|
3 |
|
- |
import com.temp.client.foundation.handler.DataClickHandler; |
4 |
|
- |
|
5 |
|
- |
import com.google.gwt.cell.client.AbstractCell; |
6 |
|
- |
import com.google.gwt.cell.client.ValueUpdater; |
7 |
|
- |
import com.google.gwt.dom.client.Element; |
8 |
|
- |
import com.google.gwt.dom.client.NativeEvent; |
9 |
|
- |
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
10 |
|
- |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
11 |
|
- |
import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant; |
|
3 |
+ |
import com.google.gwt.cell.client.*; |
|
4 |
+ |
import com.google.gwt.dom.client.*; |
|
5 |
+ |
import com.google.gwt.safehtml.shared.*; |
|
6 |
+ |
import com.google.gwt.user.client.ui.*; |
|
7 |
+ |
import com.google.gwt.user.client.ui.HasHorizontalAlignment.*; |
|
8 |
+ |
import com.temp.client.foundation.handler.*; |
12 |
9 |
|
|
13 |
10 |
|
/** |
14 |
|
- |
* @author paule, dhoude |
15 |
|
- |
* |
16 |
11 |
|
* @param <T> - the data type |
|
12 |
+ |
* |
|
13 |
+ |
* @author paule, dhoude |
17 |
14 |
|
*/ |
18 |
15 |
|
public class ClickableImageCell<T> extends AbstractCell<T> { |
19 |
16 |
|
|
20 |
|
- |
private DataClickHandler<T> clickHandler; |
21 |
|
- |
private String trustedInnerHTML; |
22 |
|
- |
private HorizontalAlignmentConstant horizontalAlignment; |
23 |
|
- |
|
24 |
|
- |
private static final String CLICK_EVENT = "click"; |
25 |
|
- |
private static final String TEXT_ALIGN_CSS_PROPERTY_NAME = "text-align"; |
26 |
|
- |
|
27 |
|
- |
public ClickableImageCell(String trustedHtmlImageElement, DataClickHandler<T> clickHandler, |
28 |
|
- |
HorizontalAlignmentConstant horizontalAlignment) { |
29 |
|
- |
super(CLICK_EVENT); |
|
17 |
+ |
private DataClickHandler<T> clickHandler; |
|
18 |
+ |
private String trustedInnerHTML; |
|
19 |
+ |
private HorizontalAlignmentConstant horizontalAlignment; |
|
20 |
+ |
|
|
21 |
+ |
private static final String CLICK_EVENT = "click"; |
|
22 |
+ |
private static final String TEXT_ALIGN_CSS_PROPERTY_NAME = "text-align"; |
|
23 |
+ |
|
|
24 |
+ |
public ClickableImageCell( String trustedHtmlImageElement, DataClickHandler<T> clickHandler, |
|
25 |
+ |
HorizontalAlignmentConstant horizontalAlignment ) { |
|
26 |
+ |
super( CLICK_EVENT ); |
30 |
27 |
|
trustedInnerHTML = trustedHtmlImageElement; |
31 |
28 |
|
this.clickHandler = clickHandler; |
32 |
29 |
|
this.horizontalAlignment = horizontalAlignment; |
33 |
30 |
|
} |
34 |
31 |
|
|
35 |
|
- |
public ClickableImageCell(String trustedHtmlImageElement, DataClickHandler<T> clickHandler) { |
36 |
|
- |
this(trustedHtmlImageElement, clickHandler, null); |
|
32 |
+ |
public ClickableImageCell( String trustedHtmlImageElement, DataClickHandler<T> clickHandler ) { |
|
33 |
+ |
this( trustedHtmlImageElement, clickHandler, null ); |
37 |
34 |
|
} |
38 |
35 |
|
|
39 |
|
- |
public String getTrustedInnerHTML(T value) { |
|
36 |
+ |
public String getTrustedInnerHTML( T value ) { |
40 |
37 |
|
return trustedInnerHTML; |
41 |
38 |
|
} |
42 |
39 |
|
|
43 |
40 |
|
@Override |
44 |
|
- |
public void render(Context context, T value, SafeHtmlBuilder sb) { |
45 |
|
- |
// Use concatenation here, since SafeHtmlBuilder only accept complete tags |
46 |
|
- |
sb.appendHtmlConstant("<div style='" + this.getHorizontalAlignmentStyle() + "'>"); |
47 |
|
- |
sb.appendHtmlConstant(getTrustedInnerHTML(value)); |
48 |
|
- |
sb.appendHtmlConstant("</div>"); |
49 |
|
- |
} |
50 |
|
- |
|
51 |
|
- |
@Override |
52 |
|
- |
public void onBrowserEvent(Context context, Element parent, T value, NativeEvent event, ValueUpdater<T> valueUpdater) { |
53 |
|
- |
if (event.getType().equals(CLICK_EVENT) && value != null) { |
54 |
|
- |
clickHandler.onClick(value); |
55 |
|
- |
} |
56 |
|
- |
} |
57 |
|
- |
|
58 |
|
- |
public void setHorizontalAlignment(HorizontalAlignmentConstant horizontalAlignment) { |
59 |
|
- |
this.horizontalAlignment = horizontalAlignment; |
60 |
|
- |
} |
61 |
|
- |
|
62 |
|
- |
private String getHorizontalAlignmentStyle() { |
63 |
|
- |
StringBuilder styleStringBuilder = new StringBuilder(); |
64 |
|
- |
|
65 |
|
- |
if(HasHorizontalAlignment.ALIGN_LEFT.equals(horizontalAlignment)) { |
66 |
|
- |
styleStringBuilder.append(TEXT_ALIGN_CSS_PROPERTY_NAME); |
67 |
|
- |
styleStringBuilder.append(": left; "); |
68 |
|
- |
} else if(HasHorizontalAlignment.ALIGN_CENTER.equals(horizontalAlignment)) { |
69 |
|
- |
styleStringBuilder.append(TEXT_ALIGN_CSS_PROPERTY_NAME); |
70 |
|
- |
styleStringBuilder.append(": center; "); |
71 |
|
- |
} else if(HasHorizontalAlignment.ALIGN_RIGHT.equals(horizontalAlignment)) { |
72 |
|
- |
styleStringBuilder.append(TEXT_ALIGN_CSS_PROPERTY_NAME); |
73 |
|
- |
styleStringBuilder.append(": right; "); |
74 |
|
- |
} |
|
41 |
+ |
public void render( Context context, T value, SafeHtmlBuilder sb ) { |
|
42 |
+ |
// Use concatenation here, since SafeHtmlBuilder only accept complete tags |
|
43 |
+ |
sb.appendHtmlConstant( "<div style='" + this.getHorizontalAlignmentStyle() + "'>" ); |
|
44 |
+ |
sb.appendHtmlConstant( getTrustedInnerHTML( value ) ); |
|
45 |
+ |
sb.appendHtmlConstant( "</div>" ); |
|
46 |
+ |
} |
|
47 |
+ |
|
|
48 |
+ |
@Override |
|
49 |
+ |
public void onBrowserEvent( Context context, Element parent, T value, NativeEvent event, ValueUpdater<T> valueUpdater ) { |
|
50 |
+ |
if ( event.getType().equals( CLICK_EVENT ) && value != null ) { |
|
51 |
+ |
clickHandler.onClick( value ); |
|
52 |
+ |
} |
|
53 |
+ |
} |
75 |
54 |
|
|
76 |
|
- |
return styleStringBuilder.toString(); |
77 |
|
- |
} |
|
55 |
+ |
public void setHorizontalAlignment( HorizontalAlignmentConstant horizontalAlignment ) { |
|
56 |
+ |
this.horizontalAlignment = horizontalAlignment; |
|
57 |
+ |
} |
78 |
58 |
|
|
|
59 |
+ |
private String getHorizontalAlignmentStyle() { |
|
60 |
+ |
StringBuilder styleStringBuilder = new StringBuilder(); |
|
61 |
+ |
|
|
62 |
+ |
if ( HasHorizontalAlignment.ALIGN_LEFT.equals( horizontalAlignment ) ) { |
|
63 |
+ |
styleStringBuilder.append( TEXT_ALIGN_CSS_PROPERTY_NAME ); |
|
64 |
+ |
styleStringBuilder.append( ": left; " ); |
|
65 |
+ |
} else if ( HasHorizontalAlignment.ALIGN_CENTER.equals( horizontalAlignment ) ) { |
|
66 |
+ |
styleStringBuilder.append( TEXT_ALIGN_CSS_PROPERTY_NAME ); |
|
67 |
+ |
styleStringBuilder.append( ": center; " ); |
|
68 |
+ |
} else if ( HasHorizontalAlignment.ALIGN_RIGHT.equals( horizontalAlignment ) ) { |
|
69 |
+ |
styleStringBuilder.append( TEXT_ALIGN_CSS_PROPERTY_NAME ); |
|
70 |
+ |
styleStringBuilder.append( ": right; " ); |
|
71 |
+ |
} |
|
72 |
+ |
|
|
73 |
+ |
return styleStringBuilder.toString(); |
|
74 |
+ |
} |
79 |
75 |
|
} |