1/*******************************************************************************
2 * Copyright (c) 2011 Google, Inc.
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 *    Google, Inc. - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.wb.internal.core.model.property.editor;
12
13import org.eclipse.wb.core.controls.CCombo3;
14import org.eclipse.wb.internal.core.model.property.Property;
15
16/**
17 * The {@link PropertyEditor} for selecting single {@link String} value from given array.
18 *
19 * @author scheglov_ke
20 * @coverage core.model.property.editor
21 */
22public class StringComboPropertyEditor extends AbstractComboPropertyEditor {
23  private final String[] m_items;
24
25  ////////////////////////////////////////////////////////////////////////////
26  //
27  // Constructor
28  //
29  ////////////////////////////////////////////////////////////////////////////
30  public StringComboPropertyEditor(String... items) {
31    m_items = items;
32  }
33
34  ////////////////////////////////////////////////////////////////////////////
35  //
36  // Presentation
37  //
38  ////////////////////////////////////////////////////////////////////////////
39  @Override
40  protected String getText(Property property) throws Exception {
41    return (String) property.getValue();
42  }
43
44  ////////////////////////////////////////////////////////////////////////////
45  //
46  // AbstractComboPropertyEditor
47  //
48  ////////////////////////////////////////////////////////////////////////////
49  @Override
50  protected void addItems(Property property, CCombo3 combo) throws Exception {
51    for (String item : m_items) {
52      combo.add(item);
53    }
54  }
55
56  @Override
57  protected void selectItem(Property property, CCombo3 combo) throws Exception {
58    combo.setText(getText(property));
59  }
60
61  @Override
62  protected void toPropertyEx(Property property, CCombo3 combo, int index) throws Exception {
63    property.setValue(m_items[index]);
64  }
65}