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

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.UpdateServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class UpdateServlet
extends BaseServlet

This servlet performs updates on server side graphs. See handlePostRequest(HttpServletRequest, HttpServletResponse) and BaseServlet.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.

The appaerance of created graph elements can be influenced by setting the defaults, e.g. setDefaultNodeRealizer(NodeRealizer), or by registering custom node realizers (registerNodeRealizer(String, NodeRealizer)).

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
UpdateServlet()
           
 
Method Summary
protected  void adjustPortOffsets(Graph2D graph, Node node, double wOld, double hOld, double wNew, double hNew)
           
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.
static EdgeRealizer getDefaultEdgeRealizer()
          Gets the default realizer used to create new edges.
static NodeRealizer getDefaultFolderNodeRealizer()
          Gets the default realizer used to create new folder nodes.
static NodeRealizer getDefaultGroupNodeRealizer()
          Gets the default realizer used to create new group nodes.
static NodeRealizer getDefaultNodeRealizer()
          Gets the default realizer used to create new nodes.
 int getGraphBoundsMargin()
          Get the margin that is added to the graph bounds reported in the servlet response.
static NodeRealizer getNodeRealizer(String type)
          Returns the node realizer registered for the given symbolic name or null.
static String[] getNodeRealizerTypes()
          Returns the symbolic names of all registered node realizers.
protected  void handlePostRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          handles update requests.
protected  void moveBends(BendList bendsToMove, double deltaX, double deltaY)
          moves the given bends by the given offset.
protected  void moveNodes(Graph2D graph, NodeList nodeList, double deltaX, double deltaY, int route)
          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.
static void registerNodeRealizer(String type, NodeRealizer defaultNodeRealizer)
          Registers the given node realizers for the given symbolic name.
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 resizeNodes(Graph2D graph, NodeList nodeList, String mode, double deltaWidth, double deltaHeight, int route)
           resizes a set of nodes by given deltas.
protected  void routeEdges(Graph2D graph)
          routes the edges of the given graph specified by the data provider with the key Layouter.SELECTED_EDGES.
static void setDefaultEdgeRealizer(EdgeRealizer edgeRealizer)
          Sets the default realizer used to create new edges.
static void setDefaultFolderNodeRealizer(NodeRealizer nodeRealizer)
          Sets the default realizer used to create new folder nodes.
static void setDefaultGroupNodeRealizer(NodeRealizer nodeRealizer)
          Sets the default realizer used to create new group nodes.
static void setDefaultNodeRealizer(NodeRealizer nodeRealizer)
          Sets the default realizer used to create new nodes.
 void setGraphBoundsMargin(int graphBoundsMargin)
          Set the margin that is added to the graph bounds reported in the servlet response.
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(javax.servlet.http.HttpSession session, String graphName, Graph2D newGraph, Graph2D oldGraph)
          switches from an old subgraph to a new subgraph in the same hierarchically organized graph (structure).
 
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, handleGetRequest, 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

UpdateServlet

public UpdateServlet()
Method Detail

getDefaultNodeRealizer

public static NodeRealizer getDefaultNodeRealizer()
Gets the default realizer used to create new nodes.

Returns:
the default node realizer
See Also:
setDefaultNodeRealizer(NodeRealizer)

setDefaultNodeRealizer

public static void setDefaultNodeRealizer(NodeRealizer nodeRealizer)
Sets the default realizer used to create new nodes.

Parameters:
nodeRealizer - the default node realizer
See Also:
getDefaultNodeRealizer()

getDefaultEdgeRealizer

public static EdgeRealizer getDefaultEdgeRealizer()
Gets the default realizer used to create new edges.

Returns:
the default node realizer
See Also:
setDefaultEdgeRealizer(EdgeRealizer)

setDefaultEdgeRealizer

public static void setDefaultEdgeRealizer(EdgeRealizer edgeRealizer)
Sets the default realizer used to create new edges.

Parameters:
edgeRealizer - the default edge realizer
See Also:
getDefaultEdgeRealizer()

getDefaultFolderNodeRealizer

public static NodeRealizer getDefaultFolderNodeRealizer()
Gets the default realizer used to create new folder nodes.

Returns:
the default folder node realizer
See Also:
setDefaultFolderNodeRealizer(NodeRealizer)

setDefaultFolderNodeRealizer

public static void setDefaultFolderNodeRealizer(NodeRealizer nodeRealizer)
Sets the default realizer used to create new folder nodes.

Parameters:
nodeRealizer - the default folder node realizer
See Also:
getDefaultFolderNodeRealizer()

getDefaultGroupNodeRealizer

public static NodeRealizer getDefaultGroupNodeRealizer()
Gets the default realizer used to create new group nodes.

