0832a8425da1716d68308e30bf8282a8089bebba
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.monitor.ui / src / net / sourceforge / phpdt / monitor / ui / internal / MonitorTableLabelProvider.java
1 /**********************************************************************
2  * Copyright (c) 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *    IBM - Initial API and implementation
10  **********************************************************************/
11 package net.sourceforge.phpdt.monitor.ui.internal;
12
13 import net.sourceforge.phpdt.monitor.core.IMonitor;
14
15 import org.eclipse.jface.viewers.ILabelProviderListener;
16
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.jface.viewers.ITableLabelProvider;
19 /**
20  * Monitor table label provider.
21  */
22 public class MonitorTableLabelProvider implements ITableLabelProvider {
23         /**
24          * MonitorTableLabelProvider constructor comment.
25          */
26         public MonitorTableLabelProvider() {
27                 super();
28         }
29
30         /**
31          * Adds a listener to this label provider. 
32          * Has no effect if an identical listener is already registered.
33          * <p>
34          * Label provider listeners are informed about state changes 
35          * that affect the rendering of the viewer that uses this label provider.
36          * </p>
37          *
38          * @param listener a label provider listener
39          */
40         public void addListener(ILabelProviderListener listener) { }
41
42         /**
43          * Disposes of this label provider.  When a label provider is
44          * attached to a viewer, the viewer will automatically call
45          * this method when the viewer is being closed.  When label providers
46          * are used outside of the context of a viewer, it is the client's
47          * responsibility to ensure that this method is called when the
48          * provider is no longer needed.
49          */
50         public void dispose() { }
51
52         /**
53          * Returns the label image for the given column of the given element.
54          *
55          * @param element the object representing the entire row, or 
56          *    <code>null</code> indicating that no input object is set
57          *    in the viewer
58          * @param columnIndex the zero-based index of the column in which
59          *   the label appears
60          */
61         public Image getColumnImage(Object element, int columnIndex) {
62                 if (columnIndex == 0) {
63                         IMonitor monitor = (IMonitor) element;
64                         if (monitor.isRunning())
65                                 return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_MONITOR_ON);
66                         else
67                                 return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_MONITOR_OFF);
68                 }
69                 return null;
70         }
71
72         /**
73          * Returns the label text for the given column of the given element.
74          *
75          * @param element the object representing the entire row, or
76          *   <code>null</code> indicating that no input object is set
77          *   in the viewer
78          * @param columnIndex the zero-based index of the column in which the label appears
79          */
80         public String getColumnText(Object element, int columnIndex) {
81                 IMonitor monitor = (IMonitor) element;
82                 if (columnIndex == 0) {
83                         if (monitor.isRunning())
84                                 return MonitorUIPlugin.getResource("%started");
85                         else
86                                 return MonitorUIPlugin.getResource("%stopped");
87                 } else if (columnIndex == 1)
88                         return monitor.getRemoteHost() + ":" + monitor.getRemotePort();
89                 else if (columnIndex == 2)
90                         return monitor.getProtocolAdapter().getName();
91                 else if (columnIndex == 3)
92                         return monitor.getLocalPort() + "";
93                 else
94                         return "X";
95         }
96         
97         protected String notNull(String s) {
98                 if (s != null)
99                         return s;
100                 else
101                         return "";
102         }
103
104         /**
105          * Returns whether the label would be affected 
106          * by a change to the given property of the given element.
107          * This can be used to optimize a non-structural viewer update.
108          * If the property mentioned in the update does not affect the label,
109          * then the viewer need not update the label.
110          *
111          * @param element the element
112          * @param property the property
113          * @return <code>true</code> if the label would be affected,
114          *    and <code>false</code> if it would be unaffected
115          */
116         public boolean isLabelProperty(Object element, String property) {
117                 return false;
118         }
119
120         /**
121          * Removes a listener to this label provider.
122          * Has no affect if an identical listener is not registered.
123          *
124          * @param listener a label provider listener
125          */
126         public void removeListener(ILabelProviderListener listener) { }
127 }