コード例 #1
0
ファイル: StatusBar.java プロジェクト: makezjdq/adempiere-1
 /**
  * Show WHO
  *
  * @param e event
  */
 void mouseClicked(MouseEvent e) {
   if (m_dse == null || m_dse.CreatedBy == null || !MRole.getDefault().isShowPreference()) return;
   //
   String title = Msg.getMsg(Env.getCtx(), "Who") + m_text;
   RecordInfo info = new RecordInfo(Env.getFrame(this), title, m_dse);
   AEnv.showCenterScreen(info);
 } //	addStatusComponent
コード例 #2
0
  void dynDepartament() {
    KeyNamePair cat = (KeyNamePair) categoryCombo.getSelectedItem();
    departmentCombo.removeActionListener(this);
    departmentCombo.removeAllItems();

    String sql = "SELECT XX_VMR_DEPARTMENT_ID, VALUE||'-'||NAME " + " FROM XX_VMR_DEPARTMENT ";

    if (cat != null && cat.getKey() != -1) {
      sql += " WHERE XX_VMR_CATEGORY_ID = " + cat.getKey();
    }
    sql += " ORDER BY VALUE||'-'||NAME ";
    sql = MRole.getDefault().addAccessSQL(sql, "", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      rs = pstmt.executeQuery();

      departmentCombo.addItem(new KeyNamePair(-1, null));
      while (rs.next()) {
        departmentCombo.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
      }
      rs.close();
      pstmt.close();

      departmentCombo.addActionListener(this);
      departmentCombo.setEnabled(true);
      departmentCombo.setEditable(true);
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
  }
コード例 #3
0
  /** Fill Picks with values */
  private void fillPicks() {
    //	Price List
    String sql =
        "SELECT M_PriceList_Version.M_PriceList_Version_ID,"
            + " M_PriceList_Version.Name || ' (' || c.Iso_Code || ')' AS ValueName "
            + "FROM M_PriceList_Version, M_PriceList pl, C_Currency c "
            + "WHERE M_PriceList_Version.M_PriceList_ID=pl.M_PriceList_ID"
            + " AND pl.C_Currency_ID=c.C_Currency_ID"
            + " AND M_PriceList_Version.IsActive='Y' AND pl.IsActive='Y'";
    //	Add Access & Order
    sql =
        MRole.getDefault()
                .addAccessSQL(sql, "M_PriceList_Version", true, false) // fully qualidfied - RO
            + " ORDER BY M_PriceList_Version.Name";
    try {
      pickPriceList.addItem(new KeyNamePair(0, ""));
      PreparedStatement pstmt = DB.prepareStatement(sql, null);
      ResultSet rs = pstmt.executeQuery();
      while (rs.next()) {
        KeyNamePair kn = new KeyNamePair(rs.getInt(1), rs.getString(2));
        pickPriceList.addItem(kn);
      }
      rs.close();
      pstmt.close();

      //	Warehouse
      sql =
          "SELECT M_Warehouse_ID, Value || ' - ' || Name AS ValueName "
              + "FROM M_Warehouse "
              + "WHERE IsActive='Y'";
      sql =
          MRole.getDefault().addAccessSQL(sql, "M_Warehouse", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO)
              + " ORDER BY Value";
      pickWarehouse.addItem(new KeyNamePair(0, ""));
      pstmt = DB.prepareStatement(sql, null);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        KeyNamePair kn = new KeyNamePair(rs.getInt("M_Warehouse_ID"), rs.getString("ValueName"));
        pickWarehouse.addItem(kn);
      }
      rs.close();
      pstmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    }
  } //	fillPicks
コード例 #4
0
ファイル: VNumber.java プロジェクト: kimhatrung/Adempiere
  /**
   * Set Field/WindowNo for ValuePreference
   *
   * @param mField field
   */
  public void setField(GridField mField) {
    m_mField = mField;

    if (m_mField != null && MRole.getDefault().isShowPreference())
      ValuePreference.addMenu(this, popupMenu);

    if (m_mField != null) FieldRecordInfo.addMenu(this, popupMenu);
  } //  setField
