Esempio n. 1
0
  public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {

    if (client.updateComponent(this, uidl, true)) {
      return;
    }

    m_client = client;
    m_paintableId = uidl.getId();

    setScale(
        uidl.getDoubleAttribute("scale"),
        uidl.getIntAttribute("clientX"),
        uidl.getIntAttribute("clientY"));
    setSemanticZoomLevel(uidl.getIntAttribute("semanticZoomLevel"));
    setActionKeys(uidl.getStringArrayAttribute("backgroundActions"));

    UIDL graph = uidl.getChildByTagName("graph");
    Iterator<?> children = graph.getChildIterator();

    GWTGraph graphConverted = GWTGraph.create();
    while (children.hasNext()) {
      UIDL child = (UIDL) children.next();

      if (child.getTag().equals("group")) {
        GWTGroup group =
            GWTGroup.create(
                child.getStringAttribute("key"),
                child.getIntAttribute("x"),
                child.getIntAttribute("y"));
        boolean booleanAttribute = child.getBooleanAttribute("selected");
        String[] actionKeys = child.getStringArrayAttribute("actionKeys");

        group.setActionKeys(actionKeys);

        group.setSelected(booleanAttribute);
        group.setIcon(child.getStringAttribute("iconUrl"));
        group.setSemanticZoomLevel(child.getIntAttribute("semanticZoomLevel"));
        graphConverted.addGroup(group);

        if (m_client != null) {
          TooltipInfo ttInfo = new TooltipInfo(group.getTooltipText());
          m_client.registerTooltip(this, group, ttInfo);
        }

      } else if (child.getTag().equals("vertex")) {

        GWTVertex vertex =
            GWTVertex.create(
                child.getStringAttribute("id"),
                child.getIntAttribute("x"),
                child.getIntAttribute("y"));
        boolean booleanAttribute = child.getBooleanAttribute("selected");
        String[] actionKeys = child.getStringArrayAttribute("actionKeys");
        vertex.setSemanticZoomLevel(child.getIntAttribute("semanticZoomLevel"));

        vertex.setActionKeys(actionKeys);

        if (child.hasAttribute("groupKey")) {
          String groupKey = child.getStringAttribute("groupKey");
          GWTGroup group = graphConverted.getGroup(groupKey);
          vertex.setParent(group);
        }

        vertex.setSelected(booleanAttribute);
        vertex.setIcon(child.getStringAttribute("iconUrl"));
        graphConverted.addVertex(vertex);

        if (m_client != null) {
          TooltipInfo ttInfo = new TooltipInfo(vertex.getTooltipText());
          m_client.registerTooltip(this, vertex, ttInfo);
        }

      } else if (child.getTag().equals("edge")) {
        GWTEdge edge =
            GWTEdge.create(
                graphConverted.findVertexById(child.getStringAttribute("source")),
                graphConverted.findVertexById(child.getStringAttribute("target")));
        String[] actionKeys = child.getStringArrayAttribute("actionKeys");
        edge.setActionKeys(actionKeys);
        graphConverted.addEdge(edge);

        if (m_client != null) {
          TooltipInfo edgeInfo = new TooltipInfo("Edge: " + edge.getId());
          m_client.registerTooltip(this, edge, edgeInfo);
        }
      } else if (child.getTag().equals("groupParent")) {
        String groupKey = child.getStringAttribute("key");
        String parentKey = child.getStringAttribute("parentKey");
        GWTGroup group = graphConverted.getGroup(groupKey);
        GWTGroup parentGroup = graphConverted.getGroup(parentKey);

        group.setParent(parentGroup);
      }
    }

    UIDL actions = uidl.getChildByTagName("actions");
    if (actions != null) {
      updateActionMap(actions);
    }

    setGraph(graphConverted);
  }
Esempio n. 2
0
    void draw() {

      GWTGraph graph = getGraph();

      D3 edgeSelection = getEdgeSelection(graph);

      D3 vertexSelection = getVertexSelection(graph);

      vertexSelection
          .enter()
          .create(GWTVertex.create())
          .call(setupEventHandlers())
          .attr(
              "transform",
              new Func<String, GWTVertex>() {

                public String call(GWTVertex vertex, int index) {
                  GWTVertex displayVertex = vertex.getDisplayVertex(m_oldSemanticZoomLevel);

                  return "translate(" + displayVertex.getX() + "," + displayVertex.getY() + ")";
                }
              })
          .attr("opacity", 1);

      // Exits
      edgeSelection.exit().with(exitTransition()).remove();
      vertexSelection
          .exit()
          .with(
              new D3Behavior() {

                @Override
                public D3 run(D3 selection) {
                  return selection.transition().delay(0).duration(500);
                }
              })
          .attr(
              "transform",
              new Func<String, GWTVertex>() {

                public String call(GWTVertex vertex, int index) {
                  GWTVertex displayVertex = vertex.getDisplayVertex(m_semanticZoomLevel);

                  return "translate(" + displayVertex.getX() + "," + displayVertex.getY() + ")";
                }
              })
          .attr("opacity", 0)
          .remove();

      // Updates
      edgeSelection.with(updateTransition()).call(GWTEdge.draw()).attr("opacity", 1);

      vertexSelection.with(updateTransition()).call(GWTVertex.draw()).attr("opacity", 1);

      // Enters
      edgeSelection
          .enter()
          .create(GWTEdge.create())
          .call(setupEdgeEventHandlers())
          .with(enterTransition());

      // vertexSelection.enter().create(GWTVertex.create()).call(setupEventHandlers()).with(enterTransition());

    }