2 * Copyright (C) 2011 Openismus GmbH
4 * This file is part of GWT-Glom.
6 * GWT-Glom is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
11 * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GWT-Glom. If not, see <http://www.gnu.org/licenses/>.
20 package org.glom.web.client.ui;
22 import java.util.ArrayList;
24 import org.glom.web.client.StringUtils;
25 import org.glom.web.client.place.ListPlace;
26 import org.glom.web.shared.Reports;
28 import com.google.gwt.core.client.GWT;
29 import com.google.gwt.event.dom.client.ClickEvent;
30 import com.google.gwt.event.dom.client.ClickHandler;
31 import com.google.gwt.event.dom.client.HasChangeHandlers;
32 import com.google.gwt.event.shared.HandlerRegistration;
33 import com.google.gwt.user.client.DOM;
34 import com.google.gwt.user.client.ui.Anchor;
35 import com.google.gwt.user.client.ui.Composite;
36 import com.google.gwt.user.client.ui.FlowPanel;
37 import com.google.gwt.user.client.ui.Label;
38 import com.google.gwt.user.client.ui.ListBox;
39 import com.google.gwt.user.client.ui.TextBox;
44 public class TableSelectionViewImpl extends Composite implements TableSelectionView {
46 // OnlineGlomConstants.java is generated in the target/ directory,
47 // from OnlineGlomConstants.properties
48 // by the gwt-maven-plugin's i18n (mvn:i18n) goal.
49 private final OnlineGlomConstants constants = GWT.create(OnlineGlomConstants.class);
51 Label documentTitleLabel = new Label();
52 ListBox tablesChooser = new ListBox();
54 Label searchLabel = new Label(constants.search());
55 TextBox searchTextBox = new TextBox();
57 Label reportsLabel = new Label(constants.reports());
58 ListBox reportsChooser = new ListBox();
60 ListBox localesChooser = new ListBox();
62 Anchor backLink = new Anchor(constants.backToList());
63 private Presenter presenter;
64 private HandlerRegistration backLinkHandlerReg;
66 public TableSelectionViewImpl() {
67 tablesChooser.setStyleName("tableschooser");
68 searchLabel.setStyleName("searchlabel"); // TODO: This is tedious.
69 searchTextBox.setStyleName("searchtextbox"); // TODO: This is tedious.
70 backLink.setStyleName("backlink");
72 // empty click handler to avoid having to check for if the HandlerRegistration is null in setBackLink()
73 backLinkHandlerReg = backLink.addClickHandler(new ClickHandler() {
75 public void onClick(final ClickEvent event) {
79 final FlowPanel titlebox = new FlowPanel();
80 DOM.setElementAttribute(titlebox.getElement(), "id", "titlebox");
81 titlebox.add(documentTitleLabel);
83 titlebox.add(localesChooser);
84 titlebox.add(reportsChooser);
85 titlebox.add(reportsLabel);
88 // Set a default value for the document title label with the opacity set to 0. The headbox will bounce up and
89 // down when retrieving the document title from the server if an empty string is used.
90 documentTitleLabel.getElement().getStyle().setOpacity(0);
91 documentTitleLabel.setText("A");
92 documentTitleLabel.addStyleName("document-title");
93 DOM.setElementAttribute(documentTitleLabel.getElement(), "id", "document-title");
95 reportsLabel.setStyleName("reportslabel"); // TODO: This is tedious.
96 reportsChooser.setStyleName("reportschooser"); // TODO: This is tedious.
98 localesChooser.setStyleName("localeschooser"); // TODO: This is tedious.
100 // headbox with the table selector
101 final FlowPanel headbox = new FlowPanel();
102 DOM.setElementAttribute(headbox.getElement(), "id", "headbox");
103 headbox.add(tablesChooser);
105 final FlowPanel searchbox = new FlowPanel();
106 DOM.setElementAttribute(searchbox.getElement(), "id", "searchbox");
107 searchbox.add(searchLabel);
108 searchbox.add(searchTextBox);
109 headbox.add(searchbox);
111 headbox.add(backLink);
113 // the main container widget
114 final FlowPanel mainPanel = new FlowPanel();
115 mainPanel.add(titlebox);
116 mainPanel.add(headbox);
118 initWidget(mainPanel);
122 public void setTableSelection(final ArrayList<String> names, final ArrayList<String> titles) {
123 tablesChooser.clear();
129 for (int i = 0; i < names.size(); i++) {
130 tablesChooser.addItem(titles.get(i), names.get(i));
135 public void setSelectedTableName(final String tableName) {
136 if (StringUtils.isEmpty(tableName)) {
137 // Make sure none are selected:
138 // TODO: Find a better way to do this.
139 for (int i = 0; i < tablesChooser.getItemCount(); i++) {
140 tablesChooser.setItemSelected(i, false);
146 for (int i = 0; i < tablesChooser.getItemCount(); i++) {
147 if (tableName.equals(tablesChooser.getValue(i))) {
148 tablesChooser.setSelectedIndex(i);
156 public HasChangeHandlers getTableSelector() {
157 return tablesChooser;
161 public String getSelectedTableName() {
162 final int selectedIndex = tablesChooser.getSelectedIndex();
163 return selectedIndex < 0 ? "" : tablesChooser.getValue(selectedIndex);
167 public void setBackLink(final String documentID, final String tableName, final String quickFind) {
168 backLinkHandlerReg.removeHandler();
169 backLinkHandlerReg = backLink.addClickHandler(new ClickHandler() {
171 public void onClick(final ClickEvent event) {
172 presenter.goTo(new ListPlace(documentID, tableName, ""));
178 public void setDocumentTitle(final String documentTitle) {
179 documentTitleLabel.setText(documentTitle);
180 documentTitleLabel.getElement().getStyle().setOpacity(100);
184 public void clear() {
185 tablesChooser.clear();
186 // Set a default value for the document title label with the opacity set to 0. The headbox will bounce up and
187 // down when retrieving the document title from the server if an empty string is used.
188 documentTitleLabel.getElement().getStyle().setOpacity(0);
189 documentTitleLabel.setText("A");
193 public void setBackLinkVisible(final boolean visible) {
194 backLink.setVisible(visible);
198 public void setPresenter(final Presenter presenter) {
199 this.presenter = presenter;
203 public String getSelectedTableTitle() {
204 final int selectedIndex = tablesChooser.getSelectedIndex();
205 return selectedIndex < 0 ? "" : tablesChooser.getItemText(selectedIndex);
209 public HasChangeHandlers getQuickFindBox() {
210 return searchTextBox;
214 public String getQuickFindText() {
215 return searchTextBox.getText();
219 public void setQuickFindText(final String quickFind) {
220 searchTextBox.setText(quickFind);
224 public HasChangeHandlers getLocaleSelector() {
225 return localesChooser;
229 public void setLocaleList(final ArrayList<String> ids, final ArrayList<String> titles) {
230 localesChooser.clear();
236 for (int i = 0; i < ids.size(); i++) {
237 localesChooser.addItem(titles.get(i), ids.get(i));
242 public String getSelectedLocale() {
243 final int selectedIndex = localesChooser.getSelectedIndex();
244 return selectedIndex < 0 ? "" : localesChooser.getValue(selectedIndex);
248 public void setSelectedLocale(final String localeID) {
249 if (StringUtils.isEmpty(localeID)) {
250 // Make sure none are selected:
251 // TODO: Find a better way to do this.
252 for (int i = 0; i < localesChooser.getItemCount(); i++) {
253 localesChooser.setItemSelected(i, false);
259 for (int i = 0; i < localesChooser.getItemCount(); i++) {
260 if (localeID.equals(localesChooser.getValue(i))) {
261 localesChooser.setSelectedIndex(i);
269 public HasChangeHandlers getReportSelector() {
270 return reportsChooser;
274 public String getSelectedReport() {
275 final int selectedIndex = reportsChooser.getSelectedIndex();
276 return selectedIndex < 0 ? "" : reportsChooser.getValue(selectedIndex);
280 public void setSelectedReport(final String reportName) {
281 if (StringUtils.isEmpty(reportName)) {
282 // Make sure none are selected:
283 // TODO: Find a better way to do this.
284 for (int i = 0; i < reportsChooser.getItemCount(); i++) {
285 reportsChooser.setItemSelected(i, false);
291 for (int i = 0; i < reportsChooser.getItemCount(); i++) {
292 if (reportName.equals(reportsChooser.getValue(i))) {
293 reportsChooser.setSelectedIndex(i);
301 public void setReportList(final Reports reports) {
302 reportsChooser.clear();
304 // Add a first item as a default for the combobox.
305 // Otherwise a report will be chosen already,
306 // so the user will not be able to choose that report to go to that page.
307 // TODO: Think of a better UI for this.
308 reportsChooser.addItem("-", "");
313 for (int i = 0; i < reports.getCount(); i++) {
314 reportsChooser.addItem(reports.getTitle(i), reports.getName(i));