Package org.apache.myfaces.tobago.model

Examples of org.apache.myfaces.tobago.model.SheetState


      if (org.apache.commons.lang.StringUtils.isNotEmpty(tip)) {
        tip +=  " - ";
      }
      tip += ResourceManagerUtil.getPropertyNotNull(facesContext, "tobago", "sheetTipSorting");

      SheetState sheetState = component.getSheetState(facesContext);
      if (column.getId().equals(sheetState.getSortedColumnId())) {
        if (sheetState.isAscending()) {
          sorterImage = imageAscending;
          sortTitle = ResourceManagerUtil.getPropertyNotNull(facesContext, "tobago", "sheetAscending");
        } else {
          sorterImage = imageDescending;
          sortTitle = ResourceManagerUtil.getPropertyNotNull(facesContext, "tobago", "sheetDescending");
View Full Code Here



    TobagoResponseWriter writer
        = (TobagoResponseWriter) facesContext.getResponseWriter();
    String sheetId = data.getClientId(facesContext);
    SheetState sheetState = data.getSheetState(facesContext);
    List<UIColumn> renderedColumnList = data.getRenderedColumns();

    HtmlStyleMap sheetStyle = (HtmlStyleMap) data.getAttributes().get(TobagoConstants.ATTR_STYLE);
    Integer sheetHeight = HtmlRendererUtil.getStyleAttributeIntValue(sheetStyle, "height");
    if (sheetHeight == null) {
      // FIXME: nullpointer if height not defined
      LOG.error("no height in parent container, setting to 100");
      sheetHeight = 100;
    }
    int footerHeight = (Integer) data.getAttributes().get(TobagoConstants.ATTR_FOOTER_HEIGHT);

    HtmlStyleMap bodyStyle = (HtmlStyleMap) data.getAttributes().get(TobagoConstants.ATTR_STYLE_BODY);
    HtmlRendererUtil.replaceStyleAttribute(data, TobagoConstants.ATTR_STYLE_BODY, "height",
        (sheetHeight - footerHeight));


    List<Integer> columnWidths = data.getWidthList();
    writer.startElement(HtmlConstants.INPUT, null);
    writer.writeIdAttribute(sheetId + WIDTHS_POSTFIX);
    writer.writeNameAttribute(sheetId + WIDTHS_POSTFIX);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    writer.writeAttribute(HtmlAttributes.VALUE, StringUtils.toString(columnWidths), false);
    writer.endElement(HtmlConstants.INPUT);

    writer.startElement(HtmlConstants.INPUT, null);
    writer.writeIdAttribute(sheetId + SCROLL_POSTFIX);
    writer.writeNameAttribute(sheetId + SCROLL_POSTFIX);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    Integer[] scrollPosition = data.getScrollPosition();
    if (scrollPosition != null) {
      String scroll = scrollPosition[0] + ";" + scrollPosition[1];
      writer.writeAttribute(HtmlAttributes.VALUE, scroll, false);
    } else {
      writer.writeAttribute(HtmlAttributes.VALUE, "", false);
    }
    writer.endElement(HtmlConstants.INPUT);
    List<Integer> selectedRows = sheetState.getSelectedRows();
    if (!UIData.NONE.equals(data.getSelectable())) {
      writer.startElement(HtmlConstants.INPUT, null);
      writer.writeIdAttribute(sheetId + SELECTED_POSTFIX);
      writer.writeNameAttribute(sheetId + SELECTED_POSTFIX);
      writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
View Full Code Here

  public void sheetSorter(ActionEvent event) {
    if (event instanceof SortActionEvent) {
      SortActionEvent sortEvent = (SortActionEvent) event;
      UISheet sheet = (UISheet) sortEvent.getComponent();
      SheetState sheetState
          = sheet.getSheetState(FacesContext.getCurrentInstance());
      String columnId = sheetState.getSortedColumnId();
      List<SolarObject> list = (List<SolarObject>) sheet.getValue();
      SolarObject sun = list.remove(0);

      Comparator<SolarObject> comparator = null;

      if ("name".equals(columnId)) {
        comparator = new Comparator<SolarObject>() {
          public int compare(SolarObject o1, SolarObject o2) {
            return o1.getName().compareToIgnoreCase(o2.getName());
          }
        };
      } else if ("orbit".equals(columnId)) {
        comparator = new Comparator<SolarObject>() {
          public int compare(SolarObject o1, SolarObject o2) {
            return o1.getOrbit().compareToIgnoreCase(o2.getOrbit());
          }
        };
      } else if ("population".equals(columnId)) {
        comparator = new Comparator<SolarObject>() {
          public int compare(SolarObject o1, SolarObject o2) {
            Integer i1 = -1;
            try {
              i1 = new Integer(o1.getPopulation().replaceAll("\\D", "").trim());
            } catch (NumberFormatException e) {
              // ignore
            }
            Integer i2 = -1;
            try {
              i2 = new Integer(o2.getPopulation().replaceAll("\\D", "").trim());
            } catch (NumberFormatException e) {
              // ignore
            }
            return i1.compareTo(i2);
          }
        };
      } else if ("distance".equals(columnId)) {
        comparator = new Comparator<SolarObject>() {
          public int compare(SolarObject o1, SolarObject o2) {
            return o1.getDistance().compareTo(o2.getDistance());
          }
        };
      } else if ("period".equals(columnId)) {
        comparator = new Comparator<SolarObject>() {
          public int compare(SolarObject o1, SolarObject o2) {
            return o1.getPeriod().compareTo(o2.getPeriod());
          }
        };
      }

      Collections.sort(list, comparator);
      if (!sheetState.isAscending()) {
        Collections.reverse(list);
      }

      list.add(0, sun);
    }
View Full Code Here

    Measure footerHeight = getFooterHeight(facesContext, sheet);
    Measure headerHeight = getHeaderHeight(facesContext, sheet);
    String selectable = sheet.getSelectable();

    Application application = facesContext.getApplication();
    SheetState state = sheet.getSheetState(facesContext);
    List<Integer> columnWidths = sheet.getWidthList();

    final List<Integer> selectedRows = getSelectedRows(sheet, state);
    final List<UIColumn> renderedColumnList = sheet.getRenderedColumns();
View Full Code Here

      }
      tip += ResourceManagerUtils.getPropertyNotNull(facesContext, "tobago", "sheetTipSorting");

      markup.add(Markup.SORTABLE);

      SheetState sheetState = sheet.getSheetState(facesContext);
      if (column.getId().equals(sheetState.getSortedColumnId())) {
        String sortTitle;
        if (sheetState.isAscending()) {
          sorterImage = contextPath + resourceManager.getImage(facesContext, "image/ascending.gif");
          sortTitle = ResourceManagerUtils.getPropertyNotNull(facesContext, "tobago", "sheetAscending");
          markup.add(Markup.ASCENDING);
        } else {
          sorterImage = contextPath + resourceManager.getImage(facesContext, "image/descending.gif");
View Full Code Here

    // TODO: Refactor: here be should use "getColumns()" instead of "getRenderedColumns()"
    List<UIColumn> renderedColumns = data.getRenderedColumns();

    final Map attributes = data.getAttributes();
    String widthListString = null;
    SheetState state = data.getSheetState(facesContext);
    if (state != null) {
      widthListString = state.getColumnWidths();
    }
    if (widthListString == null) {
      widthListString = (String) attributes.get(Attributes.WIDTH_LIST_STRING);
    }
View Full Code Here

    return (LayoutComponentRenderer) getRenderer(context);
  }

  @Override
  public void encodeBegin(FacesContext facesContext) throws IOException {
    SheetState state = getSheetState(facesContext);
    if (state.getFirst() > -1 && state.getFirst() < getRowCount()) {
      if (FacesUtils.hasValueBindingOrValueExpression(this, Attributes.FIRST)) {
        FacesUtils.setValueOfBindingOrExpression(facesContext, state.getFirst(), this, Attributes.FIRST);
      } else {
        setFirst(state.getFirst());
      }
    }
    super.encodeBegin(facesContext);
  }
View Full Code Here

  public SheetState getSheetState(FacesContext facesContext) {
    if (sheetState != null) {
      return sheetState;
    } else {
      if (FacesUtils.hasValueBindingOrValueExpression(this, Attributes.STATE)) {
        SheetState state = (SheetState)
            FacesUtils.getValueFromValueBindingOrValueExpression(facesContext, this, Attributes.STATE);
        if (state == null) {
          state = new SheetState();
          FacesUtils.setValueOfBindingOrExpression(facesContext, state, this, Attributes.STATE);
        }
        return state;
      } else {
        sheetState = new SheetState();
        return sheetState;
      }
    }
  }
View Full Code Here

  /**
   * Remove the (by user) resized column widths. An application may provide a button to access it.
   * Since 1.0.26.
   */
  public void resetColumnWidths() {
    SheetState state = getState();
    if (state != null) {
      state.setColumnWidths(null);
    }
    getAttributes().remove(Attributes.WIDTH_LIST_STRING);
  }
View Full Code Here

    super.processUpdates(context);
    updateSheetState(context);
  }

  private void updateSheetState(FacesContext facesContext) {
    SheetState state = getSheetState(facesContext);
    if (state != null) {
      // ensure sortActionListener
//      getSortActionListener();
//      state.setSortedColumn(sortActionListener != null ? sortActionListener.getColumn() : -1);
//      state.setAscending(sortActionListener != null && sortActionListener.isAscending());
      Map attributes = getAttributes();
      //noinspection unchecked
      final List<Integer> list = (List<Integer>) attributes.get(Attributes.SELECTED_LIST_STRING);
      state.setSelectedRows(list != null ? list : Collections.<Integer>emptyList());
      state.setColumnWidths((String) attributes.get(Attributes.WIDTH_LIST_STRING));
      state.setScrollPosition((Integer[]) attributes.get(Attributes.SCROLL_POSITION));
      attributes.remove(Attributes.SELECTED_LIST_STRING);
      attributes.remove(Attributes.SCROLL_POSITION);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.myfaces.tobago.model.SheetState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.