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.swt.SWT; 14 import org.eclipse.swt.events.KeyEvent; 15 import org.eclipse.swt.graphics.GC; 16 import org.eclipse.swt.graphics.Point; 17 import org.eclipse.swt.graphics.Rectangle; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.wb.internal.core.model.property.Property; 21 import org.eclipse.wb.internal.core.model.property.editor.presentation.PropertyEditorPresentation; 22 import org.eclipse.wb.internal.core.model.property.table.PropertyTable; 23 24 /** 25 * Abstract editor for {@link Property}. 26 * 27 * @author scheglov_ke 28 * @coverage core.model.property.editor 29 */ 30 public abstract class PropertyEditor { 31 //////////////////////////////////////////////////////////////////////////// 32 // 33 // Presentation 34 // 35 //////////////////////////////////////////////////////////////////////////// 36 /** 37 * @return the instance of {@link PropertyEditorPresentation}. 38 */ 39 public PropertyEditorPresentation getPresentation() { 40 return null; 41 } 42 43 /** 44 * Paints given {@link Property} given rectangle <code>(x, y, width, height)</code> of {@link GC}. 45 */ 46 public abstract void paint(Property property, GC gc, int x, int y, int width, int height) 47 throws Exception; 48 49 //////////////////////////////////////////////////////////////////////////// 50 // 51 // Editing 52 // 53 //////////////////////////////////////////////////////////////////////////// 54 /** 55 * Activates editor for given {@link Property} at given place of {@link Composite}. Activation 56 * happens when user selects property in {@link PropertyTable}. {@link PropertyEditor} should 57 * create here any {@link Control}'s required to edit {@link Property}. 58 * 59 * If any exception happens, {@link PropertyEditor} will be deactivated. 60 * 61 * @param location 62 * the mouse location, if editor is activated using mouse click, or <code>null</code> if 63 * it is activated using keyboard. 64 * 65 * @return <code>true</code> if editor should be remembered as active for future 66 * {@link #setBounds(Rectangle)} and {@link #deactivate(boolean)} invocation. Some editors 67 * need such local activation (for example for String), some - not (for boolean). 68 */ 69 public boolean activate(PropertyTable propertyTable, Property property, Point location) 70 throws Exception { 71 return false; 72 } 73 74 /** 75 * Sets the new bounds for editor's control. 76 */ 77 public void setBounds(Rectangle bounds) { 78 } 79 80 /** 81 * Deactivates editor for current {@link Property}. {@link PropertyEditor} should dispose any 82 * {@link Control}'s created before in {@link #activate(PropertyTable, Property, Point)}. 83 * 84 * If any exception happened during activation, editor still should be able to deactivate 85 * correctly. 86 * 87 * @param save 88 * is <code>true</code> if property should save value to {@link Property}. 89 */ 90 public void deactivate(PropertyTable propertyTable, Property property, boolean save) { 91 } 92 93 /** 94 * Handles double click on {@link Property} value in {@link PropertyTable}. 95 * 96 * @param location 97 * the mouse location, relative to editor 98 */ 99 public void doubleClick(Property property, Point location) throws Exception { 100 } 101 102 /** 103 * Handles {@link SWT#KeyDown} event in {@link PropertyTable}. 104 */ 105 public void keyDown(PropertyTable propertyTable, Property property, KeyEvent event) 106 throws Exception { 107 } 108 109 //////////////////////////////////////////////////////////////////////////// 110 // 111 // IAdaptable 112 // 113 //////////////////////////////////////////////////////////////////////////// 114 public <T> T getAdapter(Class<T> adapter) { 115 return null; 116 } 117 } 118