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.addKeyPressHandler(new KeyPressHandler() {
\r
78 public void onKeyPress(KeyPressEvent event) {
\r
79 char keyCode = event.getCharCode();
\r
80 if (keyCode == '\r')
\r
81 GSS.get().showSearchResults(tb.getText());
\r
82 else if (keyCode == 27) {
\r
83 // Simulate the proper behavior for the escape key
\r
85 onLostFocus((Widget)event.getSource());
\r
91 Button b = new Button(createHeaderHTML(images.searchButton(), "Search"), new ClickHandler() {
\r
93 public void onClick(ClickEvent event) {
\r
94 GSS.get().showSearchResults(tb.getText());
\r
98 HorizontalPanel panel = new HorizontalPanel();
\r
99 panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
\r
100 panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
\r
107 * Creates an HTML fragment that places an image & caption together.
\r
109 * @param imageProto an image prototype for an image
\r
110 * @param caption the caption
\r
111 * @return the HTML fragment
\r
113 private String createHeaderHTML(ImageResource imageProto, String caption) {
\r
114 String captionHTML = "<table cellpadding='0' cellspacing='0'>" + "<tr><td>" +
\r
115 AbstractImagePrototype.create(imageProto).getHTML() + "</td><td style='font-size: 90%;'> " +
\r
116 caption + "</td></tr></table>";
\r
117 return captionHTML;
\r
120 public void onLostFocus(Widget sender) {
\r
121 TextBox b = (TextBox) sender;
\r
122 if (b.getText().equals("")) {
\r
123 b.addStyleDependentName("empty");
\r
124 b.setText(TEXT_HINT);
\r
129 public void onFocus(FocusEvent event) {
\r
130 TextBox b = (TextBox) event.getSource();
\r
131 if (b.getText().equals(TEXT_HINT))
\r
133 b.removeStyleDependentName("empty");
\r
137 public void onBlur(BlurEvent event) {
\r
138 TextBox b = (TextBox) event.getSource();
\r