예제 #1
0
  /**
   * Create Window Tabs
   *
   * @param mWindowVO Window Value Object
   * @return true if tabs were created
   */
  private static boolean createTabs(GridWindowVO mWindowVO) {
    mWindowVO.Tabs = new ArrayList<GridTabVO>();

    String sql = GridTabVO.getSQL(mWindowVO.ctx);
    int TabNo = 0;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      //	create statement
      pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, mWindowVO.AD_Window_ID);
      rs = pstmt.executeQuery();
      boolean firstTab = true;
      while (rs.next()) {
        if (mWindowVO.AD_Table_ID == 0) mWindowVO.AD_Table_ID = rs.getInt("AD_Table_ID");
        //  Create TabVO
        GridTabVO mTabVO =
            GridTabVO.create(
                mWindowVO,
                TabNo,
                rs,
                mWindowVO.WindowType.equals(WINDOWTYPE_QUERY), //  isRO
                mWindowVO.WindowType.equals(WINDOWTYPE_TRX)); //  onlyCurrentRows
        if (mTabVO == null && firstTab) break; // 	don't continue if first tab is null
        if (mTabVO != null) {
          if (!mTabVO.IsReadOnly && "N".equals(mWindowVO.IsReadWrite)) mTabVO.IsReadOnly = true;
          mWindowVO.Tabs.add(mTabVO);
          TabNo++; //  must be same as mWindow.getTab(x)
          firstTab = false;
        }
      }
    } catch (SQLException e) {
      CLogger.get().log(Level.SEVERE, "createTabs", e);
      return false;
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }

    //  No Tabs
    if (TabNo == 0 || mWindowVO.Tabs.size() == 0) {
      CLogger.get()
          .log(Level.SEVERE, "No Tabs - AD_Window_ID=" + mWindowVO.AD_Window_ID + " - " + sql);
      return false;
    }

    //	Put base table of window in ctx (for VDocAction)
    Env.setContext(mWindowVO.ctx, mWindowVO.WindowNo, "BaseTable_ID", mWindowVO.AD_Table_ID);
    return true;
  } //  createTabs
예제 #2
0
  /**
   * Get matching MUserDefField related to current field and user definition for window and tab
   *
   * @param ctx
   * @param AD_Field_ID
   * @param AD_Tab_ID
   * @param AD_Window_ID
   * @return
   */
  public static MUserDefField get(
      Properties ctx, int AD_Field_ID, int AD_Tab_ID, int AD_Window_ID) {

    MUserDefWin userdefWin = MUserDefWin.getBestMatch(ctx, AD_Window_ID);
    if (userdefWin == null) return null;
    MUserDefTab userdefTab =
        MUserDefTab.getMatch(ctx, AD_Tab_ID, userdefWin.getAD_UserDef_Win_ID());
    if (userdefTab == null) return null;

    MUserDefField retValue = null;

    StringBuilder sql =
        new StringBuilder(
            "SELECT * "
                + " FROM AD_UserDef_Field f "
                + " WHERE f.AD_Field_ID=? AND f.IsActive='Y' "
                + " AND f.AD_UserDef_Tab_ID=? ");

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      //	create statement
      pstmt = DB.prepareStatement(sql.toString(), null);
      pstmt.setInt(1, AD_Field_ID);
      pstmt.setInt(2, userdefTab.getAD_UserDef_Tab_ID());
      // 	get data
      rs = pstmt.executeQuery();
      if (rs.next()) {
        retValue = new MUserDefField(ctx, rs, null);
      }
    } catch (SQLException ex) {
      CLogger.get().log(Level.SEVERE, sql.toString(), ex);
      return null;
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }

    return retValue;
  }
