Use Presenter for app navigation.
[online-glom:gwt-glom.git] / src / main / java / org / glom / web / client / ui / DocumentSelectionViewImpl.java
1 /*
2  * Copyright (C) 2011 Openismus GmbH
3  *
4  * This file is part of GWT-Glom.
5  *
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.
10  *
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
14  * for more details.
15  *
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/>.
18  */
19
20 package org.glom.web.client.ui;
21
22 import org.glom.web.client.place.OnlineGlomPlace;
23
24 import com.google.gwt.core.client.GWT;
25 import com.google.gwt.event.dom.client.ClickEvent;
26 import com.google.gwt.event.dom.client.ClickHandler;
27 import com.google.gwt.uibinder.client.UiBinder;
28 import com.google.gwt.uibinder.client.UiField;
29 import com.google.gwt.user.client.ui.Anchor;
30 import com.google.gwt.user.client.ui.Composite;
31 import com.google.gwt.user.client.ui.Label;
32 import com.google.gwt.user.client.ui.VerticalPanel;
33 import com.google.gwt.user.client.ui.Widget;
34
35 public class DocumentSelectionViewImpl extends Composite implements DocumentSelectionView {
36
37         interface DocumentSelectionViewImplUiBinder extends UiBinder<Widget, DocumentSelectionViewImpl> {
38         }
39
40         private static DocumentSelectionViewImplUiBinder uiBinder = GWT.create(DocumentSelectionViewImplUiBinder.class);
41         @UiField
42         VerticalPanel documentLinks;
43         private Presenter presenter;
44
45         public DocumentSelectionViewImpl() {
46                 initWidget(uiBinder.createAndBindUi(this));
47         }
48
49         public void addDocumentLink(final String documentTitle) {
50                 Anchor link = new Anchor(documentTitle);
51                 link.addClickHandler(new ClickHandler() {
52                         @Override
53                         public void onClick(ClickEvent event) {
54                                 presenter.goTo(new OnlineGlomPlace(documentTitle));
55                         }
56                 });
57                 documentLinks.add(link);
58         }
59
60         public void clearHyperLinks() {
61                 documentLinks.clear();
62         }
63
64         /*
65          * (non-Javadoc)
66          * 
67          * @see org.glom.web.client.ui.DocumentSelectionView#setErrorMessage(java.lang.String)
68          */
69         public void setErrorMessage(String message) {
70                 clearHyperLinks();
71                 Label label = new Label(message);
72                 label.getElement().getStyle().setColor("Red");
73                 documentLinks.add(label);
74         }
75
76         @Override
77         public void setPresenter(Presenter presenter) {
78                 this.presenter = presenter;
79         }
80 }