Example usage for com.google.gwt.ajaxfeed.client.impl ErrorWrapper getMessage

List of usage examples for com.google.gwt.ajaxfeed.client.impl ErrorWrapper getMessage

Introduction

In this page you can find the example usage for com.google.gwt.ajaxfeed.client.impl ErrorWrapper getMessage.

Prototype

public String getMessage();

Source Link

Usage

From source file:com.google.gwt.sample.feedreader.client.FeedPanel.java

License:Apache License

/**
 * Load a single feed.//  w  w  w .  j  a v  a 2s.c o m
 */
public void loadFeed() {
    loadStarted = true;
    loadFinished = false;

    getLabel().setBusy(true);

    JavaScriptObject feedJso = feedApi.construct(feed.getUrl());
    feedApi.setNumEntries(feedJso, 20);
    feedApi.load(feedJso, new FeedCallback() {
        public void onLoad(JavaScriptObject feedResult) {
            // Fix up any missing fields
            resultApi.bind(feedResult);

            ErrorWrapper errorResponse = resultApi.getError(feedResult);
            if (errorResponse != null) {
                getLabel().setText(feed.getTitle() + " (Error)");
                setText("Unable to load feed (" + errorResponse.getMessage() + ")");
                return;
            }

            JavaScriptObject jsonFeed = resultApi.getFeed(feedResult);
            entries = jsonFeedApi.getEntries(jsonFeed);

            String title = jsonFeedApi.getTitle(jsonFeed);
            feed.setTitle(title);
            getLabel().setText(title);

            getLabel().setBusy(false);

            final Date lastViewed = new Date(feed.getLastArticle());

            // Count the number of new entries while the next feed downloads
            DeferredCommand.addCommand(new IncrementalCommand() {
                final Iterator i = entries.iterator();
                int newEntries = 0;

                public boolean execute() {
                    EntryWrapper entry = (EntryWrapper) i.next();

                    try {
                        if ((new Date(entry.getPublishedDate())).after(lastViewed)) {
                            newEntries++;
                        }
                    } catch (IllegalArgumentException e) {
                        // Ignore date formats that we can't parse.
                    }

                    if (i.hasNext()) {
                        return true;

                    } else {
                        // Show the number of new entries
                        if (newEntries > 0) {
                            getLabel().addStyleName("unseen");
                            getLabel().setText("(" + newEntries + ") " + feed.getTitle());
                        } else {
                            getLabel().setText(feed.getTitle());
                        }

                        getLabel().setBusy(false);

                        return false;
                    }
                }
            });

            loadStarted = false;
            loadFinished = true;
            drawn = false;
            redraw();
        }
    });
}

From source file:com.google.gwt.sample.feedreader.client.FeedSelectPanel.java

License:Apache License

public FeedSelectPanel(final ConfigurationPanel parent, final Configuration configuration, String query) {
    super("Select feed...", parent);

    FeedCallback fc = new FeedCallback() {
        public void onLoad(final JavaScriptObject jso) {
            RESULT_API.bind(jso);//www .  j a v a 2  s  . c om

            ErrorWrapper error = RESULT_API.getError(jso);
            if (error != null) {
                Window.alert("Unable to find feeds.\n" + error.getMessage());
                return;
            }

            // Remove the loading message
            clear();

            // Update the UI piecewise
            DeferredCommand.addCommand(new IncrementalCommand() {
                List feeds = configuration.getFeeds();
                Iterator i = RESULT_API.getEntries(jso).iterator();

                public boolean execute() {
                    final FindResultApi.Entry entry = (FindResultApi.Entry) i.next();
                    if (feeds.contains(entry.getUrl())) {
                        return i.hasNext();
                    }

                    UnsunkLabel title = new UnsunkLabel(entry.getTitle(), true);
                    title.addStyleName("title");
                    UnsunkLabel snippit = new UnsunkLabel(entry.getContentSnippet(), true);
                    snippit.addStyleName("snippit");
                    UnsunkLabel url = new UnsunkLabel(entry.getUrl());
                    url.addStyleName("snippit");

                    FlowPanel vp = new FlowPanel();
                    vp.add(title);
                    vp.add(snippit);
                    vp.add(url);

                    add(new PanelLabel(vp, new Command() {
                        public void execute() {
                            History.newItem(entry.getUrl());
                        }
                    }));

                    return i.hasNext();
                }
            });
        }
    };

    Globals.API.findFeeds(query, fc);

    addStyleName("FeedSelectPanel");
    add(new PanelLabel("Waiting for results"));
}