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;
13 import net.sourceforge.phpdt.monitor.core.IMonitor;
15 import org.eclipse.jface.viewers.ILabelProviderListener;
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.jface.viewers.ITableLabelProvider;
20 * Monitor table label provider.
22 public class MonitorTableLabelProvider implements ITableLabelProvider {
24 * MonitorTableLabelProvider constructor comment.
26 public MonitorTableLabelProvider() {
31 * Adds a listener to this label provider.
32 * Has no effect if an identical listener is already registered.
34 * Label provider listeners are informed about state changes
35 * that affect the rendering of the viewer that uses this label provider.
38 * @param listener a label provider listener
40 public void addListener(ILabelProviderListener listener) { }
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.
50 public void dispose() { }
53 * Returns the label image for the given column of the given element.
55 * @param element the object representing the entire row, or
56 * <code>null</code> indicating that no input object is set
58 * @param columnIndex the zero-based index of the column in which
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);
67 return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_MONITOR_OFF);
73 * Returns the label text for the given column of the given element.
75 * @param element the object representing the entire row, or
76 * <code>null</code> indicating that no input object is set
78 * @param columnIndex the zero-based index of the column in which the label appears
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");
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() + "";
97 protected String notNull(String s) {
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.
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
116 public boolean isLabelProperty(Object element, String property) {
121 * Removes a listener to this label provider.
122 * Has no affect if an identical listener is not registered.
124 * @param listener a label provider listener
126 public void removeListener(ILabelProviderListener listener) { }