Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo')
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/CommandCursorPosition.java66
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/IDocumentSelectionMediator.java35
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/IStructuredTextUndoManager.java155
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCommand.java34
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCommandImpl.java137
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCompoundCommandImpl.java260
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextUndoManager.java652
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/UndoDocumentEvent.java45
8 files changed, 0 insertions, 1384 deletions
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/CommandCursorPosition.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/CommandCursorPosition.java
deleted file mode 100644
index 3c32f5bf73..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/CommandCursorPosition.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.undo;
-
-
-
-public interface CommandCursorPosition {
-
- /**
- * Returns the cursor position to be set to after this command is redone.
- *
- * @return int
- */
- int getRedoCursorPosition();
-
- /**
- * Returns the length of text to be selected after this command is redone.
- *
- * @return int
- */
- int getRedoSelectionLength();
-
- /**
- * Returns the cursor position to be set to after this command is undone.
- *
- * @return int
- */
- int getUndoCursorPosition();
-
- /**
- * Returns the length of text to be selected after this command is undone.
- *
- * @return int
- */
- int getUndoSelectionLength();
-
- /**
- * Sets the cursor position to be used after this command is redone.
- */
- void setRedoCursorPosition(int cursorPosition);
-
- /**
- * Sets the length of text to be selected after this command is redone.
- */
- void setRedoSelectionLength(int selectionLength);
-
- /**
- * Sets the cursor position to be used after this command is undone.
- */
- void setUndoCursorPosition(int cursorPosition);
-
- /**
- * Sets the length of text to be selected after this command is undone.
- */
- void setUndoSelectionLength(int selectionLength);
-}
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/IDocumentSelectionMediator.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/IDocumentSelectionMediator.java
deleted file mode 100644
index a63882dfda..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/IDocumentSelectionMediator.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.undo;
-
-import org.eclipse.jface.text.IDocument;
-
-
-public interface IDocumentSelectionMediator {
- /**
- * Returns the document selection mediator's input document.
- *
- * @return the document selection mediator's input document
- */
- IDocument getDocument();
-
- /**
- * Sets a new selection in the document as a result of an undo operation.
- *
- * UndoDocumentEvent contains the requester of the undo operation, and the
- * offset and length of the new selection. Implementation of
- * IDocumentSelectionMediator can check if it's the requester that caused
- * the new selection, and decide if the new selection should be applied.
- */
- void undoOperationSelectionChanged(UndoDocumentEvent event);
-}
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/IStructuredTextUndoManager.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/IStructuredTextUndoManager.java
deleted file mode 100644
index 57c741cc6a..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/IStructuredTextUndoManager.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.undo;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.CommandStack;
-
-public interface IStructuredTextUndoManager {
-
- /**
- * Begin recording undo transactions.
- */
- void beginRecording(Object requester);
-
- /**
- * Begin recording undo transactions.
- */
- void beginRecording(Object requester, int cursorPosition, int selectionLength);
-
- /**
- * Begin recording undo transactions.
- */
- void beginRecording(Object requester, String label);
-
- /**
- * Begin recording undo transactions.
- */
- void beginRecording(Object requester, String label, int cursorPosition, int selectionLength);
-
- /**
- * Begin recording undo transactions.
- */
- void beginRecording(Object requester, String label, String description);
-
- /**
- * Begin recording undo transactions.
- */
- void beginRecording(Object requester, String label, String description, int cursorPosition, int selectionLength);
-
- /**
- * Connect the mediator to the undo manager.
- */
- void connect(IDocumentSelectionMediator mediator);
-
- /**
- * Disable undo management.
- */
- void disableUndoManagement();
-
- /**
- * Disconnect the mediator from the undo manager.
- */
- void disconnect(IDocumentSelectionMediator mediator);
-
- /**
- * Enable undo management.
- */
- void enableUndoManagement();
-
- /**
- * End recording undo transactions.
- */
- void endRecording(Object requester);
-
- /**
- * End recording undo transactions.
- */
- void endRecording(Object requester, int cursorPosition, int selectionLength);
-
- /**
- * <p>
- * Normally, the undo manager can figure out the best times when to end a
- * pending command and begin a new one ... to the structure of a structued
- * document. There are times, however, when clients may wish to override
- * those algorithms and end one earlier than normal. The one known case is
- * for multipage editors. If a user is on one page, and type '123' as
- * attribute value, then click around to other parts of page, or different
- * pages, then return to '123|' and type 456, then "undo" they typically
- * expect the undo to just undo what they just typed, the 456, not the
- * whole attribute value.
- * <p>
- * If there is no pending command, the request is ignored.
- */
- public void forceEndOfPendingCommand(Object requester, int currentPosition, int length);
-
- /**
- * Some clients need to do complicated things with undo stack. Plus, in
- * some cases, if clients setCommandStack temporarily, they have
- * reponsibility to set back to original one when finished.
- */
- public CommandStack getCommandStack();
-
- /**
- * Get the redo command even if it's not committed yet.
- */
- Command getRedoCommand();
-
- /**
- * Get the undo command even if it's not committed yet.
- */
- Command getUndoCommand();
-
- /**
- * Redo the last command in the undo manager.
- */
- void redo();
-
- /**
- * Redo the last command in the undo manager and notify the requester
- * about the new selection.
- */
- void redo(IDocumentSelectionMediator requester);
-
- /**
- * Returns whether at least one text change can be repeated. A text change
- * can be repeated only if it was executed and rolled back.
- *
- * @return <code>true</code> if at least on text change can be repeated
- */
- boolean redoable();
-
- /**
- * Set the command stack.
- */
- void setCommandStack(CommandStack commandStack);
-
- /**
- * Undo the last command in the undo manager.
- */
- void undo();
-
- /**
- * Undo the last command in the undo manager and notify the requester
- * about the new selection.
- */
- void undo(IDocumentSelectionMediator requester);
-
- /**
- * Returns whether at least one text change can be rolled back.
- *
- * @return <code>true</code> if at least one text change can be rolled
- * back
- */
- boolean undoable();
-}
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCommand.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCommand.java
deleted file mode 100644
index 3c7ad37b8c..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCommand.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.undo;
-
-
-
-public interface StructuredTextCommand {
-
- String getTextDeleted();
-
- int getTextEnd();
-
- String getTextInserted();
-
- int getTextStart();
-
- void setTextDeleted(String textDeleted);
-
- void setTextEnd(int textEnd);
-
- void setTextInserted(String textInserted);
-
- void setTextStart(int textStart);
-}
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCommandImpl.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCommandImpl.java
deleted file mode 100644
index e8e282a863..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCommandImpl.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.undo;
-
-
-
-import org.eclipse.emf.common.command.AbstractCommand;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.wst.sse.core.internal.Logger;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-
-
-public class StructuredTextCommandImpl extends AbstractCommand implements StructuredTextCommand {
-
- protected IDocument fDocument = null; // needed for updating the text
- protected String fTextDeleted = null;
- protected int fTextEnd = -1;
- protected String fTextInserted = null;
- protected int fTextStart = -1;
-
- /**
- * We have no-arg constructor non-public to force document to be specfied.
- *
- */
- protected StructuredTextCommandImpl() {
- super();
- }
-
- public StructuredTextCommandImpl(IDocument document) {
- this();
- fDocument = document; // needed for updating the text
- }
-
- public void execute() {
- }
-
- /**
- * getTextDeleted method comment.
- */
- public java.lang.String getTextDeleted() {
- return fTextDeleted;
- }
-
- /**
- * textEnd is the same as (textStart + textInserted.length())
- */
- public int getTextEnd() {
- return fTextEnd;
- }
-
- /**
- * getTextInserted method comment.
- */
- public java.lang.String getTextInserted() {
- return fTextInserted;
- }
-
- /**
- * getTextStart method comment.
- */
- public int getTextStart() {
- return fTextStart;
- }
-
- protected boolean prepare() {
- return true;
- }
-
- public void redo() {
- if (fDocument instanceof IStructuredDocument) {
- // note: one of the few places we programatically ignore read-only
- // settings
- ((IStructuredDocument) fDocument).replaceText(this, fTextStart, fTextDeleted.length(), fTextInserted, true);
- } else {
- try {
- fDocument.replace(fTextStart, fTextDeleted.length(), fTextInserted);
- } catch (BadLocationException e) {
- // assumed impossible, for now
- Logger.logException(e);
- }
- }
- }
-
- /**
- * setTextDeleted method comment.
- */
- public void setTextDeleted(java.lang.String textDeleted) {
- fTextDeleted = textDeleted;
- }
-
- /**
- * setTextEnd method comment.
- */
- public void setTextEnd(int textEnd) {
- fTextEnd = textEnd;
- }
-
- /**
- * setTextInserted method comment.
- */
- public void setTextInserted(java.lang.String textInserted) {
- fTextInserted = textInserted;
- }
-
- /**
- * setTextStart method comment.
- */
- public void setTextStart(int textStart) {
- fTextStart = textStart;
- }
-
- public void undo() {
- if (fDocument instanceof IStructuredDocument) {
- // note: one of the few places we programatically ignore read-only
- // settings
- ((IStructuredDocument) fDocument).replaceText(this, fTextStart, fTextInserted.length(), fTextDeleted, true);
- } else {
- try {
- fDocument.replace(fTextStart, fTextInserted.length(), fTextDeleted);
- } catch (BadLocationException e) {
- // assumed impossible, for now
- Logger.logException(e);
- }
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCompoundCommandImpl.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCompoundCommandImpl.java
deleted file mode 100644
index 86ca4a01c0..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextCompoundCommandImpl.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.undo;
-
-
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.CompoundCommand;
-
-
-
-public class StructuredTextCompoundCommandImpl extends CompoundCommand implements CommandCursorPosition {
- protected int fRedoCursorPosition = -1;
- protected int fRedoSelectionLength = 0;
-
- protected int fUndoCursorPosition = -1;
- protected int fUndoSelectionLength = 0;
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- */
- public StructuredTextCompoundCommandImpl() {
- super();
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param resultIndex
- * int
- */
- public StructuredTextCompoundCommandImpl(int resultIndex) {
- super(resultIndex);
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param resultIndex
- * int
- * @param commandList
- * java.util.List
- */
- public StructuredTextCompoundCommandImpl(int resultIndex, java.util.List commandList) {
- super(resultIndex, commandList);
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param resultIndex
- * int
- * @param label
- * java.lang.String
- */
- public StructuredTextCompoundCommandImpl(int resultIndex, String label) {
- super(resultIndex, label);
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param resultIndex
- * int
- * @param label
- * java.lang.String
- * @param commandList
- * java.util.List
- */
- public StructuredTextCompoundCommandImpl(int resultIndex, String label, java.util.List commandList) {
- super(resultIndex, label, commandList);
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param resultIndex
- * int
- * @param label
- * java.lang.String
- * @param description
- * java.lang.String
- */
- public StructuredTextCompoundCommandImpl(int resultIndex, String label, String description) {
- super(resultIndex, label, description);
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param resultIndex
- * int
- * @param label
- * java.lang.String
- * @param description
- * java.lang.String
- * @param commandList
- * java.util.List
- */
- public StructuredTextCompoundCommandImpl(int resultIndex, String label, String description, java.util.List commandList) {
- super(resultIndex, label, description, commandList);
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param commandList
- * java.util.List
- */
- public StructuredTextCompoundCommandImpl(java.util.List commandList) {
- super(commandList);
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param label
- * java.lang.String
- */
- public StructuredTextCompoundCommandImpl(String label) {
- super(label);
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param label
- * java.lang.String
- * @param commandList
- * java.util.List
- */
- public StructuredTextCompoundCommandImpl(String label, java.util.List commandList) {
- super(label, commandList);
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param label
- * java.lang.String
- * @param description
- * java.lang.String
- */
- public StructuredTextCompoundCommandImpl(String label, String description) {
- super(label, description);
- }
-
- /**
- * StructuredTextCompoundCommandImpl constructor comment.
- *
- * @param label
- * java.lang.String
- * @param description
- * java.lang.String
- * @param commandList
- * java.util.List
- */
- public StructuredTextCompoundCommandImpl(String label, String description, java.util.List commandList) {
- super(label, description, commandList);
- }
-
- /**
- * Returns the cursor position to be set to after this command is redone.
- *
- * @return int
- */
- public int getRedoCursorPosition() {
- int cursorPosition = -1;
-
- if (fRedoCursorPosition != -1)
- cursorPosition = fRedoCursorPosition;
- else if (!commandList.isEmpty()) {
- int commandListSize = commandList.size();
- Command lastCommand = (Command) commandList.get(commandListSize - 1);
-
- if (lastCommand instanceof CommandCursorPosition)
- cursorPosition = ((CommandCursorPosition) lastCommand).getRedoCursorPosition();
- }
-
- return cursorPosition;
- }
-
- /**
- * Returns the length of text to be selected after this command is redone.
- *
- * @return int
- */
- public int getRedoSelectionLength() {
- return fRedoSelectionLength;
- }
-
- /**
- * Returns the cursor position to be set to after this command is undone.
- *
- * @return int
- */
- public int getUndoCursorPosition() {
- int cursorPosition = -1;
-
- if (fUndoCursorPosition != -1)
- cursorPosition = fUndoCursorPosition;
- else if (!commandList.isEmpty()) {
- // never used
- //int commandListSize = commandList.size();
- Command firstCommand = (Command) commandList.get(0);
-
- if (firstCommand instanceof CommandCursorPosition)
- cursorPosition = ((CommandCursorPosition) firstCommand).getUndoCursorPosition();
- }
-
- return cursorPosition;
- }
-
- /**
- * Returns the length of text to be selected after this command is undone.
- *
- * @return int
- */
- public int getUndoSelectionLength() {
- return fUndoSelectionLength;
- }
-
- /**
- * Sets the cursor position to be used after this command is redone.
- */
- public void setRedoCursorPosition(int cursorPosition) {
- fRedoCursorPosition = cursorPosition;
- }
-
- /**
- * Sets the length of text to be selected after this command is redone.
- */
- public void setRedoSelectionLength(int selectionLength) {
- fRedoSelectionLength = selectionLength;
- }
-
- /**
- * Sets the cursor position to be used after this command is undone.
- */
- public void setUndoCursorPosition(int cursorPosition) {
- fUndoCursorPosition = cursorPosition;
- }
-
- /**
- * Sets the length of text to be selected after this command is undone.
- */
- public void setUndoSelectionLength(int selectionLength) {
- fUndoSelectionLength = selectionLength;
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextUndoManager.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextUndoManager.java
deleted file mode 100644
index ebd028070b..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/StructuredTextUndoManager.java
+++ /dev/null
@@ -1,652 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- * Jesper Steen Møller - initial IDocumentExtension4 support - #102822
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.undo;
-
-import java.util.EventObject;
-
-import org.eclipse.emf.common.command.BasicCommandStack;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.CommandStack;
-import org.eclipse.emf.common.command.CommandStackListener;
-import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.jface.text.DocumentRewriteSession;
-import org.eclipse.jface.text.DocumentRewriteSessionType;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension4;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.SSECoreMessages;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener;
-import org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.util.Assert;
-import org.eclipse.wst.sse.core.internal.util.Utilities;
-
-public class StructuredTextUndoManager implements IStructuredTextUndoManager {
-
- class InternalCommandStackListener implements CommandStackListener {
- public void commandStackChanged(EventObject event) {
- resetInternalCommands();
- }
- }
-
- class InternalStructuredDocumentListener implements IStructuredDocumentListener {
-
- public void newModel(NewDocumentEvent structuredDocumentEvent) {
- // Do nothing. Do not push the new model's structuredDocument
- // changes
- // onto the undo command stack, or else the user may be able to
- // undo
- // an existing file to an empty file.
- }
-
- public void noChange(NoChangeEvent structuredDocumentEvent) {
- // Since "no change", do nothing.
- }
-
- public void nodesReplaced(StructuredDocumentRegionsReplacedEvent structuredDocumentEvent) {
- processStructuredDocumentEvent(structuredDocumentEvent);
- }
-
- private void processStructuredDocumentEvent(String textDeleted, String textInserted, int textStart, int textEnd) {
- if (fTextCommand != null && textStart == fTextCommand.getTextEnd()) {
- // append to the text command
- fTextCommand.setTextDeleted(fTextCommand.getTextDeleted().concat(textDeleted));
- fTextCommand.setTextInserted(fTextCommand.getTextInserted().concat(textInserted));
- fTextCommand.setTextEnd(textEnd);
- }
- else if (fTextCommand != null && textStart == fTextCommand.getTextStart() - (textEnd - textStart + 1) && textEnd <= fTextCommand.getTextEnd() - (textEnd - textStart + 1) && textDeleted.length() == 1 && textInserted.length() == 0) {
- // backspace pressed
-
- // erase a character just inserted
- if (fTextCommand.getTextInserted().length() > 0) {
- fTextCommand.setTextInserted(fTextCommand.getTextInserted().substring(0, fTextCommand.getTextEnd() - fTextCommand.getTextStart() - 1));
- fTextCommand.setTextEnd(textEnd);
- }
- // erase a character in the file
- else {
- fTextCommand.setTextDeleted(textDeleted.concat(fTextCommand.getTextDeleted()));
- fTextCommand.setTextStart(textStart);
- }
- }
- else {
- createNewTextCommand(textDeleted, textInserted, textStart, textEnd);
- }
-
- // save cursor position
- fCursorPosition = textEnd;
- }
-
- private void processStructuredDocumentEvent(StructuredDocumentEvent structuredDocumentEvent) {
- // Note: fListening tells us if we should listen to the
- // StructuredDocumentEvent.
- // fListening is set to false right before the undo/redo process
- // and
- // then set to true again
- // right after the undo/redo process to block out and ignore all
- // StructuredDocumentEvents generated
- // by the undo/redo process.
-
- // Process StructuredDocumentEvent if fListening is true.
- //
- // We are executing a command from the command stack if the
- // requester
- // is a command (for example, undo/redo).
- // We should not process the flat model event when we are
- // executing a
- // command from the command stack.
- if (fUndoManagementEnabled && !(structuredDocumentEvent.getOriginalRequester() instanceof Command)) {
- // check requester if not recording
- if (!fRecording)
- checkRequester(structuredDocumentEvent.getOriginalRequester());
-
- // process the structuredDocumentEvent
- String textDeleted = structuredDocumentEvent.getDeletedText();
- String textInserted = structuredDocumentEvent.getText();
- int textStart = structuredDocumentEvent.getOffset();
- int textEnd = textStart + textInserted.length();
- processStructuredDocumentEvent(textDeleted, textInserted, textStart, textEnd);
- }
- }
-
- public void regionChanged(RegionChangedEvent structuredDocumentEvent) {
- processStructuredDocumentEvent(structuredDocumentEvent);
- }
-
- public void regionsReplaced(RegionsReplacedEvent structuredDocumentEvent) {
- processStructuredDocumentEvent(structuredDocumentEvent);
- }
-
- }
-
- private static final String TEXT_CHANGE_TEXT = SSECoreMessages.Text_Change_UI_; //$NON-NLS-1$
- private CommandStack fCommandStack = null;
- private StructuredTextCompoundCommandImpl fCompoundCommand = null;
- private String fCompoundCommandDescription = null;
- private String fCompoundCommandLabel = null;
- int fCursorPosition = 0;
- // private IStructuredModel fStructuredModel = null;
- private IDocument fDocument;
- private InternalCommandStackListener fInternalCommandStackListener;
- // private Map fTextViewerToListenerMap = new HashMap();
- private IStructuredDocumentListener fInternalStructuredDocumentListener;
- private IDocumentSelectionMediator[] fMediators = null;
- private boolean fRecording = false;
- private int fRecordingCount = 0;
- private Object fRequester;
- StructuredTextCommandImpl fTextCommand = null;
- private int fUndoCursorPosition = -1;
- boolean fUndoManagementEnabled = true;
- private int fUndoSelectionLength = 0;
-
- public StructuredTextUndoManager() {
- this(new BasicCommandStack());
- }
-
- public StructuredTextUndoManager(CommandStack commandStack) {
- setCommandStack(commandStack);
- }
-
- private void addDocumentSelectionMediator(IDocumentSelectionMediator mediator) {
- if (!Utilities.contains(fMediators, mediator)) {
- int oldSize = 0;
-
- if (fMediators != null) {
- // normally won't be null, but we need to be sure, for first
- // time through
- oldSize = fMediators.length;
- }
-
- int newSize = oldSize + 1;
- IDocumentSelectionMediator[] newMediators = new IDocumentSelectionMediator[newSize];
- if (fMediators != null) {
- System.arraycopy(fMediators, 0, newMediators, 0, oldSize);
- }
-
- // add the new undo mediator to last position
- newMediators[newSize - 1] = mediator;
-
- // now switch new for old
- fMediators = newMediators;
- }
- else {
- removeDocumentSelectionMediator(mediator);
- addDocumentSelectionMediator(mediator);
- }
- }
-
- public void beginRecording(Object requester) {
- beginRecording(requester, null, null);
- }
-
- public void beginRecording(Object requester, int cursorPosition, int selectionLength) {
- beginRecording(requester, null, null);
-
- fUndoCursorPosition = cursorPosition;
- fUndoSelectionLength = selectionLength;
- }
-
- public void beginRecording(Object requester, String label) {
- beginRecording(requester, label, null);
- }
-
- public void beginRecording(Object requester, String label, int cursorPosition, int selectionLength) {
- beginRecording(requester, label, null);
-
- fUndoCursorPosition = cursorPosition;
- fUndoSelectionLength = selectionLength;
- }
-
- public void beginRecording(Object requester, String label, String description) {
- // save the requester
- fRequester = requester;
-
- // update label and desc only on the first level when recording is
- // nested
- if (fRecordingCount == 0) {
- fCompoundCommandLabel = label;
- if (fCompoundCommandLabel == null)
- fCompoundCommandLabel = TEXT_CHANGE_TEXT;
-
- fCompoundCommandDescription = description;
- if (fCompoundCommandDescription == null)
- fCompoundCommandDescription = TEXT_CHANGE_TEXT;
-
- // clear commands
- fTextCommand = null;
- fCompoundCommand = null;
- }
-
- // update counter and flag
- fRecordingCount++;
- fRecording = true;
-
- // no undo cursor position and undo selection length specified
- // reset undo cursor position and undo selection length
- fUndoCursorPosition = -1;
- fUndoSelectionLength = 0;
- }
-
- public void beginRecording(Object requester, String label, String description, int cursorPosition, int selectionLength) {
- beginRecording(requester, label, description);
-
- fUndoCursorPosition = cursorPosition;
- fUndoSelectionLength = selectionLength;
- }
-
- void checkRequester(Object requester) {
- if (fRequester != null && !fRequester.equals(requester)) {
- // Force restart of recording so the last compound command is
- // closed.
- //
- // However, we should not force restart of recording when the
- // request came from StructuredDocumentToTextAdapter or
- // XMLModelImpl
- // because cut/paste requests and character inserts to the
- // textViewer are from StructuredDocumentToTextAdapter,
- // and requests to delete a node in the XMLTableTreeViewer are
- // from XMLModelImpl (which implements IStructuredModel).
-
- if (!(requester instanceof IStructuredModel || requester instanceof IStructuredDocument)) {
- resetInternalCommands();
- }
- }
- }
-
-
-
- public void connect(IDocumentSelectionMediator mediator) {
- Assert.isNotNull(mediator);
- if (fDocument == null) {
- // add this undo manager as structured document listener
- fDocument = mediator.getDocument();
- // future_TODO: eventually we want to refactor or allow either
- // type of document, but for now, we'll do instanceof check, and
- // fail
- // if not right type
- if (fDocument instanceof IStructuredDocument) {
- ((IStructuredDocument) fDocument).addDocumentChangedListener(getInternalStructuredDocumentListener());
- }
- else {
- throw new IllegalArgumentException("only meditator with structured documents currently handled"); //$NON-NLS-1$
- }
- }
- else {
- // if we've already had our document set, we'll just do this fail
- // fast integrity check
- if (!fDocument.equals(mediator.getDocument()))
- throw new IllegalStateException("Connection to undo manager failed. Document for document selection mediator inconistent with undo manager."); //$NON-NLS-1$
- }
-
- addDocumentSelectionMediator(mediator);
- }
-
- void createNewTextCommand(String textDeleted, String textInserted, int textStart, int textEnd) {
- StructuredTextCommandImpl textCommand = new StructuredTextCommandImpl(fDocument);
- textCommand.setLabel(TEXT_CHANGE_TEXT);
- textCommand.setDescription(TEXT_CHANGE_TEXT);
- textCommand.setTextStart(textStart);
- textCommand.setTextEnd(textEnd);
- textCommand.setTextDeleted(textDeleted);
- textCommand.setTextInserted(textInserted);
-
- if (fRecording) {
- if (fCompoundCommand == null) {
- StructuredTextCompoundCommandImpl compoundCommand = new StructuredTextCompoundCommandImpl();
- compoundCommand.setUndoCursorPosition(fUndoCursorPosition);
- compoundCommand.setUndoSelectionLength(fUndoSelectionLength);
-
- compoundCommand.setLabel(fCompoundCommandLabel);
- compoundCommand.setDescription(fCompoundCommandDescription);
- compoundCommand.append(textCommand);
- fCommandStack.execute(compoundCommand);
-
- fCompoundCommand = compoundCommand;
- }
- else {
- fCompoundCommand.append(textCommand);
- }
- }
- else {
- fCommandStack.execute(textCommand);
- }
-
- fTextCommand = textCommand;
- }
-
- /**
- * Disable undo management.
- */
- public void disableUndoManagement() {
- fUndoManagementEnabled = false;
- }
-
- public void disconnect(IDocumentSelectionMediator mediator) {
- removeDocumentSelectionMediator(mediator);
-
- if (fMediators != null && fMediators.length == 0 && fDocument != null) {
- // remove this undo manager as structured document listener
- // future_TODO: eventually we want to refactor or allow either
- // type of document, but for now, we'll do instanceof check, and
- // fail
- // if not right type
- if (fDocument instanceof IStructuredDocument) {
- ((IStructuredDocument) fDocument).removeDocumentChangedListener(getInternalStructuredDocumentListener());
- }
- else {
- throw new IllegalArgumentException("only meditator with structured documents currently handled"); //$NON-NLS-1$
- }
- // if no longer listening to document, then dont even track it
- // anymore
- // (this allows connect to reconnect to document again)
- fDocument = null;
- }
- }
-
- public void enableUndoManagement() {
- fUndoManagementEnabled = true;
- }
-
- public void endRecording(Object requester) {
- int cursorPosition = (fTextCommand != null) ? fTextCommand.getTextEnd() : -1;
- int selectionLength = 0;
-
- endRecording(requester, cursorPosition, selectionLength);
- }
-
- public void endRecording(Object requester, int cursorPosition, int selectionLength) {
- // Recording could be stopped by forceEndOfPendingCommand(). Make sure
- // we are still recording before proceeding, or else fRecordingCount
- // may not be balanced.
- if (fRecording) {
- if (fCompoundCommand != null) {
- fCompoundCommand.setRedoCursorPosition(cursorPosition);
- fCompoundCommand.setRedoSelectionLength(selectionLength);
- }
-
- // end recording is a logical stopping point for text command,
- // even when fRecordingCount > 0 (in nested beginRecording)
- fTextCommand = null;
-
- // update counter and flag
- if (fRecordingCount > 0)
- fRecordingCount--;
- if (fRecordingCount == 0) {
- fRecording = false;
-
- // reset compound command only when fRecordingCount ==
- // 0
- fCompoundCommand = null;
- fCompoundCommandLabel = null;
- fCompoundCommandDescription = null;
-
- // Also reset fRequester
- fRequester = null;
- }
- }
- }
-
- /**
- * Utility method to find model given document
- */
- private IStructuredModel findStructuredModel(IDocument document) {
- IModelManager modelManager = StructuredModelManager.getModelManager();
- IStructuredModel structuredModel = modelManager.getExistingModelForRead(document);
- return structuredModel;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.undo.IStructuredTextUndoManager#forceEndOfPendingCommand(java.lang.Object,
- * int, int)
- */
- public void forceEndOfPendingCommand(Object requester, int currentPosition, int length) {
- if (fRecording)
- endRecording(requester, currentPosition, length);
- else
- resetInternalCommands();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.undo.IStructuredTextUndoManager#getCommandStack()
- */
- public CommandStack getCommandStack() {
- return fCommandStack;
- }
-
- /**
- * @return
- */
- private CommandStackListener getInternalCommandStackListener() {
- if (fInternalCommandStackListener == null) {
- fInternalCommandStackListener = new InternalCommandStackListener();
- }
- return fInternalCommandStackListener;
- }
-
- /**
- * @return
- */
- private IStructuredDocumentListener getInternalStructuredDocumentListener() {
- if (fInternalStructuredDocumentListener == null) {
- fInternalStructuredDocumentListener = new InternalStructuredDocumentListener();
- }
- return fInternalStructuredDocumentListener;
- }
-
- public Command getRedoCommand() {
- return fCommandStack.getRedoCommand();
- }
-
- public Command getUndoCommand() {
- return fCommandStack.getUndoCommand();
- }
-
- public void redo() {
- redo(null);
- }
-
- public void redo(IDocumentSelectionMediator requester) {
- IStructuredModel model = findStructuredModel(fDocument);
-
- if (redoable()) {
- IDocumentExtension4 docExt4 = null;
- DocumentRewriteSession rewriteSession = null;
- try {
- if (model != null)
- model.aboutToChangeModel();
-
- Command redoCommand = getRedoCommand();
- if (redoCommand instanceof CompoundCommand &&
- model.getStructuredDocument() instanceof IDocumentExtension4) {
- docExt4 = (IDocumentExtension4)model.getStructuredDocument();
- }
- rewriteSession = (docExt4 == null) ? null :
- docExt4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
-
- // make sure to redo before setting document selection
- fCommandStack.redo();
-
- // set document selection
- setRedoDocumentSelection(requester, redoCommand);
- }
- finally {
- if (docExt4 != null && rewriteSession != null)
- docExt4.stopRewriteSession(rewriteSession);
- if (model != null) {
- model.changedModel();
- model.releaseFromRead();
- }
- }
- }
- }
-
- public boolean redoable() {
- return fCommandStack.canRedo();
- }
-
- private void removeDocumentSelectionMediator(IDocumentSelectionMediator mediator) {
- if (fMediators != null && mediator != null) {
- // if its not in the array, we'll ignore the request
- if (Utilities.contains(fMediators, mediator)) {
- int oldSize = fMediators.length;
- int newSize = oldSize - 1;
- IDocumentSelectionMediator[] newMediators = new IDocumentSelectionMediator[newSize];
- int index = 0;
- for (int i = 0; i < oldSize; i++) {
- if (fMediators[i] == mediator) { // ignore
- }
- else {
- // copy old to new if its not the one we are removing
- newMediators[index++] = fMediators[i];
- }
- }
- // now that we have a new array, let's switch it for the old
- // one
- fMediators = newMediators;
- }
- }
- }
-
- void resetInternalCommands() {
- // Either the requester of the structured document change event is
- // changed, or the command stack is changed. Need to reset internal
- // commands so we won't continue to append changes.
- fCompoundCommand = null;
- fTextCommand = null;
-
- // Also reset fRequester
- fRequester = null;
- }
-
- public void setCommandStack(CommandStack commandStack) {
- if (fCommandStack != null)
- fCommandStack.removeCommandStackListener(getInternalCommandStackListener());
-
- fCommandStack = commandStack;
-
- if (fCommandStack != null)
- fCommandStack.addCommandStackListener(getInternalCommandStackListener());
- }
-
- private void setRedoDocumentSelection(IDocumentSelectionMediator requester, Command command) {
- int cursorPosition = -1;
- int selectionLength = 0;
-
- if (command instanceof CommandCursorPosition) {
- CommandCursorPosition commandCursorPosition = (CommandCursorPosition) command;
- cursorPosition = commandCursorPosition.getRedoCursorPosition();
- selectionLength = commandCursorPosition.getRedoSelectionLength();
- }
- else if (command instanceof StructuredTextCommand) {
- StructuredTextCommand structuredTextCommand = (StructuredTextCommand) command;
- cursorPosition = structuredTextCommand.getTextStart();
- selectionLength = structuredTextCommand.getTextInserted().length();
- }
-
- if (cursorPosition > -1 && fMediators != null && fMediators.length > 0) {
- for (int i = 0; i < fMediators.length; i++) {
- IDocument document = fMediators[i].getDocument();
- fMediators[i].undoOperationSelectionChanged(new UndoDocumentEvent(requester, document, cursorPosition, selectionLength));
- }
- }
- }
-
- private void setUndoDocumentSelection(IDocumentSelectionMediator requester, Command command) {
- int cursorPosition = -1;
- int selectionLength = 0;
-
- if (command instanceof CommandCursorPosition) {
- CommandCursorPosition commandCursorPosition = (CommandCursorPosition) command;
- cursorPosition = commandCursorPosition.getUndoCursorPosition();
- selectionLength = commandCursorPosition.getUndoSelectionLength();
- }
- else if (command instanceof StructuredTextCommand) {
- StructuredTextCommand structuredTextCommand = (StructuredTextCommand) command;
- cursorPosition = structuredTextCommand.getTextStart();
- selectionLength = structuredTextCommand.getTextDeleted().length();
- }
-
- if (cursorPosition > -1 && fMediators != null && fMediators.length > 0) {
- for (int i = 0; i < fMediators.length; i++) {
- IDocument document = fMediators[i].getDocument();
- fMediators[i].undoOperationSelectionChanged(new UndoDocumentEvent(requester, document, cursorPosition, selectionLength));
- }
- }
- }
-
- public void undo() {
- undo(null);
- }
-
- public void undo(IDocumentSelectionMediator requester) {
- // Force an endRecording before undo.
- //
- // For example, recording was turned on on the Design Page of
- // PageDesigner.
- // Then undo is invoked on the Source Page. Recording should be
- // stopped before we undo.
- // Note that redo should not be available when we switch to the Source
- // Page.
- // Therefore, this force ending of recording is not needed in redo.
- if (fRecording)
- endRecording(this);
-
- if (undoable()) {
- IStructuredModel model = findStructuredModel(fDocument);
- IDocumentExtension4 docExt4 = null;
- DocumentRewriteSession rewriteSession = null;
-
- try {
- if (model != null)
- model.aboutToChangeModel();
-
- Command undoCommand = getUndoCommand();
- if (undoCommand instanceof CompoundCommand &&
- model.getStructuredDocument() instanceof IDocumentExtension4) {
- docExt4 = (IDocumentExtension4)model.getStructuredDocument();
- }
- rewriteSession = (docExt4 == null) ? null :
- docExt4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
-
- // make sure to undo before setting document selection
- fCommandStack.undo();
-
- // set document selection
- setUndoDocumentSelection(requester, undoCommand);
- }
- finally {
- if (docExt4 != null && rewriteSession != null)
- docExt4.stopRewriteSession(rewriteSession);
- if (model != null) {
- model.changedModel();
- model.releaseFromRead();
- }
- }
- }
- }
-
- public boolean undoable() {
- return fCommandStack.canUndo();
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/UndoDocumentEvent.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/UndoDocumentEvent.java
deleted file mode 100644
index 2f2f8d71a4..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/undo/UndoDocumentEvent.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.undo;
-
-import org.eclipse.jface.text.IDocument;
-
-public class UndoDocumentEvent {
- private IDocument fDocument;
- private int fLength;
- private int fOffset;
- private IDocumentSelectionMediator fRequester;
-
- public UndoDocumentEvent(IDocumentSelectionMediator requester, IDocument document, int offset, int length) {
- fRequester = requester;
- fDocument = document;
- fOffset = offset;
- fLength = length;
- }
-
- public IDocument getDocument() {
- return fDocument;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getOffset() {
- return fOffset;
- }
-
- public IDocumentSelectionMediator getRequester() {
- return fRequester;
- }
-}

Back to the top