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