コード例 #5
0
ファイル: GwtServer.java プロジェクト: WilkerDiaz/Compiere
 /** Finalize. Remove Role */
 @Override
 protected void finalize() throws Throwable {
   if (m_context != null) {
     int gwtServerID = m_context.getContextAsInt(MRole.GWTSERVERID);
     if (gwtServerID > 0) MRole.resetGwt(gwtServerID);
   }
   super.finalize();
 } // finalize
コード例 #6
0
 /**
  * Execute Drill to Query
  *
  * @param query query
  */
 private void executeDrill(MQuery query) {
   int AD_Table_ID = MTable.getTable_ID(query.getTableName());
   if (!MRole.getDefault().isCanReport(AD_Table_ID)) {
     FDialog.error(0, null, "AccessCannotReport", query.getTableName());
     return;
   }
   if (AD_Table_ID != 0) new WReport(AD_Table_ID, query);
 } //	executeDrill
コード例 #7
0
ファイル: WWFActivity.java プロジェクト: makezjdq/adempiere-1
  /**
   * Get active activities count
   *
   * @return int
   */
  public int getActivitiesCount() {
    int count = 0;

    String sql =
        "SELECT count(*) FROM AD_WF_Activity a "
            + "WHERE a.Processed='N' AND a.WFState='OS' AND ("
            //	Owner of Activity
            + " a.AD_User_ID=?" //	#1
            //	Invoker (if no invoker = all)
            + " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
            + " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" //	#2
            // Responsible User
            + " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
            + " AND r.AD_User_ID=?)" //	#3
            //	Responsible Role
            + " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
            + " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?))"; //	#4
    //
    // + ") ORDER BY a.Priority DESC, Created";
    int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
    MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
    sql = role.addAccessSQL(sql, "a", true, false);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, AD_User_ID);
      pstmt.setInt(2, AD_User_ID);
      pstmt.setInt(3, AD_User_ID);
      pstmt.setInt(4, AD_User_ID);
      rs = pstmt.executeQuery();
      if (rs.next()) {
        count = rs.getInt(1);
      }
    } catch (Exception e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }

    return count;
  }
コード例 #8
0
 public KeyNamePair[] getTreeData() {
   return DB.getKeyNamePairs(
       MRole.getDefault()
           .addAccessSQL(
               "SELECT AD_Tree_ID, Name FROM AD_Tree WHERE IsActive='Y' AND TreeType NOT IN ('BB','PC') ORDER BY 2",
               "AD_Tree",
               MRole.SQL_NOTQUALIFIED,
               MRole.SQL_RW),
       false);
 }
コード例 #9
0
ファイル: GwtServer.java プロジェクト: WilkerDiaz/Compiere
 /**
  * Execute Query for Tab
  *
  * @param AD_Tab_ID tab
  * @param queryVO optional query
  * @param context record context for link columns and other variables
  * @param queryResultID stored query identifier provided by client
  * @return number of records or -1 if error
  */
 public int executeQuery(
     int AD_Tab_ID, QueryVO queryVO, HashMap<String, String> context, int queryResultID) {
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return -1;
   }
   ArrayList<String[]> result = tab.executeQueryString(queryVO, context, m_context);
   if (result == null) {
     log.config("Not Result for AD_Tab_ID=" + AD_Tab_ID);
     return -1;
   }
   MRole role = getRole();
   // return -1 to indicate query exceeds
   if (role.isQueryMax(result.size())) {
     m_results.put(queryResultID, new ArrayList<String[]>());
     return -1;
   }
   m_results.put(queryResultID, result);
   return result.size();
 } // executeQuery
