Disable "Refresh PHP Browser view when opening editor" and "Show PHP
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.news / src / net / sourceforge / phpeclipse / news / view / HeadlineView.java
1 /*
2  * Created on 15 mai 2004
3  * Copyright 2004 J�r�me N�gre
4  */
5 package net.sourceforge.phpeclipse.news.view;
6
7 import java.util.ArrayList;
8 import java.util.Iterator;
9
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;
15
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;
24
25 /**
26  * @author J�r�me N�gre
27  */
28 public class HeadlineView extends ViewPart implements RssListener {
29         
30         Table table;
31
32         public HeadlineView() {
33                 super();
34         }
35
36         public void dispose() {
37                 Plugin.getDefault().removeRssListener(this);
38                 super.dispose();
39         }
40
41         private TableColumn createColumn(int style, int width, String text) {
42                 TableColumn col = new TableColumn(table, style);
43                 col.setWidth(width);
44                 col.setText(text);
45                 return col;
46         }
47         
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);
59                         }
60         });
61         Plugin.getDefault().addRssListener(this);
62         }
63         
64         public void setFocus() {
65                 table.setFocus();
66         }
67
68         public void onChannelListChanged(ArrayList channels) {
69                 // NOP
70         }
71
72         public void onChannelStatusChanged(Channel channel) {
73                 // NOP
74         }
75
76         public void onChannelSelected(Channel channel) {
77                 fillTable(channel);
78         }
79
80         public void onItemSelected(Item item) {
81                 fillTable(item.getChannel());
82                 int index = item.getChannel().getItems().indexOf(item);
83                 table.setSelection(index);
84         }
85
86         public void onItemStatusChanged(Item item) {
87                 fillTable(item.getChannel());
88                 int index = item.getChannel().getItems().indexOf(item);
89                 table.setSelection(index);
90         }
91         
92         private void fillTable(Channel channel) {
93                 Iterator items = channel.getItems().iterator();
94                 table.removeAll();
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);
103                 }
104         }
105 }