com.ephox.editlive.java2.editor.operation
Interface OperationManager


public interface OperationManager


Field Summary
static String TRACK_CHANGES_ELEMENT_NAME
           
static String TRACK_CHANGES_NAMESPACE
          The namespace used for elements in the serialized XML.
static String XML_VERSION_ATTRIBUTE
           
static String XML_VERSION_ATTRIBUTE_VALUE
           
 
Method Summary
 void accept(Operation operation, HTMLDocument document)
          Accept an operation.
 void addOperationChangeListener(OperationListener listener)
          Add an operation change listener to the manager, listening for when the state of operations changes.
 Color getColorForUser(String author)
          Get the color to use to render changes by author.
 int getOperationCount()
          Get the number of operations that are currently being tracked.
 Collection getOperations()
          Get the operations currently being tracked by this operation manager.
 Collection getOperationsInRange(int start, int end)
          Get the list of operations that affect the specified range.
 Collection getOperationsToRenderInRange(int start, int end)
          Get the list of operations that affect the rendering in the specified range.
 String getUsername()
          Returns the current user name.
 boolean isRemoved(int startOffset, int endOffset)
          Determine if all content in the specified range is marked as removed.
 boolean isTrackChangesEnabled()
          Returns whether or not changes are currently being tracked.
 Operation nextOperation(int afterOffset)
          Get the operation whose affected range starts closest to, but after afterOffset.
 Operation nextOperation(Operation currentOperation)
          Get the next operation after currentOperation, ordered by the start of the affected range.
 Operation previousOperation(int beforeOffset)
          Get the operation whose affected range starts closest to, but before or equal to beforeOffset.
 Operation previousOperation(Operation currentOperation)
          Get the operation before currentOperation, ordered by the start of the affected range.
 void reject(Operation operation, HTMLDocument document)
          Reject an operation.
 void removeOperation(Operation operation)
          Remove an operation from the manager without doing anything else.
 void removeOperationChangeListener(OperationListener listener)
          Remove an operation change listener from the manager.
 

Field Detail

TRACK_CHANGES_NAMESPACE

public static final String TRACK_CHANGES_NAMESPACE
The namespace used for elements in the serialized XML.

See Also:
Constant Field Values

TRACK_CHANGES_ELEMENT_NAME

public static final String TRACK_CHANGES_ELEMENT_NAME
See Also:
Constant Field Values

XML_VERSION_ATTRIBUTE_VALUE

public static final String XML_VERSION_ATTRIBUTE_VALUE
See Also:
Constant Field Values

XML_VERSION_ATTRIBUTE

public static final String XML_VERSION_ATTRIBUTE
See Also:
Constant Field Values
Method Detail

isTrackChangesEnabled

public boolean isTrackChangesEnabled()
Returns whether or not changes are currently being tracked.

Returns:
true if track changes is enabled, otherwise false.

getOperationCount

public int getOperationCount()
Get the number of operations that are currently being tracked.

Returns:
the number of operations being tracked.

getOperations

public Collection getOperations()
Get the operations currently being tracked by this operation manager. The returned collection is backed by the operation manager and updates as operations are performed, accepted, rejected and merged.

The operations are ordered by the start of the range in the document they affect.

Returns:
the collection of operations currently being tracked by the operation manager.

getOperationsToRenderInRange

public Collection getOperationsToRenderInRange(int start,
                                               int end)
Get the list of operations that affect the rendering in the specified range.

Note that if track changes rendering is off, this method will always return an empty collection.

The operations are ordered by the start of the range in the document they affect.

Parameters:
start - the start of the range to check for operations in.
end - the end of the range to check for operations in.
Returns:
the operations that affect the specified range.

getOperationsInRange

public Collection getOperationsInRange(int start,
                                       int end)
Get the list of operations that affect the specified range.

The operations are ordered by the start of the range in the document they affect.

Parameters:
start - the start of the range to check for operations in.
end - the end of the range to check for operations in.
Returns:
the operations that affect the specified range.

accept

public void accept(Operation operation,
                   HTMLDocument document)
            throws BadLocationException
Accept an operation. Once accepted, operations are no longer tracked by the manager and their effects are fully applied to the document.

Parameters:
operation - the operation to accept. Must have been retrieved from this operation manager.
document - the document being edited. This must be the document retrieved from the HTML editing pane.
Throws:
BadLocationException - if the operation attempts to access or modify an invalid location in the document.

reject

public void reject(Operation operation,
                   HTMLDocument document)
            throws BadLocationException
Reject an operation. The effects of the operation on the document are reversed as if the operation had never been performed. The operation will no longer be tracked.

Parameters:
operation - the operation to reject. Must have been retrieved from this operation manager.
document - the document to reverse changes in. This must be the document retrieved from the HTML editing pane.
Throws:
BadLocationException - if the operation attempts to access or modify an invalid location in the document.

nextOperation

public Operation nextOperation(Operation currentOperation)
Get the next operation after currentOperation, ordered by the start of the affected range. Operations which both start at the same offset, are ordered by the order in which they occurred.

Parameters:
currentOperation - the operation to get the next operation after, or null to get the first operation in the document.
Returns:
the Operation after currentOperation.

previousOperation

public Operation previousOperation(Operation currentOperation)
Get the operation before currentOperation, ordered by the start of the affected range. Operations which both start at the same offset, are ordered by the order in which they occurred.

Parameters:
currentOperation - the operation to get the operation before, or null to get the last operation in the document.
Returns:
the Operation before currentOperation.

nextOperation

public Operation nextOperation(int afterOffset)
Get the operation whose affected range starts closest to, but after afterOffset.

Parameters:
afterOffset - the offset to find the closest operation after.
Returns:
the first tracked operation that starts after afterOffset.

previousOperation

public Operation previousOperation(int beforeOffset)
Get the operation whose affected range starts closest to, but before or equal to beforeOffset.

Parameters:
beforeOffset - the offset to find the closest operation before.
Returns:
the first tracked operation that starts at or before beforeOffset.

getColorForUser

public Color getColorForUser(String author)
Get the color to use to render changes by author.

Parameters:
author - the author to get the color for.
Returns:
the color associated with the author author.

getUsername

public String getUsername()
Returns the current user name.

Returns:
the current user name.

addOperationChangeListener

public void addOperationChangeListener(OperationListener listener)
Add an operation change listener to the manager, listening for when the state of operations changes.

Parameters:
listener - the OperationListener to receive events

removeOperationChangeListener

public void removeOperationChangeListener(OperationListener listener)
Remove an operation change listener from the manager. The listener will no longer receive event notifications.

Parameters:
listener - the OperationListener to remove.

removeOperation

public void removeOperation(Operation operation)
Remove an operation from the manager without doing anything else.
WARNING: This will have different side effects depending on the operation, some will appear accepted and others rejected.

Parameters:
operation -

isRemoved

public boolean isRemoved(int startOffset,
                         int endOffset)
Determine if all content in the specified range is marked as removed.

Parameters:
startOffset - the start of the range.
endOffset - the end of the range.
Returns:
true if all text in the range is marked as removed, otherwise false.

Copyright (c) 2005-2007 Ephox Pty Ltd. All rights reserved.