View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the License); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
11   */
12  package sk.uniba.euromath.editor.textEditor.commands;
13  
14  import org.eclipse.gef.EditDomain;
15  import org.eclipse.gef.EditPart;
16  import org.eclipse.gef.Tool;
17  import org.eclipse.gef.commands.Command;
18  
19  import sk.uniba.euromath.editor.textEditor.CaretManager;
20  import sk.uniba.euromath.editor.textEditor.ITextPieceKeeper;
21  import sk.uniba.euromath.editor.textEditor.tools.TextTool;
22  
23  /***
24   * 
25   * @author TV, refactored by Martin Kollar
26   * 10.6.2005
27   * Switches the active tool to TextTool
28   */
29  public class SwitchEditModeCommand extends Command {
30  
31      private ITextPieceKeeper startedIn;
32      
33      private EditDomain domain;
34  
35      private int caretOffset;
36      
37      private CaretManager caretManager;
38  
39  
40  	/***
41       * @param origin EditPart which calls this command
42       * @param caretOffset is offset where to activate Caret in <code>origin</code> ITextPieceKeeper  
43       * @param cManager CaretManager
44       * @param domain EditDomain on that new Tool will be instaled
45       */
46      public SwitchEditModeCommand(ITextPieceKeeper origin, int caretOffset, CaretManager cManager,
47      		                     EditDomain domain ) {
48          super();
49          this.domain = domain;
50          this.startedIn = origin;
51          this.caretOffset = caretOffset;
52          this.caretManager = cManager;
53      }
54  
55  	/***
56  	 * @return <code>true</code> if it was created in EditPart implementing <code>ITextPieceKeeper</code> 
57  	 */
58      public boolean canExecute() {
59          return (this.startedIn != null)
60                  && (this.startedIn instanceof ITextPieceKeeper);
61      }
62     
63  	/***
64  	 * Swithes tool to TextTool
65  	 */
66      public void execute() {
67          this.domain.setActiveTool(getEditingTool());
68      }
69  
70      protected Tool getEditingTool() {
71          TextTool result = new TextTool((EditPart)this.startedIn, this.caretOffset,this.caretManager );
72          return result;
73      }
74  }