1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor.xmlEditor.actions;
13
14 import javax.xml.namespace.QName;
15
16 import org.eclipse.ui.IWorkbenchPart;
17 import org.w3c.dom.Node;
18
19 import sk.baka.ikslibs.DOMUtils;
20 import sk.baka.xml.gene.ExportException;
21 import sk.uniba.euromath.editor.wizards.document.ElementLoc;
22 import sk.uniba.euromath.editor.wizards.document.InsertElementWizardProvider;
23
24 /***
25 * Action to insert element directly or by wizard.
26 *
27 * @author Tomáš Studva 10.7.2006
28 */
29 public class InsertElementAction extends InsertAction {
30
31 /***
32 * Id of action.
33 */
34 public static final String id = InsertElementAction.class.toString();
35
36 private final QName elementQName;
37
38 /***
39 * Constructor to create action to insert element directly(if
40 * <code>qName</code> in not null) or by wizard at position.
41 *
42 * @param position
43 * place where to insert node
44 * @param qName
45 * qualified name of element to insert
46 * @param part
47 * associated workbench part
48 */
49 public InsertElementAction(InsertPosition position, QName qName,
50 IWorkbenchPart part) {
51 super(position, part);
52 this.elementQName = qName;
53 if (qName != null) {
54 setId(id + qName.toString());
55 setText(DOMUtils.printQName(qName));
56 }else{
57 setId(id);
58 setText("Insert element wizard");
59 }
60 }
61
62 /***
63 * Constructor to create action to insert element directly(if
64 * <code>qName</code> in not null) or by wizard at position at
65 * positionNode.
66 *
67 * @param nodePosition
68 * insertion will be near this node
69 * @param position
70 * place where to insert node
71 * @param qName
72 * qualified name of element to insert
73 * @param part
74 * associated workbench part
75 */
76 public InsertElementAction(Node nodePosition, InsertPosition position,
77 QName qName, IWorkbenchPart part) {
78 super(nodePosition, position, part);
79 this.elementQName = qName;
80 if (qName != null) {
81 setId(id + qName.toString());
82 setText(DOMUtils.printQName(qName));
83 }else{
84 setId(id);
85 setText("Insert element wizard");
86 }
87 }
88
89 @Override
90 public void runAsCommand() {
91 ElementLoc loc = InsertElementWizardProvider.execute(
92 getShell(), getXMLAccess(), getPointer(),
93 getXMLAccess().getNsManager(),
94 this.elementQName);
95
96 try {
97 if (loc != null) {
98 getXMLAccess().getUndoManager().mark();
99 loc.insert();
100 }
101 } catch (ExportException e) {
102 handleExportException(e);
103 }
104
105 }
106
107 }