예제 #3
0
  /**
   * Create Window Value Object
   *
   * @param ctx context
   * @param WindowNo window no for ctx
   * @param AD_Window_ID window id
   * @param AD_Menu_ID menu id
   * @return MWindowVO
   */
  public static GridWindowVO create(
      Properties ctx, int WindowNo, int AD_Window_ID, int AD_Menu_ID) {
    CLogger.get()
        .config("#" + WindowNo + " - AD_Window_ID=" + AD_Window_ID + "; AD_Menu_ID=" + AD_Menu_ID);
    GridWindowVO vo = new GridWindowVO(ctx, WindowNo);
    vo.AD_Window_ID = AD_Window_ID;

    //  Get Window_ID if required	- (used by HTML UI)
    if (vo.AD_Window_ID == 0 && AD_Menu_ID != 0) {
      String sql =
          "SELECT AD_Window_ID, IsSOTrx, IsReadOnly FROM AD_Menu "
              + "WHERE AD_Menu_ID=? AND Action='W'";
      PreparedStatement pstmt = null;
      ResultSet rs = null;
      try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_Menu_ID);
        rs = pstmt.executeQuery();
        if (rs.next()) {
          vo.AD_Window_ID = rs.getInt(1);
          String IsSOTrx = rs.getString(2);
          Env.setContext(ctx, WindowNo, "IsSOTrx", (IsSOTrx != null && IsSOTrx.equals("Y")));
          //
          String IsReadOnly = rs.getString(3);
          if (IsReadOnly != null && IsReadOnly.equals("Y")) vo.IsReadWrite = "Y";
          else vo.IsReadWrite = "N";
        }
      } catch (SQLException e) {
        CLogger.get().log(Level.SEVERE, "Menu", e);
        return null;
      } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
      }
      CLogger.get().config("AD_Window_ID=" + vo.AD_Window_ID);
    }

    //  --  Get Window

    StringBuffer sql =
        new StringBuffer(
            "SELECT Name,Description,Help,WindowType, "
                + "AD_Color_ID,AD_Image_ID,WinHeight,WinWidth, "
                + "IsSOTrx, AD_Window_UU ");

    if (Env.isBaseLanguage(vo.ctx, "AD_Window"))
      sql.append("FROM AD_Window w WHERE w.AD_Window_ID=? AND w.IsActive='Y'");
    else
      sql.append("FROM AD_Window_vt w WHERE w.AD_Window_ID=?")
          .append(" AND AD_Language='")
          .append(Env.getAD_Language(vo.ctx))
          .append("'");

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      //	create statement
      pstmt = DB.prepareStatement(sql.toString(), null);
      pstmt.setInt(1, vo.AD_Window_ID);
      // 	get data
      rs = pstmt.executeQuery();
      if (rs.next()) {
        vo.Name = rs.getString(1);
        vo.Description = rs.getString(2);
        if (vo.Description == null) vo.Description = "";
        vo.Help = rs.getString(3);
        if (vo.Help == null) vo.Help = "";
        vo.WindowType = rs.getString(4);
        //
        vo.AD_Color_ID = rs.getInt(5);
        vo.AD_Image_ID = rs.getInt(6);
        // vo.IsReadWrite = rs.getString(7);
        //
        vo.WinHeight = rs.getInt(7);
        vo.WinWidth = rs.getInt(8);
        //
        vo.IsSOTrx = "Y".equals(rs.getString(9));
        vo.AD_Window_UU = rs.getString(10);
      } else vo = null;
    } catch (SQLException ex) {
      CLogger.get().log(Level.SEVERE, sql.toString(), ex);
      return null;
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }
    // Ensure ASP exceptions
    MRole role = MRole.getDefault(ctx, false);
    final Boolean windowAccess = vo != null ? role.getWindowAccess(vo.AD_Window_ID) : null;
    if (vo != null && windowAccess == null) vo = null; // 	Not found
    if (vo != null && windowAccess != null)
      vo.IsReadWrite = (windowAccess.booleanValue() ? "Y" : "N");
    if (vo == null) {
      CLogger.get()
          .log(
              Level.SEVERE,
              "No Window - AD_Window_ID=" + AD_Window_ID + ", AD_Role_ID=" + role + " - " + sql);
      CLogger.get().saveError("AccessTableNoView", "(Not found)");
      return null;
    }
    //	Read Write
    if (vo.IsReadWrite == null) {
      CLogger.get().saveError("AccessTableNoView", "(found)");
      return null;
    }

    // FR IDEMPIERE-177
    // User Customization
    MUserDefWin userDef = MUserDefWin.getBestMatch(ctx, AD_Window_ID);
    if (userDef != null) {
      if (userDef.getName() != null) vo.Name = userDef.getName();
      if (userDef.getDescription() != null) vo.Description = userDef.getDescription();
      if (userDef.getHelp() != null) vo.Help = userDef.getHelp();
      // ToDo userDef.isDefault, userDef.isReadOnly, userDef.isUserUpdateable
    }

    //  Create Tabs
    createTabs(vo);
    if (vo.Tabs == null || vo.Tabs.size() == 0) return null;

    return vo;
  } //  create