예제 #1
0
 public void nodeOrEdgeSelectionChanged() {
   final String[] edges = new String[graph.getSelectedEdges().size()];
   final String[] nodes = new String[graph.getSelectedShapes().size()];
   int i = 0;
   for (final VEdge vedge : graph.getSelectedEdges()) {
     edges[i] = vedge.toString();
     ++i;
   }
   i = 0;
   for (final VNode vnode : graph.getSelectedShapes()) {
     nodes[i] = vnode.toString();
     ++i;
   }
   client.updateVariable(paintableId, "selectedEdges", edges, false);
   client.updateVariable(paintableId, "selectedNodes", nodes, true);
 }
예제 #2
0
  /** Called whenever an update is received from the server */
  @Override
  public void updateFromUIDL(final UIDL uidl, final ApplicationConnection client) {
    if (client.updateComponent(this, uidl, true)) {
      return;
    }
    this.client = client;
    paintableId = uidl.getId();
    currentKeyModifiers = new HashSet<Integer>();
    final String operation = uidl.getStringAttribute("operation");

    if ("REPAINT".equals(operation)) {
      repaint(uidl);
    } else if ("SET_NODE_SIZE".equals(operation)) {
      style.setNodeSize(uidl.getIntAttribute("ns") / 2);
      graph.updateGraphProperties(style);
      paintGraph();
    } else if ("SET_VISUAL_STYLE".equals(operation)) {
      graph.updateGraphProperties(style);
      paintGraph();
    } else if ("SET_TEXT_VISIBILITY".equals(operation)) {
      style.setTextsVisible(uidl.getBooleanAttribute("texts"));
      graph.updateGraphProperties(style);
      paintGraph();
    } else if ("SET_OPTIMIZED_STYLES".equals(operation)) {
      graph.paintGraph();
    } else if ("UPDATE_NODE".equals(operation)) {
      graph.updateNode(uidl, uidl.getStringAttribute("node"));
    } else if ("SET_ZOOM".equals(operation)) {
      setZoom(uidl.getIntAttribute("zoom"));
    } else if ("REFRESH".equals(operation)) {
      refresh(uidl);
    } else {
      repaint(uidl);
    }
  }
예제 #3
0
  /*
   * (non-Javadoc)
   *
   * @see
   * com.vaadin.terminal.gwt.client.Paintable#updateFromUIDL(com.vaadin.terminal
   * .gwt.client.UIDL, com.vaadin.terminal.gwt.client.ApplicationConnection)
   */
  public void updateFromUIDL(UIDL childUIDL, final ApplicationConnection client) {
    if (client.updateComponent(this, childUIDL, false)) {
      return;
    }
    if (childUIDL.hasAttribute("projection")) {
      projection = Projection.get(childUIDL.getStringAttribute("projection"));
    } else {
      projection = null;
    }

    boolean update = vector != null;
    if (update) {
      // temporary remove erase the vector
      getLayer().eraseFeature(vector);
    }

    updateAttributes(childUIDL, client);

    createOrUpdateVector(childUIDL, client);
    if (childUIDL.hasAttribute("style")) {
      intent = childUIDL.getStringAttribute("style");
      getVector().setRenderIntent(intent);
    }
    updateStyle(childUIDL, client);

    if (update) {
      ((VVectorLayer) getParent()).vectorUpdated(this);
    } else {
      getLayer().addFeature(vector);
    }
  }
  public void updateFromUIDL(final UIDL uidl, final ApplicationConnection client) {

    if (!started) {
      started = true;
      client.updateVariable(uidl.getId(), "AppStarted", true, true);
    }
  }
예제 #5
0
 @Override
 public void onDoubleClick(final DoubleClickEvent event) {
   VConsole.log("onDoubleClick");
   final int x = event.getX();
   final int y = event.getY();
   final VNode node = VNode.createANode(x, y, this, graph, style);
   graph.addNode(node);
   client.updateVariable(paintableId, "createdANode", new Object[] {node.getName(), x, y}, true);
 }
예제 #6
0
 public void constructLinkTo(final VNode node2) {
   VConsole.log("linked");
   final String name =
       linkNode.getName() + "_to_" + node2.getName() + "_" + new Random().nextInt(1000);
   final VEdge edge = VEdge.createAnEdge(null, this, graph, name, linkNode, node2, style);
   client.updateVariable(
       paintableId, "edgeCreated", new String[] {linkNode.getName(), node2.getName(), name}, true);
   graph.addEdge(edge);
 }
 @Override
 protected void makeUidlRequest(String requestData, String extraParams, boolean forceSync) {
   VConsole.log("new Socket message: " + requestData);
   if (forceSync) {
     /*
      * TODO figure out if socket can be used on unload.
      */
     super.makeUidlRequest(requestData, extraParams, forceSync);
   } else {
     startRequest();
     ownRequestPending = true;
     getWebSocket().send(extraParams + "#" + requestData);
   }
 }
