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.Attr;
16  import org.w3c.dom.Node;
17  
18  import sk.baka.xml.gene.ExportException;
19  import sk.uniba.euromath.editor.xmlEditor.actions.lang.Messages;
20  
21  /***
22   * Action to modify node of any type. Node to modify is gained from contructor
23   * or from selsction(action is enabled if only one node is selected).
24   * 
25   * @author Tomáš Studva 9.12.2005
26   */
27  public class ModifyNodeAction extends NodeManipulateAction {
28  
29          /***
30           * Default id of action.
31           */
32          public static final String id = ModifyNodeAction.class.toString();
33  
34          /***
35           * Constructor.
36           */
37          public ModifyNodeAction() {
38                  this(null);
39          }
40  
41          /***
42           * Constructor. Creates action to modify node of any type from
43           * selection.
44           * 
45           * @param part
46           *                associated workbench part
47           */
48          ModifyNodeAction(IWorkbenchPart part) {
49                  super(part, NodeManipulateAction.SINGLE, false);
50                  setId(id);
51                  setText(Messages.getString("ModifyNodeAction.Text")); //$NON-NLS-1$
52          }
53  
54          /***
55           * Constructor. Creates action to modify node.
56           * 
57           * @param node
58           *                node to modify.
59           * @param part
60           */
61          public ModifyNodeAction(Node node, IWorkbenchPart part) {
62                  super(node, part);
63                  setId(id + node.toString());
64                  setText(Messages.getString("ModifyNodeAction.Text")); //$NON-NLS-1$
65          }
66  
67          /***
68           * Tries to modify node.
69           */
70          @Override
71          public void run() {
72                  // TODO Studva
73                  switch (getNode().getNodeType()) {
74                  case Node.ELEMENT_NODE:
75                          break;
76                  case Node.ATTRIBUTE_NODE:
77                          try {
78                                  getModifyHelper().modifyAttribute(getShell(),
79                                                  (Attr) getNode());
80                          } catch (ExportException e) {
81                                  handleExportException(e);
82                          }
83                          break;
84                  case Node.TEXT_NODE:
85                          try {
86                                  getModifyHelper().modifyTextNode(getShell(),
87                                                  getNode());
88                          } catch (ExportException e) {
89                                  handleExportException(e);
90                          }
91                          break;
92                  case Node.CDATA_SECTION_NODE:
93                          break;
94                  case Node.COMMENT_NODE:
95                          break;
96                  case Node.ENTITY_NODE:
97                          break;
98                  case Node.ENTITY_REFERENCE_NODE:
99                          break;
100                 case Node.PROCESSING_INSTRUCTION_NODE:
101                         break;
102                 }
103         }
104 }