Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/table/cell/TextDataCell.java

Diff revisions: vs.
  @@ -1,23 +1,14 @@
1 1 package com.temp.client.foundation.widget.table.cell;
2 2
3 - import com.temp.client.foundation.handler.DataClickHandler;
4 - import com.temp.client.foundation.handler.DataIsClickableHandler;
5 - import com.temp.shared.utils.DisplayStringHandler;
6 -
7 - import com.google.gwt.cell.client.AbstractCell;
8 - import com.google.gwt.cell.client.ValueUpdater;
9 - import com.google.gwt.dom.client.Element;
10 - import com.google.gwt.dom.client.EventTarget;
11 - import com.google.gwt.dom.client.NativeEvent;
12 - import com.google.gwt.event.dom.client.ClickEvent;
13 - import com.google.gwt.event.dom.client.ClickHandler;
14 - import com.google.gwt.event.dom.client.MouseOutEvent;
15 - import com.google.gwt.event.dom.client.MouseOutHandler;
16 - import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
17 - import com.google.gwt.user.client.ui.DecoratedPopupPanel;
18 - import com.google.gwt.user.client.ui.Label;
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.*;
7 + import com.google.gwt.user.client.ui.*;
8 + import com.temp.client.foundation.handler.*;
9 + import com.temp.shared.utils.*;
19 10
20 - public class TextDataCell<E> extends AbstractCell<E>{
11 + public class TextDataCell<E> extends AbstractCell<E> {
21 12
22 13 // full text popup variables
23 14 private static final String LINK_STYLE = "link-button";
  @@ -30,42 +21,41 @@
30 21 private static final String MOUSEOVER_EVENT = "mouseover";
31 22 private static final String CLICK_EVENT = "click";
32 23
33 -
34 24 private DataIsClickableHandler<E> isClickableHandler;
35 25 private DisplayStringHandler<E> displayStringHandler;
36 26 private DataClickHandler<E> clickHandler;
37 27 private Label fullTextLabel = new Label();
38 28 private E cellValue;
39 - private DecoratedPopupPanel popup = new DecoratedPopupPanel(true);
29 + private DecoratedPopupPanel popup = new DecoratedPopupPanel( true );
40 30
41 31 public TextDataCell() {
42 - this(null, null, null);
32 + this( null, null, null );
43 33 }
44 34
45 - public TextDataCell(DisplayStringHandler<E> displayStringHandler) {
46 - this(displayStringHandler, null, null);
35 + public TextDataCell( DisplayStringHandler<E> displayStringHandler ) {
36 + this( displayStringHandler, null, null );
47 37 }
48 38
49 39 public TextDataCell(
50 40 DisplayStringHandler<E> displayStringHandler,
51 - DataClickHandler<E> clickHandler) {
52 - this(displayStringHandler, clickHandler, null);
41 + DataClickHandler<E> clickHandler ) {
42 + this( displayStringHandler, clickHandler, null );
53 43 }
54 44
55 45 public TextDataCell(
56 46 DisplayStringHandler<E> displayStringHandler,
57 47 DataClickHandler<E> clickHandler,
58 48 DataIsClickableHandler<E> isClickableHandler
59 - ) {
49 + ) {
60 50
61 - super(MOUSEOVER_EVENT, CLICK_EVENT);
62 - setDataDisplayStringHandler(displayStringHandler);
63 - setDataClickHandler(clickHandler);
64 - setDataIsClickableHandler(isClickableHandler);
51 + super( MOUSEOVER_EVENT, CLICK_EVENT );
52 + setDataDisplayStringHandler( displayStringHandler );
53 + setDataClickHandler( clickHandler );
54 + setDataIsClickableHandler( isClickableHandler );
65 55 initializePopup();
66 56 }
67 57
68 - private void setCellValue(E value) {
58 + private void setCellValue( E value ) {
69 59 this.cellValue = value;
70 60 }
71 61
  @@ -73,11 +63,11 @@
73 63 return cellValue;
74 64 }
75 65
76 - private void setDataDisplayStringHandler(DisplayStringHandler<E> displayStringHandler) {
77 - if (displayStringHandler == null) {
66 + private void setDataDisplayStringHandler( DisplayStringHandler<E> displayStringHandler ) {
67 + if ( displayStringHandler == null ) {
78 68 displayStringHandler = new DisplayStringHandler<E>() {
79 - public String getDisplayString(E value) {
80 - if (value != null) {
69 + public String getDisplayString( E value ) {
70 + if ( value != null ) {
81 71 return value.toString();
82 72 }
83 73 return "";
  @@ -87,14 +77,14 @@
87 77 this.displayStringHandler = displayStringHandler;
88 78 }
89 79
90 - private void setDataClickHandler(DataClickHandler<E> clickHandler) {
80 + private void setDataClickHandler( DataClickHandler<E> clickHandler ) {
91 81 this.clickHandler = clickHandler;
92 82 }
93 83
94 - private void setDataIsClickableHandler(DataIsClickableHandler<E> isClickableHandler) {
95 - if (isClickableHandler == null) {
84 + private void setDataIsClickableHandler( DataIsClickableHandler<E> isClickableHandler ) {
85 + if ( isClickableHandler == null ) {
96 86 isClickableHandler = new DataIsClickableHandler<E>() {
97 - public boolean isClickable(E elem) {
87 + public boolean isClickable( E elem ) {
98 88 return true;
99 89 }
100 90 };
  @@ -103,85 +93,84 @@
103 93 }
104 94
105 95 private void initializePopup() {
106 - popup.setGlassEnabled(false);
107 - popup.setWidget(fullTextLabel);
108 - popup.setStyleName(POPUP_STYLE);
96 + popup.setGlassEnabled( false );
97 + popup.setWidget( fullTextLabel );
98 + popup.setStyleName( POPUP_STYLE );
109 99 popup.hide();
110 - popup.addDomHandler(new MouseOutHandler() {
111 - public void onMouseOut(MouseOutEvent event) {
100 + popup.addDomHandler( new MouseOutHandler() {
101 + public void onMouseOut( MouseOutEvent event ) {
112 102 popup.hide();
113 103 }
114 - }, MouseOutEvent.getType());
115 - popup.addDomHandler(new ClickHandler() {
116 - public void onClick(ClickEvent event) {
117 - if (clickHandler != null) {
104 + }, MouseOutEvent.getType() );
105 + popup.addDomHandler( new ClickHandler() {
106 + public void onClick( ClickEvent event ) {
107 + if ( clickHandler != null ) {
118 108 E value = getCellValue();
119 - if (value != null) {
120 - clickHandler.onClick(value);
109 + if ( value != null ) {
110 + clickHandler.onClick( value );
121 111 }
122 112 }
123 113 }
124 - }, ClickEvent.getType());
114 + }, ClickEvent.getType() );
125 115 }
126 116
127 - protected void showFullTextPopup(Element wrapper, E value) {
117 + protected void showFullTextPopup( Element wrapper, E value ) {
128 118 // check if some of the text is being hidden.
129 - if (isClickable(value)) {
130 - setCellValue(value);
131 - fullTextLabel.setStyleName(LINK_STYLE);
119 + if ( isClickable( value ) ) {
120 + setCellValue( value );
121 + fullTextLabel.setStyleName( LINK_STYLE );
132 122 } else {
133 - fullTextLabel.removeStyleName(LINK_STYLE);
134 - setCellValue(null);
123 + fullTextLabel.removeStyleName( LINK_STYLE );
124 + setCellValue( null );
135 125 }
136 - fullTextLabel.setText(displayStringHandler.getDisplayString(value));
126 + fullTextLabel.setText( displayStringHandler.getDisplayString( value ) );
137 127 int left = wrapper.getAbsoluteLeft() - (POPUP_PADDING_LEFT_PX + POPUP_BORDER_WIDTH_PX);
138 128 int top = wrapper.getAbsoluteTop() - (POPUP_PADDING_TOP_PX + POPUP_BORDER_WIDTH_PX);
139 - popup.setPopupPosition(left, top);
129 + popup.setPopupPosition( left, top );
140 130 popup.show();
141 131 }
142 132
143 - private boolean isClickable(E value) {
144 - return clickHandler != null && isClickableHandler.isClickable(value);
133 + private boolean isClickable( E value ) {
134 + return clickHandler != null && isClickableHandler.isClickable( value );
145 135 }
146 136
147 137 @Override
148 - public void render(com.google.gwt.cell.client.Cell.Context context, E value, SafeHtmlBuilder sb) {
149 - if (isClickable(value)) {
150 - sb.appendHtmlConstant("<span class='" + LINK_STYLE + "'>");
138 + public void render( com.google.gwt.cell.client.Cell.Context context, E value, SafeHtmlBuilder sb ) {
139 + if ( isClickable( value ) ) {
140 + sb.appendHtmlConstant( "<span class='" + LINK_STYLE + "'>" );
151 141 } else {
152 - sb.appendHtmlConstant("<span>");
142 + sb.appendHtmlConstant( "<span>" );
153 143 }
154 - sb.appendEscaped(displayStringHandler.getDisplayString(value));
155 - sb.appendHtmlConstant("</span>");
144 + sb.appendEscaped( displayStringHandler.getDisplayString( value ) );
145 + sb.appendHtmlConstant( "</span>" );
156 146 }
157 147
158 148 @Override
159 - public void onBrowserEvent(Context context, Element parent, E value, NativeEvent event, ValueUpdater<E> valueUpdater) {
149 + public void onBrowserEvent( Context context, Element parent, E value, NativeEvent event, ValueUpdater<E> valueUpdater ) {
160 150 String eventType = event.getType();
161 151
162 - if (value != null && getConsumedEvents().contains(eventType)) {
152 + if ( value != null && getConsumedEvents().contains( eventType ) ) {
163 153
164 154 EventTarget eventTarget = event.getEventTarget();
165 - if (Element.is(eventTarget)) {
155 + if ( Element.is( eventTarget ) ) {
166 156 Element target = eventTarget.cast();
167 157 Element container = parent;
168 158 Element wrapper = container.getFirstChildElement();
169 159
170 -
171 - while (wrapper != null) {
172 - if (wrapper.isOrHasChild(target)) {
173 - if (eventType.equals(MOUSEOVER_EVENT)) {
160 + while ( wrapper != null ) {
161 + if ( wrapper.isOrHasChild( target ) ) {
162 + if ( eventType.equals( MOUSEOVER_EVENT ) ) {
174 163 // on hover full text
175 164 int containerWidth = container.getAbsoluteRight() - container.getAbsoluteLeft() + CELL_PADDING_PX;
176 165 int textWidth = wrapper.getAbsoluteRight() - wrapper.getAbsoluteLeft();
177 - if (containerWidth < textWidth) {
178 - showFullTextPopup(wrapper, value);
166 + if ( containerWidth < textWidth ) {
167 + showFullTextPopup( wrapper, value );
179 168 }
180 169 break;
181 - } else if (eventType.equals(CLICK_EVENT)) {
170 + } else if ( eventType.equals( CLICK_EVENT ) ) {
182 171 // click
183 - if (isClickable(value)) {
184 - clickHandler.onClick(value);
172 + if ( isClickable( value ) ) {
173 + clickHandler.onClick( value );
185 174 }
186 175 break;
187 176 }
  @@ -191,5 +180,4 @@
191 180 }
192 181 }
193 182 }
194 -
195 183 }