예제 #8
0
 private void updateActionMap(UIDL c) {
   final Iterator<?> it = c.getChildIterator();
   while (it.hasNext()) {
     final UIDL action = (UIDL) it.next();
     final String key = action.getStringAttribute("key");
     final String caption = action.getStringAttribute("caption");
     m_actionMap.put(key + "_c", caption);
     if (action.hasAttribute("icon")) {
       // TODO need some uri handling ??
       m_actionMap.put(key + "_i", m_client.translateVaadinUri(action.getStringAttribute("icon")));
     } else {
       m_actionMap.remove(key + "_i");
     }
   }
 }
예제 #9
0
  /** Called whenever an update is received from the server */
  @Override
  public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    super.updateFromUIDL(uidl, client);
    if (client.updateComponent(this, uidl, false)) {
      hidePopup();
      return;
    }
    addStyleName(CLASSNAME);

    position = uidl.getStringAttribute("position");
    xOffset = uidl.getIntAttribute("xoffset");
    yOffset = uidl.getIntAttribute("yoffset");

    popupVisible = uidl.getBooleanVariable("popupVisible");
    if (popupVisible) {
      if (uidl.hasAttribute("popupPositionPaintable")) {
        popupPositionPaintable = uidl.getPaintableAttribute("popupPositionPaintable", client);
      } else {
        popupPositionPaintable = null;
      }

      if (uidl.hasAttribute("style")) {
        final String[] styles = uidl.getStringAttribute("style").split(" ");
        final StringBuffer styleBuf = new StringBuffer();
        final String primaryName = popup.getStylePrimaryName();
        styleBuf.append(primaryName);
        styleBuf.append(" ");
        styleBuf.append(VPopupView.CLASSNAME + "-popup");
        for (int i = 0; i < styles.length; i++) {
          styleBuf.append(" ");
          styleBuf.append(primaryName);
          styleBuf.append("-");
          styleBuf.append(styles[i]);
        }
        popup.setStyleName(styleBuf.toString());
      } else {
        popup.setStyleName(popup.getStylePrimaryName() + " " + VPopupView.CLASSNAME + "-popup");
      }

      UIDL popupUIDL = uidl.getChildUIDL(0);
      popup.setVisible(false);
      popup.show();
      popup.updateFromUIDL(popupUIDL);
      showPopup();
    } else {
      hidePopup();
    }
  }
예제 #10
0
  @Override
  public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    switch (DOM.eventGetType(event)) {
      case Event.ONCONTEXTMENU:
        EventTarget target = event.getEventTarget();

        Element svg = this.getElement().getElementsByTagName("svg").getItem(0);

        if (target.equals(svg)) {
          m_client.getContextMenu().showAt(this, event.getClientX(), event.getClientY());
          event.preventDefault();
          event.stopPropagation();
        }
        break;

      case Event.ONMOUSEDOWN:
        break;

      case Event.ONMOUSEWHEEL:
        double delta = event.getMouseWheelVelocityY() / 30.0;
        double oldScale = m_scale;
        final double newScale = oldScale + delta;
        final int clientX = event.getClientX();
        final int clientY = event.getClientY();
        // broken now need to fix it
        //    	    Command cmd = new Command() {
        //
        //                public void execute() {
        //                    m_client.updateVariable(m_paintableId, "mapScale", newScale, false);
        //                    m_client.updateVariable(m_paintableId, "clientX", clientX, false);
        //                    m_client.updateVariable(m_paintableId, "clientY", clientY, false);
        //
        //                    m_client.sendPendingVariableChanges();
        //                }
        //            };
        //
        //            if(BrowserInfo.get().isWebkit()) {
        //                Scheduler.get().scheduleDeferred(cmd);
        //            }else {
        //                cmd.execute();
        //            }

        break;
    }
  }
예제 #11
0
  /**
   * This method must be implemented to update the client-side component from UIDL data received
   * from server.
   *
   * <p>This method is called when the page is loaded for the first time, and every time UI changes
   * in the component are received from the server.
   */
  public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    // This call should be made first. Ensure correct implementation,
    // and let the containing layout manage caption, etc.
    if (client.updateComponent(this, uidl, true)) {
      return;
    }

    // Save reference to server connection object to be able to send
    // user interaction later
    this.client = client;

    // Save the UIDL identifier for the component
    uidlId = uidl.getId();

    // Get value received from server and actualize it in the GWT component
    setColor(uidl.getStringVariable("colorname"));
  }
