summaryrefslogtreecommitdiff
path: root/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/StringListPropertyEditor.java
blob: 1bb8cd85094b13c49beb70ea86a216577dced88d (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
 * Copyright (c) 2011 Google, Inc.
 * 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:
 *    Google, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.wb.internal.core.model.property.editor;

import org.eclipse.wb.core.controls.CCombo3;
import org.eclipse.wb.internal.core.model.property.Property;

/**
 * The {@link PropertyEditor} for selecting single string from given set.
 *
 * @author sablin_aa
 * @coverage core.model.property.editor
 */
public final class StringListPropertyEditor extends AbstractListPropertyEditor {
  private boolean m_ignoreCase;
  private String[] m_strings;

  ////////////////////////////////////////////////////////////////////////////
  //
  // Combo
  //
  ////////////////////////////////////////////////////////////////////////////
  @Override
  protected void toPropertyEx_simpleProperty(Property property, CCombo3 combo, int index)
      throws Exception {
    property.setValue(m_strings[index]);
  }

  ////////////////////////////////////////////////////////////////////////////
  //
  // Access to list items
  //
  ////////////////////////////////////////////////////////////////////////////
  @Override
  protected int getCount() {
    return m_strings.length;
  }

  @Override
  protected int getValueIndex(Object value) {
    if (value instanceof String) {
      String string = (String) value;
      for (int i = 0; i < getCount(); i++) {
        if (m_ignoreCase) {
          if (string.equalsIgnoreCase(m_strings[i])) {
            return i;
          }
        } else {
          if (string.equals(m_strings[i])) {
            return i;
          }
        }
      }
    }
    return -1;
  }

  @Override
  protected String getTitle(int index) {
    return m_strings[index];
  }

  @Override
  protected String getExpression(int index) throws Exception {
    //return StringConverter.INSTANCE.toJavaSource(null, m_strings[index]);
      // HACK!!
      System.out.println("HACK!");
      return m_strings[index];
  }
//
//  ////////////////////////////////////////////////////////////////////////////
//  //
//  // IConfigurablePropertyObject
//  //
//  ////////////////////////////////////////////////////////////////////////////
//  public void configure(EditorState state, Map<String, Object> parameters) throws Exception {
//    m_strings = getParameterAsArray(parameters, "strings");
//    m_ignoreCase = "true".equals(parameters.get("ignoreCase"));
//  }
//
//  /**
//   * Configures this editor externally.
//   */
//  public void configure(String[] strings) {
//    m_strings = strings;
//  }
}