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.commands;
13  
14  import org.eclipse.core.runtime.IStatus;
15  import org.eclipse.gef.commands.CompoundCommand;
16  import sk.baka.xml.gene.ExportException;
17  import sk.uniba.euromath.EuroMath;
18  import sk.uniba.euromath.document.XMLAccess;
19  
20  /***
21   * Compound command for wraping document modifiing commands.
22   * 
23   * @author Tomáš Studva 2.12.2005
24   */
25  public class DocumentModifyCompoundCommand extends CompoundCommand {
26      /***
27       * XmlAccess instance.
28       */
29      private final XMLAccess xmlAccess;
30  
31      /***
32       * Constructs an empty CompoundCommand
33       * 
34       * @since 2.0
35       * @param xmlAccess
36       *            document instance
37       */
38      public DocumentModifyCompoundCommand(XMLAccess xmlAccess) {
39          super();
40          this.xmlAccess = xmlAccess;
41      }
42  
43      /***
44       * Constructs an empty CompoundCommand with the specified label.
45       * 
46       * @param label
47       *            the label for the Command
48       * @param xmlAccess
49       *            document instance
50       */
51      public DocumentModifyCompoundCommand(XMLAccess xmlAccess, String label) {
52          super(label);
53          this.xmlAccess = xmlAccess;
54      }
55  
56      /***
57       * Wraps holded commands execution with start,end modify.
58       */
59      @Override
60      public void execute() {
61          getXmlAccess().getModifier().startModify();
62          super.execute();
63          try {
64              getXmlAccess().getModifier().endModify();
65          } catch (ExportException e) {
66              EuroMath.log(IStatus.ERROR, 0, "",e); //$NON-NLS-1$
67          }
68      }
69  
70      /***
71       * @return Returns the xmlAccess.
72       */
73      protected XMLAccess getXmlAccess() {
74          return this.xmlAccess;
75      }
76  }