1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.element.handler;
14 import org.simantics.g2d.element.IElement;
15 import org.simantics.g2d.utils.TextSegment;
18 * A handler for supporting inline editing of elements.
20 * @author Antti Villberg
22 public interface TextEditor extends ElementHandler {
24 public interface Modifier {
26 * Returns the value for the property referred by this modifier. Must
27 * not return <code>null</code> since the existence of this Modifier
28 * should be enough proof that a modifiable value actually does exist.
30 * @return the original property value to be modified
32 public String getValue(IElement element);
35 * @param text the text to test for validity
36 * @return <code>null</code> if the specified label is valid for this
37 * modifier or an error message if the label is invalid
39 public String isValid(IElement element, String text);
42 * @param element the element to modify
43 * @param text the new text value to set for the specified element
44 * @throws IllegalArgumentException if the specified text is invalid
46 void modify(IElement element, String text) throws IllegalArgumentException;
49 boolean isActive(IElement e);
50 void setActive(IElement e, boolean value);
52 String getText(IElement e);
53 void setText(IElement e, String text);
55 Modifier getModifier(IElement e);
56 void setModifier(IElement e, Modifier modifier);
60 * @return <code>null</code> if there is no selection
62 TextSegment getSelection(IElement e);
66 * @param segment a valid selection for the current text or
67 * <code>null</code> to remove selection
69 void setSelection(IElement e, TextSegment segment);
73 * @return a value between [0, {@link #getText(IElement)}.length()] or
74 * <code>null</code> if no caret.
76 Integer getCaretPosition(IElement e);
80 * @param position <code>null</code> to remove caret position
82 void setCaretPosition(IElement e, Integer position);