//-- super --//
protected void process(AuRequest request) {
final Component comp = request.getComponent();
if (comp == null)
throw new UiException(MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this);
final String[] data = request.getData();
if (data == null || data.length != 20)
throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA,
new Object[] {Objects.toString(data), this});
_spreadsheet = ((Spreadsheet)comp);
if(_spreadsheet.isInvalidated()) return;//since it is invalidate, i don't need to update
_ctrl = ((SpreadsheetCtrl)_spreadsheet.getExtraCtrl());
_hidecolhead = _spreadsheet.isHidecolumnhead();
_hiderowhead = _spreadsheet.isHiderowhead();
String token = data[0];
String sheetId = data[1];
_rowHelper = _ctrl.getRowPositionHelper(sheetId);
_colHelper = _ctrl.getColumnPositionHelper(sheetId);
Sheet sheet = _spreadsheet.getSelectedSheet();
if(!Utils.getId(sheet).equals(sheetId)) return;
_mergeMatrix = _ctrl.getMergeMatrixHelper(sheet);
String type = data[2];
String direction = data[3];
int dpWidth = Integer.parseInt(data[4]);//pixel value of data panel width
int dpHeight = Integer.parseInt(data[5]);//pixel value of data panel height
int viewWidth = Integer.parseInt(data[6]);//pixel value of view width(scrollpanel.clientWidth)
int viewHeight = Integer.parseInt(data[7]);//pixel value of value height
int blockLeft = Integer.parseInt(data[8]);
int blockTop = Integer.parseInt(data[9]);
int blockRight = Integer.parseInt(data[10]);// + blockLeft - 1;
int blockBottom = Integer.parseInt(data[11]);// + blockTop - 1;;
int fetchLeft = Integer.parseInt(data[12]);
int fetchTop = Integer.parseInt(data[13]);
int fetchWidth = Integer.parseInt(data[14]);
int fetchHeight = Integer.parseInt(data[15]);
int rangeLeft = Integer.parseInt(data[16]);//visible range
int rangeTop = Integer.parseInt(data[17]);
int rangeRight = Integer.parseInt(data[18]);
int rangeBottom = Integer.parseInt(data[19]);
if(log.debugable()){
StringBuffer sb = new StringBuffer(1024);
sb.append("CellFetchCommand:"+direction+",type:"+type+",sheetId:"+sheetId).append("\n");
sb.append("\tdata panel size >>>>w:"+dpWidth+",h:"+dpHeight).append("\n");
sb.append("\tview size >>>>w:"+viewWidth+",h:"+viewHeight).append("\n");
sb.append("\tblock range >>>>left:"+blockLeft+",top:"+blockTop+",right:"+blockRight+",b:"+blockBottom).append("\n");
sb.append("\tfetch size >>>>left:"+fetchLeft+",top:"+fetchTop+",w:"+fetchWidth+",h:"+fetchHeight).append("\n");
sb.append("\tvisible range >>>>left:"+rangeLeft+",top:"+rangeTop+",right:"+rangeRight+",bottom:"+rangeBottom).append("\n");
log.debug(sb.toString());
}
long t1 = System.currentTimeMillis();
try{
if("jump".equals(type)){
String result = null;
if("east".equals(direction)){
result = jump("E",(Spreadsheet)comp,sheetId,sheet,type,dpWidth,dpHeight,viewWidth,viewHeight,blockLeft,blockTop,blockRight,blockBottom,fetchLeft,fetchTop,rangeLeft,rangeTop,rangeRight,rangeBottom);
}else if("south".equals(direction)){
result = jump("S",(Spreadsheet)comp,sheetId,sheet,type,dpWidth,dpHeight,viewWidth,viewHeight,blockLeft,blockTop,blockRight,blockBottom,fetchLeft,fetchTop,rangeLeft,rangeTop,rangeRight,rangeBottom);
}else if("west".equals(direction)){
result = jump("W",(Spreadsheet)comp,sheetId,sheet,type,dpWidth,dpHeight,viewWidth,viewHeight,blockLeft,blockTop,blockRight,blockBottom,fetchLeft,fetchTop,rangeLeft,rangeTop,rangeRight,rangeBottom);
}else if("north".equals(direction)){
result = jump("N",(Spreadsheet)comp,sheetId,sheet,type,dpWidth,dpHeight,viewWidth,viewHeight,blockLeft,blockTop,blockRight,blockBottom,fetchLeft,fetchTop,rangeLeft,rangeTop,rangeRight,rangeBottom);
}else if("westnorth".equals(direction)){
result = jump("WN",(Spreadsheet)comp,sheetId,sheet,type,dpWidth,dpHeight,viewWidth,viewHeight,blockLeft,blockTop,blockRight,blockBottom,fetchLeft,fetchTop,rangeLeft,rangeTop,rangeRight,rangeBottom);
}else if("eastnorth".equals(direction)){
result = jump("EN",(Spreadsheet)comp,sheetId,sheet,type,dpWidth,dpHeight,viewWidth,viewHeight,blockLeft,blockTop,blockRight,blockBottom,fetchLeft,fetchTop,rangeLeft,rangeTop,rangeRight,rangeBottom);
}else if("westsouth".equals(direction)){
result = jump("WS",(Spreadsheet)comp,sheetId,sheet,type,dpWidth,dpHeight,viewWidth,viewHeight,blockLeft,blockTop,blockRight,blockBottom,fetchLeft,fetchTop,rangeLeft,rangeTop,rangeRight,rangeBottom);
}else if("eastsouth".equals(direction)){
result = jump("ES",(Spreadsheet)comp,sheetId,sheet,type,dpWidth,dpHeight,viewWidth,viewHeight,blockLeft,blockTop,blockRight,blockBottom,fetchLeft,fetchTop,rangeLeft,rangeTop,rangeRight,rangeBottom);
}else{
throw new UiException("Unknow direction:"+direction);
}
responseDataBlock(token,sheetId,result);
}else if("neighbor".equals(type)){
if("east".equals(direction)){
int right = blockRight + fetchWidth ;//blockRight+ 1 + fetchWidth - 1;
right = _mergeMatrix.getRightConnectedColumn(right,blockTop,blockBottom);
int size = right - blockRight;//right - (blockRight +1) +1
String result = loadEast(sheet,type,blockLeft,blockTop,blockRight,blockBottom,size);
responseDataBlock(token,sheetId,result);
}else if("south".equals(direction)){
int bottom = blockBottom+fetchHeight;
//check right for new load south block
int right = _mergeMatrix.getRightConnectedColumn(blockRight,blockTop,bottom);
int left = _mergeMatrix.getLeftConnectedColumn(blockLeft,blockTop,bottom);
if(right>blockRight){
String result = loadEast(sheet,type,blockLeft,blockTop,blockRight,blockBottom,right-blockRight);
responseDataBlock("",sheetId,result);
}
if(left<blockLeft){
String result = loadWest(sheet,type,blockLeft,blockTop,right,blockBottom,blockLeft - left);
responseDataBlock("",sheetId,result);
}
String result = loadSouth(sheet,type,left,blockTop,right,blockBottom,fetchHeight);
responseDataBlock(token,sheetId,result);
}else if("west".equals(direction)){
int left = blockLeft - fetchWidth ;//blockLeft - 1 - fetchWidth + 1;
//System.out.println("fetch west 1:"+left);
left = _mergeMatrix.getLeftConnectedColumn(left,blockTop,blockBottom);
//System.out.println("fetch west 2:"+left);
int size = blockLeft - left ;//blockLeft -1 - left + 1;
String result = loadWest(sheet,type,blockLeft,blockTop,blockRight,blockBottom,size);
responseDataBlock(token,sheetId,result);
}else if("north".equals(direction)){
int top = blockTop-fetchHeight;
//check right-left for new load north block
int right = _mergeMatrix.getRightConnectedColumn(blockRight,top,blockBottom);
int left = _mergeMatrix.getLeftConnectedColumn(blockLeft,top,blockBottom);
if(right>blockRight){
String result = loadEast(sheet,type,blockLeft,blockTop,blockRight,blockBottom,right-blockRight);
responseDataBlock("",sheetId,result);
}
if(left<blockLeft){
String result = loadWest(sheet,type,blockLeft,blockTop,right,blockBottom,blockLeft - left);
responseDataBlock("",sheetId,result);
}
String result = loadNorth(sheet,type,left,blockTop,right,blockBottom,fetchHeight);
responseDataBlock(token,sheetId,result);
}
}else if("visible".equals(type)){
loadForVisible((Spreadsheet)comp,sheetId,sheet,type,dpWidth,dpHeight,viewWidth,viewHeight,blockLeft,blockTop,blockRight,blockBottom,rangeLeft,rangeTop,rangeRight,rangeBottom);
//always ack for call back
String ack = ackResult();
responseDataBlock(token,sheetId,ack);
}else{
//TODO use debug warning
log.warning("unknow type:"+type);
}
}catch(Throwable x){
responseDataBlock("",sheetId,ackError(x.getMessage()));
throw new UiException(x.getMessage(),x);
}
((SpreadsheetInCtrl)_ctrl).setLoadedRect(_lastleft,_lasttop,_lastright,_lastbottom);
long t2 = System.currentTimeMillis();
log.debug("time spent in fetch: "+(t2-t1) +" ms");