Ejemplo n.º 1
0
  @Override
  public void paintContent(PaintTarget target) throws PaintException {
    target.addAttribute(DragAndDropWrapperConstants.DRAG_START_MODE, dragStartMode.ordinal());
    if (getDropHandler() != null) {
      getDropHandler().getAcceptCriterion().paint(target);
    }
    if (receivers != null && receivers.size() > 0) {
      for (Iterator<Entry<String, ProxyReceiver>> it = receivers.entrySet().iterator();
          it.hasNext(); ) {
        Entry<String, ProxyReceiver> entry = it.next();
        String id = entry.getKey();
        ProxyReceiver proxyReceiver = entry.getValue();
        Html5File html5File = proxyReceiver.file;
        if (html5File.getStreamVariable() != null) {
          if (!sentIds.contains(id)) {
            target.addVariable(this, "rec-" + id, new ProxyReceiver(id, html5File));

            /*
             * if a new batch is requested to be uploaded before the
             * last one is done, any remaining ids will be replayed.
             * We want to avoid a new ProxyReceiver to be made since
             * it'll get a new URL, so we need to keep extra track
             * on what has been sent.
             *
             * See #12330.
             */
            sentIds.add(id);

            // these are cleaned from receivers once the upload has
            // started
          }
        } else {
          // instructs the client side not to send the file
          target.addVariable(this, "rec-" + id, (String) null);
          // forget the file from subsequent paints
          it.remove();
        }
      }
    }
    target.addAttribute(DragAndDropWrapperConstants.HTML5_DATA_FLAVORS, html5DataFlavors);
  }
Ejemplo n.º 2
0
  public void paintActions(Object actionTarget, PaintTarget paintTarget) throws PaintException {

    actionMapper = null;

    LinkedHashSet<Action> actions = getActionSet(actionTarget, viewer);

    /*
     * Must repaint whenever there are actions OR if all actions have been
     * removed but still exist on client side
     */
    if (!actions.isEmpty() || clientHasActions) {
      actionMapper = new KeyMapper<Action>();

      paintTarget.addVariable((VariableOwner) viewer, "action", "");
      paintTarget.startTag("actions");

      for (final Action a : actions) {
        paintTarget.startTag("action");
        final String akey = actionMapper.key(a);
        paintTarget.addAttribute("key", akey);
        if (a.getCaption() != null) {
          paintTarget.addAttribute("caption", a.getCaption());
        }
        if (a.getIcon() != null) {
          paintTarget.addAttribute("icon", a.getIcon());
        }
        if (a instanceof ShortcutAction) {
          final ShortcutAction sa = (ShortcutAction) a;
          paintTarget.addAttribute("kc", sa.getKeyCode());

          final int[] modifiers = sa.getModifiers();
          if (modifiers != null) {
            final String[] smodifiers = new String[modifiers.length];
            for (int i = 0; i < modifiers.length; i++) {
              smodifiers[i] = String.valueOf(modifiers[i]);
            }
            paintTarget.addAttribute("mk", smodifiers);
          }
        }
        paintTarget.endTag("action");
      }

      paintTarget.endTag("actions");
    }

    /*
     * Update flag for next repaint so we know if we need to paint empty
     * actions or not (must send actions is client had actions before and
     * all actions were removed).
     */
    clientHasActions = !actions.isEmpty();
  }
