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

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.servlet.UpdateServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Direct Known Subclasses:
GroupedGraphServlet

public class UpdateServlet
extends BaseServlet

This servlet performs updates on server side graphs. See handlePostRequest(HttpServletRequest, HttpServletResponse) and handleGetRequest(HttpServletRequest, HttpServletResponse) for details.

There are several protected methods acting on the graph level which are called for handling requests, e.g. createNode(Graph2D, double, double, String). These can be customized in a subclass.

See Also:
Serialized Form

Constructor Summary
UpdateServlet()
           
 
Method Summary
protected  void closeGroup(Graph2D graph, Node node)
          converts the given group node to a folder node.
protected  Edge createEdge(Graph2D graph, Node source, Node target, int route)
          is called for creating a new edge.
protected  String createFolderName(Graph2D graph, Node groupNode)
          is used to provide a an initial name for a newly created folder node.
protected  Node createFolderNode(Graph2D graph, double x, double y, String nodeType, String parentNodeId)
          creates a new folder node.
protected  String createGroupName(Graph2D graph, Node groupNode)
          is used to provide a an initial name for a newly created group node.
protected  Node createGroupNode(Graph2D graph, double x, double y, String nodeType, String parentNodeId)
          creates a new group node.
protected  Node createNode(Graph2D graph, double x, double y, String nodeType)
          is called for creating a node.
protected  EdgeRealizer getDefaultEdgeRealizer()
          gets the default realizer used to create new edges.
protected  NodeRealizer getDefaultFolderNodeRealizer()
          gets the default realizer used to create new folder nodes.
protected  NodeRealizer getDefaultGroupNodeRealizer()
          gets the default realizer used to create new group nodes.
protected  NodeRealizer getDefaultNodeRealizer()
          gets the default realizer used to create new nodes.
protected  void handleGetRequest(HttpServletRequest request, HttpServletResponse response)
          handles "getRealizers" and "getRealizerImage" requests which do not change a server side graph, but are related to requests changing a server side graph.
protected  void handlePostRequest(HttpServletRequest request, HttpServletResponse response)
          handles update requests.
 void init(ServletConfig servletConfig)
           
protected  void moveNodes(Graph2D graph, NodeList nodeList, double deltaX, double deltaY)
          moves a set of nodes by the given vector.
protected  void moveToSubgraph(Graph2D graph, Node parentNode, NodeList subNodes)
          moves a set of nodes to the inner graph of the given parent folder or group node.
protected  void openFolder(Graph2D graph, Node node)
          converts the given folder node to a group node.
protected  void removeEdge(Graph2D graph, Edge edge)
          removes the given edge from the graph.
protected  void removeEdgeLabel(Graph2D graph, EdgeLabel edgeLabel)
          removes the given edge label from the graph.
protected  void removeNode(Graph2D graph, Node node)
          removes the given node from the graph.
protected  void removeNodeLabel(Graph2D graph, NodeLabel nodeLabel)
          removes the given node label from the graph.
protected  void setDefaultEdgeRealizer(EdgeRealizer edgeRealizer)
          sets the default realizer used to create new edges.
protected  void setDefaultFolderNodeRealizer(NodeRealizer nodeRealizer)
          sets the default realizer used to create new folder nodes.
protected  void setDefaultGroupNodeRealizer(NodeRealizer nodeRealizer)
          sets the default realizer used to create new group nodes.
protected  void setDefaultNodeRealizer(NodeRealizer nodeRealizer)
          sets the default realizer used to create new nodes.
protected  void setLabelText(Graph2D graph, Node node, String text)
          sets the text of the first label of the given node.
protected  void setText(Graph2D graph, NodeLabel nl, String text)
          sets the text of the given node label.
protected  void switchToSubgraph(HttpSession session, String graphName, Graph2D newGraph, Graph2D oldGraph)
          switches from an old subgraph to a new subgraph in the same hierarchically organized graph (structure).
protected  void writeRealizerImage(String nodeType, HttpServletResponse response)
          writes an example image for the requested node type to the given response.
protected  void writeRealizers(HttpServletResponse response)
          writes a list of available node realizers (node types) to the given response.
 
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, hasDescriptions, hasURLs, init, initialize, 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, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UpdateServlet

public UpdateServlet()
Method Detail

init

public void init(ServletConfig servletConfig)
          throws ServletException
Specified by:
init in interface Servlet
Overrides:
init in class GenericServlet
Throws:
ServletException

getDefaultNodeRealizer

protected NodeRealizer getDefaultNodeRealizer()
gets the default realizer used to create new nodes.

Returns:
the default node realizer

setDefaultNodeRealizer

