1 /*
2 * Copyright 1999-2006 Faculty of Mathematics, Physics and Informatics, Comenius
3 * University, Bratislava. This file is protected by the Mozilla Public License
4 * version 1.1 (the License); you may not use this file except in compliance
5 * with the License. You may obtain a copy of the License at
6 * http://euromath2.sourceforge.net/license.html Unless required by applicable
7 * law or agreed to in writing, software distributed under the License is
8 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 * KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12 package sk.uniba.euromath.editor.xmlEditor.actions;
13
14 import org.eclipse.ui.IWorkbenchPart;
15 import org.w3c.dom.Element;
16 import sk.baka.xml.gene.ExportException;
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.
35 */
36 public AddAttributeWizardAction() {
37 this(null);
38 }
39
40 /***
41 * Constructor. Creates action to add attribute to selected element.
42 *
43 * @param part
44 * associated workbench part
45 */
46 public AddAttributeWizardAction(IWorkbenchPart part) {
47 super(part);
48 setId(id);
49 setText(Messages.getString("AddAttributeWizardAction.Text")); //$NON-NLS-1$
50 }
51
52 /***
53 * Constructor. Creates action to add attribute to element e.
54 *
55 * @param e
56 * element for attribute addition
57 * @param part
58 * associated workbench part
59 */
60 public AddAttributeWizardAction(Element e, IWorkbenchPart part) {
61 super(e, part);
62 setId(id + e.toString());
63 setText(Messages.getString("AddAttributeWizardAction.Text")); //$NON-NLS-1$
64 }
65
66 @Override
67 protected boolean calculateEnabled() {
68 return super.calculateEnabled()
69 && (getNode() instanceof Element);
70 }
71
72 /*
73 * (non-Javadoc)
74 *
75 * @see org.eclipse.jface.action.IAction#run()
76 */
77 @Override
78 public void run() {
79 try {
80 getModifyHelper()
81 .insertNewAttribute(
82 getWorkbenchPart()
83 .getSite()
84 .getShell(),
85 (Element) getNode());
86 } catch (ExportException ex) {
87 handleExportException(ex);
88 }
89 }
90 }