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.plugin.views.outline.actions;
13  
14  import org.eclipse.ui.IWorkbenchPart;
15  import org.w3c.dom.Node;
16  
17  import sk.baka.ikslibs.ptr.DomPointerFactory;
18  import sk.baka.xml.gene.ExportException;
19  import sk.uniba.euromath.editor.xmlEditor.actions.NodeManipulateAction;
20  import sk.uniba.euromath.plugin.views.outline.actions.lang.Messages;
21  
22  /***
23   * Encloses element by another element.
24   * 
25   * @author Tomáš Studva 23.1.2006
26   */
27  public class EncloseElementAction extends NodeManipulateAction {
28  
29          /***
30           * Id of action.
31           */
32          public static final String id = EncloseElementAction.class.toString();
33  
34          /***
35           * Constructor.
36           */
37          public EncloseElementAction() {
38                  this(null);
39          }
40  
41          /***
42           * Constructor.
43           * 
44           * @param part
45           *                associated workbench part
46           */
47          public EncloseElementAction(IWorkbenchPart part) {
48                  super(part);
49                  setId(id);
50                  setText(Messages.getString("EncloseElementAction.Text")); //$NON-NLS-1$
51          }
52  
53          @Override
54          protected boolean calculateEnabled() {
55                  // TODO Auto-generated method stub
56                  return super.calculateEnabled()
57                                  && (getNode().getParentNode() != null);
58          }
59  
60          /*
61           * (non-Javadoc)
62           * 
63           * @see org.eclipse.jface.action.IAction#run()
64           */
65          @Override
66          public void run() {
67                  try {
68                          getModifyHelper()
69                                          .encloseNodes(
70                                                          getShell(),
71                                                          DomPointerFactory
72                                                                          .create(
73                                                                                          getNode()
74                                                                                                          .getParentNode(),
75                                                                                          getNode()),
76                                                          DomPointerFactory
77                                                                          .create(
78                                                                                          getNode()
79                                                                                                          .getParentNode(),
80                                                                                          getNode()
81                                                                                                          .getNextSibling()));
82                  } catch (ExportException e) {
83                          handleExportException(e);
84                  }
85          }
86  }