2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
\r
4 * This file is part of GSS.
\r
6 * GSS is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * GSS is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
\r
19 package gr.ebs.gss.client;
\r
21 import com.google.gwt.event.dom.client.BlurEvent;
\r
22 import com.google.gwt.event.dom.client.BlurHandler;
\r
23 import com.google.gwt.event.dom.client.ClickEvent;
\r
24 import com.google.gwt.event.dom.client.ClickHandler;
\r
25 import com.google.gwt.event.dom.client.FocusEvent;
\r
26 import com.google.gwt.event.dom.client.FocusHandler;
\r
27 import com.google.gwt.event.dom.client.KeyPressEvent;
\r
28 import com.google.gwt.event.dom.client.KeyPressHandler;
\r
29 import com.google.gwt.resources.client.ClientBundle;
\r
30 import com.google.gwt.resources.client.ImageResource;
\r
31 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
32 import com.google.gwt.user.client.ui.Button;
\r
33 import com.google.gwt.user.client.ui.Composite;
\r
34 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
35 import com.google.gwt.user.client.ui.HasVerticalAlignment;
\r
36 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
37 import com.google.gwt.user.client.ui.TextBox;
\r
38 import com.google.gwt.user.client.ui.Widget;
\r
41 * A component that contains the search form.
\r
43 public class Search extends Composite implements FocusHandler,BlurHandler {
\r
46 * The text hint that is displayed in the empty search box.
\r
48 private static final String TEXT_HINT = "Search for files...";
\r
51 * Specifies the images that will be bundled for this Composite.
\r
53 public interface Images extends ClientBundle {
\r
54 @Source("gr/ebs/gss/resources/search_16.png")
\r
55 ImageResource searchButton();
\r
59 * The embedded text box widget that contains the search query.
\r
61 private TextBox tb = new TextBox();
\r
64 * The search widget constructor.
\r
66 * @param images the image bundle
\r
68 public Search(final Images images) {
\r
69 tb.setWidth("200px");
\r
70 tb.setText(TEXT_HINT);
\r
71 tb.setStylePrimaryName("gss-search");
\r
72 tb.addStyleDependentName("empty");
\r
73 tb.addFocusHandler(this);
\r
74 tb.addBlurHandler(this);
\r
75 tb.getElement().setId("textBox.search");
\r
76 tb.addKeyPressHandler(new KeyPressHandler() {
\r
79 public void onKeyPress(KeyPressEvent event) {
\r
80 char keyCode = event.getCharCode();
\r
81 if (keyCode == '\r')
\r
82 GSS.get().showSearchResults(tb.getText());
\r
83 else if (keyCode == 27) {
\r
84 // Simulate the proper behavior for the escape key
\r
86 onLostFocus((Widget)event.getSource());
\r
92 Button b = new Button(createHeaderHTML(images.searchButton(), "Search"), new ClickHandler() {
\r
94 public void onClick(ClickEvent event) {
\r
95 GSS.get().showSearchResults(tb.getText());
\r
98 b.getElement().setId("button.search");
\r
100 HorizontalPanel panel = new HorizontalPanel();
\r
101 panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
\r
102 panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
\r
109 * Creates an HTML fragment that places an image & caption together.
\r
111 * @param imageProto an image prototype for an image
\r
112 * @param caption the caption
\r
113 * @return the HTML fragment
\r
115 private String createHeaderHTML(ImageResource imageProto, String caption) {
\r
116 String captionHTML = "<table cellpadding='0' cellspacing='0'>" + "<tr><td>" +
\r
117 AbstractImagePrototype.create(imageProto).getHTML() + "</td><td style='font-size: 90%;'> " +
\r
118 caption + "</td></tr></table>";
\r
119 return captionHTML;
\r
122 public void onLostFocus(Widget sender) {
\r
123 TextBox b = (TextBox) sender;
\r
124 if (b.getText().equals("")) {
\r
125 b.addStyleDependentName("empty");
\r
126 b.setText(TEXT_HINT);
\r
131 public void onFocus(FocusEvent event) {
\r
132 TextBox b = (TextBox) event.getSource();
\r
133 if (b.getText().equals(TEXT_HINT))
\r
135 b.removeStyleDependentName("empty");
\r
139 public void onBlur(BlurEvent event) {
\r
140 TextBox b = (TextBox) event.getSource();
\r