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.Attr;
16 import org.w3c.dom.Comment;
17 import org.w3c.dom.Node;
18 import org.w3c.dom.ProcessingInstruction;
19
20 import sk.baka.xml.gene.ExportException;
21 import sk.uniba.euromath.editor.xmlEditor.actions.lang.Messages;
22
23 /***
24 * Action to modify node of any type except ELEMENT_NODE, ENTITY_REFERENCE_NODE.
25 * Node to modify is gained from contructor or from selection(action is enabled
26 * if only one node is selected).
27 *
28 * @author Tomáš Studva 9.12.2005
29 */
30 public class ModifyNodeAction extends NodeManipulateAction {
31
32 /***
33 * Default id of action.
34 */
35 public static final String id = ModifyNodeAction.class.toString();
36
37 /***
38 * Constructor. Creates action to modify node of any type from
39 * selection.
40 *
41 * @param part
42 * associated workbench part
43 */
44 public ModifyNodeAction(IWorkbenchPart part) {
45 super(part, NodeAcquireType.Single, false);
46 setId(id);
47 setText(Messages.getString("ModifyNodeAction.Text"));
48 }
49
50 /***
51 * Constructor. Creates action to modify node. Node can't be element.
52 *
53 * @param node
54 * node to modify.
55 * @param part
56 */
57 public ModifyNodeAction(Node node, IWorkbenchPart part) {
58 super(node, part);
59 if ((node.getNodeType() == Node.ELEMENT_NODE)
60 || (node.getNodeType() == Node.ENTITY_REFERENCE_NODE))
61 throw new IllegalArgumentException();
62 setId(id + node.toString());
63 setText(Messages.getString("ModifyNodeAction.Text"));
64 }
65
66 @Override
67 protected boolean calculateEnabled() {
68
69
70 return super.calculateEnabled()
71 && (getNode().getNodeType() != Node.ELEMENT_NODE)
72 && (getNode().getNodeType() != Node.ENTITY_REFERENCE_NODE);
73 }
74
75 /***
76 * Tries to modify node.
77 */
78 @Override
79 public void runAsCommand() {
80 try {
81 switch (getNode().getNodeType()) {
82 case Node.ATTRIBUTE_NODE:
83 getModifyHelper().modifyAttribute(getShell(),
84 (Attr) getNode());
85 break;
86 case Node.TEXT_NODE:
87 getModifyHelper().modifyTextNode(getShell(),
88 getNode());
89 break;
90 case Node.CDATA_SECTION_NODE:
91 getModifyHelper().modifyTextNode(getShell(),
92 getNode());
93 break;
94 case Node.COMMENT_NODE:
95 getModifyHelper().modifyComment(getShell(),
96 (Comment) getNode());
97 break;
98 case Node.ENTITY_NODE:
99
100
101 break;
102 case Node.PROCESSING_INSTRUCTION_NODE:
103 getModifyHelper()
104 .modifyProcessingInstruction(
105 getShell(),
106 (ProcessingInstruction) getNode());
107 break;
108 }
109 } catch (ExportException e) {
110 handleExportException(e);
111 }
112 }
113 }