FR [ 1894651 ] Info Account: Excel Export support

This commit is contained in:
teo_sarca 2008-06-27 14:33:17 +00:00
parent 3483a4f8c1
commit 4da24b6233
4 changed files with 120 additions and 1 deletions

View File

@ -126,6 +126,9 @@ public class RColumn
m_colClass = String.class;
m_isIDcol = false;
}
else if (displayType == DisplayType.ID) {
m_colClass = Integer.class;
}
/** Table
else if (displayType == DisplayType.Table)
{
@ -249,6 +252,8 @@ public class RColumn
*/
public String getDisplaySQL()
{
if (m_displaySQL == null)
return m_columnName;
return m_displaySQL;
}
/**

View File

@ -0,0 +1,77 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.compiere.report.core;
import org.adempiere.impexp.AbstractExcelExporter;
/**
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
*
*/
public class RModelExcelExporter
extends AbstractExcelExporter
{
private RModel m_model = null;
private int m_currentRow = 0;
public RModelExcelExporter(RModel model) {
super();
m_model = model;
}
@Override
protected int getColumnCount() {
return m_model.getColumnCount();
}
@Override
protected int getDisplayType(int row, int col) {
return m_model.getRColumn(col).getDisplayType();
}
@Override
protected String getHeaderName(int col) {
return m_model.getRColumn(col).getColHeader();
}
@Override
protected int getRowCount() {
return m_model.getRowCount();
}
@Override
protected Object getValueAt(int row, int col) {
return m_model.getValueAt(row, col);
}
@Override
protected boolean isColumnPrinted(int col) {
return true;
}
@Override
protected boolean isFunctionRow() {
return m_model.isGroupRow(m_currentRow);
}
@Override
protected boolean isPageBreak(int row, int col) {
return false;
}
@Override
protected void setCurrentRow(int row) {
m_currentRow = row;
}
}

View File

@ -58,6 +58,8 @@ public class ResultTable extends JTable implements MouseListener
private int m_lastSortIndex = -1;
/** Sort direction */
private boolean m_asc = true;
/** RModel */
private RModel m_model = null;
/** Logger */
private static CLogger log = CLogger.getCLogger(ResultTable.class);
@ -79,6 +81,7 @@ public class ResultTable extends JTable implements MouseListener
public void setModel (RModel reportModel)
{
log.config(reportModel.toString());
m_model = reportModel;
super.setModel(new ResultTableModel(reportModel));
//
TableColumnModel tcm = getColumnModel();
@ -98,6 +101,13 @@ public class ResultTable extends JTable implements MouseListener
}
autoSize();
} // setModel
/**
* @return RModel
*/
public RModel getRModel() {
return m_model;
}
/**
* Set Model

View File

@ -101,6 +101,7 @@ public class AcctViewer extends CFrame
private CPanel southPanel = new CPanel();
private CButton bQuery = new CButton();
private CButton bPrint = new CButton();
private CButton bExport = new CButton();
private CLabel statusLine = new CLabel();
private BorderLayout southLayout = new BorderLayout();
private BorderLayout queryLayout = new BorderLayout();
@ -344,7 +345,12 @@ public class AcctViewer extends CFrame
bPrint.setIcon(Env.getImageIcon("Print16.gif"));
bPrint.setToolTipText(Msg.getMsg(Env.getCtx(), "Print"));
bPrint.addActionListener(this);
bExport.setIcon(Env.getImageIcon("Export16.gif"));
bExport.setToolTipText(Msg.getMsg(Env.getCtx(), "Export"));
bExport.setVisible(tabbedPane.getSelectedIndex() == 1);
bExport.addActionListener(this);
CPanel rightSide = new CPanel(new FlowLayout(FlowLayout.TRAILING, 0, 0));
rightSide.add(bExport);
rightSide.add(bPrint);
rightSide.add(bQuery);
southPanel.add(rightSide, BorderLayout.EAST);
@ -400,7 +406,8 @@ public class AcctViewer extends CFrame
*/
public void dispose()
{
m_data.dispose();
if (m_data != null)
m_data.dispose();
m_data = null;
super.dispose();
} // dispose;
@ -414,6 +421,7 @@ public class AcctViewer extends CFrame
// log.info( "AcctViewer.stateChanged");
boolean visible = m_data.documentQuery && tabbedPane.getSelectedIndex() == 1;
bRePost.setVisible(visible);
bExport.setVisible(tabbedPane.getSelectedIndex() == 1);
if (Ini.isPropertyBool(Ini.P_SHOW_ADVANCED))
forcePost.setVisible(visible);
} // stateChanged
@ -439,6 +447,8 @@ public class AcctViewer extends CFrame
actionRePost();
else if (source == bPrint)
PrintScreenPainter.printScreen(this);
else if (source == bExport)
exportExcel();
// InfoButtons
else if (source instanceof CButton)
actionButton((CButton)source);
@ -724,4 +734,21 @@ public class AcctViewer extends CFrame
}
} // actionRePost
/**
* Export to Excel
*/
private void exportExcel() {
RModel model = table.getRModel();
if (model == null) {
return;
}
try {
RModelExcelExporter exporter = new RModelExcelExporter((RModel)model);
exporter.export(null, null);
}
catch (Exception e) {
ADialog.error(0, this, "Error", e.getLocalizedMessage());
if (CLogMgt.isLevelFinest()) e.printStackTrace();
}
}
} // AcctViewer