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.string; 12 13import org.eclipse.wb.internal.core.model.property.Property; 14import org.eclipse.wb.internal.core.model.property.editor.AbstractTextPropertyEditor; 15import org.eclipse.wb.internal.core.model.property.editor.PropertyEditor; 16import org.eclipse.wb.internal.core.model.property.editor.presentation.ButtonPropertyEditorPresentation; 17import org.eclipse.wb.internal.core.model.property.editor.presentation.PropertyEditorPresentation; 18import org.eclipse.wb.internal.core.model.property.table.PropertyTable; 19 20import org.eclipse.jface.window.Window; 21 22/** 23 * The {@link PropertyEditor} for {@link String}. 24 * 25 * @author scheglov_ke 26 * @coverage core.model.property.editor 27 */ 28public class StringPropertyEditor extends AbstractTextPropertyEditor { 29 //////////////////////////////////////////////////////////////////////////// 30 // 31 // Instance 32 // 33 //////////////////////////////////////////////////////////////////////////// 34 public static final PropertyEditor INSTANCE = new StringPropertyEditor(); 35 36 private StringPropertyEditor() { 37 } 38 39 //////////////////////////////////////////////////////////////////////////// 40 // 41 // Presentation 42 // 43 //////////////////////////////////////////////////////////////////////////// 44 private final PropertyEditorPresentation m_presentation = new ButtonPropertyEditorPresentation() { 45 @Override 46 protected void onClick(PropertyTable propertyTable, Property property) throws Exception { 47 openDialog(propertyTable, property); 48 } 49 }; 50 51 @Override 52 public PropertyEditorPresentation getPresentation() { 53 return m_presentation; 54 } 55 56 //////////////////////////////////////////////////////////////////////////// 57 // 58 // Presentation 59 // 60 //////////////////////////////////////////////////////////////////////////// 61 @Override 62 public String getText(Property property) throws Exception { 63 Object value = property.getValue(); 64 if (value instanceof String) { 65 return (String) value; 66 } 67 return null; 68 } 69 70 //////////////////////////////////////////////////////////////////////////// 71 // 72 // Editing 73 // 74 //////////////////////////////////////////////////////////////////////////// 75 @Override 76 protected String getEditorText(Property property) throws Exception { 77 return getText(property); 78 } 79 80 @Override 81 protected boolean setEditorText(Property property, String text) throws Exception { 82 property.setValue(text); 83 return true; 84 } 85 86 //////////////////////////////////////////////////////////////////////////// 87 // 88 // Editing in dialog 89 // 90 //////////////////////////////////////////////////////////////////////////// 91 /** 92 * Opens editing dialog. 93 */ 94 private void openDialog(PropertyTable propertyTable, Property property) throws Exception { 95 StringPropertyDialog dialog = new StringPropertyDialog(propertyTable.getShell(), property); 96 if (dialog.open() == Window.OK) { 97 } 98 } 99} 100