Examples of SheetState


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

  /**
   * 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

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

    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

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

    Object value = data.getValue();
    if (value instanceof DataModel) {
      value = ((DataModel) value).getWrappedData();
    }
    FacesContext facesContext = FacesContext.getCurrentInstance();
    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) {

          String attributeName = child instanceof AbstractUICommand ? Attributes.LABEL:Attributes.VALUE;
          if (FacesUtils.hasValueBindingOrValueExpression(child, attributeName)) {
            String var = data.getVar();
            String expressionString = FacesUtils.getExpressionString(child, attributeName);
            if (isSimpleProperty(expressionString)) {
              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 {

              boolean descending = !sheetState.isAscending();
              actualComparator =
                  FacesUtils.getBindingOrExpressionComparator(facesContext, child, var, descending, comparator);
            }
          }

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

      // 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().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

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

    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();

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

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

      }
      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

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

    //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

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

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

  public void sheetSorter(ActionEvent event) throws AddressDaoException {
    if (event instanceof SortActionEvent) {
      SortActionEvent sortEvent = (SortActionEvent) event;
      UIColumn column = (UIColumn) sortEvent.getColumn();

      SheetState sheetState = sortEvent.getSheet().getSheetState(FacesContext.getCurrentInstance());
      currentAddressList = addressDao.findAddresses(searchCriterion, column.getId(), sheetState.isAscending());
    }
  }
View Full Code Here

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

  public void sheetSorter(ActionEvent event) {
    if (event instanceof SortActionEvent) {
      SortActionEvent sortEvent = (SortActionEvent) event;
      UIData sheet = sortEvent.getSheet();
      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

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

  /**
   * 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 = getSheetState(FacesContext.getCurrentInstance());
    if (state != null) {
      state.setColumnWidths(null);
    }
    getAttributes().remove(ATTR_WIDTH_LIST_STRING);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.