コード例 #10
0
  /** Obtiene todos los almacenes disponibles */
  private void getAllStores() {

    String sql = "SELECT M_Warehouse_ID FROM M_WAREHOUSE";
    sql = MRole.getDefault().addAccessSQL(sql, "", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    PreparedStatement prst = DB.prepareStatement(sql, null);
    try {
      ResultSet rs = prst.executeQuery();
      while (rs.next()) {
        MWarehouse store = new MWarehouse(Env.getCtx(), rs.getInt(1), null);
        stores.add(store);
      }
      rs.close();
      prst.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, e.getMessage());
    }
  }
コード例 #11
0
  /**
   * Fill the table using m_sql
   *
   * @param table table
   */
  private static void tableLoad(MiniTable table) {
    //	log.finest(m_sql + " - " +  m_groupBy);
    String sql =
        MRole.getDefault()
                .addAccessSQL(m_sql.toString(), "tab", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO)
            + m_groupBy
            + m_orderBy;

    log.finest(sql);
    try {
      Statement stmt = DB.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      table.loadTable(rs);
      stmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    }
  } //  tableLoad
コード例 #12
0
  private void llenarcombos() {
    dynCategory();
    dynDepartament();

    // Cargar el combo box de mes
    monthCombo.addItem(null);
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_January"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_February"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_March"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_April"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_May"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_June"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_July"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_August"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_September"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_October"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_November"));
    monthCombo.addItem(Msg.translate(Env.getCtx(), "XX_December"));

    // Cargar proveedores
    String sql = "SELECT b.C_BPARTNER_ID, b.NAME FROM C_BPARTNER b WHERE isVendor='Y' ";
    sql = MRole.getDefault().addAccessSQL(sql, "b", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
    sql += " ORDER BY b.NAME";
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    try {
      pstmt = DB.prepareStatement(sql, null);
      rs = pstmt.executeQuery();
      loadKNP = new KeyNamePair(0, new String());
      comboBPartner.addItem(loadKNP);
      while (rs.next()) {
        loadKNP = new KeyNamePair(rs.getInt(1), rs.getString(2));
        comboBPartner.addItem(loadKNP);
        // comboBPartner.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
      }
      comboBPartner.setEditable(false);
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
  } // fin de llenar combos
コード例 #13
0
ファイル: WFileImport.java プロジェクト: makezjdq/adempiere-1
  /** Dynamic Init */
  private void dynInit() {
    //	Load Formats
    pickFormat.appendItem(s_none, s_none);

    String sql =
        MRole.getDefault()
            .addAccessSQL(
                "SELECT Name FROM AD_ImpFormat",
                "AD_ImpFormat",
                MRole.SQL_FULLYQUALIFIED,
                MRole.SQL_RO);
    try {
      PreparedStatement pstmt = DB.prepareStatement(sql, null);
      ResultSet rs = pstmt.executeQuery();

      while (rs.next()) pickFormat.appendItem(rs.getString(1), rs.getString(1));

      rs.close();
      pstmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    }

    pickFormat.setSelectedIndex(0);
    pickFormat.addEventListener(Events.ON_SELECT, this);

    Charset charset = Ini.getCharset();

    for (int i = 0; i < fCharset.getItemCount(); i++) {
      ListItem listitem = fCharset.getItemAtIndex(i);
      Charset compare = (Charset) listitem.getValue();

      if (charset == compare) {
        fCharset.setSelectedIndex(i);
        break;
      }
    }

    fCharset.addEventListener(Events.ON_SELECT, this);

    confirmPanel.setEnabled("Ok", false);
  } //	dynInit
コード例 #14
0
ファイル: VNumber.java プロジェクト: kimhatrung/Adempiere
  /**
   * ************************************************************************ Action Listener
   *
   * @param e event
   */
  public void actionPerformed(ActionEvent e) {
    log.config(e.getActionCommand());
    if (ValuePreference.NAME.equals(e.getActionCommand())) {
      if (MRole.getDefault().isShowPreference()) ValuePreference.start(m_mField, getValue());
      return;
    } else if (e.getActionCommand().equals(FieldRecordInfo.CHANGE_LOG_COMMAND)) {
      FieldRecordInfo.start(m_mField);
      return;
    }

    if (e.getSource() == m_button) {
      m_button.setEnabled(false);
      String str = startCalculator(this, m_text.getText(), m_format, m_displayType, m_title, ' ');
      m_text.setText(str);
      m_button.setEnabled(true);
      try {
        fireVetoableChange(m_columnName, m_oldText, getValue());
      } catch (PropertyVetoException pve) {
      }
      m_text.requestFocus();
    }
  } //	actionPerformed
コード例 #15
0
ファイル: MyValidator.java プロジェクト: xinliuswie/idempiere
  /**
   * Sample Validator BefoMRolere Save Properties - to set mandatory properties on users avoid users
   * changing properties
   */
  public void beforeSaveProperties() {
    // not for SuperUser or role SysAdmin
    if (m_AD_User_ID == 0 // System
        || m_AD_User_ID == 100 // SuperUser
        || m_AD_Role_ID == 0) // System Administrator
    return;

    log.info("Setting default Properties");

    @SuppressWarnings("unused")
    MRole role = MRole.get(Env.getCtx(), m_AD_Role_ID);

    // Example - if you don't want user to select auto commit property
    // Ini.setProperty(Ini.P_A_COMMIT, false);

    // Example - if you don't want user to select auto login
    // Ini.setProperty(Ini.P_A_LOGIN, false);

    // Example - if you don't want user to select store password
    // Ini.setProperty(Ini.P_STORE_PWD, false);

    // Example - if you want your user inherit ALWAYS the show accounting from role
    // Ini.setProperty(Ini.P_SHOW_ACCT, role.isShowAcct());

    // Example - if you want to avoid your user from changing the working date
    /*
    Timestamp DEFAULT_TODAY =	new Timestamp(System.currentTimeMillis());
    //  Date (remove seconds)
    DEFAULT_TODAY.setHours(0);
    DEFAULT_TODAY.setMinutes(0);
    DEFAULT_TODAY.setSeconds(0);
    DEFAULT_TODAY.setNanos(0);
    Ini.setProperty(Ini.P_TODAY, DEFAULT_TODAY.toString());
    Env.setContext(Env.getCtx(), "#Date", DEFAULT_TODAY);
    */

  } // beforeSaveProperties
コード例 #16
0
ファイル: GwtServer.java プロジェクト: WilkerDiaz/Compiere
  /**
   * Logout
   *
   * @param expired expire
   */
  public void logout(boolean expired) {

    // End Session
    MSession session = MSession.get(m_context); // finish
    if (session != null) {
      if (expired) {
        if (session.getDescription() == null) session.setDescription("Expired");
        else session.setDescription(session.getDescription() + " Expired");
      }
      session.logout(); // saves
    }
    if (m_context != null) {
      int gwtServerID = m_context.getContextAsInt(MRole.GWTSERVERID);
      if (gwtServerID > 0) MRole.resetGwt(gwtServerID);
    }
    // Clear Cache
    m_tabs.clear();
    m_fields.clear();
    // m_windows.clear();
    m_context.clear();
    m_results.clear();
    //

  } // logout
コード例 #17
0
 /**
  * ************************************************************************ Load Resources. called
  * from variable constructor
  *
  * @return Array with resources
  */
 private KeyNamePair[] getResources() {
   if (m_lookup.size() == 0) {
     String sql =
         MRole.getDefault()
             .addAccessSQL(
                 "SELECT r.S_Resource_ID, r.Name, r.IsActive," //	1..3
                     + "uom.C_UOM_ID,uom.UOMSymbol " //	4..5
                     + "FROM S_Resource r, S_ResourceType rt, C_UOM uom "
                     + "WHERE r.S_ResourceType_ID=rt.S_ResourceType_ID AND rt.C_UOM_ID=uom.C_UOM_ID",
                 "r",
                 MRole.SQL_FULLYQUALIFIED,
                 MRole.SQL_RO);
     try {
       PreparedStatement pstmt = DB.prepareStatement(sql, null);
       ResultSet rs = pstmt.executeQuery();
       while (rs.next()) {
         StringBuffer sb = new StringBuffer(rs.getString(2));
         if (!"Y".equals(rs.getString(3))) sb.insert(0, '~').append('~'); // 	inactive marker
         //	Key		S_Resource_ID/Name
         KeyNamePair key = new KeyNamePair(rs.getInt(1), sb.toString());
         //	Value	C_UOM_ID/Name
         KeyNamePair value = new KeyNamePair(rs.getInt(4), rs.getString(5).trim());
         m_lookup.put(key, value);
       }
       rs.close();
       pstmt.close();
     } catch (SQLException e) {
       log.log(Level.SEVERE, sql, e);
     }
   }
   //	Convert to Array
   KeyNamePair[] retValue = new KeyNamePair[m_lookup.size()];
   m_lookup.keySet().toArray(retValue);
   Arrays.sort(retValue);
   return retValue;
 } //	getResources
コード例 #18
0
  // Datos
  void dynCategory() {

    categoryCombo.removeActionListener(this);
    String sql = "SELECT XX_VMR_CATEGORY_ID, VALUE||'-'||NAME " + " FROM XX_VMR_CATEGORY ";
    sql += " ORDER BY VALUE||'-'||NAME ";
    sql = MRole.getDefault().addAccessSQL(sql, "", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      rs = pstmt.executeQuery();

      categoryCombo.addItem(new KeyNamePair(-1, null));
      while (rs.next()) {
        categoryCombo.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
      }
      categoryCombo.addActionListener(this);
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
  }
コード例 #19
0
ファイル: InfoProduct.java プロジェクト: ecartago/opensixen
  /**
   * Fill Picks with values
   *
   * @param M_PriceList_ID price list
   */
  private void fillPicks(int M_PriceList_ID) {
    //	Price List
    String SQL =
        "SELECT M_PriceList_Version.M_PriceList_Version_ID,"
            + " M_PriceList_Version.Name || ' (' || c.Iso_Code || ')' AS ValueName "
            + "FROM M_PriceList_Version, M_PriceList pl, C_Currency c "
            + "WHERE M_PriceList_Version.M_PriceList_ID=pl.M_PriceList_ID"
            + " AND pl.C_Currency_ID=c.C_Currency_ID"
            + " AND M_PriceList_Version.IsActive='Y' AND pl.IsActive='Y'";
    //	Same PL currency as original one
    if (M_PriceList_ID != 0)
      SQL +=
          " AND EXISTS (SELECT * FROM M_PriceList xp WHERE xp.M_PriceList_ID="
              + M_PriceList_ID
              + " AND pl.C_Currency_ID=xp.C_Currency_ID)";
    //	Add Access & Order
    SQL =
        MRole.getDefault()
                .addAccessSQL(SQL, "M_PriceList_Version", true, false) // fully qualified - RO
            + " ORDER BY M_PriceList_Version.Name";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pickPriceList.addItem(new KeyNamePair(0, ""));
      pstmt = DB.prepareStatement(SQL, null);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        KeyNamePair kn = new KeyNamePair(rs.getInt(1), rs.getString(2));
        pickPriceList.addItem(kn);
      }
      DB.close(rs, pstmt);

      //	Warehouse
      SQL =
          MRole.getDefault()
                  .addAccessSQL(
                      "SELECT M_Warehouse_ID, Value || ' - ' || Name AS ValueName "
                          + "FROM M_Warehouse "
                          + "WHERE IsActive='Y'",
                      "M_Warehouse",
                      MRole.SQL_NOTQUALIFIED,
                      MRole.SQL_RO)
              + " ORDER BY Value";
      pickWarehouse.addItem(new KeyNamePair(0, ""));
      pstmt = DB.prepareStatement(SQL, null);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        KeyNamePair kn = new KeyNamePair(rs.getInt("M_Warehouse_ID"), rs.getString("ValueName"));
        pickWarehouse.addItem(kn);
      }
      DB.close(rs, pstmt);

      //	Product Category
      SQL =
          MRole.getDefault()
                  .addAccessSQL(
                      "SELECT M_Product_Category_ID, Value || ' - ' || Name FROM M_Product_Category WHERE IsActive='Y'",
                      "M_Product_Category",
                      MRole.SQL_NOTQUALIFIED,
                      MRole.SQL_RO)
              + " ORDER BY Value";
      for (KeyNamePair kn : DB.getKeyNamePairs(SQL, true)) {
        pickProductCategory.addItem(kn);
      }

      // Attribute Set - @Trifon
      SQL =
          MRole.getDefault()
                  .addAccessSQL(
                      "SELECT M_AttributeSet_ID, Name FROM M_AttributeSet WHERE IsActive='Y'",
                      "M_AttributeSet",
                      MRole.SQL_NOTQUALIFIED,
                      MRole.SQL_RO)
              + " ORDER BY Name";
      for (KeyNamePair kn : DB.getKeyNamePairs(SQL, true)) {
        pickAS.addItem(kn);
      }
    } catch (SQLException e) {
      log.log(Level.SEVERE, SQL, e);
      setStatusLine(e.getLocalizedMessage(), true);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }
  } //	fillPicks
