inserted nodes.clear() for every Partitioner initializing
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.news / src / net / sourceforge / phpeclipse / news / view / NewsTreeViewerProvider.java
1 /*
2  * Created on 16 mai 2004
3  * Copyright 2004 Jérôme Nègre
4  */
5 package net.sourceforge.phpeclipse.news.view;
6
7 import net.sourceforge.phpeclipse.news.Channel;
8 import net.sourceforge.phpeclipse.news.IconManager;
9 import net.sourceforge.phpeclipse.news.Item;
10 import net.sourceforge.phpeclipse.news.Plugin;
11
12 import org.eclipse.jface.viewers.ILabelProvider;
13 import org.eclipse.jface.viewers.ILabelProviderListener;
14 import org.eclipse.jface.viewers.ITreeContentProvider;
15 import org.eclipse.jface.viewers.Viewer;
16 import org.eclipse.swt.graphics.Image;
17
18 /**
19  * @author Jérôme Nègre
20  */
21 public class NewsTreeViewerProvider
22                 implements
23                         ITreeContentProvider,
24                         ILabelProvider {
25
26         public Object[] getChildren(Object parentElement) {
27                 if(parentElement instanceof Channel) {
28                         return ((Channel)parentElement).getItems().toArray();
29                 } else {
30                         return null;
31                 }
32         }
33
34         /* (non-Javadoc)
35          * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
36          */
37         public Object getParent(Object element) {
38                 // TODO Auto-generated method stub
39                 return null;
40         }
41
42         public boolean hasChildren(Object element) {
43                 if(element instanceof Channel) {
44                         return !((Channel)element).getItems().isEmpty();
45                 } else {
46                         return false;
47                 }
48         }
49
50         public Object[] getElements(Object inputElement) {
51                 return ((Plugin)inputElement).getChannelList().toArray();
52         }
53
54         /* (non-Javadoc)
55          * @see org.eclipse.jface.viewers.IContentProvider#dispose()
56          */
57         public void dispose() {
58                 // TODO Auto-generated method stub
59                 
60         }
61
62         /* (non-Javadoc)
63          * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
64          */
65         public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
66                 // TODO Auto-generated method stub
67         }
68
69         public Image getImage(Object element) {
70
71                 String iconId;
72                 
73                 if(element instanceof Channel) {
74                         Channel channel = (Channel)element;
75                         if(channel.isRefreshing()) {
76                                 iconId = IconManager.ICON_STATUS_REFRESH;
77                         } else if(channel.getErrorMessage()!=null) {
78                                 iconId = IconManager.ICON_STATUS_ERROR;
79                         } else if(channel.isUnread()) {
80                                 iconId = IconManager.ICON_STATUS_UNREAD;
81                         } else {
82                                 iconId = IconManager.ICON_STATUS_READ;
83                         }
84                 } else if(element instanceof Item) {
85                         Item item = (Item)element;
86                         if(item.isReadFlag()) {
87                                 iconId = IconManager.ICON_STATUS_READ;
88                         } else {
89                                 iconId = IconManager.ICON_STATUS_UNREAD;
90                         }
91                 } else {
92                         return null;
93                 }
94                 return Plugin.getDefault().getImageRegistry().getDescriptor(iconId).createImage();
95         }
96
97         public String getText(Object element) {
98                 if(element instanceof Channel) {
99                         return ((Channel)element).getTitle();
100                 } else if(element instanceof Item) {
101                         return ((Item)element).getUsableTitle();
102                 } else {
103                         return "Unexpected object: "+element;
104                 }
105         }
106
107         /* (non-Javadoc)
108          * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
109          */
110         public void addListener(ILabelProviderListener listener) {
111                 // TODO Auto-generated method stub
112                 
113         }
114
115         /* (non-Javadoc)
116          * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
117          */
118         public boolean isLabelProperty(Object element, String property) {
119                 // TODO Auto-generated method stub
120                 return false;
121         }
122
123         /* (non-Javadoc)
124          * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
125          */
126         public void removeListener(ILabelProviderListener listener) {
127                 // TODO Auto-generated method stub
128                 
129         }
130 }