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.inputBox.actions;
13  
14  import org.eclipse.jface.viewers.IInputProvider;
15  import org.eclipse.ui.IWorkbenchPart;
16  import org.w3c.dom.Node;
17  
18  import sk.baka.ikslibs.modify.DOMMutils;
19  import sk.baka.xml.gene.ExportException;
20  import sk.uniba.euromath.document.DocumentModifier;
21  import sk.uniba.euromath.editor.xmlEditor.actions.XMLAccessModifyAction;
22  import sk.uniba.euromath.plugin.views.inputBox.lang.Messages;
23  
24  /***
25   * @author Tomáš Studva 20.7.2005
26   */
27  public class InsertTextAction extends XMLAccessModifyAction {
28  
29          /***
30           * Id.
31           */
32          public static final String id = InsertTextAction.class.toString();
33  
34          /***
35           * Constructor.
36           */
37          public InsertTextAction(IWorkbenchPart part) {
38                  super(part);
39                  setId(id);
40                  setText(Messages.getString("InsertTextAction.Text")); //$NON-NLS-1$
41          }
42  
43          @Override
44          public void run() {
45                  DocumentModifier dm = getXMLAccess().getModifier();
46                  try {
47                          dm.startModify();
48                          DOMMutils.insertText(getPointer(), getInputText(),
49                                          Node.TEXT_NODE);
50                          dm.endModify();
51                  } catch (ExportException te) {
52                          handleExportException(te);
53                  }
54          }
55  
56          protected String getInputText() {
57                  return (String) ((IInputProvider) (getWorkbenchPart()
58                                  .getAdapter(IInputProvider.class))).getInput();
59          }
60  
61          @Override
62          protected boolean calculateEnabled() {
63                  return (getPointer() != null) && (getInputText().length() > 0);
64          }
65  
66  }