org.xwiki.gwt.user.client.ui.rta
Class SelectionPreserver

java.lang.Object
  extended by org.xwiki.gwt.user.client.ui.rta.SelectionPreserver

public class SelectionPreserver
extends java.lang.Object

Most of the plugins alter the DOM document edited with the rich text area by executing commands on the current selection (thus on the current range). In some cases, a plugin needs to get user input before executing such a command. It can gather the needed information by opening a dialog, for instance. In some browsers this may lead to loosing the selection on the rich text area. In this case the plugin has to saveSelection() before the dialog is shown and restoreSelection() after the dialog is closed.
The selection preserver can be also used to restore the selection after executing commands like insert HTML. In this particular case the restored selection will contain the HTML that replaced the previous selection.

Version:
$Id: SelectionPreserver.java 25849 2009-12-18 20:08:55Z mflorea $

Constructor Summary
SelectionPreserver(RichTextArea rta)
          Creates a new selection preserver for the specified rich text area.
 
Method Summary
 void clearPlaceHolders()
          Removes the markers from the document and clears the list of saved range place holders.
 void restoreSelection()
          Restores the saved selection on the underlying rich text area and resets the state of the selection preserver.
 void restoreSelection(boolean reset)
          Restores the saved selection on the underlying rich text area.
 void saveSelection()
          Saves the current selection for later changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectionPreserver

public SelectionPreserver(RichTextArea rta)
Creates a new selection preserver for the specified rich text area.

Parameters:
rta - The rich text area whose selection will be preserved.
Method Detail

clearPlaceHolders

public void clearPlaceHolders()
Removes the markers from the document and clears the list of saved range place holders.


saveSelection

public void saveSelection()
Saves the current selection for later changes. The selection is taken from the underlying rich text area.

See Also:
restoreSelection()

restoreSelection

public void restoreSelection()
Restores the saved selection on the underlying rich text area and resets the state of the selection preserver.

See Also:
saveSelection()

restoreSelection

public void restoreSelection(boolean reset)
Restores the saved selection on the underlying rich text area. You can specify if the selection preserver should reset its state. When you're calling this method multiple times for the same selection it's more convenient to keep the state between the calls rather than call saveSelection() before.

Parameters:
reset - true if you want to reset the state of the selection preserver, false otherwise.
See Also:
saveSelection()


Copyright © 2004-2010 XWiki. All Rights Reserved.