inital plugin from webtools project
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.monitor.ui / src / net / sourceforge / phpdt / monitor / ui / internal / view / TreeLabelProvider.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.view;
12
13 import net.sourceforge.phpdt.monitor.core.IRequest;
14 import net.sourceforge.phpdt.monitor.ui.internal.*;
15
16 import org.eclipse.jface.viewers.ILabelProvider;
17 import org.eclipse.jface.viewers.ILabelProviderListener;
18 import org.eclipse.swt.graphics.Image;
19 /**
20  * A label provider for the monitor server view.
21  */
22 public class TreeLabelProvider implements ILabelProvider {
23         /**
24          * TreeLabelProvider constructor comment.
25          */
26         public TreeLabelProvider() {
27                 super();
28         }
29
30         /**
31          * Adds a listener to this label provider. Label provider listeners are 
32          * informed about state changes that affect the rendering of the viewer
33          * that uses this label provider.
34          *
35          * @param listener a label provider listener
36          */
37         public void addListener(ILabelProviderListener listener) {}
38
39         /**
40          * Disposes of this label provider.
41          * <p>
42          * [Issue: This method should be changed to take a Viewer,
43          * renamed and repurposed to disconnect a label provider from
44          * a viewer.
45          * ]
46          * </p>
47          */
48         public void dispose() {}
49
50         /**
51          * Returns the image for the label of the given element for use
52          * in the given viewer.
53          *
54          * @param element the element for which to provide the label image
55          * @return the image used to label the element, or <code>null</code>
56          *   if these is no image for the given object
57          */
58         public Image getImage(Object element) {
59                 if (element instanceof IRequest)
60                         return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_REQUEST_RESPONSE);
61                 else
62                         return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_HOST);
63         }
64
65         /**
66          * Returns the text for the label of the given element for use
67          * in the given viewer.
68          *
69          * @param viewer the viewer that displays the element
70          * @param element the element for which to provide the label text
71          * @return the text string used to label the element, or <code>null</code>
72          *   if these is no text label for the given object
73          */
74         public String getText(Object element) {
75                 if (element instanceof IRequest) {
76                         IRequest call = (IRequest) element;
77                         return call.getLabel();
78                 } else if (element instanceof Integer) {
79                         Integer in = (Integer) element;
80                         return "localhost:" + in.intValue();
81                 } else
82                         return element.toString();
83         }
84
85         /**
86          * Returns whether the label would be affected 
87          * by a change to the given property of the given element.
88          * This can be used to optimize a non-structural viewer update.
89          * If the property mentioned in the update does not affect the label,
90          * then the viewer need not update the label.
91          *
92          * @param element the element
93          * @param property the property
94          * @return <code>true</code> if the label would be affected,
95          *    and <code>false</code> if it would be unaffected
96          */
97         public boolean isLabelProperty(Object element, String property) {
98                 return false;
99         }
100         
101         /**
102          * Removes a listener to this label provider.
103          * Has no affect if the listener is not registered.
104          *
105          * @param listener a label provider listener
106          */
107         public void removeListener(ILabelProviderListener listener) {}
108 }