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 string from given set. 18 * 19 * @author sablin_aa 20 * @coverage core.model.property.editor 21 */ 22public final class StringListPropertyEditor extends AbstractListPropertyEditor { 23 private boolean m_ignoreCase; 24 private String[] m_strings; 25 26 //////////////////////////////////////////////////////////////////////////// 27 // 28 // Combo 29 // 30 //////////////////////////////////////////////////////////////////////////// 31 @Override 32 protected void toPropertyEx_simpleProperty(Property property, CCombo3 combo, int index) 33 throws Exception { 34 property.setValue(m_strings[index]); 35 } 36 37 //////////////////////////////////////////////////////////////////////////// 38 // 39 // Access to list items 40 // 41 //////////////////////////////////////////////////////////////////////////// 42 @Override 43 protected int getCount() { 44 return m_strings.length; 45 } 46 47 @Override 48 protected int getValueIndex(Object value) { 49 if (value instanceof String) { 50 String string = (String) value; 51 for (int i = 0; i < getCount(); i++) { 52 if (m_ignoreCase) { 53 if (string.equalsIgnoreCase(m_strings[i])) { 54 return i; 55 } 56 } else { 57 if (string.equals(m_strings[i])) { 58 return i; 59 } 60 } 61 } 62 } 63 return -1; 64 } 65 66 @Override 67 protected String getTitle(int index) { 68 return m_strings[index]; 69 } 70 71 @Override 72 protected String getExpression(int index) throws Exception { 73 //return StringConverter.INSTANCE.toJavaSource(null, m_strings[index]); 74 // HACK!! 75 System.out.println("HACK!"); 76 return m_strings[index]; 77 } 78// 79// //////////////////////////////////////////////////////////////////////////// 80// // 81// // IConfigurablePropertyObject 82// // 83// //////////////////////////////////////////////////////////////////////////// 84// public void configure(EditorState state, Map<String, Object> parameters) throws Exception { 85// m_strings = getParameterAsArray(parameters, "strings"); 86// m_ignoreCase = "true".equals(parameters.get("ignoreCase")); 87// } 88// 89// /** 90// * Configures this editor externally. 91// */ 92// public void configure(String[] strings) { 93// m_strings = strings; 94// } 95} 96