protected void setDefaultNodeRealizer(NodeRealizer nodeRealizer)
sets the default realizer used to create new nodes.

Parameters:
nodeRealizer - the default node realizer

getDefaultEdgeRealizer

protected EdgeRealizer getDefaultEdgeRealizer()
gets the default realizer used to create new edges.

Returns:
the default node realizer

setDefaultEdgeRealizer

protected void setDefaultEdgeRealizer(EdgeRealizer edgeRealizer)
sets the default realizer used to create new edges.

Parameters:
edgeRealizer - the default edge realizer

getDefaultFolderNodeRealizer

protected NodeRealizer getDefaultFolderNodeRealizer()
gets the default realizer used to create new folder nodes.

Returns:
the default folder node realizer

setDefaultFolderNodeRealizer

protected void setDefaultFolderNodeRealizer(NodeRealizer nodeRealizer)
sets the default realizer used to create new folder nodes.

Parameters:
nodeRealizer - the default folder node realizer

getDefaultGroupNodeRealizer

protected NodeRealizer getDefaultGroupNodeRealizer()
gets the default realizer used to create new group nodes.

Returns:
the default group node realizer

setDefaultGroupNodeRealizer

protected void setDefaultGroupNodeRealizer(NodeRealizer nodeRealizer)
sets the default realizer used to create new group nodes.

Parameters:
nodeRealizer - the default group node realizer

handlePostRequest

protected void handlePostRequest(HttpServletRequest request,
                                 HttpServletResponse response)
                          throws ServletException,
                                 IOException
handles update requests. The following requests are handled. 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 pretected methods in this class which act on the graph like createNode(Graph2D, double, double, String).

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

moveNodes

protected void moveNodes(Graph2D graph,
                         NodeList nodeList,
                         double deltaX,
                         double deltaY)
moves a set of nodes by the given vector. If a group node is to be moved, all its children are additionally moved (recursively in the case of children which are again group nodes). Moving a non-empty group node with the auto bounds feature normally has no effect, since its bounds are calculated from its children. Note that this implementation temporarily selects some nodes and deselects them lateron.

Parameters:
graph - the current graph
nodeList - the nodes to be moved
deltaX - x-coordinate of movement vector (world units)
deltaY - y-coordinate of movement vector (world units)

setText

protected void setText(Graph2D graph,
                       NodeLabel nl,
                       String text)
sets the text of the given node label.

Parameters:
graph - the current graph
nl - the node label
text - the new text for the label

setLabelText

protected void setLabelText(Graph2D graph,
                            Node node,
                            String text)
sets the text of the first label of the given node.

Parameters:
graph - the current graph
node - the node
text - the new text for the first node label

handleGetRequest

protected void handleGetRequest(HttpServletRequest request,
                                HttpServletResponse response)
                         throws ServletException,
                                IOException
handles "getRealizers" and "getRealizerImage" requests which do not change a server side graph, but are related to requests changing a server side graph.

Overrides:
handleGetRequest in class BaseServlet
Parameters:
request - the request
response - the response to write to
Throws:
ServletException
IOException
See Also:
writeRealizers(HttpServletResponse), writeRealizerImage(String, HttpServletResponse)

writeRealizerImage

protected void writeRealizerImage(String nodeType,
                                  HttpServletResponse response)
                           throws IOException
writes an example image for the requested node type to the given response. This implementation writes PNGs of size 30 by 30 pixels. If the requested node type is not supported this method sets the status of the response to 404 and does not write an image. Subclasses can overwrite this method.

Parameters:
nodeType - the type of node (node realizer to be used)
response - the response to write to
Throws:
IOException - if there are problems writing the response
See Also:
createNode(Graph2D, double, double, String), writeRealizers(HttpServletResponse)

writeRealizers

protected void writeRealizers(HttpServletResponse response)
                       throws IOException
writes a list of available node realizers (node types) to the given response. Subclasses can overwrite this method. The output should be in JSON format and contain all supported node types, e.g.
 {nodeRealizers:['yellow square','blue square','red circle','blue diamond']}
 
Subclasses can overwrite this method.

Parameters:
response - output is written to this
Throws:
IOException - if there are problems writing the response
See Also:
createNode(Graph2D, double, double, String), writeRealizerImage(String, HttpServletResponse)

createNode

protected Node createNode(Graph2D graph,
                          double x,
                          double y,
                          String nodeType)
is called for creating a node. Subclasses can overwrite this method.

Parameters:
graph - the graph to add a node to
x - the x coordinate of the new node in world coordinates
y - the y coordinate of the new node in world coordinates
nodeType - the type of node to be created (may be null)
Returns:
the new node
See Also:
writeRealizers(HttpServletResponse), writeRealizerImage(String, HttpServletResponse)