예제 #12
0
  @Override
  public void onBrowserEvent(Event event) {
    if (disabled || readonly) {
      return;
    }
    final Element targ = DOM.eventGetTarget(event);

    if (DOM.eventGetType(event) == Event.ONMOUSEWHEEL) {
      processMouseWheelEvent(event);
    } else if (dragging || targ == handle) {
      processHandleEvent(event);
    } else if (targ == smaller) {
      decreaseValue(true);
    } else if (targ == bigger) {
      increaseValue(true);
    } else if (DOM.eventGetType(event) == Event.MOUSEEVENTS) {
      processBaseEvent(event);
    } else if ((BrowserInfo.get().isGecko() && DOM.eventGetType(event) == Event.ONKEYPRESS)
        || (!BrowserInfo.get().isGecko() && DOM.eventGetType(event) == Event.ONKEYDOWN)) {

      if (handleNavigation(event.getKeyCode(), event.getCtrlKey(), event.getShiftKey())) {

        feedbackPopup.show();

        delayedValueUpdater.trigger();

        DOM.eventPreventDefault(event);
        DOM.eventCancelBubble(event, true);
      }
    } else if (targ.equals(getElement()) && DOM.eventGetType(event) == Event.ONFOCUS) {
      feedbackPopup.show();
    } else if (targ.equals(getElement()) && DOM.eventGetType(event) == Event.ONBLUR) {
      feedbackPopup.hide();
    } else if (DOM.eventGetType(event) == Event.ONMOUSEDOWN) {
      feedbackPopup.show();
      processBaseEvent(event);
    }
    if (Util.isTouchEvent(event)) {
      event.preventDefault(); // avoid simulated events
      event.stopPropagation();
    }
    if (client != null) {
      client.handleTooltipEvent(event, this);
    }
  }
예제 #13
0
  private void zoom(final double factor) {
    if (factor < 1) {
      zoomFactor--;
    } else {
      zoomFactor++;
    }
    for (final VNode n : graph.getPaintedShapes()) {
      n.setX((float) ((n.getX() - centerX) * factor) + centerX);
      n.setY((float) ((n.getY() - centerY) * factor) + centerY);

      if (n.getView() instanceof Circle) {
        if (factor > 1) {
          ((Circle) n.getView()).setRadius((((Circle) n.getView()).getRadius() + 1));
        } else {
          ((Circle) n.getView()).setRadius((((Circle) n.getView()).getRadius() - 1));
        }
      }
      graph.updateEdges(n, false);
    }
    client.updateVariable(paintableId, "zoomFactor", zoomFactor, true);
  }
예제 #14
0
  /** Override the method to communicate the new value to server. */
  @Override
  public void setColor(String newcolor) {
    // Ignore if no change
    if (newcolor.equals(currentcolor.getText())) {
      return;
    }

    // Let the original implementation to do whatever it needs to do
    super.setColor(newcolor);

    // Updating the state to the server can not be done before
    // the server connection is known, i.e., before updateFromUIDL()
    // has been called.
    if (uidlId == null || client == null) {
      return;
    }

    // Communicate the user interaction parameters to server. This call will
    // initiate an AJAX request to the server.
    client.updateVariable(uidlId, "colorname", newcolor, true);
  }
예제 #15
0
 private void deleteEdge(final VEdge edge, final boolean immediate) {
   client.updateVariable(paintableId, "removedEdge", edge.getName(), immediate);
   graph.removeEdge(edge);
 }
예제 #16
0
 public void deleteNode(final VNode node, final boolean immediate) {
   client.updateVariable(paintableId, "removedNode", node.getName(), immediate);
   graph.removeNode(node);
 }
예제 #17
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);
  }
예제 #18
0
  public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {

    this.client = client;
    id = uidl.getId();

    // Ensure correct implementation
    if (client.updateComponent(this, uidl, true)) {
      return;
    }

    immediate = uidl.getBooleanAttribute("immediate");
    disabled = uidl.getBooleanAttribute("disabled");
    readonly = uidl.getBooleanAttribute("readonly");

    vertical = uidl.hasAttribute("vertical");
    arrows = uidl.hasAttribute("arrows");

    String style = "";
    if (uidl.hasAttribute("style")) {
      style = uidl.getStringAttribute("style");
    }

    scrollbarStyle = style.indexOf("scrollbar") > -1;

    if (arrows) {
      DOM.setStyleAttribute(smaller, "display", "block");
      DOM.setStyleAttribute(bigger, "display", "block");
    }

    if (vertical) {
      addStyleName(CLASSNAME + "-vertical");
    } else {
      removeStyleName(CLASSNAME + "-vertical");
    }

    min = uidl.getDoubleAttribute("min");
    max = uidl.getDoubleAttribute("max");
    resolution = uidl.getIntAttribute("resolution");
    value = new Double(uidl.getDoubleVariable("value"));

    setFeedbackValue(value);

    handleSize = uidl.getIntAttribute("hsize");

    buildBase();

    if (!vertical) {
      // Draw handle with a delay to allow base to gain maximum width
      Scheduler.get()
          .scheduleDeferred(
              new Command() {
                public void execute() {
                  buildHandle();
                  setValue(value, false);
                }
              });
    } else {
      buildHandle();
      setValue(value, false);
    }
  }
 @Override
 public void init(WidgetSet widgetSet, ApplicationConfiguration cnf) {
   super.init(widgetSet, cnf);
   // First opening of WS will repaint all -> start the app
   getWebSocket();
 }
예제 #20
0
 private void updateValueToServer() {
   client.updateVariable(id, "value", value.doubleValue(), immediate);
 }
예제 #21
0
 private boolean isOrHasChildOfConsole(Element element) {
   Console console = ApplicationConnection.getConsole();
   return console instanceof VDebugConsole
       && ((VDebugConsole) console).getElement().isOrHasChild(element);
 }