david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
amywu | ecebb04 | 2007-04-10 20:07:35 +0000 | [diff] [blame] | 2 | * Copyright (c) 2001, 2005 IBM Corporation and others. |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
amywu | ecebb04 | 2007-04-10 20:07:35 +0000 | [diff] [blame] | 7 | * |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | * Jens Lukowski/Innoopract - initial renaming/restructuring |
| 11 | * |
| 12 | *******************************************************************************/ |
| 13 | package org.eclipse.wst.sse.core.internal.undo; |
| 14 | |
| 15 | |
| 16 | |
| 17 | import org.eclipse.emf.common.command.Command; |
| 18 | import org.eclipse.emf.common.command.CompoundCommand; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 19 | |
| 20 | |
| 21 | |
| 22 | public class StructuredTextCompoundCommandImpl extends CompoundCommand implements CommandCursorPosition { |
| 23 | protected int fRedoCursorPosition = -1; |
| 24 | protected int fRedoSelectionLength = 0; |
| 25 | |
| 26 | protected int fUndoCursorPosition = -1; |
| 27 | protected int fUndoSelectionLength = 0; |
| 28 | |
| 29 | /** |
| 30 | * StructuredTextCompoundCommandImpl constructor comment. |
| 31 | */ |
| 32 | public StructuredTextCompoundCommandImpl() { |
| 33 | super(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * StructuredTextCompoundCommandImpl constructor comment. |
| 38 | * |
| 39 | * @param resultIndex |
| 40 | * int |
| 41 | */ |
| 42 | public StructuredTextCompoundCommandImpl(int resultIndex) { |
| 43 | super(resultIndex); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * StructuredTextCompoundCommandImpl constructor comment. |
| 48 | * |
| 49 | * @param resultIndex |
| 50 | * int |
| 51 | * @param commandList |
| 52 | * java.util.List |
| 53 | */ |
| 54 | public StructuredTextCompoundCommandImpl(int resultIndex, java.util.List commandList) { |
| 55 | super(resultIndex, commandList); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * StructuredTextCompoundCommandImpl constructor comment. |
| 60 | * |
| 61 | * @param resultIndex |
| 62 | * int |
| 63 | * @param label |
| 64 | * java.lang.String |
| 65 | */ |
| 66 | public StructuredTextCompoundCommandImpl(int resultIndex, String label) { |
| 67 | super(resultIndex, label); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * StructuredTextCompoundCommandImpl constructor comment. |
| 72 | * |
| 73 | * @param resultIndex |
| 74 | * int |
| 75 | * @param label |
| 76 | * java.lang.String |
| 77 | * @param commandList |
| 78 | * java.util.List |
| 79 | */ |
| 80 | public StructuredTextCompoundCommandImpl(int resultIndex, String label, java.util.List commandList) { |
| 81 | super(resultIndex, label, commandList); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * StructuredTextCompoundCommandImpl constructor comment. |
| 86 | * |
| 87 | * @param resultIndex |
| 88 | * int |
| 89 | * @param label |
| 90 | * java.lang.String |
| 91 | * @param description |
| 92 | * java.lang.String |
| 93 | */ |
| 94 | public StructuredTextCompoundCommandImpl(int resultIndex, String label, String description) { |
| 95 | super(resultIndex, label, description); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * StructuredTextCompoundCommandImpl constructor comment. |
| 100 | * |
| 101 | * @param resultIndex |
| 102 | * int |
| 103 | * @param label |
| 104 | * java.lang.String |
| 105 | * @param description |
| 106 | * java.lang.String |
| 107 | * @param commandList |
| 108 | * java.util.List |
| 109 | */ |
| 110 | public StructuredTextCompoundCommandImpl(int resultIndex, String label, String description, java.util.List commandList) { |
| 111 | super(resultIndex, label, description, commandList); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * StructuredTextCompoundCommandImpl constructor comment. |
| 116 | * |
| 117 | * @param commandList |
| 118 | * java.util.List |
| 119 | */ |
| 120 | public StructuredTextCompoundCommandImpl(java.util.List commandList) { |
| 121 | super(commandList); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * StructuredTextCompoundCommandImpl constructor comment. |
| 126 | * |
| 127 | * @param label |
| 128 | * java.lang.String |
| 129 | */ |
| 130 | public StructuredTextCompoundCommandImpl(String label) { |
| 131 | super(label); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * StructuredTextCompoundCommandImpl constructor comment. |
| 136 | * |
| 137 | * @param label |
| 138 | * java.lang.String |
| 139 | * @param commandList |
| 140 | * java.util.List |
| 141 | */ |
| 142 | public StructuredTextCompoundCommandImpl(String label, java.util.List commandList) { |
| 143 | super(label, commandList); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * StructuredTextCompoundCommandImpl constructor comment. |
| 148 | * |
| 149 | * @param label |
| 150 | * java.lang.String |
| 151 | * @param description |
| 152 | * java.lang.String |
| 153 | */ |
| 154 | public StructuredTextCompoundCommandImpl(String label, String description) { |
| 155 | super(label, description); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * StructuredTextCompoundCommandImpl constructor comment. |
| 160 | * |
| 161 | * @param label |
| 162 | * java.lang.String |
| 163 | * @param description |
| 164 | * java.lang.String |
| 165 | * @param commandList |
| 166 | * java.util.List |
| 167 | */ |
| 168 | public StructuredTextCompoundCommandImpl(String label, String description, java.util.List commandList) { |
| 169 | super(label, description, commandList); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Returns the cursor position to be set to after this command is redone. |
| 174 | * |
| 175 | * @return int |
| 176 | */ |
| 177 | public int getRedoCursorPosition() { |
| 178 | int cursorPosition = -1; |
| 179 | |
| 180 | if (fRedoCursorPosition != -1) |
| 181 | cursorPosition = fRedoCursorPosition; |
| 182 | else if (!commandList.isEmpty()) { |
| 183 | int commandListSize = commandList.size(); |
| 184 | Command lastCommand = (Command) commandList.get(commandListSize - 1); |
| 185 | |
| 186 | if (lastCommand instanceof CommandCursorPosition) |
| 187 | cursorPosition = ((CommandCursorPosition) lastCommand).getRedoCursorPosition(); |
| 188 | } |
| 189 | |
| 190 | return cursorPosition; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Returns the length of text to be selected after this command is redone. |
| 195 | * |
| 196 | * @return int |
| 197 | */ |
| 198 | public int getRedoSelectionLength() { |
| 199 | return fRedoSelectionLength; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Returns the cursor position to be set to after this command is undone. |
| 204 | * |
| 205 | * @return int |
| 206 | */ |
| 207 | public int getUndoCursorPosition() { |
| 208 | int cursorPosition = -1; |
| 209 | |
| 210 | if (fUndoCursorPosition != -1) |
| 211 | cursorPosition = fUndoCursorPosition; |
| 212 | else if (!commandList.isEmpty()) { |
| 213 | // never used |
| 214 | //int commandListSize = commandList.size(); |
| 215 | Command firstCommand = (Command) commandList.get(0); |
| 216 | |
| 217 | if (firstCommand instanceof CommandCursorPosition) |
| 218 | cursorPosition = ((CommandCursorPosition) firstCommand).getUndoCursorPosition(); |
| 219 | } |
| 220 | |
| 221 | return cursorPosition; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Returns the length of text to be selected after this command is undone. |
| 226 | * |
| 227 | * @return int |
| 228 | */ |
| 229 | public int getUndoSelectionLength() { |
| 230 | return fUndoSelectionLength; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Sets the cursor position to be used after this command is redone. |
| 235 | */ |
| 236 | public void setRedoCursorPosition(int cursorPosition) { |
| 237 | fRedoCursorPosition = cursorPosition; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Sets the length of text to be selected after this command is redone. |
| 242 | */ |
| 243 | public void setRedoSelectionLength(int selectionLength) { |
| 244 | fRedoSelectionLength = selectionLength; |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Sets the cursor position to be used after this command is undone. |
| 249 | */ |
| 250 | public void setUndoCursorPosition(int cursorPosition) { |
| 251 | fUndoCursorPosition = cursorPosition; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Sets the length of text to be selected after this command is undone. |
| 256 | */ |
| 257 | public void setUndoSelectionLength(int selectionLength) { |
| 258 | fUndoSelectionLength = selectionLength; |
| 259 | } |
| 260 | } |