2 * Created on 15 mai 2004
3 * Copyright 2004 J�r�me N�gre
5 package net.sourceforge.phpeclipse.news.view;
7 import java.util.ArrayList;
8 import java.util.Iterator;
10 import net.sourceforge.phpeclipse.news.Channel;
11 import net.sourceforge.phpeclipse.news.IconManager;
12 import net.sourceforge.phpeclipse.news.Item;
13 import net.sourceforge.phpeclipse.news.Plugin;
14 import net.sourceforge.phpeclipse.news.RssListener;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.SelectionAdapter;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Table;
21 import org.eclipse.swt.widgets.TableColumn;
22 import org.eclipse.swt.widgets.TableItem;
23 import org.eclipse.ui.part.ViewPart;
26 * @author J�r�me N�gre
28 public class HeadlineView extends ViewPart implements RssListener {
32 public HeadlineView() {
36 public void dispose() {
37 Plugin.getDefault().removeRssListener(this);
41 private TableColumn createColumn(int style, int width, String text) {
42 TableColumn col = new TableColumn(table, style);
48 public void createPartControl(Composite parent) {
49 table = new Table(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
50 //TODO remember the width of the columns
51 createColumn(SWT.LEFT, 120, "Publication Date");
52 createColumn(SWT.CENTER, 20, "");
53 createColumn(SWT.LEFT, 600, "Title");
54 table.setHeaderVisible(true);
55 table.addSelectionListener(new SelectionAdapter() {
56 public void widgetSelected(SelectionEvent e) {
57 Item item = (Item) e.item.getData();
58 Plugin.getDefault().notifyItemSelected(item,HeadlineView.this);
61 Plugin.getDefault().addRssListener(this);
64 public void setFocus() {
68 public void onChannelListChanged(ArrayList channels) {
72 public void onChannelStatusChanged(Channel channel) {
76 public void onChannelSelected(Channel channel) {
80 public void onItemSelected(Item item) {
81 fillTable(item.getChannel());
82 int index = item.getChannel().getItems().indexOf(item);
83 table.setSelection(index);
86 public void onItemStatusChanged(Item item) {
87 fillTable(item.getChannel());
88 int index = item.getChannel().getItems().indexOf(item);
89 table.setSelection(index);
92 private void fillTable(Channel channel) {
93 Iterator items = channel.getItems().iterator();
95 while(items.hasNext()) {
96 Item item = (Item)items.next();
97 TableItem tableItem = new TableItem(table,SWT.NONE);
98 tableItem.setText(0,item.getDate());
99 String image = item.isReadFlag()? IconManager.ICON_STATUS_READ : IconManager.ICON_STATUS_UNREAD;
100 tableItem.setImage(1,IconManager.getImage(image));
101 tableItem.setText(2,item.getUsableTitle());
102 tableItem.setData(item);