2 * Created on 16 mai 2004
3 * Copyright 2004 Jérôme Nègre
5 package net.sourceforge.phpeclipse.news.view;
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;
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;
19 * @author Jérôme Nègre
21 public class NewsTreeViewerProvider
26 public Object[] getChildren(Object parentElement) {
27 if(parentElement instanceof Channel) {
28 return ((Channel)parentElement).getItems().toArray();
35 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
37 public Object getParent(Object element) {
38 // TODO Auto-generated method stub
42 public boolean hasChildren(Object element) {
43 if(element instanceof Channel) {
44 return !((Channel)element).getItems().isEmpty();
50 public Object[] getElements(Object inputElement) {
51 return ((Plugin)inputElement).getChannelList().toArray();
55 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
57 public void dispose() {
58 // TODO Auto-generated method stub
63 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
65 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
66 // TODO Auto-generated method stub
69 public Image getImage(Object element) {
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;
82 iconId = IconManager.ICON_STATUS_READ;
84 } else if(element instanceof Item) {
85 Item item = (Item)element;
86 if(item.isReadFlag()) {
87 iconId = IconManager.ICON_STATUS_READ;
89 iconId = IconManager.ICON_STATUS_UNREAD;
94 return Plugin.getDefault().getImageRegistry().getDescriptor(iconId).createImage();
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();
103 return "Unexpected object: "+element;
108 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
110 public void addListener(ILabelProviderListener listener) {
111 // TODO Auto-generated method stub
116 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
118 public boolean isLabelProperty(Object element, String property) {
119 // TODO Auto-generated method stub
124 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
126 public void removeListener(ILabelProviderListener listener) {
127 // TODO Auto-generated method stub