From c937785ed0f73d56175c2c984e2b724f4a0c4b51 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 14 Jan 2008 05:01:45 +0000 Subject: [PATCH] [ 1711633 ] Speedup for main panel - don't look activities every time --- client/src/org/compiere/apps/AMenu.java | 5 +- .../src/org/compiere/apps/wf/WFActivity.java | 56 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/client/src/org/compiere/apps/AMenu.java b/client/src/org/compiere/apps/AMenu.java index 1be8544e78..63427ecac5 100644 --- a/client/src/org/compiere/apps/AMenu.java +++ b/client/src/org/compiere/apps/AMenu.java @@ -658,7 +658,7 @@ public final class AMenu extends CFrame int notes = getNotes(); bNotes.setText(Msg.translate(m_ctx, "AD_Note_ID") + ": " + notes); // Activities - int activities = wfActivity.loadActivities(); + int activities = wfActivity.getActivitiesCount(); centerPane.setTitleAt(m_tabActivities, Msg.getMsg (m_ctx, "WorkflowActivities") + ": " + activities); // log.config(msg @@ -699,7 +699,10 @@ public final class AMenu extends CFrame //updateInfo(); // show activities if (centerPane.getSelectedIndex() == m_tabActivities) + { + wfActivity.loadActivities(); wfActivity.display(); + } } // stateChanged public WindowManager getWindowManager() { diff --git a/client/src/org/compiere/apps/wf/WFActivity.java b/client/src/org/compiere/apps/wf/WFActivity.java index b10b01cd5b..4d0141cb6a 100644 --- a/client/src/org/compiere/apps/wf/WFActivity.java +++ b/client/src/org/compiere/apps/wf/WFActivity.java @@ -261,7 +261,63 @@ public class WFActivity extends CPanel m_frame.dispose(); m_frame = null; } // dispose + + /** + * 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()); + PreparedStatement pstmt = 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); + ResultSet rs = pstmt.executeQuery (); + if (rs.next ()) { + count = rs.getInt(1); + } + rs.close(); + } + catch (Exception e) + { + log.log(Level.SEVERE, sql, e); + } + try + { + if (pstmt != null) + pstmt.close (); + pstmt = null; + } + catch (Exception e) + { + pstmt = null; + } + + return count; + + } /** * Load Activities