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 *******************************************************************************/ 11 package org.eclipse.wb.internal.core.model.property.editor; 12 13 import org.eclipse.wb.internal.core.model.property.Property; 14 import org.eclipse.wb.internal.core.model.property.editor.presentation.ButtonPropertyEditorPresentation; 15 import org.eclipse.wb.internal.core.model.property.editor.presentation.PropertyEditorPresentation; 16 import org.eclipse.wb.internal.core.model.property.table.PropertyTable; 17 18 import org.eclipse.swt.graphics.Point; 19 20 /** 21 * Abstract {@link PropertyEditor} that displays text and button to open dialog. 22 * 23 * @author scheglov_ke 24 * @coverage core.model.property.editor 25 */ 26 public abstract class TextDialogPropertyEditor extends TextDisplayPropertyEditor { 27 //////////////////////////////////////////////////////////////////////////// 28 // 29 // Presentation 30 // 31 //////////////////////////////////////////////////////////////////////////// 32 private final PropertyEditorPresentation m_presentation = new ButtonPropertyEditorPresentation() { 33 @Override 34 protected void onClick(PropertyTable propertyTable, Property property) throws Exception { 35 openDialog(property); 36 } 37 }; 38 39 @Override 40 public final PropertyEditorPresentation getPresentation() { 41 return m_presentation; 42 } 43 44 //////////////////////////////////////////////////////////////////////////// 45 // 46 // Editing 47 // 48 //////////////////////////////////////////////////////////////////////////// 49 @Override 50 public boolean activate(PropertyTable propertyTable, Property property, Point location) 51 throws Exception { 52 // activate using keyboard 53 if (location == null) { 54 openDialog(property); 55 } 56 // don't activate 57 return false; 58 } 59 60 /** 61 * Opens editing dialog. 62 */ 63 protected abstract void openDialog(Property property) throws Exception; 64 }