2
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.carbide.cpp.internal.news.reader.editor;
|
|
19 |
|
|
20 |
import java.net.URL;
|
|
21 |
import java.util.ArrayList;
|
|
22 |
import java.util.Collections;
|
|
23 |
import java.util.Date;
|
|
24 |
import java.util.Iterator;
|
|
25 |
import java.util.List;
|
|
26 |
import java.util.regex.Matcher;
|
|
27 |
import java.util.regex.Pattern;
|
|
28 |
|
|
29 |
import org.eclipse.jface.preference.IPreferenceStore;
|
|
30 |
import org.eclipse.jface.preference.PreferenceDialog;
|
|
31 |
import org.eclipse.jface.viewers.ArrayContentProvider;
|
|
32 |
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
|
33 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
34 |
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
|
35 |
import org.eclipse.jface.viewers.TableViewer;
|
|
36 |
import org.eclipse.swt.SWT;
|
|
37 |
import org.eclipse.swt.browser.Browser;
|
|
38 |
import org.eclipse.swt.browser.LocationEvent;
|
|
39 |
import org.eclipse.swt.browser.LocationListener;
|
|
40 |
import org.eclipse.swt.events.SelectionAdapter;
|
|
41 |
import org.eclipse.swt.events.SelectionEvent;
|
|
42 |
import org.eclipse.swt.layout.GridData;
|
|
43 |
import org.eclipse.swt.layout.GridLayout;
|
|
44 |
import org.eclipse.swt.widgets.Button;
|
|
45 |
import org.eclipse.swt.widgets.Composite;
|
|
46 |
import org.eclipse.ui.PlatformUI;
|
|
47 |
import org.eclipse.ui.dialogs.PreferencesUtil;
|
|
48 |
import org.eclipse.ui.forms.IManagedForm;
|
|
49 |
import org.eclipse.ui.forms.SectionPart;
|
|
50 |
import org.eclipse.ui.forms.editor.FormEditor;
|
|
51 |
import org.eclipse.ui.forms.editor.FormPage;
|
|
52 |
import org.eclipse.ui.forms.widgets.FormToolkit;
|
|
53 |
import org.eclipse.ui.forms.widgets.ScrolledForm;
|
|
54 |
import org.eclipse.ui.forms.widgets.Section;
|
|
55 |
|
|
56 |
import com.nokia.carbide.cpp.internal.news.reader.CarbideNewsReaderPlugin;
|
|
57 |
import com.nokia.carbide.cpp.internal.news.reader.Messages;
|
|
58 |
import com.nokia.carbide.cpp.internal.news.reader.feed.CarbideSyndEntry;
|
|
59 |
import com.nokia.carbide.cpp.internal.news.reader.feed.CarbideSyndFeed;
|
|
60 |
import com.nokia.carbide.cpp.internal.news.reader.ui.NewsPreferenceConstants;
|
|
61 |
import com.nokia.carbide.cpp.internal.news.reader.ui.NewsUIHelpIDs;
|
|
62 |
import com.sun.syndication.feed.synd.SyndFeed;
|
|
63 |
import com.sun.syndication.feed.synd.SyndFeedImpl;
|
|
64 |
import com.sun.syndication.io.impl.DateParser;
|
|
65 |
|
|
66 |
/**
|
|
67 |
* A form page to display Carbide.c++ news contents.
|
|
68 |
*
|
|
69 |
*/
|
|
70 |
public class NewsPage extends FormPage {
|
|
71 |
|
|
72 |
public final static String NEWS_PAGE_ID = "news";
|
|
73 |
public final static String NEWS_PAGE_TITLE = "Carbide.c++ News Page";
|
|
74 |
public final static String NEWS_SUMMARY_TITLE = "All News";
|
|
75 |
private final static String ECLIPSE_NETWORK_PREFERENCES_ID = "org.eclipse.ui.net.NetPreferences";
|
|
76 |
private final static String LINK_MARK_ALL_ENTRIES_READ = "about:removeAll";
|
|
77 |
private final static String LINK_MARK_ENTRY_READ = "about:removeEntry";
|
|
78 |
private final static String LINK_NEWS_PREFERENCES = "about:newsPreferences";
|
|
79 |
private final static String LINK_NETWORK_PREFERENCES = "about:networkPreferences";
|
|
80 |
private final static String LINK_SHOW_ALL_ENTRIES = "about:showAll";
|
|
81 |
private final static String LINK_SHOW_UNREAD_ENTRIES = "about:showUnreadOnly";
|
|
82 |
private final static String LINK_UPDATE_FEEDS = "about:updateFeeds";
|
|
83 |
private final static String DELIMETER = "::";
|
|
84 |
private final static String HTML_BODY_HEADER = "<html><head><title></title><style type=\"text/css\">div.item {font-family : sans-serif; font-size : 12px; margin-bottom : 16px;} div.itemBody {padding-top : 3px; padding-bottom : 3px;} div.itemInfo {background-color : #EEEEEE; color : #333333;} div.feedflare {display: none;} a.itemTitle {font-size : 12px; font-weight : bold;} a.markItemRead {font-size : 10px; color : #333333;}</style></head><body>";
|
|
85 |
private final static String HTML_BODY_FOOTER = "</body></html>";
|
|
86 |
private final static String HTML_CONTROLS_HEADER_START = "<div class=\"item\"><div class=\"itemInfo\">";
|
|
87 |
private final static String HTML_CONTROLS_HEADER_END = "</div></div>";
|
|
88 |
private final static String HTML_CONTROLS_DIVIDER = " | ";
|
|
89 |
private final static String HTML_MARK_ALL_ENTRIES_READ_CONTROL = "<a class=\"markItemRead\" href=\"about:removeAll\">Mark All Read</a>";
|
|
90 |
private final static String HTML_NEWS_PREFERENCES_CONTROL = "<a class=\"markItemRead\" href=\"about:newsPreferences\">Preferences</a>";
|
|
91 |
private final static String HTML_NETWORK_PREFERENCES_CONTROL = "<a href=\"about:networkPreferences\">Network Connections Preferences</a>";
|
|
92 |
private final static String HTML_SHOW_ALL_ENTIES_CONTROL = "<a class=\"markItemRead\" href=\"about:showAll\">All Items</a>";
|
|
93 |
private final static String HTML_SHOW_UNREAD_ENTIES_CONTROL = "<a class=\"markItemRead\" href=\"about:showUnreadOnly\">Unread Items Only</a>";
|
|
94 |
private final static String HTML_UPDATE_FEEDS_CONTROL = "<a class=\"markItemRead\" href=\"about:updateFeeds\">Update</a>";
|
|
95 |
private Pattern MarkEntryReadPattern = Pattern.compile("about:removeEntry::(.*)::(.*)");
|
|
96 |
private List<CarbideSyndFeed> newsFeeds;
|
|
97 |
private int currentFeed;
|
|
98 |
private Button launchCtrlButton;
|
|
99 |
private SectionPart gsSectionPart;
|
|
100 |
private SectionPart newsFeedsSectionPart;
|
|
101 |
private SectionPart newsContentsSectionPart;
|
|
102 |
private TableViewer gsTableViewer;
|
|
103 |
private TableViewer newsFeedsTableViewer;
|
|
104 |
private Browser newsBrowser;
|
|
105 |
private boolean showUnreadOnly;
|
|
106 |
|
|
107 |
/**
|
|
108 |
* The constructor.
|
|
109 |
*/
|
|
110 |
public NewsPage() {
|
|
111 |
super(NEWS_PAGE_ID, NEWS_PAGE_TITLE);
|
|
112 |
currentFeed = 0;
|
|
113 |
showUnreadOnly = true;
|
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
* The constructor.
|
|
118 |
* @param editor - the editor hosting this page
|
|
119 |
*/
|
|
120 |
public NewsPage(FormEditor editor) {
|
|
121 |
super(editor, NEWS_PAGE_ID, NEWS_PAGE_TITLE);
|
|
122 |
currentFeed = 0;
|
|
123 |
showUnreadOnly = true;
|
|
124 |
}
|
|
125 |
|
|
126 |
/**
|
|
127 |
* Refresh the contents of this page.
|
|
128 |
*/
|
|
129 |
public void refresh() {
|
|
130 |
refreshGettingStartedSection();
|
|
131 |
refreshNewsFeeds();
|
|
132 |
}
|
|
133 |
|
|
134 |
/*
|
|
135 |
* (non-Javadoc)
|
|
136 |
* @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
|
|
137 |
*/
|
|
138 |
@Override
|
|
139 |
protected void createFormContent(IManagedForm managedForm) {
|
|
140 |
FormToolkit toolkit = managedForm.getToolkit();
|
|
141 |
ScrolledForm form = managedForm.getForm();
|
|
142 |
form.setText(Messages.NewsPage_Title);
|
|
143 |
Composite container = form.getBody();
|
|
144 |
final GridLayout layout = new GridLayout();
|
|
145 |
layout.numColumns = 2;
|
|
146 |
container.setLayout(layout);
|
|
147 |
toolkit.paintBordersFor(container);
|
|
148 |
|
|
149 |
// News Feeds Section
|
|
150 |
createNewsFeedsSection(container, toolkit);
|
|
151 |
|
|
152 |
// News Contents Section
|
|
153 |
createNewsContentsSection(container, toolkit);
|
|
154 |
|
|
155 |
// Getting Started Section
|
|
156 |
createGettingStartedSection(container, toolkit);
|
|
157 |
|
|
158 |
// Button controlling whether to launch this page during startup
|
|
159 |
launchCtrlButton = toolkit.createButton(form.getBody(), Messages.NewsPage_LaunchCtrlLabel, SWT.CHECK);
|
|
160 |
launchCtrlButton.setToolTipText(Messages.NewsPage_LaunchCtrlMessage);
|
|
161 |
launchCtrlButton.addSelectionListener(new SelectionAdapter() {
|
|
162 |
public void widgetSelected(SelectionEvent e) {
|
|
163 |
setStoredPreferenceValues();
|
|
164 |
}
|
|
165 |
});
|
|
166 |
getStoredPreferenceValues();
|
|
167 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(container, NewsUIHelpIDs.NEWSREADER_EDITOR_PAGE);
|
|
168 |
}
|
|
169 |
|
|
170 |
/**
|
|
171 |
* Create the getting started section.
|
|
172 |
* @param container - the container composite of this section
|
|
173 |
* @param toolkit - the toolkit of this section
|
|
174 |
*/
|
|
175 |
private void createGettingStartedSection(Composite container, FormToolkit toolkit) {
|
|
176 |
gsSectionPart = new SectionPart(container, toolkit, Section.TITLE_BAR | Section.EXPANDED);
|
|
177 |
final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, false, true);
|
|
178 |
layoutData.widthHint = 250;
|
|
179 |
layoutData.heightHint = 150;
|
|
180 |
gsSectionPart.getSection().setLayoutData(layoutData);
|
|
181 |
gsSectionPart.getSection().setText(Messages.NewsPage_GettingStartedSectionTitle);
|
|
182 |
|
|
183 |
Composite composite = toolkit.createComposite(gsSectionPart.getSection());
|
|
184 |
final GridLayout layout = new GridLayout();
|
|
185 |
composite.setLayout(layout);
|
|
186 |
toolkit.paintBordersFor(composite);
|
|
187 |
gsSectionPart.getSection().setClient(composite);
|
|
188 |
|
|
189 |
gsTableViewer = new TableViewer(composite, SWT.NONE);
|
|
190 |
final GridData layoutData1 = new GridData(SWT.FILL, SWT.FILL, true, true);
|
|
191 |
gsTableViewer.getTable().setLayoutData(layoutData1);
|
|
192 |
gsTableViewer.setLabelProvider(new NewsPageLabelProvider(SWT.COLOR_DARK_BLUE));
|
|
193 |
gsTableViewer.setContentProvider(new ArrayContentProvider());
|
|
194 |
if (CarbideNewsReaderPlugin.getFeedManager().getResourceFeed() != null) {
|
|
195 |
gsTableViewer.setInput(CarbideNewsReaderPlugin.getFeedManager().getResourceFeed().getEntries());
|
|
196 |
}
|
|
197 |
gsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
|
198 |
public void selectionChanged(SelectionChangedEvent event) {
|
|
199 |
try {
|
|
200 |
Object element = ((IStructuredSelection)event.getSelection()).getFirstElement();
|
|
201 |
if (element instanceof CarbideSyndEntry) {
|
|
202 |
CarbideSyndEntry entry = (CarbideSyndEntry)element;
|
|
203 |
newsBrowser.setText(createGettingStartedContents(entry));
|
|
204 |
}
|
|
205 |
} catch (Exception e) {
|
|
206 |
CarbideNewsReaderPlugin.log(e);
|
|
207 |
}
|
|
208 |
}
|
|
209 |
});
|
|
210 |
}
|
|
211 |
|
|
212 |
/**
|
|
213 |
* Create the new feeds section.
|
|
214 |
* @param container - the container composite of this section
|
|
215 |
* @param toolkit - the toolkit of this section
|
|
216 |
*/
|
|
217 |
private void createNewsFeedsSection(Composite container, FormToolkit toolkit) {
|
|
218 |
newsFeedsSectionPart = new SectionPart(container, toolkit, Section.TITLE_BAR | Section.EXPANDED);
|
|
219 |
final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, false, true);
|
|
220 |
layoutData.widthHint = 250;
|
|
221 |
layoutData.heightHint = 150;
|
|
222 |
newsFeedsSectionPart.getSection().setLayoutData(layoutData);
|
|
223 |
newsFeedsSectionPart.getSection().setText(Messages.NewsPage_NewsFeedsSectionTitle);
|
|
224 |
|
|
225 |
Composite composite = toolkit.createComposite(newsFeedsSectionPart.getSection());
|
|
226 |
final GridLayout layout = new GridLayout();
|
|
227 |
composite.setLayout(layout);
|
|
228 |
toolkit.paintBordersFor(composite);
|
|
229 |
newsFeedsSectionPart.getSection().setClient(composite);
|
|
230 |
|
|
231 |
newsFeedsTableViewer = new TableViewer(composite, SWT.NONE);
|
|
232 |
final GridData layoutData1 = new GridData(SWT.FILL, SWT.FILL, true, true);
|
|
233 |
newsFeedsTableViewer.getTable().setLayoutData(layoutData1);
|
|
234 |
newsFeedsTableViewer.setLabelProvider(new NewsPageLabelProvider(SWT.COLOR_DARK_BLUE));
|
|
235 |
newsFeedsTableViewer.setContentProvider(new ArrayContentProvider());
|
|
236 |
if (CarbideNewsReaderPlugin.getFeedManager().getSubscribedNewsFeeds() != null) {
|
|
237 |
createNewsFeeds();
|
|
238 |
newsFeedsTableViewer.setInput(newsFeeds);
|
|
239 |
newsFeedsTableViewer.getTable().setSelection(currentFeed);
|
|
240 |
newsFeedsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
|
241 |
public void selectionChanged(SelectionChangedEvent event) {
|
|
242 |
setCurrentFeed();
|
|
243 |
}
|
|
244 |
});
|
|
245 |
}
|
|
246 |
}
|
|
247 |
|
|
248 |
/**
|
|
249 |
* Create the news content section.
|
|
250 |
* @param container - the container composite of this section
|
|
251 |
* @param toolkit - the toolkit of this section
|
|
252 |
*/
|
|
253 |
private void createNewsContentsSection(Composite container, FormToolkit toolkit) {
|
|
254 |
newsContentsSectionPart = new SectionPart(container, toolkit, Section.TITLE_BAR);
|
|
255 |
final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
|
|
256 |
layoutData.verticalSpan = 2;
|
|
257 |
newsContentsSectionPart.getSection().setLayoutData(layoutData);
|
|
258 |
newsContentsSectionPart.getSection().setText(Messages.NewsPage_NewsContentsSectionTitle);
|
|
259 |
|
|
260 |
Composite composite = toolkit.createComposite(newsContentsSectionPart.getSection());
|
|
261 |
final GridLayout layout = new GridLayout();
|
|
262 |
composite.setLayout(layout);
|
|
263 |
toolkit.paintBordersFor(composite);
|
|
264 |
newsContentsSectionPart.getSection().setClient(composite);
|
|
265 |
|
|
266 |
newsBrowser = new Browser(composite, SWT.NONE);
|
|
267 |
final GridData browserLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
|
|
268 |
newsBrowser.setLayoutData(browserLayoutData);
|
|
269 |
try {
|
|
270 |
if (CarbideNewsReaderPlugin.getFeedManager().getSubscribedNewsFeeds() != null) {
|
|
271 |
newsBrowser.setText(createNewsContents());
|
|
272 |
}
|
|
273 |
} catch (Exception e) {
|
|
274 |
CarbideNewsReaderPlugin.log(e);
|
|
275 |
}
|
|
276 |
newsBrowser.addLocationListener(new LocationListener() {
|
|
277 |
public void changing(LocationEvent event) {
|
|
278 |
handleChangingLocation(event);
|
|
279 |
}
|
|
280 |
|
|
281 |
public void changed(LocationEvent event) {
|
|
282 |
}
|
|
283 |
});
|
|
284 |
}
|
|
285 |
|
|
286 |
/**
|
|
287 |
* Create the Getting Started content.
|
|
288 |
* @param entry - getting started entry in question
|
|
289 |
* @return HTML getting started entry content
|
|
290 |
*/
|
|
291 |
private String createGettingStartedContents(CarbideSyndEntry entry) {
|
|
292 |
String contents = HTML_BODY_HEADER;
|
|
293 |
String content = "";
|
|
294 |
if (entry != null) {
|
|
295 |
String entryLink = entry.getLink();
|
|
296 |
String entryTitle = entry.getTitle();
|
|
297 |
content += "<div class=\"item\"><a class=\"itemTitle\" href=\""
|
|
298 |
+ entryLink + "\">" + entryTitle + "</a>";
|
|
299 |
|
|
300 |
if (entry.getDescription() != null) {
|
|
301 |
String entryDescription = entry.getDescription();
|
|
302 |
content += "<div class=\"itemBody\">" + entryDescription + "</div>";
|
|
303 |
}
|
|
304 |
|
|
305 |
String title = Messages.NewsPage_GettingStartedSectionTitle;
|
|
306 |
String entryDate = "";
|
|
307 |
Date date = entry.getPublishedDate();
|
|
308 |
if (date != null) {
|
|
309 |
entryDate = DateParser.formatRFC822(date);
|
|
310 |
}
|
|
311 |
content += "<div class=\"itemInfo\">" + title + " (" + entryDate + ")</div></div>";
|
|
312 |
}
|
|
313 |
contents += createGettingStartedControlsHeader() + content + HTML_BODY_FOOTER;
|
|
314 |
return contents;
|
|
315 |
}
|
|
316 |
|
|
317 |
/**
|
|
318 |
* Create the HTML controls header for Getting Started content.
|
|
319 |
* @return HTML controls header for Getting Started content
|
|
320 |
*/
|
|
321 |
private String createGettingStartedControlsHeader() {
|
|
322 |
String header = HTML_CONTROLS_HEADER_START; // controls header start
|
|
323 |
|
|
324 |
header += HTML_NEWS_PREFERENCES_CONTROL;
|
|
325 |
header += HTML_CONTROLS_DIVIDER;
|
|
326 |
header += HTML_UPDATE_FEEDS_CONTROL;
|
|
327 |
|
|
328 |
header += HTML_CONTROLS_HEADER_END; // controls header end
|
|
329 |
return header;
|
|
330 |
}
|
|
331 |
|
|
332 |
/**
|
|
333 |
* Create the HTML news content.
|
|
334 |
* @return HTML news content
|
|
335 |
*/
|
|
336 |
private String createNewsContents() {
|
|
337 |
String contents = HTML_BODY_HEADER;
|
|
338 |
String news = "";
|
|
339 |
if (CarbideNewsReaderPlugin.getFeedManager().isCacheEmpty()) {
|
|
340 |
news += createNewsErrorMessage();
|
|
341 |
}
|
|
342 |
else if (currentFeed < newsFeeds.size()) {
|
|
343 |
CarbideSyndFeed feed = newsFeeds.get(currentFeed);
|
|
344 |
news += getFeedContents(feed);
|
|
345 |
}
|
|
346 |
contents += createNewsControlsHeader() + news + HTML_BODY_FOOTER;
|
|
347 |
return contents;
|
|
348 |
}
|
|
349 |
|
|
350 |
/**
|
|
351 |
* Create the HTML controls header for news content.
|
|
352 |
* @return HTML controls header for news content
|
|
353 |
*/
|
|
354 |
private String createNewsControlsHeader() {
|
|
355 |
String header = HTML_CONTROLS_HEADER_START; // controls header start
|
|
356 |
|
|
357 |
header += HTML_MARK_ALL_ENTRIES_READ_CONTROL;
|
|
358 |
header += HTML_CONTROLS_DIVIDER;
|
|
359 |
|
|
360 |
if (showUnreadOnly) {
|
|
361 |
header += HTML_SHOW_ALL_ENTIES_CONTROL;
|
|
362 |
header += HTML_CONTROLS_DIVIDER;
|
|
363 |
}
|
|
364 |
else {
|
|
365 |
header += HTML_SHOW_UNREAD_ENTIES_CONTROL;
|
|
366 |
header += HTML_CONTROLS_DIVIDER;
|
|
367 |
}
|
|
368 |
|
|
369 |
header += HTML_NEWS_PREFERENCES_CONTROL;
|
|
370 |
header += HTML_CONTROLS_DIVIDER;
|
|
371 |
header += HTML_UPDATE_FEEDS_CONTROL;
|
|
372 |
|
|
373 |
header += HTML_CONTROLS_HEADER_END; // controls header end
|
|
374 |
return header;
|
|
375 |
}
|
|
376 |
|
|
377 |
/**
|
|
378 |
* Create error message when local cache is empty and network connection fails.
|
|
379 |
* @return error message.
|
|
380 |
*/
|
|
381 |
private String createNewsErrorMessage() {
|
|
382 |
String message = "<div class=\"itemBody\">Unable to fetch feeds from news servers. Please check the "
|
|
383 |
+ HTML_NETWORK_PREFERENCES_CONTROL + ".</div>";
|
|
384 |
return message;
|
|
385 |
}
|
|
386 |
|
|
387 |
/**
|
|
388 |
* Retrieve the cached news feeds.
|
|
389 |
*/
|
|
390 |
private void createNewsFeeds() {
|
|
391 |
if (newsFeeds == null) {
|
|
392 |
newsFeeds = new ArrayList<CarbideSyndFeed>();
|
|
393 |
}
|
|
394 |
|
|
395 |
CarbideSyndFeed summaryFeed = createSummaryFeed();
|
|
396 |
newsFeeds.add(summaryFeed);
|
|
397 |
List<CarbideSyndFeed> subscribedNewsFeeds = CarbideNewsReaderPlugin.getFeedManager().getSubscribedNewsFeeds();
|
|
398 |
newsFeeds.addAll(subscribedNewsFeeds);
|
|
399 |
}
|
|
400 |
|
|
401 |
/**
|
|
402 |
* Create a summary feed for entries from all available news feeds.
|
|
403 |
* @return summary feed
|
|
404 |
*/
|
|
405 |
private CarbideSyndFeed createSummaryFeed() {
|
|
406 |
List<CarbideSyndFeed> newsFeeds = CarbideNewsReaderPlugin.getFeedManager().getSubscribedNewsFeeds();
|
|
407 |
SyndFeed sFeed = new SyndFeedImpl();
|
|
408 |
sFeed.setTitle(NEWS_SUMMARY_TITLE);
|
|
409 |
CarbideSyndFeed summaryFeed = new CarbideSyndFeed(sFeed);
|
|
410 |
List<CarbideSyndEntry> entries = new ArrayList<CarbideSyndEntry>();
|
|
411 |
for (Iterator<CarbideSyndFeed> iterator = newsFeeds.iterator(); iterator.hasNext();) {
|
|
412 |
CarbideSyndFeed feed = iterator.next();
|
|
413 |
entries.addAll(feed.getEntries());
|
|
414 |
}
|
|
415 |
Collections.sort(entries);
|
|
416 |
summaryFeed.setEntries(entries);
|
|
417 |
return summaryFeed;
|
|
418 |
}
|
|
419 |
|
|
420 |
/**
|
|
421 |
* Retrieve contents of a feed in HTML format.
|
|
422 |
* @param feed - the feed in question
|
|
423 |
* @return feed contents in HTML format
|
|
424 |
*/
|
|
425 |
private String getFeedContents(CarbideSyndFeed feed) {
|
|
426 |
String contents = "";
|
|
427 |
List<CarbideSyndEntry> entries;
|
|
428 |
if (showUnreadOnly) {
|
|
429 |
entries = feed.getUnreadEntries();
|
|
430 |
}
|
|
431 |
else {
|
|
432 |
entries = feed.getEntries();
|
|
433 |
}
|
|
434 |
for (Iterator<CarbideSyndEntry> iterator = entries.iterator(); iterator.hasNext();) {
|
|
435 |
CarbideSyndEntry entry = iterator.next();
|
|
436 |
contents += getFeedEntryContents(feed, entry);
|
|
437 |
}
|
|
438 |
return contents;
|
|
439 |
}
|
|
440 |
|
|
441 |
/**
|
|
442 |
* Retrieve contents of a feed entry in HTML format.
|
|
443 |
* @param feed - feed in question
|
|
444 |
* @param entry - feed entry in question
|
|
445 |
* @return feed entry content in HTML format
|
|
446 |
*/
|
|
447 |
private String getFeedEntryContents(CarbideSyndFeed feed, CarbideSyndEntry entry) {
|
|
448 |
String result = "";
|
|
449 |
if (entry != null) {
|
|
450 |
String entryLink = entry.getLink();
|
|
451 |
String entryTitle = entry.getTitle();
|
|
452 |
result += "<div class=\"item\"><a class=\"itemTitle\" href=\""
|
|
453 |
+ entryLink + "\">" + entryTitle + "</a>";
|
|
454 |
|
|
455 |
if (entry.getDescription() != null) {
|
|
456 |
String entryDescription = entry.getDescription();
|
|
457 |
result += "<div class=\"itemBody\">" + entryDescription + "</div>";
|
|
458 |
}
|
|
459 |
|
|
460 |
String feedTitle = feed.getTitle();
|
|
461 |
String entryDate = "";
|
|
462 |
Date date = entry.getPublishedDate();
|
|
463 |
if (date == null) {
|
|
464 |
date = feed.getPublishedDate();
|
|
465 |
}
|
|
466 |
if (date != null) {
|
|
467 |
entryDate = DateParser.formatRFC822(date);
|
|
468 |
}
|
|
469 |
result += "<div class=\"itemInfo\">" + feedTitle + " (" + entryDate + ") ";
|
|
470 |
|
|
471 |
if (!entry.isRead()) {
|
|
472 |
result += "<a class=\"markItemRead\" href=\""
|
|
473 |
+ LINK_MARK_ENTRY_READ
|
|
474 |
+ DELIMETER + feedTitle
|
|
475 |
+ DELIMETER + entryTitle
|
|
476 |
+ "\">Mark Read</a>";
|
|
477 |
}
|
|
478 |
|
|
479 |
result += "</div></div>";
|
|
480 |
}
|
|
481 |
return result;
|
|
482 |
}
|
|
483 |
|
|
484 |
/**
|
|
485 |
* Retrieve the stored preference settings values of this page.
|
|
486 |
*/
|
|
487 |
private void getStoredPreferenceValues() {
|
|
488 |
IPreferenceStore store = CarbideNewsReaderPlugin.getPrefsStore();
|
|
489 |
boolean launchAtStartup = store.getBoolean(NewsPreferenceConstants.LAUNCH_AT_STARTUP);
|
|
490 |
launchCtrlButton.setSelection(launchAtStartup);
|
|
491 |
}
|
|
492 |
|
|
493 |
/**
|
|
494 |
* Handle navigation of the browser widget in the news contents section.
|
|
495 |
* @param event - LocationEvent sent by the browser widget
|
|
496 |
*/
|
|
497 |
private void handleChangingLocation(LocationEvent event) {
|
|
498 |
try {
|
|
499 |
String targetLocation = event.location;
|
|
500 |
if (targetLocation.startsWith("http")) {
|
|
501 |
event.doit = false;
|
|
502 |
URL url = new URL(event.location);
|
|
503 |
PlatformUI.getWorkbench().getBrowserSupport().createBrowser(null).openURL(url);
|
|
504 |
}
|
|
505 |
else if (targetLocation.startsWith(LINK_MARK_ALL_ENTRIES_READ)) {
|
|
506 |
handleMarkAllRead();
|
|
507 |
}
|
|
508 |
else if (targetLocation.startsWith(LINK_MARK_ENTRY_READ)) {
|
|
509 |
Matcher matcher = MarkEntryReadPattern.matcher(targetLocation);
|
|
510 |
if (matcher.matches()) {
|
|
511 |
String feedTitle = matcher.group(1).replaceAll("%20", " ");
|
|
512 |
String entryTitle = matcher.group(2).replaceAll("%20", " ");
|
|
513 |
handleMarkEntryRead(feedTitle, entryTitle);
|
|
514 |
}
|
|
515 |
}
|
|
516 |
else if (targetLocation.startsWith(LINK_NEWS_PREFERENCES)) {
|
|
517 |
handleOpenNewsPreferencePage();
|
|
518 |
}
|
|
519 |
else if (targetLocation.startsWith(LINK_NETWORK_PREFERENCES)) {
|
|
520 |
handleOpenNetworkPreferencePage();
|
|
521 |
}
|
|
522 |
else if (targetLocation.startsWith(LINK_SHOW_ALL_ENTRIES)) {
|
|
523 |
handleShowAll();
|
|
524 |
}
|
|
525 |
else if (targetLocation.startsWith(LINK_SHOW_UNREAD_ENTRIES)) {
|
|
526 |
handleShowUnreadOnly();
|
|
527 |
}
|
|
528 |
else if (targetLocation.startsWith(LINK_UPDATE_FEEDS)) {
|
|
529 |
handleUpdateFeeds();
|
|
530 |
}
|
|
531 |
} catch (Exception e) {
|
|
532 |
CarbideNewsReaderPlugin.log(e);
|
|
533 |
}
|
|
534 |
}
|
|
535 |
|
|
536 |
/**
|
|
537 |
* Handle marking all entries from a given feed as read.
|
|
538 |
*/
|
|
539 |
private void handleMarkAllRead() {
|
|
540 |
if (currentFeed < newsFeeds.size()) {
|
|
541 |
CarbideSyndFeed feed = newsFeeds.get(currentFeed);
|
|
542 |
for (Iterator<CarbideSyndEntry> eIterator = feed.getEntries().iterator(); eIterator.hasNext();) {
|
|
543 |
CarbideSyndEntry entry = eIterator.next();
|
|
544 |
entry.setRead(true);
|
|
545 |
}
|
|
546 |
}
|
|
547 |
newsBrowser.setText(createNewsContents());
|
|
548 |
newsFeedsTableViewer.refresh();
|
|
549 |
CarbideNewsReaderPlugin.getFeedManager().unreadEntriesCountChanged();
|
|
550 |
}
|
|
551 |
|
|
552 |
/**
|
|
553 |
* Handle marking a feed entry as read.
|
|
554 |
* @param feedTitle - title of the feed in question
|
|
555 |
* @param entryTitle - title of the feed entry in question
|
|
556 |
*/
|
|
557 |
private void handleMarkEntryRead(String feedTitle, String entryTitle) {
|
|
558 |
CarbideSyndFeed feed = newsFeeds.get(currentFeed);
|
|
559 |
if (feed != null) {
|
99
|
560 |
CarbideNewsReaderPlugin.getFeedManager().markEntryAsRead(feed.getEntries(), entryTitle);
|
2
|
561 |
}
|
|
562 |
newsBrowser.setText(createNewsContents());
|
|
563 |
newsFeedsTableViewer.refresh();
|
|
564 |
CarbideNewsReaderPlugin.getFeedManager().unreadEntriesCountChanged();
|
|
565 |
}
|
|
566 |
|
|
567 |
/**
|
|
568 |
* Handle opening the Carbide.c++ news preference page.
|
|
569 |
*/
|
|
570 |
private void handleOpenNewsPreferencePage() {
|
|
571 |
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getSite().getShell(), NewsPreferenceConstants.PREFERENCE_PAGE_ID, null, null);
|
|
572 |
dialog.open();
|
|
573 |
newsBrowser.setText(createNewsContents());
|
|
574 |
}
|
|
575 |
|
|
576 |
/**
|
|
577 |
* Handle opening the Eclipse network connections preference page.
|
|
578 |
*/
|
|
579 |
private void handleOpenNetworkPreferencePage() {
|
|
580 |
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getSite().getShell(), ECLIPSE_NETWORK_PREFERENCES_ID, null, null);
|
|
581 |
dialog.open();
|
|
582 |
newsBrowser.setText(createNewsContents());
|
|
583 |
CarbideNewsReaderPlugin.loadFeeds();
|
|
584 |
}
|
|
585 |
|
|
586 |
/**
|
|
587 |
* Handle displaying all read and unread feed entries.
|
|
588 |
*/
|
|
589 |
private void handleShowAll() {
|
|
590 |
showUnreadOnly = false;
|
|
591 |
newsBrowser.setText(createNewsContents());
|
|
592 |
newsFeedsTableViewer.refresh();
|
|
593 |
}
|
|
594 |
|
|
595 |
/**
|
|
596 |
* Handle displaying only unread feed entries.
|
|
597 |
*/
|
|
598 |
private void handleShowUnreadOnly() {
|
|
599 |
showUnreadOnly = true;
|
|
600 |
newsBrowser.setText(createNewsContents());
|
|
601 |
newsFeedsTableViewer.refresh();
|
|
602 |
}
|
|
603 |
|
|
604 |
/**
|
|
605 |
* Handle updating feeds.
|
|
606 |
*/
|
|
607 |
private void handleUpdateFeeds() {
|
|
608 |
newsBrowser.setText(createNewsContents());
|
|
609 |
CarbideNewsReaderPlugin.updateFeeds();
|
|
610 |
}
|
|
611 |
|
|
612 |
/**
|
|
613 |
* Update content of the getting started section.
|
|
614 |
*/
|
|
615 |
private void refreshGettingStartedSection() {
|
|
616 |
if (CarbideNewsReaderPlugin.getFeedManager().getResourceFeed() != null) {
|
|
617 |
gsTableViewer.setInput(CarbideNewsReaderPlugin.getFeedManager().getResourceFeed().getEntries());
|
|
618 |
gsTableViewer.refresh();
|
|
619 |
}
|
|
620 |
}
|
|
621 |
|
|
622 |
/**
|
|
623 |
* Update the news feeds list.
|
|
624 |
*/
|
|
625 |
private void refreshNewsFeeds() {
|
|
626 |
if (CarbideNewsReaderPlugin.getFeedManager().getSubscribedNewsFeeds() != null) {
|
|
627 |
newsFeeds.clear();
|
|
628 |
CarbideSyndFeed summaryFeed = createSummaryFeed();
|
|
629 |
newsFeeds.add(summaryFeed);
|
|
630 |
List<CarbideSyndFeed> subscribedNewsFeeds = CarbideNewsReaderPlugin.getFeedManager().getSubscribedNewsFeeds();
|
|
631 |
newsFeeds.addAll(subscribedNewsFeeds);
|
|
632 |
newsFeedsTableViewer.refresh();
|
|
633 |
}
|
|
634 |
}
|
|
635 |
|
|
636 |
/**
|
|
637 |
* Set the current feed based on user selection in the news feeds section.
|
|
638 |
*/
|
|
639 |
private void setCurrentFeed() {
|
|
640 |
currentFeed = newsFeedsTableViewer.getTable().getSelectionIndex();
|
|
641 |
if (currentFeed == -1) {
|
|
642 |
currentFeed = 0;
|
|
643 |
}
|
|
644 |
newsBrowser.setText(createNewsContents());
|
|
645 |
newsFeedsTableViewer.getTable().setSelection(currentFeed);
|
|
646 |
}
|
|
647 |
|
|
648 |
/**
|
|
649 |
* Save the preference settings values of this page.
|
|
650 |
*/
|
|
651 |
private void setStoredPreferenceValues() {
|
|
652 |
IPreferenceStore store = CarbideNewsReaderPlugin.getPrefsStore();
|
|
653 |
boolean launchAtStartup = launchCtrlButton.getSelection();
|
|
654 |
store.setValue(NewsPreferenceConstants.LAUNCH_AT_STARTUP, launchAtStartup);
|
|
655 |
}
|
|
656 |
|
|
657 |
}
|