Package org.zkoss.zss.app.zul.ctrl

Examples of org.zkoss.zss.app.zul.ctrl.WorkbookCtrl


   *
   * @param target
   * @param replacement
   */
  private boolean replaceFormulaReference(String target, String replacement) {
    final WorkbookCtrl bookCtrl = getDesktopWorkbenchContext().getWorkbookCtrl();
    int refStartIndex = -1;
    for (int i = newEdit.length() - 1; i >= 0; i--) {
      char c = newEdit.charAt(i);
      if (Separator.contains(c)) {
        refStartIndex = i;
        break;
      }
    }

    if (refStartIndex >= 0 && target != null && !target.equals(replacement) &&
        (newEdit.indexOf(target, refStartIndex) + target.length() ==  newEdit.length())) {
      newEdit = newEdit.substring(0, refStartIndex + 1) + replacement;
      setText(newEdit);
      bookCtrl.escapeAndUpdateText(formulaCell, newEdit);
      return true;
    }
    return false;
  }
View Full Code Here


    }
    return false;
  }

  private void appendFormulaReference(String cellRef) {
    final WorkbookCtrl bookCtrl = getDesktopWorkbenchContext().getWorkbookCtrl();
    if (allowAppendCellReference(newEdit)) {
      newEdit += focusCellRef;
      setText(newEdit);
      bookCtrl.escapeAndUpdateText(formulaCell, newEdit);
    }
  }
View Full Code Here

      bookCtrl.escapeAndUpdateText(formulaCell, newEdit);
    }
  }
 
  private void clearCellReferenceFocus() {
    WorkbookCtrl bookCtrl = getDesktopWorkbenchContext().getWorkbookCtrl();
    for (String name : addedFocusNames) {
      bookCtrl.removeEditorFocus(name);
    }
    addedFocusNames.clear();
  }
