Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: e302240a46598c627c2d2c215d37a2a240cf46cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
 *     
 *******************************************************************************/
package org.eclipse.wst.xml.ui.internal.properties;



import java.util.Arrays;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.PropertyDescriptor;

/**
 * This class should be used for properties which require a combo box cell
 * editor and whose values consist of a list of enumerated strings.
 */
public class EnumeratedStringPropertyDescriptor extends PropertyDescriptor {
	protected StringComboBoxCellEditor fEditor;
	protected Composite fParent;

	/**
	 * The enumerated possible values for the described property
	 */
	protected String fValues[] = null;

	public EnumeratedStringPropertyDescriptor(Object id, String newDisplayName, String[] valuesArray) {
		super(id, newDisplayName);
		setDescription((String) id);
		fValues = valuesArray;
	}

	/**
	 * Creates and returns a new cell editor for editing this property.
	 * Returns <code>null</code> if the property is not editable.
	 * 
	 * @param parent
	 *            the parent widget for the cell editor
	 * @return the cell editor for this property, or <code>null</code> if
	 *         this property cannot be edited
	 */
	public CellEditor createPropertyEditor(Composite parent) {
		// Check to see if we already have a Cell Editor with a valid Control
		// under the given parent.
		// If any of that's not true, create and return a new Cell Editor
		if (fEditor == null || fEditor.getControl() == null || fEditor.getControl().isDisposed() || parent != fParent)
			fEditor = new StringComboBoxCellEditor(parent, fValues);
		fParent = parent;
		return fEditor;
	}

	public void updateValues(String newValues[]) {
		if (Arrays.equals(fValues, newValues))
			return;
		fValues = newValues;
		if (fEditor != null) {
			fEditor.setItems(newValues);
		}
	}
}

Back to the top