コード例 #20
0
ファイル: WWFActivity.java プロジェクト: makezjdq/adempiere-1
  /**
   * Load Activities
   *
   * @return int
   */
  public int loadActivities() {
    long start = System.currentTimeMillis();

    int MAX_ACTIVITIES_IN_LIST =
        MSysConfig.getIntValue("MAX_ACTIVITIES_IN_LIST", 200, Env.getAD_Client_ID(Env.getCtx()));

    model = new ListModelTable();

    ArrayList<MWFActivity> list = new ArrayList<MWFActivity>();
    String sql =
        "SELECT * FROM AD_WF_Activity a "
            + "WHERE a.Processed='N' AND a.WFState='OS' AND ("
            //	Owner of Activity
            + " a.AD_User_ID=?" //	#1
            //	Invoker (if no invoker = all)
            + " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
            + " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" //	#2
            // Responsible User
            + " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
            + " AND r.AD_User_ID=?)" //	#3
            //	Responsible Role
            + " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
            + " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?)" //	#4
            //
            + ") ORDER BY a.Priority DESC, Created";
    int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
    MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
    sql = role.addAccessSQL(sql, "a", true, false);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, AD_User_ID);
      pstmt.setInt(2, AD_User_ID);
      pstmt.setInt(3, AD_User_ID);
      pstmt.setInt(4, AD_User_ID);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        MWFActivity activity = new MWFActivity(Env.getCtx(), rs, null);
        list.add(activity);
        List<Object> rowData = new ArrayList<Object>();
        rowData.add(activity.getPriority());
        rowData.add(activity.getNodeName());
        rowData.add(activity.getSummary());
        model.add(rowData);
        if (list.size() > MAX_ACTIVITIES_IN_LIST && MAX_ACTIVITIES_IN_LIST > 0) {
          log.warning("More then 200 Activities - ignored");
          break;
        }
      }
    } catch (Exception e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }
    m_activities = new MWFActivity[list.size()];
    list.toArray(m_activities);
    //
    log.fine("#" + m_activities.length + "(" + (System.currentTimeMillis() - start) + "ms)");
    m_index = 0;

    String[] columns =
        new String[] {
          Msg.translate(Env.getCtx(), "Priority"),
          Msg.translate(Env.getCtx(), "AD_WF_Node_ID"),
          Msg.translate(Env.getCtx(), "Summary")
        };

    WListItemRenderer renderer = new WListItemRenderer(Arrays.asList(columns));
    ListHeader header = new ListHeader();
    header.setWidth("30px");
    renderer.setListHeader(0, header);
    renderer.addTableValueChangeListener(listbox);
    model.setNoColumns(columns.length);
    listbox.setModel(model);
    listbox.setItemRenderer(renderer);
    listbox.repaint();
    listbox.setFixedLayout(true);

    return m_activities.length;
  } //	loadActivities
