david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 | *******************************************************************************/ |
nitind | 1395066 | 2005-02-13 20:17:33 +0000 | [diff] [blame] | 13 | package org.eclipse.wst.xml.ui.internal.properties; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | |
| 17 | import java.util.Arrays; |
| 18 | |
| 19 | import org.eclipse.jface.viewers.CellEditor; |
| 20 | import org.eclipse.swt.widgets.Composite; |
| 21 | import 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 | */ |
| 27 | public 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_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 36 | 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 | } |