blob: e302240a46598c627c2d2c215d37a2a240cf46cf [file] [log] [blame]
david_williamscfdb2cd2004-11-11 08:37:49 +00001/*******************************************************************************
2 * Copyright (c) 2001, 2004 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 * Jens Lukowski/Innoopract - initial renaming/restructuring
11 *
12 *******************************************************************************/
nitind13950662005-02-13 20:17:33 +000013package org.eclipse.wst.xml.ui.internal.properties;
david_williamscfdb2cd2004-11-11 08:37:49 +000014
15
16
17import java.util.Arrays;
18
19import org.eclipse.jface.viewers.CellEditor;
20import org.eclipse.swt.widgets.Composite;
21import org.eclipse.ui.views.properties.PropertyDescriptor;
22
23/**
24 * This class should be used for properties which require a combo box cell
25 * editor and whose values consist of a list of enumerated strings.
26 */
27public class EnumeratedStringPropertyDescriptor extends PropertyDescriptor {
28 protected StringComboBoxCellEditor fEditor;
29 protected Composite fParent;
30
31 /**
32 * The enumerated possible values for the described property
33 */
34 protected String fValues[] = null;
35
david_williamscfdb2cd2004-11-11 08:37:49 +000036 public EnumeratedStringPropertyDescriptor(Object id, String newDisplayName, String[] valuesArray) {
37 super(id, newDisplayName);
38 setDescription((String) id);
39 fValues = valuesArray;
40 }
41
42 /**
43 * Creates and returns a new cell editor for editing this property.
44 * Returns <code>null</code> if the property is not editable.
45 *
46 * @param parent
47 * the parent widget for the cell editor
48 * @return the cell editor for this property, or <code>null</code> if
49 * this property cannot be edited
50 */
51 public CellEditor createPropertyEditor(Composite parent) {
52 // Check to see if we already have a Cell Editor with a valid Control
53 // under the given parent.
54 // If any of that's not true, create and return a new Cell Editor
55 if (fEditor == null || fEditor.getControl() == null || fEditor.getControl().isDisposed() || parent != fParent)
56 fEditor = new StringComboBoxCellEditor(parent, fValues);
57 fParent = parent;
58 return fEditor;
59 }
60
61 public void updateValues(String newValues[]) {
62 if (Arrays.equals(fValues, newValues))
63 return;
64 fValues = newValues;
65 if (fEditor != null) {
66 fEditor.setItems(newValues);
67 }
68 }
69}