コード例 #21
0
  public ArrayList<ListItem> getTreeItemData() {
    ArrayList<ListItem> data = new ArrayList<ListItem>();

    String fromClause = m_tree.getSourceTableName(false); // 	fully qualified
    String columnNameX = m_tree.getSourceTableName(true);
    String actionColor = m_tree.getActionColorName();
    String fieldName = null;
    String fieldDescription = null;
    String join = null;
    if (m_tree
            .getTreeType()
            .equals(MTree.TREETYPE_Menu) // IDEMPIERE-1581 (see MTree.getNodeDetails)
        && !Env.isBaseLanguage(Env.getCtx(), "AD_Menu")) {
      fieldName = "trl.Name";
      fieldDescription = "trl.Description";
      join =
          " LEFT JOIN AD_Menu_Trl trl ON (t.AD_Menu_ID = trl.AD_Menu_ID AND trl.AD_Language='"
              + Env.getAD_Language(Env.getCtx())
              + "')";
    } else {
      fieldName = "t.Name";
      fieldDescription = "t.Description";
      join = "";
    }

    StringBuilder sqlb =
        new StringBuilder("SELECT t.")
            .append(columnNameX)
            .append("_ID,")
            .append(fieldName)
            .append(",")
            .append(fieldDescription)
            .append(",t.IsSummary,")
            .append(actionColor)
            .append(" FROM ")
            .append(fromClause)
            .append(join)
            //	.append(" WHERE t.IsActive='Y'") // R/O
            .append(" ORDER BY 2");
    String sql =
        MRole.getDefault()
            .addAccessSQL(sqlb.toString(), "t", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
    log.config(sql);
    //
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        ListItem item =
            new ListItem(
                rs.getInt(1),
                rs.getString(2),
                rs.getString(3),
                "Y".equals(rs.getString(4)),
                rs.getString(5));
        data.add(item);
      }
    } catch (Exception e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }

    return data;
  }
