Package org.zkoss.zss.engine

Examples of org.zkoss.zss.engine.Ref


  }
 
  protected abstract void removeSelf();
 
  /*package*/ Ref addPrecedent(String name) {
    final Ref precedent = _ownerSheet.getOwnerBook().getOrCreateVariableRef(name, _ownerSheet);
    this.getPrecedents().add(precedent);
    precedent.getDependents().add(this);
    return precedent;
  }
View Full Code Here


    precedent.getDependents().add(this);
    return precedent;
  }
 
  /*package*/ Ref removePrecedent(String name) {
    final Ref precedent = _ownerSheet.getOwnerBook().getOrCreateVariableRef(name, _ownerSheet);
    if (precedent != null) {
      this.getPrecedents().remove(precedent);
      precedent.getDependents().remove(this);
    }
    return precedent;
  }
View Full Code Here

 
  /*package*/ Ref addPrecedent(RefSheet refSheet, int tRow, int lCol, int bRow, int rCol) {
    if (refSheet == null) {
      refSheet = _ownerSheet;
    }
    final Ref precedent = 
      refSheet.getOrCreateRef(tRow, lCol, bRow, rCol);
    this.getPrecedents().add(precedent);
    precedent.getDependents().add(this);
    return precedent;
  }
View Full Code Here

 
  @Override
  public void delete(int shift) {
    synchronized(_sheet) {
      if (_refs != null && !_refs.isEmpty()) {
        final Ref ref = _refs.iterator().next();
        final RefSheet refSheet = ref.getOwnerSheet();
        final RefBook refBook = refSheet.getOwnerBook();
        final Worksheet sheet = BookHelper.getSheet(_sheet, refSheet);
        if (!((SheetCtrl)sheet).isEvalAll()) {
          ((SheetCtrl)sheet).evalAll();
        }
        switch(shift) {
        default:
        case SHIFT_DEFAULT:
          if (ref.isWholeRow()) {
            final ChangeInfo info = BookHelper.deleteRows(sheet, ref.getTopRow(), ref.getRowCount());
            notifyMergeChange(refBook, info, ref, SSDataEvent.ON_RANGE_DELETE, SSDataEvent.MOVE_V);
          } else if (ref.isWholeColumn()) {
            final ChangeInfo info = BookHelper.deleteColumns(sheet, ref.getLeftCol(), ref.getColumnCount());
            notifyMergeChange(refBook, info, ref, SSDataEvent.ON_RANGE_DELETE, SSDataEvent.MOVE_H);
          }
          break;
        case SHIFT_LEFT:
          if (ref.isWholeRow() || ref.isWholeColumn()) {
            delete(SHIFT_DEFAULT);
          } else {
            final ChangeInfo info = BookHelper.deleteRange(sheet, ref.getTopRow(), ref.getLeftCol(), ref.getBottomRow(), ref.getRightCol(), true);
            notifyMergeChange(refBook, info, ref, SSDataEvent.ON_RANGE_DELETE, SSDataEvent.MOVE_H);
          }
          break;
        case SHIFT_UP:
          if (ref.isWholeRow() || ref.isWholeColumn()) {
            delete(SHIFT_DEFAULT);
          } else {
            final ChangeInfo info = BookHelper.deleteRange(sheet, ref.getTopRow(), ref.getLeftCol(), ref.getBottomRow(), ref.getRightCol(), false);
            notifyMergeChange(refBook, info, ref, SSDataEvent.ON_RANGE_DELETE, SSDataEvent.MOVE_V);
          }
          break;
        }
      }
View Full Code Here

 
  @Override
  public void insert(int shift, int copyOrigin) {
    synchronized(_sheet) {
      if (_refs != null && !_refs.isEmpty()) {
        final Ref ref = _refs.iterator().next();
        final RefSheet refSheet = ref.getOwnerSheet();
        final RefBook refBook = refSheet.getOwnerBook();
        final Worksheet sheet = BookHelper.getSheet(_sheet, refSheet);
        if (!((SheetCtrl)sheet).isEvalAll()) {
          ((SheetCtrl)sheet).evalAll();
        }
        switch(shift) {
        default:
        case SHIFT_DEFAULT:
          if (ref.isWholeRow()) {
            final ChangeInfo info = BookHelper.insertRows(sheet, ref.getTopRow(), ref.getRowCount(), copyOrigin);
            notifyMergeChange(refBook, info, ref, SSDataEvent.ON_RANGE_INSERT, SSDataEvent.MOVE_V);
          } else if (ref.isWholeColumn()) {
            final ChangeInfo info = BookHelper.insertColumns(sheet, ref.getLeftCol(), ref.getColumnCount(), copyOrigin);
            notifyMergeChange(refBook, info, ref, SSDataEvent.ON_RANGE_INSERT, SSDataEvent.MOVE_H);
          }
          break;
        case SHIFT_RIGHT:
          if (ref.isWholeRow() || ref.isWholeColumn()) {
            insert(SHIFT_DEFAULT, copyOrigin);
          } else {
            final ChangeInfo info = BookHelper.insertRange(sheet, ref.getTopRow(), ref.getLeftCol(), ref.getBottomRow(), ref.getRightCol(), true, copyOrigin);
            notifyMergeChange(refBook, info, ref, SSDataEvent.ON_RANGE_INSERT, SSDataEvent.MOVE_H);
          }
          break;
        case SHIFT_DOWN:
          if (ref.isWholeRow() || ref.isWholeColumn()) {
            insert(SHIFT_DEFAULT, copyOrigin);
          } else {
            final ChangeInfo info = BookHelper.insertRange(sheet, ref.getTopRow(), ref.getLeftCol(), ref.getBottomRow(), ref.getRightCol(), false, copyOrigin);
            notifyMergeChange(refBook, info, ref, SSDataEvent.ON_RANGE_INSERT, SSDataEvent.MOVE_V);
          }
          break;
        }
      }
View Full Code Here

    if (event != null && ref != null) {
      refBook.publish(new SSDataEvent(event, ref, orient));
    }
    //must delete and add in batch, or merge ranges can interfere to each other
    for(MergeChange change : info.getMergeChanges()) {
      final Ref orgMerge = change.getOrgMerge();
      if (orgMerge != null) {
        refBook.publish(new SSDataEvent(SSDataEvent.ON_MERGE_DELETE, orgMerge, orient));
      }
    }
    for(MergeChange change : info.getMergeChanges()) {
      final Ref merge = change.getMerge();
      if (merge != null) {
        refBook.publish(new SSDataEvent(SSDataEvent.ON_MERGE_ADD, merge, orient));
      }
    }
    BookHelper.reevaluateAndNotify((Book) _sheet.getWorkbook(), last, all);
View Full Code Here

  @Override
  public Range pasteSpecial(Range dstRange, int pasteType, int pasteOp, boolean skipBlanks, boolean transpose) {
    final Worksheet[] sheets = getLockSheets(dstRange); //enforce lock sequence
    synchronized(sheets[0]) {
      synchronized(sheets[1]) {
        final Ref ref = paste0(dstRange, pasteType, pasteOp, skipBlanks, transpose);
        return ref == null ? null : new RangeImpl(ref, BookHelper.getSheet(_sheet, ref.getOwnerSheet()));
      }
    }
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public void sort(Range rng1, boolean desc1, Range rng2, int type, boolean desc2, Range rng3, boolean desc3, int header, int orderCustom,
      boolean matchCase, boolean sortByRows, int sortMethod, int dataOption1, int dataOption2, int dataOption3) {
    synchronized(_sheet) {
      final Ref key1 = rng1 != null ? ((RangeImpl)rng1).getRefs().iterator().next() : null;
      final Ref key2 = rng2 != null ? ((RangeImpl)rng2).getRefs().iterator().next() : null;
      final Ref key3 = rng3 != null ? ((RangeImpl)rng3).getRefs().iterator().next() : null;
      if (_refs != null && !_refs.isEmpty()) {
        final Ref ref = _refs.iterator().next();
        final int tRow = ref.getTopRow();
        final int lCol = ref.getLeftCol();
        final int bRow = ref.getBottomRow();
        final int rCol = ref.getRightCol();
        final Worksheet sheet = BookHelper.getSheet(_sheet, ref.getOwnerSheet());
        final RefBook refBook = ref.getOwnerSheet().getOwnerBook();
        ChangeInfo info = BookHelper.sort(sheet, tRow, lCol, bRow, rCol,
                  key1, desc1, key2, type, desc2, key3, desc3, header,
                  orderCustom, matchCase, sortByRows, sortMethod, dataOption1, dataOption2, dataOption3);
        if (info == null) {
          info = new ChangeInfo(new HashSet<Ref>(0), new HashSet<Ref>(), new ArrayList<MergeChange>(0));
View Full Code Here

  @Override
  public Range copy(Range dstRange) {
    final Worksheet[] sheets = getLockSheets(dstRange); //enforce lock sequence
    synchronized(sheets[0]) { //enforce lock sequence
      synchronized(sheets[1]) {
        final Ref ref = paste0(dstRange, Range.PASTE_ALL, Range.PASTEOP_NONE, false, false);
        return ref == null ? null : new RangeImpl(ref, BookHelper.getSheet(_sheet, ref.getOwnerSheet()));
      }
    }
  }
View Full Code Here

      if (((RangeImpl)dstRange).getRefs().size() > 1) {
        throw new UiException("Command cannot be used on multiple selections");
      }
      //source range can handle only same rows/columns multiple references
      Iterator<Ref> it = _refs.iterator();
      Ref ref1 = it.next();
      int srcRowCount = ref1.getRowCount();
      int srcColCount = ref1.getColumnCount();
      final Ref dstRef = ((RangeImpl)dstRange).getRefs().iterator().next();
      final Set<Ref> toEval = new HashSet<Ref>();
      final Set<Ref> affected = new HashSet<Ref>();
      final List<MergeChange> mergeChanges = new ArrayList<MergeChange>();
      final ChangeInfo info = new ChangeInfo(toEval, affected, mergeChanges);
      Ref pasteRef = null;
      if (_refs.size() > 1) { //multiple src references
        final SortedMap<Integer, Ref> srcRefs = new TreeMap<Integer, Ref>();
        boolean sameRow = false;
        boolean sameCol = false;
        final int lCol = ref1.getLeftCol();
        final int tRow = ref1.getTopRow();
        final int rCol = ref1.getRightCol();
        final int bRow = ref1.getBottomRow();
        while (it.hasNext()) {
          final Ref ref = it.next();
          if (lCol == ref.getLeftCol() && rCol == ref.getRightCol()) { //same column
            if (sameRow) { //cannot be both sameRow and sameColumn
              throw new UiException("Command cannot be used on multiple selections");
            }
            if (srcRefs.isEmpty()) {
              srcRefs.put(new Integer(tRow), ref1); //sorted on Row
            }
            srcRefs.put(new Integer(ref.getTopRow()), ref);
            sameCol = true;
            srcRowCount += ref.getRowCount();
          } else if (tRow == ref.getTopRow() && bRow == ref.getBottomRow()) { //same row
            if (sameCol) { //cannot be both sameRow and sameColumn
              throw new UiException("Command cannot be used on multiple selections");
            }
            if (srcRefs.isEmpty()) {
              srcRefs.put(Integer.valueOf(lCol), ref1); //sorted on column
            }
            srcRefs.put(Integer.valueOf(ref.getLeftCol()), ref);
            sameRow = true;
            srcColCount += ref.getColumnCount();
          } else { //not the same column or same row
            throw new UiException("Command cannot be used on multiple selections");
          }
        }
        pasteType = pasteType + Range.PASTE_VALUES; //no formula
View Full Code Here

TOP

Related Classes of org.zkoss.zss.engine.Ref

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.