View | Details | Raw Unified | Return to bug 21013 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/views/properties/ComboBoxPropertyDescriptor.java (-27 / +50 lines)
Lines 12-23 Link Here
12
12
13
import org.eclipse.jface.viewers.CellEditor;
13
import org.eclipse.jface.viewers.CellEditor;
14
import org.eclipse.jface.viewers.ComboBoxCellEditor;
14
import org.eclipse.jface.viewers.ComboBoxCellEditor;
15
import org.eclipse.jface.viewers.ILabelProvider;
16
15
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Composite;
17
19
18
/**
20
/**
19
 * Descriptor for a property that has a value which should be edited
21
 * Descriptor for a property that has a value which should be edited
20
 * with a combo box cell editor.
22
 * with a combo box cell editor.  This class provides a default 
23
 * <code>ILabelProvider</code> that will render the label of the given 
24
 * descriptor as the <code>String</code> found in the value array at the 
25
 * currently selected index.
21
 * <p>
26
 * <p>
22
 * This class may be instantiated; it is not intended to be subclassed.
27
 * This class may be instantiated; it is not intended to be subclassed.
23
 * </p>
28
 * </p>
Lines 35-64 Link Here
35
	 * The list of possible values to display in the combo box
40
	 * The list of possible values to display in the combo box
36
	 */
41
	 */
37
	private String[] values;
42
	private String[] values;
38
/**
43
39
 * Creates an property descriptor with the given id, display name, and list
44
    /**
40
 * of value labels to display in the combo box cell editor.
45
     * Creates an property descriptor with the given id, display name, and list
41
 * 
46
     * of value labels to display in the combo box cell editor.
42
 * @param id the id of the property
47
     * 
43
 * @param displayName the name to display for the property
48
     * @param id the id of the property
44
 * @param valuesArray the list of possible values to display in the combo box
49
     * @param displayName the name to display for the property
45
 */
50
     * @param valuesArray the list of possible values to display in the combo box
46
public ComboBoxPropertyDescriptor(Object id, String displayName, String[] valuesArray) {
51
     */
47
	super(id, displayName);
52
    public ComboBoxPropertyDescriptor(Object id, String displayName, String[] valuesArray) {
48
	values = valuesArray;
53
    	super(id, displayName);
49
}
54
    	values = valuesArray;
50
/**
55
    }
51
 * The <code>ComboBoxPropertyDescriptor</code> implementation of this 
56
    
52
 * <code>IPropertyDescriptor</code> method creates and returns a new
57
    /**
53
 * <code>ComboBoxCellEditor</code>.
58
     * The <code>ComboBoxPropertyDescriptor</code> implementation of this 
54
 * <p>
59
     * <code>IPropertyDescriptor</code> method creates and returns a new
55
 * The editor is configured with the current validator if there is one.
60
     * <code>ComboBoxCellEditor</code>.
56
 * </p>
61
     * <p>
57
 */
62
     * The editor is configured with the current validator if there is one.
58
public CellEditor createPropertyEditor(Composite parent) {
63
     * </p>
59
	CellEditor editor = new ComboBoxCellEditor(parent, values, SWT.READ_ONLY);
64
     */
60
	if (getValidator() != null)
65
    public CellEditor createPropertyEditor(Composite parent) {
61
		editor.setValidator(getValidator());
66
    	CellEditor editor = new ComboBoxCellEditor(parent, values, SWT.READ_ONLY);
62
	return editor;
67
    	if (getValidator() != null)
63
}
68
    		editor.setValidator(getValidator());
69
    	return editor;
70
    }
71
    
72
    /**
73
     * The <code>ComboBoxPropertyDescriptor</code> implementation of this 
74
     * <code>IPropertyDescriptor</code> method returns the value set by
75
     * the <code>setProvider</code> method or, if no value has been set
76
     * it returns a <code>ComboBoxLabelProvider</code> created from the 
77
     * valuesArray of this <code>ComboBoxPropertyDescriptor</code>.
78
     *
79
     * @see #setLabelProvider
80
     */
81
    public ILabelProvider getLabelProvider() {
82
        if (isLabelProviderSet())
83
            return super.getLabelProvider();
84
        else
85
            return new ComboBoxLabelProvider(values); 
86
    }    
64
}
87
}
(-)src/org/eclipse/ui/views/properties/PropertyDescriptor.java (+11 lines)
Lines 205-210 Link Here
205
protected ICellEditorValidator getValidator() {
205
protected ICellEditorValidator getValidator() {
206
	return validator;
206
	return validator;
207
}
207
}
208
209
/** 
210
 * Returns whether a label provider has been set on the receiver.
211
 * @return whether a label provider has been set on the receiver.
212
 * @see #setLabelProvider
213
 * @since 3.0
214
 */
215
public boolean isLabelProviderSet() {
216
    return labelProvider != null;
217
}
218
208
/**
219
/**
209
 * The <code>SimplePropertyDescriptor</code> implementation of this 
220
 * The <code>SimplePropertyDescriptor</code> implementation of this 
210
 * <code>IPropertyDescriptor</code> method returns true if the other
221
 * <code>IPropertyDescriptor</code> method returns true if the other
(-)src/org/eclipse/ui/views/properties/ComboBoxLabelProvider.java (+81 lines)
Added Link Here
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 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 [] values;
29
    
30
    /**
31
     * @param values the possible label values that this 
32
     * <code>ILabelProvider</code> may return.
33
     */
34
    public ComboBoxLabelProvider(String[] 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[] 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[] 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 getText(Object element) {
65
        if (element == null) {
66
            return ""; //$NON-NLS-1$
67
        }
68
    
69
        if (element instanceof Integer) {
70
            int index = ((Integer)element).intValue();
71
            if (index >= 0 && index < values.length) {
72
                return values[index];
73
            }
74
            else {
75
                return ""; //$NON-NLS-1$
76
            }
77
        }
78
               
79
        return ""; //$NON-NLS-1$
80
    }
81
}

Return to bug 21013