1
2
3
4
5
6
7
8
9
10
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 }