]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/TextEditor.java
Sync git svn branch with SVN repository r33324.
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / TextEditor.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.element.handler;\r
13 \r
14 import org.simantics.g2d.element.IElement;\r
15 import org.simantics.g2d.utils.TextSegment;\r
16 \r
17 /**\r
18  * A handler for supporting inline editing of elements.\r
19  * \r
20  * @author Antti Villberg\r
21  */\r
22 public interface TextEditor extends ElementHandler {\r
23 \r
24     public interface Modifier {\r
25         /**\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
29          * \r
30          * @return the original property value to be modified\r
31          */\r
32         public String getValue(IElement element);\r
33 \r
34         /**\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
38          */\r
39         public String isValid(IElement element, String text);\r
40 \r
41         /**\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
45          */\r
46         void modify(IElement element, String text) throws IllegalArgumentException;\r
47     }\r
48 \r
49     boolean isActive(IElement e);\r
50     void setActive(IElement e, boolean value);\r
51 \r
52     String getText(IElement e);\r
53     void setText(IElement e, String text);\r
54 \r
55     Modifier getModifier(IElement e);\r
56     void setModifier(IElement e, Modifier modifier);\r
57 \r
58     /**\r
59      * @param e\r
60      * @return <code>null</code> if there is no selection\r
61      */\r
62     TextSegment getSelection(IElement e);\r
63 \r
64     /**\r
65      * @param e\r
66      * @param segment a valid selection for the current text or\r
67      *        <code>null</code> to remove selection\r
68      */\r
69     void setSelection(IElement e, TextSegment segment);\r
70 \r
71     /**\r
72      * @param e\r
73      * @return a value between [0, {@link #getText(IElement)}.length()] or\r
74      *         <code>null</code> if no caret.\r
75      */\r
76     Integer getCaretPosition(IElement e);\r
77 \r
78     /**\r
79      * @param e\r
80      * @param position <code>null</code> to remove caret position\r
81      */\r
82     void setCaretPosition(IElement e, Integer position);\r
83 \r
84 }\r