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