Returns:
the default group node realizer
See Also:
setDefaultGroupNodeRealizer(NodeRealizer)

setDefaultGroupNodeRealizer

public static void setDefaultGroupNodeRealizer(NodeRealizer nodeRealizer)
Sets the default realizer used to create new group nodes.

Parameters:
nodeRealizer - the default group node realizer
See Also:
getDefaultGroupNodeRealizer()

getGraphBoundsMargin

public int getGraphBoundsMargin()
Get the margin that is added to the graph bounds reported in the servlet response. Older versions of this servlet secretly added a margin of 10 pixels to the bounds reported as part of the servlet response. Now, no margin is added to these bounds anymore (i.e., the default value of this property is 0). For backwards compatibility, this property can be set to 10.


setGraphBoundsMargin

public void setGraphBoundsMargin(int graphBoundsMargin)
Set the margin that is added to the graph bounds reported in the servlet response. Older versions of this servlet secretly added a margin of 10 pixels to the bounds reported as part of the servlet response. Now, no margin is added to these bounds anymore (i.e., the default value of this property is 0). For backwards compatibility, this property can be set to 10.


handlePostRequest

protected void handlePostRequest(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response)
                          throws javax.servlet.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:
javax.servlet.ServletException
IOException

moveNodes

protected void moveNodes(Graph2D graph,
                         NodeList nodeList,
                         double deltaX,
                         double deltaY,
                         int route)
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 later on.

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)
route - whether to route the affected edges

moveBends

protected void moveBends(BendList bendsToMove,
                         double deltaX,
                         double deltaY)
moves the given bends by the given offset. This method is called by moveNodes(y.view.Graph2D, y.base.NodeList, double, double, int) unless an edge router is used to reroute the affected edges.

Parameters:
bendsToMove - the bends to move
deltaX - x-coordinate of movement vector (world units)
deltaY - y-coordinate of movement vector (world units)

routeEdges

protected void routeEdges(Graph2D graph)
routes the edges of the given graph specified by the data provider with the key Layouter.SELECTED_EDGES. This method is called by moveNodes(y.view.Graph2D, y.base.NodeList, double, double, int) if using an edge router was requested.

Parameters:
graph - a graph

resizeNodes

protected void resizeNodes(Graph2D graph,
                           NodeList nodeList,
                           String mode,
                           double deltaWidth,
                           double deltaHeight,
                           int route)

resizes a set of nodes by given deltas. The size change is specified by the mode and the delta values for width and height. The mode specifies the changing corner or side of the bounding boxes of the resized nodes.

Resizing a non-empty group node with the auto bounds feature may not have the desired effect, since its bounds are calculated from its children. Each node will have a width and height of at least 1.0 after the resize even if the corresponding delta is larger.

Parameters:
graph - the current graph
nodeList - the nodes to be moved
mode - either "NW", "N", "NE", "W", "E", "SW", "S" or "SE"
deltaWidth - the change of the width (world units)
deltaHeight - the change of the height (world units)
route - whether to route the affected edges

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

createNode

protected Node createNode(Graph2D graph,
                          double x,
                          double y,
                          String nodeType)
is called for creating a node. If nodeType is null the default node realizer is used. 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:
getDefaultNodeRealizer(), registerNodeRealizer(String, NodeRealizer), getNodeRealizerTypes()

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(javax.servlet.http.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. The method simply returns, if the given parentNode is already the parent of the nodes to be moved or if a node should be moved to a subgraph of itself.

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

registerNodeRealizer

public static void registerNodeRealizer(String type,
                                        NodeRealizer defaultNodeRealizer)
Registers the given node realizers for the given symbolic name. The registered realizers can be used in client requests for creating nodes which are handled by createNode(Graph2D, double, double, String). No node realizers are registered initially.

Parameters:
type - a symbolic name
defaultNodeRealizer - a node realizer
See Also:
createNode(Graph2D, double, double, String), getNodeRealizer(String), getNodeRealizerTypes()

getNodeRealizer

public static NodeRealizer getNodeRealizer(String type)
Returns the node realizer registered for the given symbolic name or null.

Parameters:
type - a symbolic name
Returns:
the node realizer registered for the given symbolic name or null
See Also:
registerNodeRealizer(String, NodeRealizer)

getNodeRealizerTypes

public static String[] getNodeRealizerTypes()
Returns the symbolic names of all registered node realizers. No node realizers are registered initially.

Returns:
an array of symbolic names
See Also:
registerNodeRealizer(String, NodeRealizer)

adjustPortOffsets

protected void adjustPortOffsets(Graph2D graph,
                                 Node node,
                                 double wOld,
                                 double hOld,
                                 double wNew,
                                 double hNew)


Copyright © 2006-2013 yWorks GmbH. All rights reserved