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