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