Ejemplo n.º 3
0
  /**
   * Paints any needed component-specific things to the given UIDL stream.
   *
   * @see com.vaadin.ui.AbstractComponent#paintContent(PaintTarget)
   */
  @Override
  public void paintContent(PaintTarget target) throws PaintException {
    initialPaint = false;

    if (partialUpdate) {
      target.addAttribute("partialUpdate", true);
      target.addAttribute("rootKey", itemIdMapper.key(expandedItemId));
    } else {
      getCaptionChangeListener().clear();

      // The tab ordering number
      if (getTabIndex() > 0) {
        target.addAttribute("tabindex", getTabIndex());
      }

      // Paint tree attributes
      if (isSelectable()) {
        target.addAttribute("selectmode", (isMultiSelect() ? "multi" : "single"));
        if (isMultiSelect()) {
          target.addAttribute("multiselectmode", multiSelectMode.toString());
        }
      } else {
        target.addAttribute("selectmode", "none");
      }
      if (isNewItemsAllowed()) {
        target.addAttribute("allownewitem", true);
      }

      if (isNullSelectionAllowed()) {
        target.addAttribute("nullselect", true);
      }

      if (dragMode != TreeDragMode.NONE) {
        target.addAttribute("dragMode", dragMode.ordinal());
      }
    }

    // Initialize variables
    final Set<Action> actionSet = new LinkedHashSet<Action>();

    // rendered selectedKeys
    LinkedList<String> selectedKeys = new LinkedList<String>();

    final LinkedList<String> expandedKeys = new LinkedList<String>();

    // Iterates through hierarchical tree using a stack of iterators
    final Stack<Iterator<?>> iteratorStack = new Stack<Iterator<?>>();
    Collection<?> ids;
    if (partialUpdate) {
      ids = getChildren(expandedItemId);
    } else {
      ids = rootItemIds();
    }

    if (ids != null) {
      iteratorStack.push(ids.iterator());
    }

    /*
     * Body actions - Actions which has the target null and can be invoked
     * by right clicking on the Tree body
     */
    if (actionHandlers != null) {
      final ArrayList<String> keys = new ArrayList<String>();
      for (Handler ah : actionHandlers) {

        // Getting action for the null item, which in this case
        // means the body item
        final Action[] aa = ah.getActions(null, this);
        if (aa != null) {
          for (int ai = 0; ai < aa.length; ai++) {
            final String akey = actionMapper.key(aa[ai]);
            actionSet.add(aa[ai]);
            keys.add(akey);
          }
        }
      }
      target.addAttribute("alb", keys.toArray());
    }

    while (!iteratorStack.isEmpty()) {

      // Gets the iterator for current tree level
      final Iterator<?> i = iteratorStack.peek();

      // If the level is finished, back to previous tree level
      if (!i.hasNext()) {

        // Removes used iterator from the stack
        iteratorStack.pop();

        // Closes node
        if (!iteratorStack.isEmpty()) {
          target.endTag("node");
        }
      }

      // Adds the item on current level
      else {
        final Object itemId = i.next();

        // Starts the item / node
        final boolean isNode = areChildrenAllowed(itemId);
        if (isNode) {
          target.startTag("node");
        } else {
          target.startTag("leaf");
        }

        if (itemStyleGenerator != null) {
          String stylename = itemStyleGenerator.getStyle(this, itemId);
          if (stylename != null) {
            target.addAttribute(TreeConstants.ATTRIBUTE_NODE_STYLE, stylename);
          }
        }

        if (itemDescriptionGenerator != null) {
          String description = itemDescriptionGenerator.generateDescription(this, itemId, null);
          if (description != null && !description.equals("")) {
            target.addAttribute("descr", description);
          }
        }

        // Adds the attributes
        target.addAttribute(TreeConstants.ATTRIBUTE_NODE_CAPTION, getItemCaption(itemId));
        final Resource icon = getItemIcon(itemId);
        if (icon != null) {
          target.addAttribute(TreeConstants.ATTRIBUTE_NODE_ICON, getItemIcon(itemId));
          target.addAttribute(
              TreeConstants.ATTRIBUTE_NODE_ICON_ALT, getItemIconAlternateText(itemId));
        }
        final String key = itemIdMapper.key(itemId);
        target.addAttribute("key", key);
        if (isSelected(itemId)) {
          target.addAttribute("selected", true);
          selectedKeys.add(key);
        }
        if (areChildrenAllowed(itemId) && isExpanded(itemId)) {
          target.addAttribute("expanded", true);
          expandedKeys.add(key);
        }

        // Add caption change listener
        getCaptionChangeListener().addNotifierForItem(itemId);

        // Actions
        if (actionHandlers != null) {
          final ArrayList<String> keys = new ArrayList<String>();
          final Iterator<Action.Handler> ahi = actionHandlers.iterator();
          while (ahi.hasNext()) {
            final Action[] aa = ahi.next().getActions(itemId, this);
            if (aa != null) {
              for (int ai = 0; ai < aa.length; ai++) {
                final String akey = actionMapper.key(aa[ai]);
                actionSet.add(aa[ai]);
                keys.add(akey);
              }
            }
          }
          target.addAttribute("al", keys.toArray());
        }

        // Adds the children if expanded, or close the tag
        if (isExpanded(itemId) && hasChildren(itemId) && areChildrenAllowed(itemId)) {
          iteratorStack.push(getChildren(itemId).iterator());
        } else {
          if (isNode) {
            target.endTag("node");
          } else {
            target.endTag("leaf");
          }
        }
      }
    }

    // Actions
    if (!actionSet.isEmpty()) {
      target.addVariable(this, "action", "");
      target.startTag("actions");
      final Iterator<Action> i = actionSet.iterator();
      while (i.hasNext()) {
        final Action a = i.next();
        target.startTag("action");
        if (a.getCaption() != null) {
          target.addAttribute(TreeConstants.ATTRIBUTE_ACTION_CAPTION, a.getCaption());
        }
        if (a.getIcon() != null) {
          target.addAttribute(TreeConstants.ATTRIBUTE_ACTION_ICON, a.getIcon());
        }
        target.addAttribute("key", actionMapper.key(a));
        target.endTag("action");
      }
      target.endTag("actions");
    }

    if (partialUpdate) {
      partialUpdate = false;
    } else {
      // Selected
      target.addVariable(this, "selected", selectedKeys.toArray(new String[selectedKeys.size()]));

      // Expand and collapse
      target.addVariable(this, "expand", new String[] {});
      target.addVariable(this, "collapse", new String[] {});

      // New items
      target.addVariable(this, "newitem", new String[] {});

      if (dropHandler != null) {
        dropHandler.getAcceptCriterion().paint(target);
      }
    }
  }