* Refactoring - move business logic to model, clean up.
This commit is contained in:
parent
6dd45a2ed6
commit
9f1bf18713
|
@ -21,6 +21,8 @@ import java.awt.event.*;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
|
import javax.sql.RowSet;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import org.compiere.apps.*;
|
import org.compiere.apps.*;
|
||||||
import org.compiere.model.*;
|
import org.compiere.model.*;
|
||||||
|
@ -99,34 +101,23 @@ public class AReport implements ActionListener
|
||||||
private void getPrintFormats (int AD_Table_ID, JComponent invoker)
|
private void getPrintFormats (int AD_Table_ID, JComponent invoker)
|
||||||
{
|
{
|
||||||
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
|
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
|
||||||
//
|
RowSet rowSet = MPrintFormat.getAccessiblePrintFormats(AD_Table_ID, -1, null);
|
||||||
String sql = MRole.getDefault().addAccessSQL (
|
|
||||||
"SELECT AD_PrintFormat_ID, Name, AD_Client_ID "
|
|
||||||
+ "FROM AD_PrintFormat "
|
|
||||||
+ "WHERE AD_Table_ID=? AND IsTableBased='Y' "
|
|
||||||
+ "ORDER BY AD_Client_ID DESC, IsDefault DESC, Name", // Own First
|
|
||||||
"AD_PrintFormat", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
|
||||||
KeyNamePair pp = null;
|
KeyNamePair pp = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
while (rowSet.next())
|
||||||
pstmt.setInt(1, AD_Table_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
{
|
||||||
pp = new KeyNamePair (rs.getInt(1), rs.getString(2));
|
pp = new KeyNamePair (rowSet.getInt(1), rowSet.getString(2));
|
||||||
if (rs.getInt(3) == AD_Client_ID)
|
if (rowSet.getInt(3) == AD_Client_ID)
|
||||||
{
|
{
|
||||||
m_list.add(pp);
|
m_list.add(pp);
|
||||||
m_popup.add(pp.toString()).addActionListener(this);
|
m_popup.add(pp.toString()).addActionListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, sql, e);
|
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No Format exists - create it
|
// No Format exists - create it
|
||||||
|
@ -198,24 +189,13 @@ public class AReport implements ActionListener
|
||||||
|
|
||||||
// Execute Process
|
// Execute Process
|
||||||
ProcessCtl worker = ProcessCtl.process(parent, WindowNo, pi, null);
|
ProcessCtl worker = ProcessCtl.process(parent, WindowNo, pi, null);
|
||||||
if(worker == null) // Process has been canceled
|
|
||||||
return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
worker.start();
|
|
||||||
} catch(java.lang.IllegalThreadStateException itse) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// It's a default report using the standard printing engine
|
// It's a default report using the standard printing engine
|
||||||
ReportEngine re = new ReportEngine (Env.getCtx(), pf, m_query, info);
|
ReportEngine re = new ReportEngine (Env.getCtx(), pf, m_query, info);
|
||||||
Viewer viewer = new Viewer(re);
|
ReportCtl.preview(re);
|
||||||
AEnv.addToWindowManager(viewer);
|
|
||||||
}
|
}
|
||||||
// if (m_popup.isVisible())
|
|
||||||
// m_popup.setVisible(false);
|
|
||||||
} // launchReport
|
} // launchReport
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -240,28 +220,12 @@ public class AReport implements ActionListener
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Get AD_Table_ID for Table Name
|
* Get AD_Table_ID for Table Name
|
||||||
* @param TableName table name
|
* @param tableName table name
|
||||||
* @return AD_Table_ID or 0
|
* @return AD_Table_ID or 0
|
||||||
*/
|
*/
|
||||||
static public int getAD_Table_ID (String TableName)
|
public static int getAD_Table_ID (String tableName)
|
||||||
{
|
{
|
||||||
int AD_Table_ID = 0;
|
return MTable.getTable_ID(tableName);
|
||||||
String sql = "SELECT AD_Table_ID FROM AD_Table WHERE TableName=?";
|
|
||||||
try
|
|
||||||
{
|
|
||||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
|
||||||
pstmt.setString(1, TableName);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
if (rs.next())
|
|
||||||
AD_Table_ID = rs.getInt(1);
|
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
return AD_Table_ID;
|
|
||||||
} // getAD_Table_ID
|
} // getAD_Table_ID
|
||||||
|
|
||||||
} // AReport
|
} // AReport
|
||||||
|
|
|
@ -267,7 +267,11 @@ public class ReportCtl
|
||||||
re.print();
|
re.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void preview(ReportEngine re)
|
/**
|
||||||
|
* Launch viewer for report
|
||||||
|
* @param re
|
||||||
|
*/
|
||||||
|
public static void preview(ReportEngine re)
|
||||||
{
|
{
|
||||||
ReportViewerProvider provider = getReportViewerProvider();
|
ReportViewerProvider provider = getReportViewerProvider();
|
||||||
provider.openViewer(re);
|
provider.openViewer(re);
|
||||||
|
|
Loading…
Reference in New Issue