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.Element;
16
17 import sk.baka.xml.gene.ExportException;
18 import sk.uniba.euromath.editor.xmlEditor.actions.lang.Messages;
19
20 /***
21 * Action to add new attribute to element.
22 *
23 * @author Tomáš Studva 19.12.2005
24 */
25 public class AddAttributeWizardAction extends NodeManipulateAction {
26
27 /***
28 * Id.
29 */
30 public static final String id = AddAttributeWizardAction.class
31 .toString();
32
33 /***
34 * Constructor. Creates action to add attribute to selected element.
35 *
36 * @param part
37 * associated workbench part
38 */
39 public AddAttributeWizardAction(IWorkbenchPart part) {
40 super(part, NodeAcquireType.Single, true);
41 setId(id);
42 setText(Messages.getString("AddAttributeWizardAction.Text"));
43 }
44
45 /***
46 * Constructor. Creates action to add attribute to element e.
47 *
48 * @param e
49 * element for attribute addition
50 * @param part
51 * associated workbench part
52 */
53 public AddAttributeWizardAction(Element e, IWorkbenchPart part) {
54 super(e, part);
55 setId(id + e.toString());
56 setText(Messages.getString("AddAttributeWizardAction.Text"));
57 }
58
59 @Override
60 protected boolean calculateEnabled() {
61 return super.calculateEnabled()
62 && (getNode() instanceof Element);
63 }
64
65 @Override
66 public void runAsCommand() {
67 try {
68 getModifyHelper()
69 .insertNewAttribute(
70 getWorkbenchPart()
71 .getSite()
72 .getShell(),
73 (Element) getNode());
74 } catch (ExportException ex) {
75 handleExportException(ex);
76 }
77 }
78 }