package com.danielvaughan.rssreader.client;
import com.danielvaughan.rssreader.client.lists.FeedList;
import com.danielvaughan.rssreader.client.services.FeedServiceAsync;
import com.danielvaughan.rssreader.client.windows.FeedWindow;
import com.danielvaughan.rssreader.shared.Feed;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.ToggleButton;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.tips.ToolTipConfig;
import com.google.gwt.user.client.rpc.AsyncCallback;
public class RssNavigationPanel extends ContentPanel {
final LinkFeedPopup linkFeedPopup;
public RssNavigationPanel(){
setHeading("Navigation");
final ToggleButton btnLinkFeed = new ToggleButton("Link Feed");
btnLinkFeed.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
if (btnLinkFeed.isPressed()){
linkFeedPopup.show(btnLinkFeed.getElement(), "bl-tl");
} else {
linkFeedPopup.hide();
}
}
});
btnLinkFeed.setIconStyle("link-feed");
setButtonAlign(HorizontalAlignment.LEFT);
Button btnCreateFeed = new Button("Create Feed");
btnCreateFeed.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
createNewFeedWindow();
}
});
setLayout(new FitLayout());
btnCreateFeed.setIconStyle("create-feed");
addButton(btnCreateFeed);
addButton(btnLinkFeed);
ToolTipConfig createFeedToolTipConfig = new ToolTipConfig();
createFeedToolTipConfig.setTitle("Create new RSS feed");
createFeedToolTipConfig.setText("Creates a new RSS feed");
btnCreateFeed.setToolTip(createFeedToolTipConfig);
ToolTipConfig linkFeedToolTipConfig = new ToolTipConfig();
linkFeedToolTipConfig.setTitle("Link to existing RSS feed");
linkFeedToolTipConfig.setText("Allows you to enter the URL of an " +
"existing RSS feed you would like to link to");
btnLinkFeed.setToolTip(linkFeedToolTipConfig);
linkFeedPopup = new LinkFeedPopup();
linkFeedPopup.setConstrainViewport(true);
add(new FeedList());
}
private void createNewFeedWindow(){
final FeedServiceAsync feedService = Registry.get(RSSReaderConstants.FEED_SERVICE);
feedService.createFeed(new AsyncCallback<Feed>() {
@Override
public void onSuccess(Feed feed) {
final Window newFeedWindow = new FeedWindow(feed);
newFeedWindow.show();
}
@Override
public void onFailure(Throwable caught) {
Info.display("RSSReader", "Unable to create a new feed because of:\n" + caught.getMessage());
}
});
}
}