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