package com.antonytrupe.client.ui;
import com.antonytrupe.client.Index;
import com.antonytrupe.client.PageServiceAsync;
import com.antonytrupe.client.place.DisplayPlace;
import com.antonytrupe.client.place.EditPlace;
import com.antonytrupe.client.place.HistoryPlace;
import com.antonytrupe.client.place.TalkPlace;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.http.client.URL;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.InlineHyperlink;
import com.google.gwt.user.client.ui.Widget;
public class DisplayViewImpl extends Composite implements DisplayView {
interface DisplayViewImplUiBinder extends UiBinder<Widget, DisplayViewImpl> {
}
private static DisplayViewImplUiBinder uiBinder = GWT
.create(DisplayViewImplUiBinder.class);
@SuppressWarnings("unused")
private Presenter listener;
@UiField
String pageName;
@UiField
SpanElement editSpan, loginSpan;
@UiField
ContentViewImpl content;
@UiField
InlineHyperlink talkLink, historyLink, editLink;
@UiField
Anchor loginLink;
@SuppressWarnings("unused")
private PageServiceAsync pageService;
public static final String IDENTITY = "identity";
public DisplayViewImpl() {
initWidget(uiBinder.createAndBindUi(this));
// if there is a user set
String cookie = Cookies.getCookie(IDENTITY);
this.editSpan.getStyle().setDisplay(
cookie == null ? Display.NONE : Display.INLINE_BLOCK);
this.loginSpan.getStyle().setDisplay(
cookie != null ? Display.NONE : Display.INLINE_BLOCK);
this.historyLink.getElement().setAttribute("rel", "nofollow");
this.editLink.getElement().setAttribute("rel", "nofollow");
this.loginLink.getElement().setAttribute("rel", "nofollow");
}
@Override
protected void onAttach() {
super.onAttach();
}
@Override
public void setContent(SafeHtml content) {
this.content.setContent(content);
}
// name is not encoded
@Override
public void setPageName(String name) {
this.pageName = name;
this.editLink.setTargetHistoryToken(EditPlace.PREFIX
+ ":"
+ new EditPlace.Tokenizer().getToken(new EditPlace(
this.pageName)));
this.talkLink.setTargetHistoryToken(TalkPlace.PREFIX
+ ":"
+ new TalkPlace.Tokenizer().getToken(new TalkPlace(
this.pageName)));
this.historyLink.setTargetHistoryToken(HistoryPlace.PREFIX
+ ":"
+ new HistoryPlace.Tokenizer().getToken(new HistoryPlace(
this.pageName)));
this.loginLink.setHref("/login.html?return_to="
+ URL.encodeQueryString("#"
+ DisplayPlace.PREFIX
+ ":"
+ new DisplayPlace.Tokenizer()
.getToken(new DisplayPlace(this.pageName))));
Window.setTitle(name + Index.ANTONY_TRUPE);
}
@Override
public void setPageService(PageServiceAsync pageService) {
this.pageService = pageService;
}
@Override
public void setPresenter(Presenter listener) {
this.listener = listener;
}
}