//Note. setSrcName will set spreadsheet's src name, but not the book name
// if setSrc will init a book, then setSrcName only change the src name,
// if setSrc again with the first same book, the book will register two listener
//spreadsheet.setSrcName("Untitled");
final DesktopWorkbenchContext workbenchContext = getDesktopWorkbenchContext();
workbenchContext.doTargetChange(new SSWorkbookCtrl(spreadsheet));
workbenchContext.setWorkbenchCtrl(this);
// if (!FileHelper.hasSavePermission())
// saveBtn.setVisible(false);
workbenchContext.addEventListener(Consts.ON_WORKBOOK_SAVED, new EventListener() {
public void onEvent(Event event) throws Exception {
if (!FileHelper.hasSavePermission())
return;
spreadsheet.setActionDisabled(true, Action.SAVE_BOOK);
}
});
workbenchContext.addEventListener(Consts.ON_WORKBOOK_CHANGED, new EventListener() {
public void onEvent(Event event) throws Exception {
boolean isOpen = spreadsheet.getBook() != null;
// toolbarMask.setVisible(!isOpen);
// closeBtn.setVisible(isOpen);
spreadsheet.setActionDisabled(true, Action.SAVE_BOOK);
// gridlinesCheckbox.setChecked(isOpen && spreadsheet.getSelectedSheet().isDisplayGridlines());
// protectSheet.setChecked(isOpen && spreadsheet.getSelectedSheet().getProtect());
// protectSheet.setDisabled(!isOpen);
//TODO: provide clip board interface, to allow save cut, copy, high light info
//use set setHighlight null can cancel selection, but need to re-store selection when select same sheet again
spreadsheet.setHighlight(null);
if (isOpen) {
getCellStyleContext().doTargetChange(
new SSRectCellStyle(Utils.getOrCreateCell(spreadsheet.getSelectedSheet(), 0, 0), spreadsheet));
// syncAutoFilterStatus();
}
}
});
workbenchContext.addEventListener(Consts.ON_SHEET_CONTENTS_CHANGED, new EventListener(){
public void onEvent(Event event) throws Exception {
doContentChanged();
}}
);
workbenchContext.addEventListener(Consts.ON_SHEET_INSERT_FORMULA, new EventListener() {
public void onEvent(Event event) throws Exception {
String formula = (String)event.getData();
Rect rect = spreadsheet.getSelection();
Range rng = Ranges.range(spreadsheet.getSelectedSheet(), rect.getTop(), rect.getLeft());
rng.setEditText(formula);
}
});
workbenchContext.getWorkbookCtrl().addBookEventListener(new EventListener() {
public void onEvent(Event event) throws Exception {
String evtName = event.getName();
if (evtName == SSDataEvent.ON_CONTENTS_CHANGE) {
doContentChanged();
}