*/\r
package gr.ebs.gss.client;\r
\r
+import com.google.gwt.event.dom.client.BlurEvent;\r
+import com.google.gwt.event.dom.client.BlurHandler;\r
+import com.google.gwt.event.dom.client.ClickEvent;\r
+import com.google.gwt.event.dom.client.ClickHandler;\r
+import com.google.gwt.event.dom.client.FocusEvent;\r
+import com.google.gwt.event.dom.client.FocusHandler;\r
+import com.google.gwt.event.dom.client.KeyPressEvent;\r
+import com.google.gwt.event.dom.client.KeyPressHandler;\r
+import com.google.gwt.resources.client.ClientBundle;\r
+import com.google.gwt.resources.client.ImageResource;\r
import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
import com.google.gwt.user.client.ui.Button;\r
-import com.google.gwt.user.client.ui.ClickListener;\r
import com.google.gwt.user.client.ui.Composite;\r
-import com.google.gwt.user.client.ui.FocusListener;\r
import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
import com.google.gwt.user.client.ui.HasVerticalAlignment;\r
import com.google.gwt.user.client.ui.HorizontalPanel;\r
-import com.google.gwt.user.client.ui.ImageBundle;\r
-import com.google.gwt.user.client.ui.KeyboardListenerAdapter;\r
import com.google.gwt.user.client.ui.TextBox;\r
import com.google.gwt.user.client.ui.Widget;\r
\r
/**\r
* A component that contains the search form.\r
*/\r
-public class Search extends Composite implements FocusListener {\r
+public class Search extends Composite implements FocusHandler,BlurHandler {\r
\r
/**\r
* The text hint that is displayed in the empty search box.\r
/**\r
* Specifies the images that will be bundled for this Composite.\r
*/\r
- public interface Images extends ImageBundle {\r
- @Resource("gr/ebs/gss/resources/search_16.png")\r
- AbstractImagePrototype searchButton();\r
+ public interface Images extends ClientBundle {\r
+ @Source("gr/ebs/gss/resources/search_16.png")\r
+ ImageResource searchButton();\r
}\r
\r
/**\r
tb.setText(TEXT_HINT);\r
tb.setStylePrimaryName("gss-search");\r
tb.addStyleDependentName("empty");\r
- tb.addFocusListener(this);\r
- tb.addKeyboardListener(new KeyboardListenerAdapter() {\r
+ tb.addFocusHandler(this);\r
+ tb.addBlurHandler(this);\r
+ tb.getElement().setId("textBox.search");\r
+ tb.addKeyPressHandler(new KeyPressHandler() {\r
\r
@Override\r
- public void onKeyPress(Widget sender, char keyCode, int modifiers) {\r
+ public void onKeyPress(KeyPressEvent event) {\r
+ char keyCode = event.getCharCode();\r
if (keyCode == '\r')\r
GSS.get().showSearchResults(tb.getText());\r
else if (keyCode == 27) {\r
- // Simulate the proper behavior for the escape key (27 ==\r
- // ESC).\r
- onLostFocus(sender);\r
+ // Simulate the proper behavior for the escape key\r
+ // (27 == ESC).\r
+ onLostFocus((Widget)event.getSource());\r
tb.setFocus(false);\r
}\r
}\r
});\r
\r
- Button b = new Button(createHeaderHTML(images.searchButton(), "Search"), new ClickListener() {\r
-\r
- public void onClick(Widget sender) {\r
+ Button b = new Button(createHeaderHTML(images.searchButton(), "Search"), new ClickHandler() {\r
+ @Override\r
+ public void onClick(ClickEvent event) {\r
GSS.get().showSearchResults(tb.getText());\r
}\r
});\r
-\r
+ b.getElement().setId("button.search");\r
+ \r
HorizontalPanel panel = new HorizontalPanel();\r
panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);\r
panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);\r
* @param caption the caption\r
* @return the HTML fragment\r
*/\r
- private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {\r
+ private String createHeaderHTML(ImageResource imageProto, String caption) {\r
String captionHTML = "<table cellpadding='0' cellspacing='0'>" + "<tr><td>" +\r
- imageProto.getHTML() + "</td><td style='font-size: 90%;'> " +\r
+ AbstractImagePrototype.create(imageProto).getHTML() + "</td><td style='font-size: 90%;'> " +\r
caption + "</td></tr></table>";\r
return captionHTML;\r
}\r
\r
- public void onFocus(Widget sender) {\r
- TextBox b = (TextBox) sender;\r
- if (b.getText().equals(TEXT_HINT))\r
- b.setText("");\r
- sender.removeStyleDependentName("empty");\r
- }\r
-\r
public void onLostFocus(Widget sender) {\r
TextBox b = (TextBox) sender;\r
if (b.getText().equals("")) {\r
b.setText(TEXT_HINT);\r
}\r
}\r
+\r
+ @Override\r
+ public void onFocus(FocusEvent event) {\r
+ TextBox b = (TextBox) event.getSource();\r
+ if (b.getText().equals(TEXT_HINT))\r
+ b.setText("");\r
+ b.removeStyleDependentName("empty");\r
+ }\r
+\r
+ @Override\r
+ public void onBlur(BlurEvent event) {\r
+ TextBox b = (TextBox) event.getSource();\r
+ onLostFocus(b);\r
+ }\r
}\r