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.ikslibs.modify.DOMMutils;
19 import sk.baka.xml.gene.ExportException;
20 import sk.uniba.euromath.document.DocumentModifier;
21 import sk.uniba.euromath.editor.xmlEditor.actions.XMLAccessModifyAction;
22 import sk.uniba.euromath.plugin.views.inputBox.lang.Messages;
23
24 /***
25 * @author Tomáš Studva 20.7.2005
26 */
27 public class InsertTextAction extends XMLAccessModifyAction {
28
29 /***
30 * Id.
31 */
32 public static final String id = InsertTextAction.class.toString();
33
34 /***
35 * Constructor.
36 */
37 public InsertTextAction(IWorkbenchPart part) {
38 super(part);
39 setId(id);
40 setText(Messages.getString("InsertTextAction.Text"));
41 }
42
43 @Override
44 public void run() {
45 DocumentModifier dm = getXMLAccess().getModifier();
46 try {
47 dm.startModify();
48 DOMMutils.insertText(getPointer(), getInputText(),
49 Node.TEXT_NODE);
50 dm.endModify();
51 } catch (ExportException te) {
52 handleExportException(te);
53 }
54 }
55
56 protected String getInputText() {
57 return (String) ((IInputProvider) (getWorkbenchPart()
58 .getAdapter(IInputProvider.class))).getInput();
59 }
60
61 @Override
62 protected boolean calculateEnabled() {
63 return (getPointer() != null) && (getInputText().length() > 0);
64 }
65
66 }