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.place.ListPlace;
26 import com.google.gwt.event.dom.client.ClickEvent;
27 import com.google.gwt.event.dom.client.ClickHandler;
28 import com.google.gwt.event.dom.client.HasChangeHandlers;
29 import com.google.gwt.event.shared.HandlerRegistration;
30 import com.google.gwt.user.client.DOM;
31 import com.google.gwt.user.client.ui.Anchor;
32 import com.google.gwt.user.client.ui.Composite;
33 import com.google.gwt.user.client.ui.FlowPanel;
34 import com.google.gwt.user.client.ui.ListBox;
37 * @author Ben Konrath <ben@bagu.org>
39 public class TableSelectionViewImpl extends Composite implements TableSelectionView {
41 ListBox tableChooser = new ListBox();
42 Anchor backLink = new Anchor("Back to List");
43 private Presenter presenter;
44 private HandlerRegistration backLinkHandlerReg;
46 public TableSelectionViewImpl() {
47 tableChooser.setStyleName("tablechooser");
48 backLink.setStyleName("backlink");
50 // empty click handler to avoid having to check for if the HandlerRegistration is null in setBackLink()
51 backLinkHandlerReg = backLink.addClickHandler(new ClickHandler() {
53 public void onClick(ClickEvent event) {
57 // the main container widget
58 FlowPanel mainPanel = new FlowPanel();
59 DOM.setElementAttribute(mainPanel.getElement(), "id", "headbox");
61 mainPanel.add(backLink);
62 mainPanel.add(tableChooser);
64 initWidget(mainPanel);
68 public void setTableSelection(ArrayList<String> names, ArrayList<String> titles) {
70 for (int i = 0; i < names.size(); i++) {
71 tableChooser.addItem(titles.get(i), names.get(i));
76 public void setSelectedTableName(String tableName) {
77 for (int i = 0; i < tableChooser.getItemCount(); i++) {
78 if (tableName.equals(tableChooser.getValue(i))) {
79 tableChooser.setSelectedIndex(i);
87 public HasChangeHandlers getTableSelector() {
92 public String getSelectedTable() {
93 int selectedIndex = tableChooser.getSelectedIndex();
94 return selectedIndex < 0 ? "" : tableChooser.getValue(selectedIndex);
97 public void setBackLink(final String documentID, final String tableName) {
98 backLinkHandlerReg.removeHandler();
99 backLinkHandlerReg = backLink.addClickHandler(new ClickHandler() {
101 public void onClick(ClickEvent event) {
102 presenter.goTo(new ListPlace(documentID, tableName));
108 public void clear() {
109 tableChooser.clear();
113 public void setBackLinkVisible(boolean visible) {
114 backLink.setVisible(visible);
118 public void setPresenter(Presenter presenter) {
119 this.presenter = presenter;