コード例 #1
0
    public OrderChanger(final Indexed container, final Object itemId) {
      HorizontalLayout layout = new HorizontalLayout();
      layout.addComponent(up);
      up.setIcon(new ThemeResource("../runo/icons/32/arrow-up.png"));
      up.addStyleName(BaseTheme.BUTTON_LINK);
      up.addListener(
          new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
              int newIndex = container.indexOfId(itemId) - 1;
              container.removeItem(itemId);
              container.addItemAt(newIndex, itemId);
              up.setEnabled(newIndex > 0);
            }
          });
      up.setEnabled(container.indexOfId(itemId) > 0);

      layout.addComponent(down);
      down.setIcon(new ThemeResource("../runo/icons/32/arrow-down.png"));
      down.addStyleName(BaseTheme.BUTTON_LINK);
      down.addListener(
          new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
              int newIndex = container.indexOfId(itemId) + 1;
              container.removeItem(itemId);
              container.addItemAt(newIndex, itemId);
              down.setEnabled(newIndex < container.size() - 1);
            }
          });
      down.setEnabled(container.indexOfId(itemId) < container.size() - 1);

      setCompositionRoot(layout);
    }
コード例 #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * com.vaadin.addon.calendar.event.CalendarEventProvider#getEvents(java.
   * util.Date, java.util.Date)
   */
  @Override
  public List<CalendarEvent> getEvents(Date startDate, Date endDate) {
    eventCache.clear();

    int[] rangeIndexes = getFirstAndLastEventIndex(startDate, endDate);
    for (int i = rangeIndexes[0]; i <= rangeIndexes[1] && i < container.size(); i++) {
      eventCache.add(getEvent(i));
    }
    return Collections.unmodifiableList(eventCache);
  }
コード例 #3
0
  /**
   * Get the first event for a date
   *
   * @param date The date to search for, NUll returns first event in container
   * @return Returns an array where the first item is the start index and the second item is the end
   *     item
   */
  private int[] getFirstAndLastEventIndex(Date start, Date end) {
    int startIndex = 0;
    int size = container.size();
    assert size >= 0;
    int endIndex = size - 1;

    if (start != null) {
      /*
       * Iterating from the start of the container, if range is in the end
       * of the container then this will be slow TODO This could be
       * improved by using some sort of divide and conquer algorithm
       */
      while (startIndex < size) {
        Object id = container.getIdByIndex(startIndex);
        Item item = container.getItem(id);
        Date d = (Date) item.getItemProperty(startDateProperty).getValue();
        if (d.compareTo(start) >= 0) {
          break;
        }
        startIndex++;
      }
    }

    if (end != null) {
      /*
       * Iterate from the start index until range ends
       */
      endIndex = startIndex;
      while (endIndex < size - 1) {
        Object id = container.getIdByIndex(endIndex);
        Item item = container.getItem(id);
        Date d = (Date) item.getItemProperty(endDateProperty).getValue();
        if (d == null) {
          // No end date present, use start date
          d = (Date) item.getItemProperty(startDateProperty).getValue();
        }
        if (d.compareTo(end) >= 0) {
          endIndex--;
          break;
        }
        endIndex++;
      }
    }

    return new int[] {startIndex, endIndex};
  }