1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.plugin.views.inputBox.actions;
13
14 import org.eclipse.jface.viewers.IInputProvider;
15 import org.eclipse.ui.IWorkbenchPart;
16 import org.w3c.dom.Node;
17
18 import sk.baka.xml.gene.ExportException;
19 import sk.uniba.euromath.document.DocumentModifier;
20 import sk.uniba.euromath.editor.textEditor.actions.AtCaretAction;
21 import sk.uniba.euromath.plugin.views.inputBox.lang.Messages;
22
23 /***
24 * @author Tomáš Studva 20.7.2005
25 */
26 public class InsertTextAction extends AtCaretAction {
27
28 /***
29 * Id.
30 */
31 public static final String id = InsertTextAction.class.toString();
32
33 /***
34 * Constructor.
35 */
36 public InsertTextAction(IWorkbenchPart part) {
37 super(part);
38 setId(id);
39 setText(Messages.getString("InsertTextAction.Text"));
40 }
41
42 @Override
43 public void run() {
44 DocumentModifier dm = getXMLAccess().getModifier();
45 try {
46 dm.startModify();
47 dm.insertText(getPointer(), getInputText(), Node.TEXT_NODE);
48 dm.endModify();
49 } catch (ExportException te) {
50 handleExportException(te);
51 }
52 }
53
54 protected String getInputText() {
55 return (String) ((IInputProvider) (getWorkbenchPart()
56 .getAdapter(IInputProvider.class))).getInput();
57 }
58
59 @Override
60 protected boolean calculateEnabled() {
61 return super.calculateEnabled() && (getInputText().length() > 0);
62 }
63
64 }