KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > properties > ComboBoxLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.views.properties;
12
13 import org.eclipse.jface.viewers.LabelProvider;
14
15 /**
16  * An <code>ILabelProvider</code> that assists in rendering labels for
17  * <code>ComboBoxPropertyDescriptors</code>. The label for a given
18  * <code>Integer</code> value is the <code>String</code> at the value in
19  * the provided values array.
20  *
21  * @since 3.0
22  */

23 public class ComboBoxLabelProvider extends LabelProvider {
24
25     /**
26      * The array of String labels.
27      */

28     private String JavaDoc[] values;
29
30     /**
31      * @param values the possible label values that this
32      * <code>ILabelProvider</code> may return.
33      */

34     public ComboBoxLabelProvider(String JavaDoc[] values) {
35         this.values = values;
36     }
37
38     /**
39      * @return the possible label values that this
40      * <code>ILabelProvider</code> may return.
41      */

42     public String JavaDoc[] getValues() {
43         return values;
44     }
45
46     /**
47      * @param values the possible label values that this
48      * <code>ILabelProvider</code> may return.
49      */

50     public void setValues(String JavaDoc[] values) {
51         this.values = values;
52     }
53
54     /**
55      * Returns the <code>String</code> that maps to the given
56      * <code>Integer</code> offset in the values array.
57      *
58      * @param element an <code>Integer</code> object whose value is a valid
59      * location within the values array of the receiver
60      * @return a <code>String</code> from the provided values array, or the
61      * empty <code>String</code>
62      * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
63      */

64     public String JavaDoc getText(Object JavaDoc element) {
65         if (element == null) {
66             return ""; //$NON-NLS-1$
67
}
68
69         if (element instanceof Integer JavaDoc) {
70             int index = ((Integer JavaDoc) element).intValue();
71             if (index >= 0 && index < values.length) {
72                 return values[index];
73             } else {
74                 return ""; //$NON-NLS-1$
75
}
76         }
77
78         return ""; //$NON-NLS-1$
79
}
80 }
81
Popular Tags