Package org.zkoss.zss.model

Examples of org.zkoss.zss.model.Range


System.out.println(Objects.toString(ssl.getList()));
    assertEquals(2, ssl.getList().size());

    for(final Iterator it = ssl.getList().iterator(); it.hasNext();) {
      final SSDataEvent evt = (SSDataEvent) it.next();
      final Range rng = evt.getRange();
      if (rng.getLeft() == 1 && rng.getTop() == 0) {
        assertEquals(5d, ((Number)sheet1.getCell(0,1).getResult()).doubleValue(), 0d);
      } else  if (rng.getLeft() == 5 && rng.getTop() == 5) {
        assertEquals(10d, ((Number)sheet1.getCell(5,5).getResult()).doubleValue(), 0d);
      } else {
        assertFalse("should not come here", false);
      }
    }
View Full Code Here


    book.notifyChange(new String[] {"ABCD"});
    events = listener.getList();
    assertEquals(1, events.size());

    SSDataEvent event = (SSDataEvent) events.get(0);
    Range rng = event.getRange();
   
    assertEquals(0, rng.getTop()); //row
    assertEquals(0, rng.getLeft()); //column
   
    assertEquals("Hello ZK", sheet1.getCell(rng.getTop(),rng.getLeft()).getText());
   
  }
View Full Code Here

  private static double sumDeviation(double total, Object arg, double mean, XelContext ctx) {
    if (arg instanceof SSError) {
      throw new SSErrorXelException((SSError) arg);
    } else if (arg instanceof Range) { // a range, iterator thru available
                      // cells
      final Range rng = (Range) arg;
      final Book book = rng.getSheet().getBook();
      final Collection cells = rng.getCells();
      for(final Iterator it = cells.iterator(); it.hasNext();) {
        final Cell cell = (Cell) it.next();
        total= sumDeviation(total, cell.getResult(),mean, (XelContext) book); // recursive
      }
      return total;
View Full Code Here

  private Reference connectRefs(List ranges, XelContext ctx) {
    //connect DAG ref nodes
    final Reference orgref = ctx != null ?
        (Reference) ctx.getVariableResolver().resolveVariable("zkoss.ss.Ref") : null;
    for(final Iterator it = ranges.iterator(); it.hasNext(); ) {
      final Range xrng = (Range) it.next();
      if (xrng instanceof RangeRef) {
        final RangeRef rng = (RangeRef) xrng;
        orgref.addPrecedent(rng.getRef());
      }
    }
    final Sheet orgSheet = orgref.getSheet();
    if (orgSheet != null) {
      for(final Iterator it = ranges.iterator(); it.hasNext(); ) {
        final Range xrng = (Range) it.next();
        if (xrng instanceof RangeRef) {
          final RangeRef rng = (RangeRef) xrng;
          if (rng.getSheetTo() == null && rng.getSheet() != orgSheet) {
            rng.setSheetAbsolute(true);
          }
View Full Code Here

 
  public String getText() {
    final Format format = getFormat();
    Object result = getResult();
    if (result instanceof Range) {
      final Range rng = (Range) result;
      final Cell[][][] rngcella = rng.getCellsArray();
      final int colsz = rng.getColumnSize();
      final int rowsz = rng.getRowSize();
      if (colsz == 1 && rowsz == 1) { //single cell range
        final Cell rngcell = rngcella[0][0][0];
        if (rngcell == null) {
          result = Objects.ZERO_DOUBLE;
        } else {
          result = rngcell.getResult();
        }
      } else if (colsz > 1 && rowsz > 1) {
        result = SSError.VALUE;
      } else if (colsz == 1) {
        final int row = getRow();
        final int rngtop = rng.getTop();
        final int rngbottom = rng.getBottom();
        if (row >= rngtop && row <= rngbottom) {
          final int rowidx = row - rngtop;
          final Cell rngcell = rngcella[0][rowidx][0];
          if (rngcell == null) {
            result = Objects.ZERO_DOUBLE;
          } else {
            result = rngcell.getResult();
          }
        } else {
          result = SSError.VALUE;
        }
      } else { //rowsz == 1
        final int col = getColumn();
        final int rngleft = rng.getLeft();
        final int rngright = rng.getRight();
        if (col >= rngleft && col <= rngright) {
          final int colidx = col - rngleft;
          final Cell rngcell = rngcella[0][0][colidx];
          if (rngcell == null) {
            result = Objects.ZERO_DOUBLE;
View Full Code Here

          //prepare Range operator token
          operand.setType(TokenType.OP_IN);
          operand.setValue(":"); //as a Range operator
          if (var1) {
            //lookup NameRange
            final Range rng = book.lookupNameRange(cell1);
            if (rng != null) {
              ranges.add(rng);
              operand.addOperand(new Token(rng, TokenType.OPERAND, TokenSubtype.RANGE));
            } else {
              operand.addOperand(new Token(cell1, TokenType.OPERAND, TokenSubtype.VAR));
              if (!((BookImpl)book).addVariable(cell1, orgref)) {
                throw new XelException("Illegal variable name: "+cell1);
              }
            }
          } else {
            final Token token1 =
              new Token(cell1, TokenType.OPERAND, TokenSubtype.CELL);
            //TODO: matain ref DAG graph
            //TODO: How do we handle variable range2d?
//            final SheetImpl psheet = sheet1 != null ? sheet1 : sheet;
//            final Abacus pabacus = psheet.getBook().getAbacus();
            final int left = lt[0];
            final int top = lt[1];
            final int right = left;
            final int bottom = top;
            final boolean absleft = lt[2] != 0;
            final boolean abstop = lt[3] != 0;
            final boolean absright = absleft;
            final boolean absbottom = abstop;
            final Range rng = psheet1 == null ? RangeRefError.RANGE_REF_ERROR :
              new RangeRef(psheet1, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
            ranges.add(rng);
/*            if (orgref != null) {
              final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
              orgref.addPrecedent(precedent);
            }
*/            token1.setValue(rng);
            operand.addOperand(token1);
          }
         
          if (var2) {
            //lookup NameRange
            final Range rng = book.lookupNameRange(cell2);
            if (rng != null) {
              ranges.add(rng);
              operand.addOperand(new Token(rng, TokenType.OPERAND, TokenSubtype.RANGE));
            } else {
              operand.addOperand(new Token(cell2, TokenType.OPERAND, TokenSubtype.VAR));
              if (!((BookImpl)book).addVariable(cell2, orgref)) {
                throw new XelException("Illegal variable name: "+cell2);
              }
            }
          } else {
            final Token token2 =
              new Token(cell2, TokenType.OPERAND, TokenSubtype.CELL);
            //TODO: matain ref DAG graph
            //TODO: How do we handle variable range2d?
//            final SheetImpl psheet = sheet2 != null ? sheet2 : sheet;
//            final Abacus pabacus = psheet.getBook().getAbacus();
            final int left = rb[0];
            final int top = rb[1];
            final int right = left;
            final int bottom = top;
            final boolean absleft = rb[2] != 0;
            final boolean abstop = rb[3] != 0;
            final boolean absright = absleft;
            final boolean absbottom = abstop;
            final Range rng =
              new RangeRef(psheet2, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
            ranges.add(rng);
/*            if (orgref != null) {
              final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
              orgref.addPrecedent(precedent);
            }
*/            token2.setValue(rng);
            operand.addOperand(token2);
          }
        } else { //a const cell or a const range
          if (sheetnm1 == null || (sheetnm2 == null || sheetnm1.equals(sheetnm2))) { //single sheet
            if (cell1.equals(cell2)) { //a cell reference
              if (lt[0] == -1 || lt[1] == -1) { //single row || single column
//                final SheetImpl psheet = sheet1 != null ? sheet1 : sheet;
//                final Abacus pabacus = psheet.getBook().getAbacus();
                final int left = lt[0];
                final int top = lt[1];
                final int right = rb[0];
                final int bottom = rb[1];
                final boolean absleft = lt[2] != 0;
                final boolean abstop = lt[3] != 0;
                final boolean absright = rb[2] != 0;
                final boolean absbottom = rb[3] != 0;
                final Range rng = psheet1 == null ? RangeRefError.RANGE_REF_ERROR :
                  new RangeRef(psheet1, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
                ranges.add(rng);
/*                if (orgref != null) {
                  final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
                  orgref.addPrecedent(precedent);
                }
*/                operand.setValue(rng);
              } else { //degrad to single cell
                operand.setSubtype(TokenSubtype.CELL);
                //TODO: maintain DAG reference
//                final SheetImpl psheet = sheet1 != null ? sheet1 : sheet;
//                final Abacus pabacus = psheet.getBook().getAbacus();
                final int left = lt[0];
                final int top = lt[1];
                final int right = left;
                final int bottom = top;
                final boolean absleft = lt[2] != 0;
                final boolean abstop = lt[3] != 0;
                final boolean absright = absleft;
                final boolean absbottom = abstop;
                final Range rng = psheet1 == null ? RangeRefError.RANGE_REF_ERROR :
                  new RangeRef(psheet1, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
                ranges.add(rng);
/*                if (orgref != null) {
                  final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
                  orgref.addPrecedent(precedent);
                }
*/                operand.setValue(rng);
              }
            } else { //a range reference
              //TODO: maintain DAG reference
//              final SheetImpl psheet = sheet1 != null ? sheet1 : sheet;
//              final Abacus pabacus = psheet.getBook().getAbacus();
              final int left = lt[0];
              final int top = lt[1];
              final int right = rb[0];
              final int bottom = rb[1];
              final boolean absleft = lt[2] != 0;
              final boolean abstop = lt[3] != 0;
              final boolean absright = rb[2] != 0;
              final boolean absbottom = rb[3] != 0;
              final Range rng = psheet1 == null ? RangeRefError.RANGE_REF_ERROR :
                new RangeRef(psheet1, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
              ranges.add(rng);
/*              if (orgref != null) {
                final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
                orgref.addPrecedent((Reference)precedent);
              }
*/              operand.setValue(rng);
            }
          } else { //range 3d
            //TODO: maintain DAG reference
            //TODO: for each sheet between two sheet name
            final int left = lt[0];
            final int top = lt[1];
            final int right = rb[0];
            final int bottom = rb[1];
            final boolean absleft = lt[2] != 0;
            final boolean abstop = lt[3] != 0;
            final boolean absright = rb[2] != 0;
            final boolean absbottom = rb[3] != 0;
            final Range rng = (psheet1 == null || psheet2 == null) ? RangeRefError.RANGE_REF_ERROR :
              new RangeRef(psheet1, psheet2, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
            ranges.add(rng);
/*            if (orgref != null) {
              final Book pbook = sheet1.getBook();
              final int from = pbook.indexOfSheet(sheet1);
              final int to = pbook.indexOfSheet(sheet2);
              final Abacus pabacus = pbook.getAbacus();
              final List sheets = book.getSheets();
              for (int j=from; j <= to; ++j) {
                final SheetImpl psheet = (SheetImpl) sheets.get(j);
                final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
                orgref.addPrecedent((Reference)precedent);
              }
            }
*/            operand.setValue(rng);
          }
        }
      } else if (var1) { //single variable
        //lookup NameRange
        final Range rng = book.lookupNameRange(cell1);
        if (rng != null) {
          ranges.add(rng);
          operand.setValue(rng);
        } else {
          operand.setSubtype(TokenSubtype.VAR);
          if (!((BookImpl)book).addVariable(cell1, orgref)) {
            throw new XelException("Illegal variable name: "+cell1);
          }
        }
      } else {//single cell
        operand.setSubtype(TokenSubtype.CELL);
        //TODO: maintain DAG reference
//        final SheetImpl psheet = sheet1 != null ? sheet1 : sheet;
//        final Abacus pabacus = psheet.getBook().getAbacus();
        final int left = lt[0];
        final int top = lt[1];
        final int right = left;
        final int bottom = top;
        final boolean absleft = lt[2] != 0;
        final boolean abstop = lt[3] != 0;
        final boolean absright = absleft;
        final boolean absbottom = abstop;
        final Range rng = psheet1 == null ? RangeRefError.RANGE_REF_ERROR :
          new RangeRef(psheet1, null, left, top, right, bottom, absleft, abstop, absright, absbottom, abssheet);
        ranges.add(rng);
/*        if (orgref != null) {
          final Reference precedent = pabacus.addRef(new SimpleRef(psheet, rng, orgrow, orgcol));
          orgref.addPrecedent((Reference)precedent);
View Full Code Here

 
  private void applyFilter (Worksheet worksheet, Map data) {
    final boolean selectAll = (Boolean) data.get("all");
    final String cellRangeAddr = (String) data.get("range");
    final int field = (Integer) data.get("field");
    final Range range = Ranges.range(worksheet, cellRangeAddr);
   
    if (selectAll) {
      range.autoFilter(field, null, AutoFilter.FILTEROP_VALUES, null, null);
    } else { //partial selection
      JSONArray ary = (JSONArray) data.get("criteria");
      range.autoFilter(field, ary.toArray(new String[ary.size()]), AutoFilter.FILTEROP_VALUES, null, null);
    }
  }
View Full Code Here

 
  private void processFilter (int row, int col, int field, Worksheet worksheet, Spreadsheet spreadsheet) {
    final AutoFilter autoFilter = worksheet.getAutoFilter();
    final FilterColumn filterColumn = autoFilter.getFilterColumn(field - 1);
    final String rangeAddr = autoFilter.getRangeAddress().formatAsString();
    final Range range = Ranges.range(worksheet, rangeAddr);
   
    spreadsheet.smartUpdate("autoFilterPopup",
      convertFilterInfoToJSON(row, col, field, rangeAddr, scanRows(field, filterColumn, range, worksheet)));
  }
View Full Code Here

    final AreasImpl areas = new AreasImpl();
    if (getRefs().size() == 1) {
      areas.addArea(this);
    } else {
      for(Ref ref : getRefs()) {
        final Range rng = refToRange(ref);
        areas.addArea(rng);
      }
    }
    return areas;
  }
View Full Code Here

  public AutoFilter autoFilter() {
    synchronized (_sheet) {
      CellRangeAddress affectedArea;
      if(_sheet.isAutoFilterMode()){
        affectedArea = _sheet.removeAutoFilter();
        Range unhideArea = Ranges.range(_sheet,
            affectedArea.getFirstRow(),affectedArea.getFirstColumn(),
            affectedArea.getLastRow(),affectedArea.getLastColumn());
        unhideArea.getRows().setHidden(false);
      } else {
        //The logic to decide the actual affected range to implement autofilter:
        //If it's a multi cell range, it's the range intersect with largest range of the sheet.
        //If it's a single cell range, it has to be extend to a continuous range by looking up the near 8 cells of the single cell.
        affectedArea = new CellRangeAddress(getRow(), getLastRow(), getColumn(), getLastColumn());
View Full Code Here

TOP

Related Classes of org.zkoss.zss.model.Range

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.