com.yworks.yfiles.server.tiles.demos
Class TreeCollapserServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.yworks.yfiles.server.tiles.servlet.BaseServlet
              extended by com.yworks.yfiles.server.tiles.demos.TreeCollapserServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public class TreeCollapserServlet
extends BaseServlet

This servlet implements expanding and collapsing of subtrees of a rooted tree.

This servlet initially creates a rooted tree with several nodes. However, most of the nodes are not shown, because their subtrees are collapsed. The user can explore parts of the tree by expanding and collapsing subtrees. Collapsed subtrees are indicated by a plus sign in the upper right corner of the still visible root node. Collapsible nodes, those which have child nodes, are indicated by a minus sign.

After a change of the visible nodes of the tree, the tree is redrawn using either a TreeLayouter or an OrganicLayouter.

See Also:
Serialized Form

Constructor Summary
TreeCollapserServlet()
           
 
Method Summary
protected  Rectangle2D.Double getDoubleBounds(HttpSession session)
          returns the world bounds of the current tree as a Rectangle2D.
protected  void handlePostRequest(HttpServletRequest request, HttpServletResponse response)
           this method handles "POST" requests for this servlet.
 void initialize()
          This method initializes the layouter objects used for redrawing the tree after an expand or collapse operation.
 
Methods inherited from class com.yworks.yfiles.server.tiles.servlet.BaseServlet
cachedGraphs, cacheGraph, doGet, doPost, getEdgeDescription, getEdgeURL, getForId, getGraph, getGraphBounds, getId, getId, getId, getId, getNodeDescription, getNodeURL, getWriter, handleGetRequest, hasDescriptions, hasURLs, init, newGraph, setEdgeDescription, setEdgeURL, setNodeDescription, setNodeURL, uncacheGraph, 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

TreeCollapserServlet

public TreeCollapserServlet()
Method Detail

initialize

public void initialize()
                throws ServletException
This method initializes the layouter objects used for redrawing the tree after an expand or collapse operation.

Overrides:
initialize in class BaseServlet
Throws:
ServletException

handlePostRequest

protected void handlePostRequest(HttpServletRequest request,
                                 HttpServletResponse response)
                          throws ServletException,
                                 IOException

this method handles "POST" requests for this servlet.

There are requests for expanding a node or a whole subtree, "expandNode", "expandSubtree". There are their counterparts for collapsing a node or a subtree, "collapseNode" and "collpaseSubtree". Moreover, there are two requests for toggling the expanded/collapsed state of a node or a subtree, "toggleNode" and "toggleSubtree".

Initially, a graph is created and cached for the session of the request by calling "initialize".

"initialize" has no parameters. All other requests have a parameter "id" and a parameter "layout". The value of the "id" parameter determines the node (or the subtree rooted at that node) to be expanded or collapsed. The value of the "layout" parameter determines the layout algorithm used for redrawing the tree after the expand or collapse operation.

Since the cached graph gets initialized or changed by each request, all of the requests are handled by handlePostRequest().

If an operation succeeds, the bounds of the area of the graph, which changed due to redrawing, are returned together with a shift vector, which describes the movement of the given root node of the expand or collapse operation due to redrawing ((0,0) for "initialize"). This information can be used in the client to request updated graph tiles and to move the viewport such that the root node of the expand or collapse operation stays at the same view position.

Overrides:
handlePostRequest in class BaseServlet
Parameters:
request - the request
response - the response for the request
Throws:
ServletException
IOException

getDoubleBounds

protected Rectangle2D.Double getDoubleBounds(HttpSession session)
returns the world bounds of the current tree as a Rectangle2D.

Parameters:
session - the current session
Returns:
the world bounds of the current tree


Copyright © 2006-2008 yWorks GmbH. All rights reserved