01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.util;
11:
12: import org.eclipse.jface.viewers.CellEditor;
13: import org.eclipse.jface.viewers.ComboBoxCellEditor;
14: import org.eclipse.swt.SWT;
15: import org.eclipse.swt.widgets.Composite;
16: import org.eclipse.ui.views.properties.PropertyDescriptor;
17:
18: public class ChoicePropertyDescriptor extends PropertyDescriptor {
19:
20: /**
21: * The list of possible values to display in the combo box
22: */
23: private String[] values;
24:
25: /**
26: * Creates an property descriptor with the given id, display name, and list
27: * of value labels to display in the combo box cell editor.
28: *
29: * @param id the id of the property
30: * @param displayName the name to display for the property
31: * @param valuesArray the list of possible values to display in the combo box
32: */
33: public ChoicePropertyDescriptor(Object id, String displayName,
34: String[] valuesArray) {
35: super (id, displayName);
36: values = valuesArray;
37: }
38:
39: /**
40: * The <code>ComboBoxPropertyDescriptor</code> implementation of this
41: * <code>IPropertyDescriptor</code> method creates and returns a new
42: * <code>ComboBoxCellEditor</code>.
43: * <p>
44: * The editor is configured with the current validator if there is one.
45: * </p>
46: */
47: public CellEditor createPropertyEditor(Composite parent) {
48: CellEditor editor = new ComboBoxCellEditor(parent, values,
49: SWT.READ_ONLY);
50: if (getValidator() != null)
51: editor.setValidator(getValidator());
52: return editor;
53: }
54: }
|