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