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.user.client.ui.AbstractImagePrototype;
\r
22 import com.google.gwt.user.client.ui.Button;
\r
23 import com.google.gwt.user.client.ui.ClickListener;
\r
24 import com.google.gwt.user.client.ui.Composite;
\r
25 import com.google.gwt.user.client.ui.FocusListener;
\r
26 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
27 import com.google.gwt.user.client.ui.HasVerticalAlignment;
\r
28 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
29 import com.google.gwt.user.client.ui.ImageBundle;
\r
30 import com.google.gwt.user.client.ui.KeyboardListenerAdapter;
\r
31 import com.google.gwt.user.client.ui.TextBox;
\r
32 import com.google.gwt.user.client.ui.Widget;
\r
35 * A component that contains the search form.
\r
37 public class Search extends Composite implements FocusListener {
\r
40 * The text hint that is displayed in the empty search box.
\r
42 private static final String TEXT_HINT = "Search for files...";
\r
45 * Specifies the images that will be bundled for this Composite.
\r
47 public interface Images extends ImageBundle {
\r
48 @Resource("gr/ebs/gss/resources/search_16.png")
\r
49 AbstractImagePrototype searchButton();
\r
53 * The embedded text box widget that contains the search query.
\r
55 private TextBox tb = new TextBox();
\r
58 * The search widget constructor.
\r
60 * @param images the image bundle
\r
62 public Search(final Images images) {
\r
63 tb.setWidth("200px");
\r
64 tb.setText(TEXT_HINT);
\r
65 tb.setStylePrimaryName("gss-search");
\r
66 tb.addStyleDependentName("empty");
\r
67 tb.addFocusListener(this);
\r
68 tb.addKeyboardListener(new KeyboardListenerAdapter() {
\r
71 public void onKeyPress(Widget sender, char keyCode, int modifiers) {
\r
72 if (keyCode == '\r')
\r
73 GSS.get().showSearchResults(tb.getText());
\r
74 else if (keyCode == 27) {
\r
75 // Simulate the proper behavior for the escape key (27 ==
\r
77 onLostFocus(sender);
\r
83 Button b = new Button(createHeaderHTML(images.searchButton(), "Search"), new ClickListener() {
\r
85 public void onClick(Widget sender) {
\r
86 GSS.get().showSearchResults(tb.getText());
\r
90 HorizontalPanel panel = new HorizontalPanel();
\r
91 panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
\r
92 panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
\r
99 * Creates an HTML fragment that places an image & caption together.
\r
101 * @param imageProto an image prototype for an image
\r
102 * @param caption the caption
\r
103 * @return the HTML fragment
\r
105 private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
\r
106 String captionHTML = "<table cellpadding='0' cellspacing='0'>" + "<tr><td>" +
\r
107 imageProto.getHTML() + "</td><td style='font-size: 90%;'> " +
\r
108 caption + "</td></tr></table>";
\r
109 return captionHTML;
\r
112 public void onFocus(Widget sender) {
\r
113 TextBox b = (TextBox) sender;
\r
114 if (b.getText().equals(TEXT_HINT))
\r
116 sender.removeStyleDependentName("empty");
\r
119 public void onLostFocus(Widget sender) {
\r
120 TextBox b = (TextBox) sender;
\r
121 if (b.getText().equals("")) {
\r
122 b.addStyleDependentName("empty");
\r
123 b.setText(TEXT_HINT);
\r