View Full Code Here

    }
    addedFocusNames.clear();
  }
 
  private void endEditingFormula(boolean confirmChange) {
    WorkbookCtrl bookCtrl = getDesktopWorkbenchContext().getWorkbookCtrl();
   
    Range range = Ranges.range(formulaSheet, formulaCell.getRowIndex(), formulaCell.getColumnIndex());
    if (confirmChange) {
      range.setEditText(newEdit);
      bookCtrl.focusTo(formulaRow, formulaColumn, false);
    }
    clearCellReferenceFocus();
    editExistingFormula = false;
    formulaCell = null;
    formulaText = null;
View Full Code Here

    formulaRow = 0;
    formulaColumn = 0;
  }

  public void onCreate() {
    final WorkbookCtrl bookCtrl = getDesktopWorkbenchContext().getWorkbookCtrl();
    bookCtrl.addEventListener(Events.ON_CELL_FOUCSED, new EventListener() {
      @Override
      public void onEvent(Event event) throws Exception {
        CellEvent cellEvent = (CellEvent)event;
        everFocusCell = true;

        if (!isComposingFormula(newEdit)) {
          Cell cell = Utils.getCell(cellEvent.getSheet(), cellEvent.getRow(), cellEvent.getColumn());
          String editText = Utils.getEditText(cell);
          setText(cell == null ? "" : (editText == null ? "" : editText));
        } else {
          if (!editExistingFormula) {
            FormulaEditor.this.focus();
            String lastFocusRef = focusCellRef;
            focusCellRef = bookCtrl.getReference(cellEvent.getRow(), cellEvent.getColumn());
            if (replaceFormulaReference(lastFocusRef, focusCellRef))
              return;
            else
              appendFormulaReference(focusCellRef);
            generateCellFocus(newEdit);
          }
        } 
      }
    });

    bookCtrl.addEventListener(Events.ON_STOP_EDITING,
        new EventListener() {
          public void onEvent(Event event) throws Exception {
            StopEditingEvent evt = (StopEditingEvent)event;
            //setText((String) evt.getEditingValue());

            //chart not implement yet
//            // to notify all widgets there is a cell changed
//            for (int i = 0; i < chartKey; i++) {
//              try {
//                Window win = (Window) mainWin.getFellow("chartWin" + i);
//                if (win != null) {
//                  Chart myChart = (Chart) win.getFellow("myChart");
//                  CellEvent event = new StopEditingEvent(
//                      org.zkoss.zss.ui.event.Events.ON_STOP_EDITING,
//                      myChart, evt.getSheet(), evt.getRow(), evt
//                          .getColumn(), (String) evt.getData());
//                  org.zkoss.zk.ui.event.Events.postEvent(event);
//                }
//              } catch (Exception e) {
//                // the chart may be deleted
//              }
//            }
          }
        });
    //TODO: add ON_START_EDITING, add cell focus if cell is formula
//    bookCtrl.addEventListener(Events.ON_START_EDITING,
//        new EventListener() {
//      public void onEvent(Event event) throws Exception {
//        StartEditingEvent evt = (StartEditingEvent)event;
//        newEdit = (String) evt.getClientValue();
//        if (isStartEditingFormula(newEdit)) {
//          cacheFormulaEditingInfo();
//        }
//        if (isComposingFormula(newEdit)) {
//          int left = bookCtrl.getSelection().getLeft();
//          int top = bookCtrl.getSelection().getTop();
//          formulaCell = Utils.getCell(bookCtrl.getSelectedSheet(), top, left);
//
//          addedFocusNames.add(FORMULA_FOCUS_NAME);
//          bookCtrl.moveEditorFocus(FORMULA_FOCUS_NAME, FORMULA_COLOR, top, left);
//        }
//        setText((String) evt.getEditingValue());
//      }
//    });
   
    bookCtrl.addEventListener(Events.ON_EDITBOX_EDITING,
        new EventListener() {
      public void onEvent(Event event) throws Exception {
        EditboxEditingEvent evt = (EditboxEditingEvent)event;
        setText((String) evt.getEditingValue());
      }
View Full Code Here

    data.put("row", Integer.valueOf(row));
    insertWidgetAtDialog.fireOnClose(data);
  }
 
  private void buildHeaderModel() {
    final WorkbookCtrl workbookCtrl = getWorkbookCtrl();
   
    int maxCol = getWorkbookCtrl().getMaxcolumns();
    ArrayList<String> strs = new ArrayList<String>();
    for (int i = 0; i < maxCol; i++) {
      strs.add(workbookCtrl.getColumnTitle(i));
    }
    availableColumns = new ListModelList(strs);
   
    int maxRow = getWorkbookCtrl().getMaxrows();
    strs = new ArrayList<String>();
    for (int i = 0; i < maxRow; i++) {
      strs.add(workbookCtrl.getRowTitle(i));
    }
    availableRows = new ListModelList(strs);
  }
View Full Code Here

  public void onClick$okBtn() {
    setHeaderSize();
  }
 
  private void setHeaderSize() {
    WorkbookCtrl bookCtrl = Zssapp.getDesktopWorkbenchContext(self).getWorkbookCtrl();
    if (headerType ==  WorkbookCtrl.HEADER_TYPE_ROW)
      bookCtrl.setRowHeightInPx(headerSize.getValue(), selection);
    else
      bookCtrl.setColumnWidthInPx(headerSize.getValue(), selection);
    _headerSizeDialog.fireOnClose(null);
  }
View Full Code Here

  public FormulaEditor() {
    setMultiline(true);
  }

  private void addFormulaEditCellFocus() {
    WorkbookCtrl bookCtrl = getDesktopWorkbenchContext().getWorkbookCtrl();
    bookCtrl.moveEditorFocus(FORMULA_FOCUS_NAME, FORMULA_FOCUS_NAME, FORMULA_COLOR, formulaRow, formulaColumn);
    addedFocusNames.add(FORMULA_FOCUS_NAME);
  }
View Full Code Here

 
  /**
   * Generate cell focus from edit label
   */
  private void generateCellFocus(String edit) {
    WorkbookCtrl bookCtrl = getDesktopWorkbenchContext().getWorkbookCtrl();
    boolean startEditingFormula = addedFocusNames.size() == 0;
    int maxCol = bookCtrl.getMaxcolumns();
    int maxRow = bookCtrl.getMaxrows();
   
    int currentColumn = bookCtrl.getSelection().getLeft();
    int currentRow = bookCtrl.getSelection().getTop();
   
    LinkedHashSet<String> currentFocus = new LinkedHashSet<String>(addedFocusNames);
    LinkedHashSet<String> newFocus = new LinkedHashSet<String>();
    if (addedFocusNames.contains(FORMULA_FOCUS_NAME))
      newFocus.add(FORMULA_FOCUS_NAME);

    LinkedHashSet<String> cellRefs = parseCellReference(edit);
    for (String name : cellRefs) {
      if (addedFocusNames.contains(name) || "".equals(name)) {
        newFocus.add(name);
        continue;
      }
      Range rng = null;
      try {
        rng = Ranges.range(formulaSheet, name);
      } catch (NullPointerException ex) { /*input wrong cell reference will cause NPE or IllegalArgumentException*/
      } catch (IllegalArgumentException ex) {
      }
      if (rng == null)
        continue;
      int col = rng.getColumn();
      int row = rng.getRow();
      if (col >= maxCol || row >= maxRow ||
        (col == formulaColumn && row == formulaRow) ||
        (col == currentColumn && row == currentRow))
        continue;

      String color = FORMULA_COLORS[
                     (addedFocusNames.contains(FORMULA_FOCUS_NAME) ? addedFocusNames.size() - 1 : addedFocusNames.size()) % FORMULA_COLORS.length];
      newFocus.add(name);
      addedFocusNames.add(name);
      bookCtrl.moveEditorFocus(name, name, color, row, col);
    }
    if (startEditingFormula) {
      newFocus.add(FORMULA_FOCUS_NAME);
      addFormulaEditCellFocus();
    }
View Full Code Here

TOP

Related Classes of org.zkoss.zss.app.zul.ctrl.WorkbookCtrl

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.