View Javadoc

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  
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")); //$NON-NLS-1$
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")); //$NON-NLS-1$
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  }