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