📄 info.java
字号:
if (p_multiSelection)
{
}
else // singleSelection
{
Integer data = getSelectedRowKey();
if (data != null)
m_results.add(data);
}
log.config(getSelectedSQL());
// Save Settings of detail info screens
saveSelectionDetail();
// Clean-up
p_table.removeAll();
p_table = null;
} // saveSelection
/**
* Get the key of currently selected row
* @return selected key
*/
protected Integer getSelectedRowKey()
{
int row = p_table.getSelectedRow();
if (row != -1 && m_keyColumnIndex != -1)
{
Object data = p_table.getModel().getValueAt(row, m_keyColumnIndex);
if (data instanceof IDColumn)
data = ((IDColumn)data).getRecord_ID();
if (data instanceof Integer)
return (Integer)data;
}
return null;
} // getSelectedRowKey
/**
* Get selected Keys
* @return selected keys (Integers)
*/
public Object[] getSelectedKeys()
{
if (!m_ok || m_results.size() == 0)
return null;
return m_results.toArray();
} // getSelectedKeys;
/**
* Get (first) selected Key
* @return selected key
*/
public Object getSelectedKey()
{
if (!m_ok || m_results.size() == 0)
return null;
return m_results.get(0);
} // getSelectedKey
/**
* Is cancelled?
* - if pressed Cancel = true
* - if pressed OK or window closed = false
* @return true if cancelled
*/
public boolean isCancelled()
{
return m_cancel;
} // isCancelled
/**
* Get where clause for (first) selected key
* @return WHERE Clause
*/
public String getSelectedSQL()
{
// No results
Object[] keys = getSelectedKeys();
if (keys == null || keys.length == 0)
{
log.config("No Results - OK="
+ m_ok + ", Cancel=" + m_cancel);
return "";
}
//
StringBuffer sb = new StringBuffer(getKeyColumn());
if (keys.length > 1)
sb.append(" IN (");
else
sb.append("=");
// Add elements
for (int i = 0; i < keys.length; i++)
{
if (getKeyColumn().endsWith("_ID"))
sb.append(keys[i].toString()).append(",");
else
sb.append("'").append(keys[i].toString()).append("',");
}
sb.replace(sb.length()-1, sb.length(), "");
if (keys.length > 1)
sb.append(")");
return sb.toString();
} // getSelectedSQL;
/**************************************************************************
* (Button) Action Listener & Popup Menu
* @param e event
*/
public void actionPerformed(ActionEvent e)
{
// Popup => Calculator
if (e.getSource().equals(calcMenu))
{
BigDecimal number = null;
Object data = p_table.getSelectedValue();
try
{
if (data != null)
{
if (data instanceof BigDecimal)
number = (BigDecimal)data;
else
number = new BigDecimal(data.toString());
}
}
catch (Exception ex) {}
Calculator c = new Calculator(null, number);
c.setVisible(true);
return;
} // popup
// Confirm Panel
String cmd = e.getActionCommand();
if (cmd.equals(ConfirmPanel.A_OK))
{
dispose(true);
}
else if (cmd.equals(ConfirmPanel.A_CANCEL))
{
m_cancel = true;
dispose(false);
}
//
else if (cmd.equals(ConfirmPanel.A_HISTORY))
showHistory();
else if (cmd.equals(ConfirmPanel.A_CUSTOMIZE))
customize();
else if (cmd.equals(ConfirmPanel.A_ZOOM))
zoom();
else if (cmd.equals(ConfirmPanel.A_RESET))
doReset();
else if (cmd.equals(ConfirmPanel.A_PRINT))
PrintScreenPainter.printScreen(this);
// Default
else
executeQuery();
} // actionPerformed
/**
* Zoom to target
* @param AD_Window_ID window id
* @param zoomQuery zoom query
*/
void zoom (int AD_Window_ID, MQuery zoomQuery)
{
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
final AWindow frame = new AWindow();
if (!frame.initWindow(AD_Window_ID, zoomQuery))
return;
// Modal Window causes UI lock
if (isModal())
{
setModal(false); // remove modal option has no effect
dispose(); // VLookup.actionButton - Result = null (not cancelled)
}
else
setCursor(Cursor.getDefaultCursor());
// VLookup gets info after method finishes
new Thread()
{
public void run()
{
try
{
sleep(50);
}
catch (Exception e)
{
}
AEnv.showCenterScreen(frame);
}
}.start();
} // zoom
/**
* Dispose (not OK)
*/
public void dispose()
{
dispose(false);
} // dispose
/**
* Dispose and save Selection
* @param ok OK pressed
*/
public void dispose(boolean ok)
{
log.config("OK=" + ok);
m_ok = ok;
// End Worker
if (m_worker != null)
{
// worker continues, but it does not block UI
if (m_worker.isAlive())
m_worker.interrupt();
log.config("Worker alive=" + m_worker.isAlive());
}
m_worker = null;
//
saveSelection();
removeAll();
super.dispose();
} // dispose
/**
* Get Table name Synonym
* @return table name
*/
String getTableName()
{
return p_tableName;
} // getTableName
/**
* Get Key Column Name
* @return column name
*/
String getKeyColumn()
{
return p_keyColumn;
} // getKeyColumn
/**************************************************************************
* Table Selection Changed
* @param e event
*/
public void valueChanged(ListSelectionEvent e)
{
if (e.getValueIsAdjusting())
return;
enableButtons();
} // calueChanged
/**
* Enable OK, History, Zoom if row selected
*/
void enableButtons ()
{
boolean enable = p_table.getSelectedRow() != -1;
confirmPanel.getOKButton().setEnabled(enable);
if (hasHistory())
confirmPanel.getHistoryButton().setEnabled(enable);
if (hasZoom())
confirmPanel.getZoomButton().setEnabled(enable);
} // enableButtons
/**************************************************************************
* Get dynamic WHERE part of SQL
* To be overwritten by concrete classes
* @return WHERE clause
*/
abstract String getSQLWhere();
/**
* Set Parameters for Query
* To be overwritten by concrete classes
* @param pstmt statement
* @param forCount for counting records
* @throws SQLException
*/
abstract void setParameters (PreparedStatement pstmt, boolean forCount)
throws SQLException;
/**
* Reset Parameters
* To be overwritten by concrete classes
*/
void doReset() {}
/**
* Has Reset (false)
* To be overwritten by concrete classes
* @return true if it has reset (default false)
*/
boolean hasReset() {return false;}
/**
* History dialog
* To be overwritten by concrete classes
*/
void showHistory() {}
/**
* Has History (false)
* To be overwritten by concrete classes
* @return true if it has history (default false)
*/
boolean hasHistory() {return false;}
/**
* Customize dialog
* To be overwritten by concrete classes
*/
void customize() {}
/**
* Has Customize (false)
* To be overwritten by concrete classes
* @return true if it has customize (default false)
*/
boolean hasCustomize() {return false;}
/**
* Zoom action
* To be overwritten by concrete classes
*/
void zoom() {}
/**
* Has Zoom (false)
* To be overwritten by concrete classes
* @return true if it has zoom (default false)
*/
boolean hasZoom() {return false;}
/**
* Save Selection Details
* To be overwritten by concrete classes
*/
void saveSelectionDetail() {}
/**
* Get Zoom Window
* @param tableName table name
* @param isSOTrx sales trx
* @return AD_Window_ID
*/
protected int getAD_Window_ID (String tableName, boolean isSOTrx)
{
if (!isSOTrx && m_PO_Window_ID > 0)
return m_PO_Window_ID;
if (m_SO_Window_ID > 0)
return m_SO_Window_ID;
//
String sql = "SELECT AD_Window_ID, PO_Window_ID FROM AD_Table WHERE TableName=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setString(1, tableName);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
m_SO_Window_ID = rs.getInt(1);
m_PO_Window_ID = rs.getInt(2);
}
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;
}
//
if (!isSOTrx && m_PO_Window_ID > 0)
return m_PO_Window_ID;
return m_SO_Window_ID;
} // getAD_Window_ID
/**************************************************************************
* Mouse Clicked
* @param e event
*/
public void mouseClicked(MouseEvent e)
{
// log.fine( "Info.mouseClicked",
// "ClickCount=" + e.getClickCount() + ", Right=" + SwingUtilities.isRightMouseButton(e)
// + ", r=" + m_table.getSelectedRow() + ", c=" + m_table.getSelectedColumn());
// Double click with selected row => exit
if (e.getClickCount() > 1 && p_table.getSelectedRow() != -1)
{
dispose(true); // double_click same as OK
}
// Right Click => start Calculator
else if (SwingUtilities.isRightMouseButton(e))
{
popup.show(e.getComponent(), e.getX(), e.getY());
}
} // mouseClicked
/**
* Worker
*/
class Worker extends Thread
{
/**
* Do Work (load data)
*/
public void run()
{
// setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// setStatusLine(Msg.getMsg(Env.getCtx(), "StartSearch"), false);
long start = System.currentTimeMillis();
// Clear Table
p_table.setRowCount(0);
//
String dynWhere = getSQLWhere();
StringBuffer sql = new StringBuffer (m_sqlMain);
if (dynWhere.length() > 0)
sql.append(dynWhere); // includes first AND
sql.append(m_sqlOrder);
String dataSql = Msg.parseTranslation(Env.getCtx(), sql.toString()); // Variables
dataSql = MRole.getDefault().addAccessSQL(dataSql, getTableName(),
MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
log.finer(dataSql);
try
{
PreparedStatement pstmt = DB.prepareStatement(dataSql, null);
setParameters (pstmt, false); // no count
log.fine("Start query - " + (System.currentTimeMillis()-start) + "ms");
ResultSet rs = pstmt.executeQuery();
log.fine("End query - " + (System.currentTimeMillis()-start) + "ms");
while (!isInterrupted() & rs.next())
{
int row = p_table.getRowCount();
p_table.setRowCount(row+1);
int colOffset = 1; // columns start with 1
for (int col = 0; col < p_layout.length; col++)
{
Object data = null;
Class c = p_layout[col].getColClass();
int colIndex = col + colOffset;
if (c == IDColumn.class)
data = new IDColumn(rs.getInt(colIndex));
else if (c == Boolean.class)
data = new Boolean("Y".equals(rs.getString(colIndex)));
else if (c == Timestamp.class)
data = rs.getTimestamp(colIndex);
else if (c == BigDecimal.class)
data = rs.getBigDecimal(colIndex);
else if (c == Double.class)
data = new Double(rs.getDouble(colIndex));
else if (c == Integer.class)
data = new Integer(rs.getInt(colIndex));
else if (c == KeyNamePair.class)
{
String display = rs.getString(colIndex);
int key = rs.getInt(colIndex+1);
data = new KeyNamePair(key, display);
colOffset++;
}
else
data = rs.getString(colIndex);
// store
p_table.setValueAt(data, row, col);
// log.fine( "r=" + row + ", c=" + col + " " + m_layout[col].getColHeader(),
// "data=" + data.toString() + " " + data.getClass().getName() + " * " + m_table.getCellRenderer(row, col));
}
}
if (isInterrupted())
log.finer("Interrupted");
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, dataSql, e);
}
int no = p_table.getRowCount();
log.fine("#" + no + " - " + (System.currentTimeMillis()-start) + "ms");
p_table.autoSize();
//
setCursor(Cursor.getDefaultCursor());
setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
setStatusDB(Integer.toString(no));
if (no == 0)
log.fine(dataSql);
else
{
p_table.getSelectionModel().setSelectionInterval(0, 0);
p_table.requestFocus();
}
} // run
} // Worker
} // Info
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -