Index: src/org/eclipse/ui/views/properties/ComboBoxPropertyDescriptor.java
===================================================================
RCS file: /home/eclipse/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/ComboBoxPropertyDescriptor.java,v
retrieving revision 1.5
diff -u -r1.5 ComboBoxPropertyDescriptor.java
--- src/org/eclipse/ui/views/properties/ComboBoxPropertyDescriptor.java 10 Mar 2003 22:09:05 -0000 1.5
+++ src/org/eclipse/ui/views/properties/ComboBoxPropertyDescriptor.java 14 Oct 2003 18:34:46 -0000
@@ -12,12 +12,17 @@
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.ILabelProvider;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
/**
* Descriptor for a property that has a value which should be edited
- * with a combo box cell editor.
+ * with a combo box cell editor. This class provides a default
+ * ILabelProvider
that will render the label of the given
+ * descriptor as the String
found in the value array at the
+ * currently selected index.
*
* This class may be instantiated; it is not intended to be subclassed. *
@@ -35,30 +40,48 @@ * The list of possible values to display in the combo box */ private String[] values; -/** - * Creates an property descriptor with the given id, display name, and list - * of value labels to display in the combo box cell editor. - * - * @param id the id of the property - * @param displayName the name to display for the property - * @param valuesArray the list of possible values to display in the combo box - */ -public ComboBoxPropertyDescriptor(Object id, String displayName, String[] valuesArray) { - super(id, displayName); - values = valuesArray; -} -/** - * TheComboBoxPropertyDescriptor
implementation of this
- * IPropertyDescriptor
method creates and returns a new
- * ComboBoxCellEditor
.
- * - * The editor is configured with the current validator if there is one. - *
- */ -public CellEditor createPropertyEditor(Composite parent) { - CellEditor editor = new ComboBoxCellEditor(parent, values, SWT.READ_ONLY); - if (getValidator() != null) - editor.setValidator(getValidator()); - return editor; -} + + /** + * Creates an property descriptor with the given id, display name, and list + * of value labels to display in the combo box cell editor. + * + * @param id the id of the property + * @param displayName the name to display for the property + * @param valuesArray the list of possible values to display in the combo box + */ + public ComboBoxPropertyDescriptor(Object id, String displayName, String[] valuesArray) { + super(id, displayName); + values = valuesArray; + } + + /** + * TheComboBoxPropertyDescriptor
implementation of this
+ * IPropertyDescriptor
method creates and returns a new
+ * ComboBoxCellEditor
.
+ * + * The editor is configured with the current validator if there is one. + *
+ */ + public CellEditor createPropertyEditor(Composite parent) { + CellEditor editor = new ComboBoxCellEditor(parent, values, SWT.READ_ONLY); + if (getValidator() != null) + editor.setValidator(getValidator()); + return editor; + } + + /** + * TheComboBoxPropertyDescriptor
implementation of this
+ * IPropertyDescriptor
method returns the value set by
+ * the setProvider
method or, if no value has been set
+ * it returns a ComboBoxLabelProvider
created from the
+ * valuesArray of this ComboBoxPropertyDescriptor
.
+ *
+ * @see #setLabelProvider
+ */
+ public ILabelProvider getLabelProvider() {
+ if (isLabelProviderSet())
+ return super.getLabelProvider();
+ else
+ return new ComboBoxLabelProvider(values);
+ }
}
Index: src/org/eclipse/ui/views/properties/PropertyDescriptor.java
===================================================================
RCS file: /home/eclipse/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/PropertyDescriptor.java,v
retrieving revision 1.4
diff -u -r1.4 PropertyDescriptor.java
--- src/org/eclipse/ui/views/properties/PropertyDescriptor.java 10 Mar 2003 22:09:05 -0000 1.4
+++ src/org/eclipse/ui/views/properties/PropertyDescriptor.java 14 Oct 2003 18:34:46 -0000
@@ -205,6 +205,17 @@
protected ICellEditorValidator getValidator() {
return validator;
}
+
+/**
+ * Returns whether a label provider has been set on the receiver.
+ * @return whether a label provider has been set on the receiver.
+ * @see #setLabelProvider
+ * @since 3.0
+ */
+public boolean isLabelProviderSet() {
+ return labelProvider != null;
+}
+
/**
* The SimplePropertyDescriptor
implementation of this
* IPropertyDescriptor
method returns true if the other
Index: src/org/eclipse/ui/views/properties/ComboBoxLabelProvider.java
===================================================================
RCS file: src/org/eclipse/ui/views/properties/ComboBoxLabelProvider.java
diff -N src/org/eclipse/ui/views/properties/ComboBoxLabelProvider.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/views/properties/ComboBoxLabelProvider.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ui.views.properties;
+
+import org.eclipse.jface.viewers.LabelProvider;
+
+/**
+ * An ILabelProvider
that assists in rendering labels for
+ * ComboBoxPropertyDescriptors
. The label for a given
+ * Integer
value is the String
at the value in
+ * the provided values array.
+ *
+ * @since 3.0
+ */
+public class ComboBoxLabelProvider extends LabelProvider {
+
+ /**
+ * The array of String labels.
+ */
+ private String [] values;
+
+ /**
+ * @param values the possible label values that this
+ * ILabelProvider
may return.
+ */
+ public ComboBoxLabelProvider(String[] values) {
+ this.values = values;
+ }
+
+ /**
+ * @return the possible label values that this
+ * ILabelProvider
may return.
+ */
+ public String[] getValues() {
+ return values;
+ }
+
+ /**
+ * @param values the possible label values that this
+ * ILabelProvider
may return.
+ */
+ public void setValues(String[] values) {
+ this.values = values;
+ }
+
+ /**
+ * Returns the String
that maps to the given
+ * Integer
offset in the values array.
+ *
+ * @param element an Integer
object whose value is a valid
+ * location within the values array of the receiver
+ * @return a String
from the provided values array, or the
+ * empty String
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+ */
+ public String getText(Object element) {
+ if (element == null) {
+ return ""; //$NON-NLS-1$
+ }
+
+ if (element instanceof Integer) {
+ int index = ((Integer)element).intValue();
+ if (index >= 0 && index < values.length) {
+ return values[index];
+ }
+ else {
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+ return ""; //$NON-NLS-1$
+ }
+}