summaryrefslogtreecommitdiff
path: root/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/PropertyEditor.java
blob: fd2fa8f6f8d5af05ffdda34759f224d3ed650727 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*******************************************************************************
 * 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.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.wb.internal.core.model.property.Property;
import org.eclipse.wb.internal.core.model.property.editor.presentation.PropertyEditorPresentation;
import org.eclipse.wb.internal.core.model.property.table.PropertyTable;

/**
 * Abstract editor for {@link Property}.
 *
 * @author scheglov_ke
 * @coverage core.model.property.editor
 */
public abstract class PropertyEditor {
  ////////////////////////////////////////////////////////////////////////////
  //
  // Presentation
  //
  ////////////////////////////////////////////////////////////////////////////
  /**
   * @return the instance of {@link PropertyEditorPresentation}.
   */
  public PropertyEditorPresentation getPresentation() {
    return null;
  }

  /**
   * Paints given {@link Property} given rectangle <code>(x, y, width, height)</code> of {@link GC}.
   */
  public abstract void paint(Property property, GC gc, int x, int y, int width, int height)
      throws Exception;

  ////////////////////////////////////////////////////////////////////////////
  //
  // Editing
  //
  ////////////////////////////////////////////////////////////////////////////
  /**
   * Activates editor for given {@link Property} at given place of {@link Composite}. Activation
   * happens when user selects property in {@link PropertyTable}. {@link PropertyEditor} should
   * create here any {@link Control}'s required to edit {@link Property}.
   *
   * If any exception happens, {@link PropertyEditor} will be deactivated.
   *
   * @param location
   *          the mouse location, if editor is activated using mouse click, or <code>null</code> if
   *          it is activated using keyboard.
   *
   * @return <code>true</code> if editor should be remembered as active for future
   *         {@link #setBounds(Rectangle)} and {@link #deactivate(boolean)} invocation. Some editors
   *         need such local activation (for example for String), some - not (for boolean).
   */
  public boolean activate(PropertyTable propertyTable, Property property, Point location)
      throws Exception {
    return false;
  }

  /**
   * Sets the new bounds for editor's control.
   */
  public void setBounds(Rectangle bounds) {
  }

  /**
   * Deactivates editor for current {@link Property}. {@link PropertyEditor} should dispose any
   * {@link Control}'s created before in {@link #activate(PropertyTable, Property, Point)}.
   *
   * If any exception happened during activation, editor still should be able to deactivate
   * correctly.
   *
   * @param save
   *          is <code>true</code> if property should save value to {@link Property}.
   */
  public void deactivate(PropertyTable propertyTable, Property property, boolean save) {
  }

  /**
   * Handles double click on {@link Property} value in {@link PropertyTable}.
   *
   * @param location
   *          the mouse location, relative to editor
   */
  public void doubleClick(Property property, Point location) throws Exception {
  }

  /**
   * Handles {@link SWT#KeyDown} event in {@link PropertyTable}.
   */
  public void keyDown(PropertyTable propertyTable, Property property, KeyEvent event)
      throws Exception {
  }

  ////////////////////////////////////////////////////////////////////////////
  //
  // IAdaptable
  //
  ////////////////////////////////////////////////////////////////////////////
  public <T> T getAdapter(Class<T> adapter) {
    return null;
  }
}