IDEMPIERE-530 improve performance to enable attachments and chat buttons (Thanks to Juliana Corredor)
This commit is contained in:
parent
2e5fb7c33f
commit
565b5b0dca
|
@ -0,0 +1,6 @@
|
|||
CREATE UNIQUE INDEX cm_chat_record ON cm_chat (ad_table_id, record_id);
|
||||
|
||||
|
||||
SELECT register_migration_script('201212131100_IDEMPIERE-530.sql') FROM dual
|
||||
;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
CREATE UNIQUE INDEX cm_chat_record ON cm_chat (ad_table_id, record_id);
|
||||
|
||||
|
||||
SELECT register_migration_script('201212131100_IDEMPIERE-530.sql') FROM dual
|
||||
;
|
||||
|
|
@ -28,7 +28,6 @@ import java.sql.SQLException;
|
|||
import java.sql.Timestamp;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
@ -111,7 +110,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 336562925897569888L;
|
||||
private static final long serialVersionUID = -1638364577972806113L;
|
||||
|
||||
public static final String DEFAULT_STATUS_MESSAGE = "NavigateOrUpdate";
|
||||
|
||||
|
@ -163,10 +162,6 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
|||
|
||||
private String m_parentColumnName = "";
|
||||
private String m_extendedWhere;
|
||||
/** Attachments */
|
||||
private HashMap<Integer,Integer> m_Attachments = null;
|
||||
/** Chats */
|
||||
private HashMap<Integer,Integer> m_Chats = null;
|
||||
/** Locks */
|
||||
private ArrayList<Integer> m_Lock = null;
|
||||
|
||||
|
@ -333,12 +328,6 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
|||
//
|
||||
m_depOnField.clear();
|
||||
m_depOnField = null;
|
||||
if (m_Attachments != null)
|
||||
m_Attachments.clear();
|
||||
m_Attachments = null;
|
||||
if (m_Chats != null)
|
||||
m_Chats.clear();
|
||||
m_Chats = null;
|
||||
//
|
||||
if (m_vo.isInitFields())
|
||||
m_vo.getFields().clear();
|
||||
|
@ -2034,43 +2023,6 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
|||
|
||||
} // loadDependentInfo
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Load Attachments for this table
|
||||
*/
|
||||
public void loadAttachments()
|
||||
{
|
||||
log.fine("#" + m_vo.TabNo);
|
||||
if (!canHaveAttachment())
|
||||
return;
|
||||
|
||||
String SQL = "SELECT AD_Attachment_ID, Record_ID FROM AD_Attachment "
|
||||
+ "WHERE AD_Table_ID=?";
|
||||
try
|
||||
{
|
||||
if (m_Attachments == null)
|
||||
m_Attachments = new HashMap<Integer,Integer>();
|
||||
else
|
||||
m_Attachments.clear();
|
||||
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
|
||||
pstmt.setInt(1, m_vo.AD_Table_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
Integer key = new Integer(rs.getInt(2));
|
||||
Integer value = new Integer(rs.getInt(1));
|
||||
m_Attachments.put(key, value);
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, "loadAttachments", e);
|
||||
}
|
||||
log.config("#" + m_Attachments.size());
|
||||
} // loadAttachment
|
||||
|
||||
/**
|
||||
* Can this tab have Attachments?.
|
||||
* <p>
|
||||
|
@ -2091,13 +2043,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
|||
*/
|
||||
public boolean hasAttachment()
|
||||
{
|
||||
if (m_Attachments == null)
|
||||
loadAttachments();
|
||||
if (m_Attachments == null || m_Attachments.isEmpty())
|
||||
return false;
|
||||
//
|
||||
Integer key = new Integer(m_mTable.getKeyID (m_currentRow));
|
||||
return m_Attachments.containsKey(key);
|
||||
return getAD_AttachmentID() > 0;
|
||||
} // hasAttachment
|
||||
|
||||
/**
|
||||
|
@ -2106,54 +2052,11 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
|||
*/
|
||||
public int getAD_AttachmentID()
|
||||
{
|
||||
if (m_Attachments == null)
|
||||
loadAttachments();
|
||||
if (m_Attachments.isEmpty())
|
||||
return 0;
|
||||
//
|
||||
Integer key = new Integer(m_mTable.getKeyID (m_currentRow));
|
||||
Integer value = (Integer)m_Attachments.get(key);
|
||||
if (value == null)
|
||||
return 0;
|
||||
else
|
||||
return value.intValue();
|
||||
} // getAttachmentID
|
||||
|
||||
/**************************************************************************
|
||||
* Load Chats for this table
|
||||
*/
|
||||
public void loadChats()
|
||||
{
|
||||
log.fine("#" + m_vo.TabNo);
|
||||
if (!canHaveAttachment())
|
||||
return;
|
||||
|
||||
String sql = "SELECT CM_Chat_ID, Record_ID FROM CM_Chat "
|
||||
+ "WHERE AD_Table_ID=?";
|
||||
try
|
||||
{
|
||||
if (m_Chats == null)
|
||||
m_Chats = new HashMap<Integer,Integer>();
|
||||
else
|
||||
m_Chats.clear();
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, m_vo.AD_Table_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
Integer key = new Integer(rs.getInt(2)); // Record_ID
|
||||
Integer value = new Integer(rs.getInt(1)); // CM_Chat_ID
|
||||
m_Chats.put(key, value);
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
log.config("#" + m_Chats.size());
|
||||
} // loadChats
|
||||
return 0;
|
||||
int recordID = m_mTable.getKeyID(m_currentRow);
|
||||
return MAttachment.getID(m_vo.AD_Table_ID, recordID);
|
||||
} // getAttachmentID
|
||||
|
||||
/**
|
||||
* Returns true, if current row has a Chat
|
||||
|
@ -2161,13 +2064,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
|||
*/
|
||||
public boolean hasChat()
|
||||
{
|
||||
if (m_Chats == null)
|
||||
loadChats();
|
||||
if (m_Chats == null || m_Chats.isEmpty())
|
||||
return false;
|
||||
//
|
||||
Integer key = new Integer(m_mTable.getKeyID (m_currentRow));
|
||||
return m_Chats.containsKey(key);
|
||||
return getCM_ChatID() > 0;
|
||||
} // hasChat
|
||||
|
||||
/**
|
||||
|
@ -2176,17 +2073,10 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
|||
*/
|
||||
public int getCM_ChatID()
|
||||
{
|
||||
if (m_Chats == null)
|
||||
loadChats();
|
||||
if (m_Chats.isEmpty())
|
||||
if (!canHaveAttachment())
|
||||
return 0;
|
||||
//
|
||||
Integer key = new Integer(m_mTable.getKeyID (m_currentRow));
|
||||
Integer value = (Integer)m_Chats.get(key);
|
||||
if (value == null)
|
||||
return 0;
|
||||
else
|
||||
return value.intValue();
|
||||
int recordID = m_mTable.getKeyID(m_currentRow);
|
||||
return MChat.getID(m_vo.AD_Table_ID, recordID);
|
||||
} // getCM_ChatID
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Properties;
|
|||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.MimeType;
|
||||
|
||||
|
@ -47,7 +48,7 @@ public class MAttachment extends X_AD_Attachment
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -8013716602070647299L;
|
||||
private static final long serialVersionUID = -8261865873158774665L;
|
||||
|
||||
/**
|
||||
* Get Attachment (if there are more than one attachment it gets the first in no specific order)
|
||||
|
@ -94,9 +95,7 @@ public class MAttachment extends X_AD_Attachment
|
|||
*/
|
||||
public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String trxName)
|
||||
{
|
||||
this (ctx
|
||||
, MAttachment.get(ctx, AD_Table_ID, Record_ID) == null ? 0 : MAttachment.get(ctx, AD_Table_ID, Record_ID).get_ID()
|
||||
, trxName);
|
||||
this (ctx, MAttachment.getID(AD_Table_ID, Record_ID) > 0 ? MAttachment.getID(AD_Table_ID, Record_ID) : 0, trxName);
|
||||
if (get_ID() == 0) {
|
||||
setAD_Table_ID (AD_Table_ID);
|
||||
setRecord_ID (Record_ID);
|
||||
|
@ -598,4 +597,17 @@ public class MAttachment extends X_AD_Attachment
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* IDEMPIERE-530
|
||||
* Get the attachment ID based on table_id and record_id
|
||||
* @param AD_Table_ID
|
||||
* @param Record_ID
|
||||
* @return AD_Attachment_ID
|
||||
*/
|
||||
public static int getID(int Table_ID, int Record_ID) {
|
||||
String sql="SELECT AD_Attachment_ID FROM AD_Attachment WHERE AD_Table_ID=? AND Record_ID=?";
|
||||
int attachid = DB.getSQLValue(null, sql, Table_ID, Record_ID);
|
||||
return attachid;
|
||||
}
|
||||
|
||||
} // MAttachment
|
||||
|
|
|
@ -44,8 +44,7 @@ public class MChat extends X_CM_Chat
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5053130533036069784L;
|
||||
|
||||
private static final long serialVersionUID = 9165439123618441913L;
|
||||
|
||||
/**
|
||||
* Get Chats Of Table - of client in context
|
||||
|
@ -240,7 +239,19 @@ public class MChat extends X_CM_Chat
|
|||
} // entry
|
||||
//
|
||||
return history;
|
||||
} // getHistory
|
||||
|
||||
} // getHistory
|
||||
|
||||
/**
|
||||
* IDEMPIERE-530
|
||||
* Get the chat ID based on table_id and record_id
|
||||
* @param AD_Table_ID
|
||||
* @param Record_ID
|
||||
* @return CM_Chat_ID
|
||||
*/
|
||||
public static int getID(int Table_ID, int Record_ID) {
|
||||
String sql="SELECT CM_Chat_ID FROM CM_Chat WHERE AD_Table_ID=? AND Record_ID=?";
|
||||
int chatID = DB.getSQLValueEx(null, sql, Table_ID, Record_ID);
|
||||
return chatID;
|
||||
}
|
||||
|
||||
} // MChat
|
||||
|
|
|
@ -2304,11 +2304,10 @@ public final class APanel extends CPanel
|
|||
return;
|
||||
}
|
||||
|
||||
// Attachment va =
|
||||
new Attachment (AEnv.getFrame(this), m_curWindowNo,
|
||||
@SuppressWarnings("unused")
|
||||
Attachment va = new Attachment (AEnv.getFrame(this), m_curWindowNo,
|
||||
m_curTab.getAD_AttachmentID(), m_curTab.getAD_Table_ID(), record_ID, null);
|
||||
//
|
||||
m_curTab.loadAttachments(); // reload
|
||||
aAttachment.setPressed(m_curTab.hasAttachment());
|
||||
} // attachment
|
||||
|
||||
|
@ -2345,7 +2344,6 @@ public final class APanel extends CPanel
|
|||
m_curTab.getCM_ChatID(), m_curTab.getAD_Table_ID(), record_ID,
|
||||
description, null);
|
||||
//
|
||||
m_curTab.loadChats(); // reload
|
||||
aChat.setPressed(m_curTab.hasChat());
|
||||
} // chat
|
||||
|
||||
|
@ -2368,7 +2366,6 @@ public final class APanel extends CPanel
|
|||
else
|
||||
{
|
||||
m_curTab.lock (Env.getCtx(), record_ID, aLock.getButton().isSelected());
|
||||
m_curTab.loadAttachments(); // reload
|
||||
}
|
||||
aLock.setPressed(m_curTab.isLocked());
|
||||
} // lock
|
||||
|
|
|
@ -78,7 +78,7 @@ public final class Attachment extends CDialog
|
|||
int AD_Table_ID, int Record_ID, String trxName)
|
||||
{
|
||||
super (frame, Msg.getMsg(Env.getCtx(), "Attachment"), true);
|
||||
// needs to be modal otherwise APanel does not recongize change.
|
||||
// needs to be modal otherwise APanel does not recognize change.
|
||||
log.config("ID=" + AD_Attachment_ID
|
||||
+ ", Table=" + AD_Table_ID + ", Record=" + Record_ID);
|
||||
//
|
||||
|
@ -93,10 +93,10 @@ public final class Attachment extends CDialog
|
|||
log.log(Level.SEVERE, "", ex);
|
||||
}
|
||||
// Create Model
|
||||
if (AD_Attachment_ID == 0)
|
||||
m_attachment = new MAttachment (Env.getCtx(), AD_Table_ID, Record_ID, trxName);
|
||||
else
|
||||
if (AD_Attachment_ID > 0)
|
||||
m_attachment = new MAttachment (Env.getCtx(), AD_Attachment_ID, trxName);
|
||||
else
|
||||
m_attachment = new MAttachment (Env.getCtx(), AD_Table_ID, Record_ID, trxName);
|
||||
loadAttachments();
|
||||
//
|
||||
try
|
||||
|
@ -112,7 +112,7 @@ public final class Attachment extends CDialog
|
|||
/** Window No */
|
||||
private int m_WindowNo;
|
||||
/** Attachment */
|
||||
private MAttachment m_attachment;
|
||||
private MAttachment m_attachment = null;
|
||||
/** Change */
|
||||
private boolean m_change = false;
|
||||
/** Logger */
|
||||
|
@ -380,7 +380,10 @@ public final class Attachment extends CDialog
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_attachment.delete(true);
|
||||
m_attachment = null;
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
// Cancel
|
||||
|
@ -468,8 +471,10 @@ public final class Attachment extends CDialog
|
|||
private void deleteAttachment()
|
||||
{
|
||||
log.info("");
|
||||
if (ADialog.ask(m_WindowNo, this, "AttachmentDelete?"))
|
||||
if (ADialog.ask(m_WindowNo, this, "AttachmentDelete?")) {
|
||||
m_attachment.delete(true);
|
||||
m_attachment = null;
|
||||
}
|
||||
} // deleteAttachment
|
||||
|
||||
/**
|
||||
|
|
|
@ -801,7 +801,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
|
|||
public void onEvent(Event event) throws Exception
|
||||
{
|
||||
adTabbox.getSelectedGridTab().lock(Env.getCtx(), adTabbox.getSelectedGridTab().getRecord_ID(), !toolbar.getButton("Lock").isPressed());
|
||||
adTabbox.getSelectedGridTab().loadAttachments(); // reload
|
||||
adTabbox.getSelectedGridTab().loadLocks(); // reload
|
||||
|
||||
toolbar.lock(adTabbox.getSelectedGridTab().isLocked());
|
||||
}
|
||||
|
@ -850,8 +850,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
|
|||
EventListener<Event> listener = new EventListener<Event>() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
adTabbox.getSelectedGridTab().loadAttachments(); // reload
|
||||
public void onEvent(Event event) throws Exception {
|
||||
toolbar.getButton("Attachment").setPressed(adTabbox.getSelectedGridTab().hasAttachment());
|
||||
focusToActivePanel();
|
||||
}
|
||||
|
@ -899,8 +898,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
|
|||
WChat chat = new WChat(curWindowNo, adTabbox.getSelectedGridTab().getCM_ChatID(), adTabbox.getSelectedGridTab().getAD_Table_ID(), recordId, description, null);
|
||||
chat.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener<Event>() {
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
adTabbox.getSelectedGridTab().loadChats();
|
||||
public void onEvent(Event event) throws Exception {
|
||||
toolbar.getButton("Chat").setPressed(adTabbox.getSelectedGridTab().hasChat());
|
||||
focusToActivePanel();
|
||||
Clients.clearBusy(getComponent());
|
||||
|
|
|
@ -76,7 +76,7 @@ public class WAttachment extends Window implements EventListener<Event>
|
|||
private int m_WindowNo;
|
||||
|
||||
/** Attachment */
|
||||
private MAttachment m_attachment;
|
||||
private MAttachment m_attachment = null;
|
||||
|
||||
/** Change */
|
||||
private boolean m_change = false;
|
||||
|
@ -168,10 +168,10 @@ public class WAttachment extends Window implements EventListener<Event>
|
|||
|
||||
// Create Model
|
||||
|
||||
if (AD_Attachment_ID == 0)
|
||||
m_attachment = new MAttachment (Env.getCtx(), AD_Table_ID, Record_ID, trxName);
|
||||
else
|
||||
if (AD_Attachment_ID > 0)
|
||||
m_attachment = new MAttachment (Env.getCtx(), AD_Attachment_ID, trxName);
|
||||
else
|
||||
m_attachment = new MAttachment (Env.getCtx(), AD_Table_ID, Record_ID, trxName);
|
||||
|
||||
loadAttachments();
|
||||
|
||||
|
@ -483,7 +483,10 @@ public class WAttachment extends Window implements EventListener<Event>
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_attachment.delete(true);
|
||||
m_attachment = null;
|
||||
}
|
||||
|
||||
dispose();
|
||||
}
|
||||
|
@ -614,6 +617,7 @@ public class WAttachment extends Window implements EventListener<Event>
|
|||
if (result)
|
||||
{
|
||||
m_attachment.delete(true);
|
||||
m_attachment = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue