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
9 * IBM - Initial API and implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.monitor.ui.internal.view;
13 import net.sourceforge.phpdt.monitor.core.IRequest;
14 import net.sourceforge.phpdt.monitor.ui.internal.*;
16 import org.eclipse.jface.viewers.ILabelProvider;
17 import org.eclipse.jface.viewers.ILabelProviderListener;
18 import org.eclipse.swt.graphics.Image;
20 * A label provider for the monitor server view.
22 public class TreeLabelProvider implements ILabelProvider {
24 * TreeLabelProvider constructor comment.
26 public TreeLabelProvider() {
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.
35 * @param listener a label provider listener
37 public void addListener(ILabelProviderListener listener) {}
40 * Disposes of this label provider.
42 * [Issue: This method should be changed to take a Viewer,
43 * renamed and repurposed to disconnect a label provider from
48 public void dispose() {}
51 * Returns the image for the label of the given element for use
52 * in the given viewer.
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
58 public Image getImage(Object element) {
59 if (element instanceof IRequest)
60 return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_REQUEST_RESPONSE);
62 return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_HOST);
66 * Returns the text for the label of the given element for use
67 * in the given viewer.
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
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();
82 return element.toString();
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.
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
97 public boolean isLabelProperty(Object element, String property) {
102 * Removes a listener to this label provider.
103 * Has no affect if the listener is not registered.
105 * @param listener a label provider listener
107 public void removeListener(ILabelProviderListener listener) {}