Package org.apache.myfaces.tobago.model

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


    getAttributes().remove(ATTR_WIDTH_LIST_STRING);
  }

  public void encodeBegin(FacesContext facesContext) throws IOException {
    UILayout.prepareDimension(facesContext, this);
    SheetState state = getSheetState(facesContext);
    if (state.getFirst() > -1 && state.getFirst() < getRowCount()) {
      ValueBinding valueBinding = getValueBinding(ATTR_FIRST);
      if (valueBinding != null) {
        valueBinding.setValue(facesContext, state.getFirst());
      } else {
        setFirst(state.getFirst());
      }
    }
    super.encodeBegin(facesContext);
  }
View Full Code Here


  public void setDirectLinkCount(Integer directLinkCount) {
    this.directLinkCount = directLinkCount;
  }

  private void setupState(FacesContext facesContext) {
    SheetState state = getSheetState(facesContext);
    ensureColumnWidthList(facesContext, state);
  }
View Full Code Here

    if (sheetState != null) {
      return sheetState;
    } else {
      ValueBinding stateBinding = getValueBinding(ATTR_STATE);
      if (stateBinding != null) {
        SheetState state = (SheetState) stateBinding.getValue(facesContext);
        if (state == null) {
          state = new SheetState();
          stateBinding.setValue(facesContext, state);
        }
        return state;
      } else {
        sheetState = new SheetState();
        return sheetState;
      }
    }
  }
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
      state.setSelectedRows((List<Integer>) attributes.get(ATTR_SELECTED_LIST_STRING));
      state.setColumnWidths((String) attributes.get(ATTR_WIDTH_LIST_STRING));
      state.setScrollPosition((Integer[]) attributes.get(ATTR_SCROLL_POSITION));
      attributes.remove(ATTR_SELECTED_LIST_STRING);
      attributes.remove(ATTR_SCROLL_POSITION);
    }
  }
View Full Code Here

      Object value = data.getValue();
      if (value instanceof DataModel) {
        value = ((DataModel) value).getWrappedData();
      }
      SheetState sheetState = data.getSheetState(facesContext);

      Comparator actualComparator = null;

      if (value instanceof List || value instanceof Object[]) {
        String sortProperty;

        try {

          UIComponent child = getFirstSortableChild(column.getChildren());
          if (child != null) {
            ValueBinding valueBinding = child.getValueBinding("value");
            String var = data.getVar();

            if (valueBinding != null) {
              if (isSimpleProperty(valueBinding.getExpressionString())) {
                String expressionString = valueBinding.getExpressionString();
                if (expressionString.startsWith("#{")
                    && expressionString.endsWith("}")) {
                  expressionString =
                      expressionString.substring(2,
                          expressionString.length() - 1);
                }
                sortProperty = expressionString.substring(var.length() + 1);

                actualComparator = new BeanComparator(
                    sortProperty, comparator, !sheetState.isAscending());

                if (LOG.isDebugEnabled()) {
                  LOG.debug("Sort property is " + sortProperty);
                }
              } else {
                actualComparator = new ValueBindingComparator(facesContext, var,
                    valueBinding, !sheetState.isAscending(), comparator);
              }
            }

          } else {
            LOG.error("No sorting performed. Value is not instanceof List or Object[]!");
            unsetSortableAttribute(column);
            return null;
          }
        } catch (Exception e) {
          LOG.error("Error while extracting sortMethod :" + e.getMessage(), e);
          if (column != null) {
            unsetSortableAttribute(column);
          }
          return null;
        }

        // TODO: locale / comparator parameter?
        // don't compare numbers with Collator.getInstance() comparator
//        Comparator comparator = Collator.getInstance();
//          comparator = new RowComparator(ascending, method);

        // memorize selected rows
        List<Object> selectedDataRows = null;
        if (sheetState.getSelectedRows() != null && sheetState.getSelectedRows().size() > 0) {
          selectedDataRows = new ArrayList<Object>(sheetState.getSelectedRows().size());
          Object dataRow;
          for (Integer index : sheetState.getSelectedRows()) {
            if (value instanceof List) {
              dataRow = ((List) value).get(index);
            } else {
              dataRow = ((Object[]) value)[index];
            }
            selectedDataRows.add(dataRow);
          }
        }
       
        // do sorting
        if (value instanceof List) {
          Collections.sort((List) value, actualComparator);
        } else { // value is instanceof Object[]
          Arrays.sort((Object[]) value, actualComparator);
        }

        // restore selected rows
        if (selectedDataRows != null) {
          sheetState.getSelectedRows().clear();
          for (Object dataRow : selectedDataRows) {
            int index = -1;
            if (value instanceof List) {
              for (int i = 0; i < ((List) value).size() && index < 0; i++) {
                if (dataRow == ((List) value).get(i)) {
                  index = i;
                }
              }
            } else {
              for (int i = 0; i < ((Object[]) value).length && index < 0; i++) {
                if (dataRow == ((Object[]) value)[i]) {
                  index = i;
                }
              }
            }
            if (index >= 0) {
              sheetState.getSelectedRows().add(index);
            }
          }
        }
       
      } else // DataModel?, ResultSet, Result or Object
View Full Code Here

  private transient LayoutTokens columnLayout;

  public void encodeBegin(FacesContext facesContext) throws IOException {
    UILayout.prepareDimension(facesContext, this);
    SheetState state = getSheetState(facesContext);
    if (state.getFirst() > -1 && state.getFirst() < getRowCount()) {
      ValueBinding valueBinding = getValueBinding(ATTR_FIRST);
      if (valueBinding != null) {
        valueBinding.setValue(facesContext, state.getFirst());
      } else {
        setFirst(state.getFirst());
      }
    }
    super.encodeBegin(facesContext);
  }
View Full Code Here

  public void setDirectLinkCount(Integer directLinkCount) {
    this.directLinkCount = directLinkCount;
  }

  private void setupState(FacesContext facesContext) {
    SheetState state = getSheetState(facesContext);
    ensureColumnWidthList(facesContext, state);
  }
View Full Code Here

    if (sheetState != null) {
      return sheetState;
    } else {
      ValueBinding stateBinding = getValueBinding(ATTR_STATE);
      if (stateBinding != null) {
        SheetState state = (SheetState) stateBinding.getValue(facesContext);
        if (state == null) {
          state = new SheetState();
          stateBinding.setValue(facesContext, state);
        }
        return state;
      } else {
        sheetState = new SheetState();
        return sheetState;
      }
    }
  }
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
      state.setSelectedRows((List<Integer>) attributes.get(ATTR_SELECTED_LIST_STRING));
      state.setColumnWidths((String) attributes.get(ATTR_WIDTH_LIST_STRING));
      state.setScrollPosition((Integer[]) attributes.get(ATTR_SCROLL_POSITION));
      attributes.remove(ATTR_SELECTED_LIST_STRING);
      attributes.remove(ATTR_SCROLL_POSITION);
    }
  }
View Full Code Here

    //HtmlStyleMap bodyStyle = (HtmlStyleMap) attributes.get(ATTR_STYLE_BODY);
    int footerHeight = (Integer) attributes.get(ATTR_FOOTER_HEIGHT);

    String selectable = data.getSelectable();

    SheetState state = data.getSheetState(facesContext);
    List<Integer> columnWidths = data.getWidthList();

    String selectedRows = StringUtils.toString(getSelectedRows(data, state));
    List<UIColumn> renderedColumnList = data.getRenderedColumns();
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.