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;
16 import org.eclipse.jface.viewers.ITableLabelProvider;
17 import org.eclipse.swt.graphics.Image;
19 * Monitor table label provider.
21 public class MonitorTableLabelProvider implements ITableLabelProvider {
23 * MonitorTableLabelProvider constructor comment.
25 public MonitorTableLabelProvider() {
30 * Adds a listener to this label provider.
31 * Has no effect if an identical listener is already registered.
33 * Label provider listeners are informed about state changes
34 * that affect the rendering of the viewer that uses this label provider.
37 * @param listener a label provider listener
39 public void addListener(ILabelProviderListener listener) { }
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.
49 public void dispose() { }
52 * Returns the label image for the given column of the given element.
54 * @param element the object representing the entire row, or
55 * <code>null</code> indicating that no input object is set
57 * @param columnIndex the zero-based index of the column in which
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);
66 return MonitorUIPlugin.getImage(MonitorUIPlugin.IMG_MONITOR_OFF);
72 * Returns the label text for the given column of the given element.
74 * @param element the object representing the entire row, or
75 * <code>null</code> indicating that no input object is set
77 * @param columnIndex the zero-based index of the column in which the label appears
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");
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() + "";
96 protected String notNull(String s) {
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.
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
115 public boolean isLabelProperty(Object element, String property) {
120 * Removes a listener to this label provider.
121 * Has no affect if an identical listener is not registered.
123 * @param listener a label provider listener
125 public void removeListener(ILabelProviderListener listener) { }