private void cmd_save(boolean saveQuery){
  StringBuffer code=codeUserQuery();
  String name=fQueryName.getValue();
  if (name == null) {
    return;
  }
  if (name.equals(m_sNew) || name.equals(m_sLast) || name.equals(m_sTipText)|| Util.isEmpty(name,true)) {
  }
 else {
    MUserQuery uq=MUserQuery.get(Env.getCtx(),m_AD_Tab_ID,name);
    if (code.length() > 0) {
      if (uq == null) {
        uq=new MUserQuery(Env.getCtx(),0,null);
        uq.setName(name);
        uq.setAD_Table_ID(m_AD_Table_ID);
        uq.setAD_Tab_ID(m_AD_Tab_ID);
        uq.setAD_User_ID(Env.getAD_User_ID(Env.getCtx()));
      }
      uq.setCode(code.toString());
    }
 else     if (code.length() <= 0) {
      if (uq.delete(true)) {
        FDialog.info(m_targetWindowNo,this,"Deleted",name);
        refreshUserQueries();
      }
 else       FDialog.warn(m_targetWindowNo,this,"DeleteError",name);
      return;
    }
    if (uq.save()) {
      refreshUserQueries();
    }
 else     FDialog.warn(m_targetWindowNo,this,"SaveError",name);
  }
  if (saveQuery) {
    MUserQuery last=MUserQuery.get(Env.getCtx(),m_AD_Tab_ID,m_sLast);
    if (code.length() > 0) {
      if (last == null) {
        last=new MUserQuery(Env.getCtx(),0,null);
        last.setName(m_sLast);
        last.setAD_Table_ID(m_AD_Table_ID);
        last.setAD_Tab_ID(m_AD_Tab_ID);
        last.setAD_User_ID(Env.getAD_User_ID(Env.getCtx()));
      }
      last.setCode(code.toString());
    }
 else     if (code.length() <= 0) {
      if (last != null && !last.delete(true))       FDialog.warn(m_targetWindowNo,this,"DeleteError",name);
      return;
    }
    if (!last.save())     FDialog.warn(m_targetWindowNo,this,"SaveError",name);
  }
}

private void cmd_save ( boolean saveQuery ) { StringBuffer code = codeUserQuery ( ) ; String name = fQueryName . getValue ( ) ; if ( name == null ) { return ; } if ( name . equals ( m_sNew ) || name . equals ( m_sLast ) || name . equals ( m_sTipText ) || Util . isEmpty ( name , true ) ) { } else { MUserQuery uq = MUserQuery . get ( Env . getCtx ( ) , m_AD_Tab_ID , name ) ; if ( code . length ( ) > 0 ) { if ( uq == null ) { uq = new MUserQuery ( Env . getCtx ( ) , 0 , null ) ; uq . setName ( name ) ; uq . setAD_Table_ID ( m_AD_Table_ID ) ; uq . setAD_Tab_ID ( m_AD_Tab_ID ) ; uq . setAD_User_ID ( Env . getAD_User_ID ( Env . getCtx ( ) ) ) ; } uq . setCode ( code . toString ( ) ) ; } else if ( code . length ( ) <= 0 ) { if ( uq . delete ( true ) ) { FDialog . info ( m_targetWindowNo , this , "Deleted" , name ) ; refreshUserQueries ( ) ; } else FDialog . warn ( m_targetWindowNo , this , "DeleteError" , name ) ; return ; } if ( uq . save ( ) ) { refreshUserQueries ( ) ; } else FDialog . warn ( m_targetWindowNo , this , "SaveError" , name ) ; } if ( saveQuery ) { MUserQuery last = MUserQuery . get ( Env . getCtx ( ) , m_AD_Tab_ID , m_sLast ) ; if ( code . length ( ) > 0 ) { if ( last == null ) { last = new MUserQuery ( Env . getCtx ( ) , 0 , null ) ; last . setName ( m_sLast ) ; last . setAD_Table_ID ( m_AD_Table_ID ) ; last . setAD_Tab_ID ( m_AD_Tab_ID ) ; last . setAD_User_ID ( Env . getAD_User_ID ( Env . getCtx ( ) ) ) ; } last . setCode ( code . toString ( ) ) ; } else if ( code . length ( ) <= 0 ) { if ( last != null && ! last . delete ( true ) ) FDialog . warn ( m_targetWindowNo , this , "DeleteError" , name ) ; return ; } if ( ! last . save ( ) ) FDialog . warn ( m_targetWindowNo , this , "SaveError" , name ) ; } }
save the advanced query in the database using the query name . if the query name is set , the query will be updated or a new query saved .