createGroupNode

protected Node createGroupNode(Graph2D graph,
                               double x,
                               double y,
                               String nodeType,
                               String parentNodeId)
creates a new group node. The new node is created in the given graph (if no parent node id is given) or as a child of the group or folder node with the given parent node id. This method is called for handling "createGroup" requests.

Parameters:
graph - the current subgraph
x - x-coordinate of the center of the new group node
y - y-coordinate of the center of the new group node
nodeType - a symbolic name for a type of node to create, if null the default is used
parentNodeId - id of the parent node of the new group node (may be null)
Returns:
a new group node
See Also:
getDefaultGroupNodeRealizer()

createFolderNode

protected Node createFolderNode(Graph2D graph,
                                double x,
                                double y,
                                String nodeType,
                                String parentNodeId)
creates a new folder node. The new node is created in the given graph (if no parent node id is given) or as a child of the group or folder node with the given parent node id. This method is called for handling "createGroup" requests.

Parameters:
graph - the current subgraph
x - x-coordinate of the center of the new folder node
y - y-coordinate of the center of the new folder node
nodeType - a symbolic name for a type of node to create, if null the default is used
parentNodeId - the id of the parent node for the new folder node (may be null)
Returns:
a new folder node
See Also:
getDefaultFolderNodeRealizer()

createGroupName

protected String createGroupName(Graph2D graph,
                                 Node groupNode)
is used to provide a an initial name for a newly created group node.

Parameters:
graph - the current subgraph
groupNode - the node to be named
Returns:
the name

createFolderName

protected String createFolderName(Graph2D graph,
                                  Node groupNode)
is used to provide a an initial name for a newly created folder node.

Parameters:
graph - the current subgraph
groupNode - the node to be named
Returns:
the name

openFolder

protected void openFolder(Graph2D graph,
                          Node node)
converts the given folder node to a group node. This method is called to serve the "openFolder" request. If the given node is not a folder node, the method just does nothing.

Parameters:
graph - the current subgraph.
node - the folder to be opened

closeGroup

protected void closeGroup(Graph2D graph,
                          Node node)
converts the given group node to a folder node. This method is called to serve the "closeGroup" request. If the given node is not a group node, the method just does nothing.

Parameters:
graph - the current subgraph.
node - the group to be closed

switchToSubgraph

protected void switchToSubgraph(HttpSession session,
                                String graphName,
                                Graph2D newGraph,
                                Graph2D oldGraph)
switches from an old subgraph to a new subgraph in the same hierarchically organized graph (structure). This method is called to serve the "switchToSubgraph" as well as the "switchToParent" requests and can be extended in subclasses. In this case it is important to include a super call.

Parameters:
session - the session for the request
graphName - the symbolic name of the whole hierarchically organized graph
newGraph - the subgraph to switch to
oldGraph - the subgraph before serving the request

moveToSubgraph

protected void moveToSubgraph(Graph2D graph,
                              Node parentNode,
                              NodeList subNodes)
moves a set of nodes to the inner graph of the given parent folder or group node.

Parameters:
graph - the current graph
parentNode - the new parent for the nodes to be moved, null for the root graph
subNodes - the nodes to be moved

createEdge

protected Edge createEdge(Graph2D graph,
                          Node source,
                          Node target,
                          int route)
is called for creating a new edge. Subclasses can overwrite this method.

Parameters:
graph - the graph to add an edge to
source - the source node for the edge
target - the target node for the edge
route - if this is not equal to zero, the new edge should be routed
Returns:
the new edge

removeNode

protected void removeNode(Graph2D graph,
                          Node node)
removes the given node from the graph. This method is called for handling "remove" and "removeAt" requests.

Parameters:
graph - the current graph
node - the node to be removed

removeEdge

protected void removeEdge(Graph2D graph,
                          Edge edge)
removes the given edge from the graph. This method is called for handling "remove" and "removeAt" requests.

Parameters:
graph - the current graph
edge - the edge to be removed

removeNodeLabel

protected void removeNodeLabel(Graph2D graph,
                               NodeLabel nodeLabel)
removes the given node label from the graph. This method is called for handling "remove" requests.

Parameters:
graph - the current graph
nodeLabel - the node label to be removed

removeEdgeLabel

protected void removeEdgeLabel(Graph2D graph,
                               EdgeLabel edgeLabel)
removes the given edge label from the graph. This method is called for handling "remove" requests.

Parameters:
graph - the current graph
edgeLabel - the node label to be removed


Copyright © 2006-2008 yWorks GmbH. All rights reserved