]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/TextEditor.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / TextEditor.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/TextEditor.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/TextEditor.java
new file mode 100644 (file)
index 0000000..5079387
--- /dev/null
@@ -0,0 +1,84 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.element.handler;\r
+\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.utils.TextSegment;\r
+\r
+/**\r
+ * A handler for supporting inline editing of elements.\r
+ * \r
+ * @author Antti Villberg\r
+ */\r
+public interface TextEditor extends ElementHandler {\r
+\r
+    public interface Modifier {\r
+        /**\r
+         * Returns the value for the property referred by this modifier. Must\r
+         * not return <code>null</code> since the existence of this Modifier\r
+         * should be enough proof that a modifiable value actually does exist.\r
+         * \r
+         * @return the original property value to be modified\r
+         */\r
+        public String getValue(IElement element);\r
+\r
+        /**\r
+         * @param text the text to test for validity\r
+         * @return <code>null</code> if the specified label is valid for this\r
+         *         modifier or an error message if the label is invalid\r
+         */\r
+        public String isValid(IElement element, String text);\r
+\r
+        /**\r
+         * @param element the element to modify\r
+         * @param text the new text value to set for the specified element\r
+         * @throws IllegalArgumentException if the specified text is invalid\r
+         */\r
+        void modify(IElement element, String text) throws IllegalArgumentException;\r
+    }\r
+\r
+    boolean isActive(IElement e);\r
+    void setActive(IElement e, boolean value);\r
+\r
+    String getText(IElement e);\r
+    void setText(IElement e, String text);\r
+\r
+    Modifier getModifier(IElement e);\r
+    void setModifier(IElement e, Modifier modifier);\r
+\r
+    /**\r
+     * @param e\r
+     * @return <code>null</code> if there is no selection\r
+     */\r
+    TextSegment getSelection(IElement e);\r
+\r
+    /**\r
+     * @param e\r
+     * @param segment a valid selection for the current text or\r
+     *        <code>null</code> to remove selection\r
+     */\r
+    void setSelection(IElement e, TextSegment segment);\r
+\r
+    /**\r
+     * @param e\r
+     * @return a value between [0, {@link #getText(IElement)}.length()] or\r
+     *         <code>null</code> if no caret.\r
+     */\r
+    Integer getCaretPosition(IElement e);\r
+\r
+    /**\r
+     * @param e\r
+     * @param position <code>null</code> to remove caret position\r
+     */\r
+    void setCaretPosition(IElement e, Integer position);\r
+\r
+}\r