001: /*
002: * Copyright (c) 2005 Your Corporation. All Rights Reserved.
003: */
004: package desktop;
005:
006: import com.sun.syndication.feed.synd.SyndEntryImpl;
007: import com.sun.syndication.feed.synd.SyndFeed;
008: import org.wings.*;
009: import org.wings.session.SessionManager;
010:
011: import javax.swing.event.ListSelectionEvent;
012: import javax.swing.event.ListSelectionListener;
013:
014: /**
015: * @author hengels
016: */
017: public class NewsFeedPanel extends SPanel implements
018: FeedUpdatedListener {
019: private static Poller poller;
020: private String feed;
021: private String user;
022: private String password;
023: private SList list = new SList();
024: private java.util.Map<String, Object> values = new java.util.HashMap<String, Object>();
025:
026: private static org.wings.util.SessionLocal<Integer> feedNo = new org.wings.util.SessionLocal<Integer>() {
027: @Override
028: protected Integer initialValue() {
029: return 0;
030: }
031: };
032:
033: public NewsFeedPanel() {
034: setName("newsfeedpanel" + feedNo.get().toString());
035: feedNo.set(feedNo.get() + 1);
036: setLayout(new SBorderLayout());
037: }
038:
039: public String getFeed() {
040: return feed;
041: }
042:
043: public void setFeed(String feed) {
044: this .feed = feed;
045:
046: if (poller == null)
047: poller = new Poller();
048:
049: poller.registerFeedUpdatedListener(feed,
050: (FeedUpdatedListener) this );
051:
052: list = new SList();
053: list.setShowAsFormComponent(false);
054: list
055: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
056: list.setOrderType("none");
057:
058: list.addListSelectionListener(new ListSelectionListener() {
059: public void valueChanged(ListSelectionEvent e) {
060: if (list.getSelectedIndex() == -1)
061: return;
062:
063: NewsFeedEntry entry = (NewsFeedEntry) list
064: .getSelectedValue();
065: SessionManager.getSession().setRedirectAddress(
066: entry.getUrl());
067: list.clearSelection();
068: }
069: });
070:
071: add(list);
072: this .reload();
073: }
074:
075: public boolean feedUpdated(SyndFeed feed) {
076: SDefaultListModel model = new SDefaultListModel();
077:
078: for (Object obj : feed.getEntries()) {
079: SyndEntryImpl entry = (SyndEntryImpl) obj;
080: model.addElement(new NewsFeedEntry(entry.getTitle(), entry
081: .getLink()));
082: }
083:
084: list.setModel(model);
085: list.reload();
086: return true;
087: }
088:
089: public void destroy() {
090: poller.unregisterFeedUpdatedListener(this .feed,
091: (FeedUpdatedListener) this );
092:
093: }
094:
095: private class NewsFeedEntry {
096: private String text;
097: private String url;
098:
099: public NewsFeedEntry(String text, String url) {
100: this .text = text;
101: this .url = url;
102: }
103:
104: public String getText() {
105: return text;
106: }
107:
108: public void setText(String text) {
109: this .text = text;
110: }
111:
112: public String getUrl() {
113: return url;
114: }
115:
116: public void setUrl(String url) {
117: this .url = url;
118: }
119:
120: public String toString() {
121: return getText();
122: }
123: }
124:
125: }
|