Subversion Repository Public Repository

litesoft

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

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