コード例 #22
0
  /**
   * Hit Enter in Text Field
   *
   * @param only_Warehouse_ID if not 0 restrict warehouse
   * @param only_Product_ID of not 0 restricted product
   * @return true if found
   */
  private boolean actionText(int only_Warehouse_ID, int only_Product_ID) {
    String text = getComponent().getText();
    log.fine(text);

    //	Null

    if (text == null || text.length() == 0) {
      if (isMandatory()) return false;
      else {
        setValue(null, true);
        return true;
      }
    }

    if (text.endsWith("%")) text = text.toUpperCase();
    else text = text.toUpperCase() + "%";

    //	Look up - see MLocatorLookup.run

    StringBuffer sql =
        new StringBuffer("SELECT M_Locator_ID FROM M_Locator ")
            .append(" WHERE IsActive='Y' AND UPPER(Value) LIKE ")
            .append(DB.TO_STRING(text));

    if (getOnly_Warehouse_ID() != 0) sql.append(" AND M_Warehouse_ID=?");

    if (getOnly_Product_ID() != 0)
      sql.append(" AND (IsDefault='Y' ") // 	Default Locator
          .append("OR EXISTS (SELECT * FROM M_Product p ") // 	Product Locator
          .append("WHERE p.M_Locator_ID=M_Locator.M_Locator_ID AND p.M_Product_ID=?)")
          .append("OR EXISTS (SELECT * FROM M_Storage s ") // 	Storage Locator
          .append("WHERE s.M_Locator_ID=M_Locator.M_Locator_ID AND s.M_Product_ID=?))");

    String finalSql =
        MRole.getDefault(Env.getCtx(), false)
            .addAccessSQL(sql.toString(), "M_Locator", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);

    int M_Locator_ID = 0;
    PreparedStatement pstmt = null;

    try {
      pstmt = DB.prepareStatement(finalSql, null);
      int index = 1;

      if (only_Warehouse_ID != 0) pstmt.setInt(index++, only_Warehouse_ID);

      if (only_Product_ID != 0) {
        pstmt.setInt(index++, only_Product_ID);
        pstmt.setInt(index++, only_Product_ID);
      }

      ResultSet rs = pstmt.executeQuery();

      if (rs.next()) {
        M_Locator_ID = rs.getInt(1);

        if (rs.next()) M_Locator_ID = 0; // 	more than one
      }
      rs.close();
      pstmt.close();
      pstmt = null;
    } catch (SQLException ex) {
      log.log(Level.SEVERE, finalSql, ex);
    }

    try {
      if (pstmt != null) pstmt.close();
    } catch (SQLException ex1) {
    }

    pstmt = null;

    if (M_Locator_ID == 0) return false;

    setValue(new Integer(M_Locator_ID), true);
    return true;
  } // actionText
