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 java.util.Collections;
15  import java.util.Set;
16  import org.eclipse.ui.IWorkbenchPart;
17  import org.w3c.dom.Element;
18  import sk.baka.xml.gene.ExportException;
19  import sk.uniba.euromath.editor.xmlEditor.actions.lang.Messages;
20  
21  /***
22   * Deletes element specified in constructor.
23   * 
24   * @author Tomáš Studva 9.7.2005
25   */
26  public class DeleteElementAction extends XMLAccessModifyAction {
27  
28      /***
29       * Id of action.
30       */
31      public static final String id = DeleteElementAction.class.toString();
32  
33      /***
34       * Element to delete.
35       */
36      private Element element;
37  
38      /***
39       * Constructor.
40       * 
41       * @param e
42       *            element to delete.
43       * @param part
44       *            associated workbench part
45       */
46      public DeleteElementAction(Element e, IWorkbenchPart part) {
47          super(part);
48          setElement(e);
49          setId(id + e.getLocalName());
50          setText(Messages.getString("DeleteElementAction.Text")); //$NON-NLS-1$
51      }
52  
53      @Override
54      public void run() {
55          final Set<Element> elements = Collections.singleton(getElement());
56          try {
57              getModifyHelper().deleteElements(getShell(), elements);
58          } catch (ExportException ex) {
59              handleExportException(ex);
60          }
61      }
62  
63      /***
64       * @return Returns the element.
65       */
66      protected Element getElement() {
67          return this.element;
68      }
69  
70      /***
71       * @param element
72       *            The element to set.
73       */
74      protected void setElement(Element element) {
75          this.element = element;
76      }
77  }