com.yworks.yfiles.server.tiles.servlet
Class UndoServlet

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended bycom.yworks.yfiles.server.tiles.servlet.BaseServlet
              extended bycom.yworks.yfiles.server.tiles.servlet.UndoServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class UndoServlet
extends BaseServlet

This servlet handles requests related to undo/redo.

Since undo/redo requires extra resources it is not enabled by default. This servlet handles requests for enabling and disabling undo/redo for a graph cached at the current session. ("setUndoRedoEnabled" and "isUndoRedoEnabled").

Even if undo/redo is enabled undo can only be performed, if there was at least one update to a graph after undo/redo was enabled for the graph. So there is a request for checking whether undo or redo is possible ("canUndoRedo").

Finally, this servlet handles the requests for performing an undo or redo operation ("undo", "redo").

The requests for performing the operations which actually change the state ("setUndoRedoEnabled", "undo" and "redo") have to be POST requests. The requests for performing a query operation ("isUndoRedoEnabled", "canUndoRedo") may be GET or POST requests.

If undo/redo is enabled for a graph then a standard Graph2DUndoManager is created and registered as the backup realizers handler at the graph. This manager is then used by all other operations. Subclasses may implement their undo management differently by redefining createUndoManager(y.view.Graph2D) and getUndoManager(y.view.Graph2D).

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.yworks.yfiles.server.tiles.servlet.BaseServlet
EDGE_DESCRIPTION_KEY, EDGE_URL_KEY, NODE_DESCRIPTION_KEY, NODE_URL_KEY
 
Constructor Summary
UndoServlet()
           
 
Method Summary
protected  boolean canRedo(Graph2D graph)
          Returns whether a redo can be performed for the given graph.
protected  boolean canUndo(Graph2D graph)
          Returns whether an undo can be performed for the given graph.
protected  Graph2DUndoManager createUndoManager(Graph2D graph)
          Creates and returns a new undo manager for the given graph.
protected  Graph2DUndoManager getUndoManager(Graph2D graph)
          Returns the undo manager for the given graph.
protected  void handleGetRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           handles "isUndoRedoEnabled" and "canUndoRedo" requests.
protected  void handlePostRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           handles "setUndoRedoEnabled", "undo" and "redo" requests.
protected  boolean isUndoRedoEnabled(Graph2D graph)
          Returns whether undo/redo is enabled for the given graph.
protected  void redo(Graph2D graph)
          reverts the last undo for the given graph.
protected  void setUndoRedoEnabled(Graph2D graph, boolean enabled)
          Sets whether undo/redo is enabled for the given graph.
protected  void undo(Graph2D graph)
          reverts the last change for the given graph.
 
Methods inherited from class com.yworks.yfiles.server.tiles.servlet.BaseServlet
addViewConfigurator, cachedGraphs, cacheGraph, doGet, doPost, getEdgeDescription, getEdgeURL, getForId, getGraph, getGraphBounds, getGraphContentBounds, getId, getId, getId, getId, getNodeDescription, getNodeURL, getReadWriteLock, getSessionMonitor, getViewConfigurators, getWriter, hasDescriptions, hasURLs, init, initialize, isUseJSONPrefixing, lookupId, lookupId, lookupId, lookupId, newGraph, readLock, registerLicense, removeViewConfigurator, setEdgeDescription, setEdgeURL, setNodeDescription, setNodeURL, uncacheGraph, unlockRead, unlockWrite, updateEdgePaths, validateIds, writeContentBounds, writeLock, writeWorldBounds
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UndoServlet

public UndoServlet()
Method Detail

handlePostRequest

protected void handlePostRequest(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response)
                          throws javax.servlet.ServletException,
                                 IOException

handles "setUndoRedoEnabled", "undo" and "redo" requests. The parameter "name" is mandatory for all requests. It is the symbolic name of the graph to be used.

This method detects the operation to perform, fetches the necessary parameters from the requests and the graph from the session and then calls one of the protected methods in this class which act on the graph like undo(y.view.Graph2D).

If the requests is neither "setUndoRedoEnabled", "undo" or "redo" then the method for handling GET requests is called. Thus a query operation ("isUndoRedoEnabled", "canUndoRedo") can also be initiated by a POST request.

Overrides:
handlePostRequest in class BaseServlet
Parameters:
request - the request
response - the response to write to
Throws:
javax.servlet.ServletException
IOException

handleGetRequest

protected void handleGetRequest(javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response)
                         throws javax.servlet.ServletException,
                                IOException

handles "isUndoRedoEnabled" and "canUndoRedo" requests. The parameter "name" is mandatory for all requests. It is the symbolic name of the graph to be used. "canUndoRedo" returns an object in JSON format like the following.

 { "canUndo" : true, "canRedo" : false }
 

This method detects the operation to perform, fetches the necessary parameters from the requests and the graph from the session and then calls one of the protected methods in this class which act on the graph like canUndo(y.view.Graph2D).

Overrides:
handleGetRequest in class BaseServlet
Parameters:
request - the request
response - the response to write to
Throws:
javax.servlet.ServletException
IOException

isUndoRedoEnabled

protected boolean isUndoRedoEnabled(Graph2D graph)
Returns whether undo/redo is enabled for the given graph. This method checks whether an undo manager is available using getUndoManager(y.view.Graph2D).

Parameters:
graph - a graph
Returns:
whether undo/redo is enabled

setUndoRedoEnabled

protected void setUndoRedoEnabled(Graph2D graph,
                                  boolean enabled)
Sets whether undo/redo is enabled for the given graph. This method checks whether an undo manager is available using getUndoManager(y.view.Graph2D). This method creates an undo manager if necessary using createUndoManager(y.view.Graph2D).

Parameters:
graph - a graph
enabled - if true enable undo/redo, disable it otherwise

undo

protected void undo(Graph2D graph)
reverts the last change for the given graph. This method uses the undo manager returned by getUndoManager(y.view.Graph2D).

Parameters:
graph - a graph

redo

protected void redo(Graph2D graph)
reverts the last undo for the given graph. This method uses the undo manager returned by getUndoManager(y.view.Graph2D).

Parameters:
graph - a graph

canUndo

protected boolean canUndo(Graph2D graph)
Returns whether an undo can be performed for the given graph. This method uses the undo manager returned by getUndoManager(y.view.Graph2D).

Parameters:
graph - a graph
Returns:
whether an undo can be performed

canRedo

protected boolean canRedo(Graph2D graph)
Returns whether a redo can be performed for the given graph. This method uses the undo manager returned by getUndoManager(y.view.Graph2D).

Parameters:
graph - a graph
Returns:
whether a redo can be performed

createUndoManager

protected Graph2DUndoManager createUndoManager(Graph2D graph)
Creates and returns a new undo manager for the given graph.

Parameters:
graph - the graph
Returns:
an undo manager
See Also:
getUndoManager(y.view.Graph2D)

getUndoManager

protected Graph2DUndoManager getUndoManager(Graph2D graph)
Returns the undo manager for the given graph.

Parameters:
graph - a graph
Returns:
the undo manager or null
See Also:
createUndoManager(y.view.Graph2D)


Copyright © 2006-2013 yWorks GmbH. All rights reserved