String mustFill = "reserved";
String str = getCurrentStatement(gKarEditorPanel1.getEditor().getCaretPosition());
boolean decide=false;
int caretPos = gKarEditorPanel1.getEditor().getCaretPosition();
while(!decide){
gKarSQLToken strText = getPrevToken(str,caretPos);
//dbg("search for <"+str+">:"+strText.getToken()+".");
if(words.indexOf(strText.getToken().toLowerCase())>=0){
decide = true;
str = strText.getToken().toLowerCase();
break;
}
if(strText.getToken()==null){
decide = true;
}
str = str.substring(0,strText.getStartPos());
caretPos = strText.getStartPos()-1;
}
if(str.equalsIgnoreCase("from")){
mustFill = "tables";
}
if(str.equalsIgnoreCase("select")||str.equalsIgnoreCase("where")){
mustFill = "columns";
}
String tables = "EC_REF_DATA";
if(mustFill.equalsIgnoreCase("tables")){
gKarSQLToken lex = getCurrentWord(gKarEditorPanel1.getEditor().getText(),gKarEditorPanel1.getEditor().getCaretPosition());
fillPopupItems(mustFill,lex.getToken(),"");
}
if(mustFill.equalsIgnoreCase("columns")){
str = getCurrentStatement(gKarEditorPanel1.getEditor().getCaretPosition()).toLowerCase();
int fromStart = str.indexOf(" from ");
int whereStart = str.indexOf(" where ");
if(whereStart<0){
whereStart = str.length();
}
tables = "'"+str.substring(fromStart+6,whereStart).toUpperCase().replace(" ","").replace(",","','")+"'";
fillPopupItems(mustFill,"",tables);
}
if(mustFill.equalsIgnoreCase("reserved")){
gKarSQLToken lex = getCurrentWord(gKarEditorPanel1.getEditor().getText(),gKarEditorPanel1.getEditor().getCaretPosition());
fillPopupItems(mustFill,lex.getToken(),"");
}
// popupMenu1.show(com,x,y);
}