コード例 #23
0
  /**
   * Get Grid Element
   *
   * @param xValue X value
   * @param yValue Y value
   * @return Panel with Info
   */
  private CPanel getGridElement(MAttributeValue xValue, MAttributeValue yValue) {
    CPanel element = new CPanel();
    element.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
    element.setLayout(new BoxLayout(element, BoxLayout.Y_AXIS));

    String sql = "SELECT * FROM M_Product WHERE IsActive='Y'";
    //	Product Attributes
    if (xValue != null)
      sql +=
          " AND M_AttributeSetInstance_ID IN "
              + "(SELECT M_AttributeSetInstance_ID "
              + "FROM M_AttributeInstance "
              + "WHERE M_Attribute_ID="
              + xValue.getM_Attribute_ID()
              + " AND M_AttributeValue_ID="
              + xValue.getM_AttributeValue_ID()
              + ")";
    if (yValue != null)
      sql +=
          " AND M_AttributeSetInstance_ID IN "
              + "(SELECT M_AttributeSetInstance_ID "
              + "FROM M_AttributeInstance "
              + "WHERE M_Attribute_ID="
              + yValue.getM_Attribute_ID()
              + " AND M_AttributeValue_ID="
              + yValue.getM_AttributeValue_ID()
              + ")";
    sql = MRole.getDefault().addAccessSQL(sql, "M_Product", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    PreparedStatement pstmt = null;
    int noProducts = 0;
    try {
      pstmt = DB.prepareStatement(sql, null);
      ResultSet rs = pstmt.executeQuery();
      while (rs.next()) {
        MProduct product = new MProduct(Env.getCtx(), rs, null);
        addProduct(element, product);
        noProducts++;
      }
      rs.close();
      pstmt.close();
      pstmt = null;
    } catch (Exception e) {
      log.log(Level.SEVERE, sql, e);
    }
    try {
      if (pstmt != null) pstmt.close();
      pstmt = null;
    } catch (Exception e) {
      pstmt = null;
    }

    int mode = modeCombo.getSelectedIndex();
    //	No Products
    if (noProducts == 0 && mode == MODE_VIEW) {
      //	CButton button = ConfirmPanel.createNewButton(true);
      //	button.addActionListener(this);
      //	element.add(button);
    } else //	Additional Elements
    {
      if (mode == MODE_PRICE) {
        //	Price Field
      } else if (mode == MODE_PO) {
        //	Qty Field
      }
    }
    return element;
  } //	getGridElement