FR [ 1943731 ] Window data export functionality
https://sourceforge.net/tracker/?func=detail&atid=879335&aid=1943731&group_id=176962
This commit is contained in:
parent
1f7c79a6a1
commit
a314fcc615
|
|
@ -0,0 +1,146 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* 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.adempiere.impexp;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.compiere.model.GridField;
|
||||||
|
import org.compiere.model.GridTab;
|
||||||
|
import org.compiere.model.Lookup;
|
||||||
|
import org.compiere.model.MLookup;
|
||||||
|
import org.compiere.model.MLookupFactory;
|
||||||
|
import org.compiere.util.DisplayType;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Excel Exporter Adapter for GridTab
|
||||||
|
* @author Teo Sarca, www.arhipac.ro
|
||||||
|
* <li>FR [ 1943731 ] Window data export functionality
|
||||||
|
*/
|
||||||
|
public class GridTabExcelExporter extends AbstractExcelExporter
|
||||||
|
{
|
||||||
|
private GridTab m_tab = null;
|
||||||
|
|
||||||
|
public GridTabExcelExporter(Properties ctx, GridTab tab)
|
||||||
|
{
|
||||||
|
m_tab = tab;
|
||||||
|
setFreezePane(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getColumnCount()
|
||||||
|
{
|
||||||
|
return m_tab.getFieldCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDisplayType(int row, int col)
|
||||||
|
{
|
||||||
|
return m_tab.getField(col).getDisplayType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getHeaderName(int col)
|
||||||
|
{
|
||||||
|
return m_tab.getField(col).getHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getRowCount()
|
||||||
|
{
|
||||||
|
return m_tab.getRowCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object getValueAt(int row, int col)
|
||||||
|
{
|
||||||
|
GridField f = m_tab.getField(col);
|
||||||
|
Object key = m_tab.getValue(row, f.getColumnName());
|
||||||
|
Object value = key;
|
||||||
|
Lookup lookup = f.getLookup();
|
||||||
|
if (lookup != null)
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
|
else if (f.getDisplayType() == DisplayType.Button)
|
||||||
|
{
|
||||||
|
lookup = getButtonLookup(f);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
if (lookup != null)
|
||||||
|
{
|
||||||
|
value = lookup.getDisplay(key);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isColumnPrinted(int col)
|
||||||
|
{
|
||||||
|
GridField f = m_tab.getField(col);
|
||||||
|
// Hide not displayed fields
|
||||||
|
if (!f.isDisplayed())
|
||||||
|
return false;
|
||||||
|
// Hide encrypted fields
|
||||||
|
if (f.isEncrypted())
|
||||||
|
return false;
|
||||||
|
// Hide simple button fields without a value
|
||||||
|
if (f.getDisplayType() == DisplayType.Button && f.getAD_Reference_Value_ID() == 0)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isFunctionRow()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isPageBreak(int row, int col)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setCurrentRow(int row)
|
||||||
|
{
|
||||||
|
; // nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashMap<String, MLookup> m_buttonLookups = new HashMap<String, MLookup>();
|
||||||
|
|
||||||
|
private MLookup getButtonLookup(GridField mField)
|
||||||
|
{
|
||||||
|
MLookup lookup = m_buttonLookups.get(mField.getColumnName());
|
||||||
|
if (lookup != null)
|
||||||
|
return lookup;
|
||||||
|
// TODO: refactor with org.compiere.grid.ed.VButton.setField(GridField)
|
||||||
|
if (mField.getColumnName().endsWith("_ID") && !mField.getColumnName().equals("Record_ID"))
|
||||||
|
{
|
||||||
|
lookup = MLookupFactory.get(Env.getCtx(), mField.getWindowNo(), 0,
|
||||||
|
mField.getAD_Column_ID(), DisplayType.Search);
|
||||||
|
}
|
||||||
|
else if (mField.getAD_Reference_Value_ID() != 0)
|
||||||
|
{
|
||||||
|
// Assuming List
|
||||||
|
lookup = MLookupFactory.get(Env.getCtx(), mField.getWindowNo(), 0,
|
||||||
|
mField.getAD_Column_ID(), DisplayType.List);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
m_buttonLookups.put(mField.getColumnName(), lookup);
|
||||||
|
return lookup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,106 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* 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.apps;
|
||||||
|
|
||||||
|
import java.awt.Cursor;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
|
||||||
|
import org.adempiere.impexp.GridTabExcelExporter;
|
||||||
|
import org.compiere.model.GridTab;
|
||||||
|
import org.compiere.util.CLogMgt;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.ExtensionFileFilter;
|
||||||
|
import org.compiere.util.Msg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export button consequences
|
||||||
|
* @author Teo Sarca, www.arhipac.ro
|
||||||
|
* <li>FR [ 1943731 ] Window data export functionality
|
||||||
|
*/
|
||||||
|
public class AExport
|
||||||
|
{
|
||||||
|
private CLogger log = CLogger.getCLogger(getClass());
|
||||||
|
private Properties m_ctx = null;
|
||||||
|
private int m_WindowNo = 0;
|
||||||
|
|
||||||
|
public AExport(APanel parent)
|
||||||
|
{
|
||||||
|
m_ctx = Env.getCtx();
|
||||||
|
m_WindowNo = parent.getWindowNo();
|
||||||
|
//
|
||||||
|
JFileChooser chooser = new JFileChooser();
|
||||||
|
chooser.addChoosableFileFilter(new ExtensionFileFilter("xls", Msg.getMsg(m_ctx, "FileXLS")));
|
||||||
|
if (chooser.showSaveDialog(parent) != JFileChooser.APPROVE_OPTION)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Create File
|
||||||
|
File outFile = ExtensionFileFilter.getFile(chooser.getSelectedFile(), chooser.getFileFilter());
|
||||||
|
try
|
||||||
|
{
|
||||||
|
outFile.createNewFile();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
log.log(Level.SEVERE, "", e);
|
||||||
|
ADialog.error(m_WindowNo, parent, "FileCannotCreate", e.getLocalizedMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ext = outFile.getPath();
|
||||||
|
// no extension
|
||||||
|
if (ext.lastIndexOf('.') == -1)
|
||||||
|
{
|
||||||
|
ADialog.error(m_WindowNo, parent, "FileInvalidExtension");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ext = ext.substring(ext.lastIndexOf('.')+1).toLowerCase();
|
||||||
|
log.config( "File=" + outFile.getPath() + "; Type=" + ext);
|
||||||
|
|
||||||
|
parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (ext.equals("xls"))
|
||||||
|
{
|
||||||
|
createXLS(outFile, parent.getCurrentTab());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ADialog.error(m_WindowNo, parent, "FileInvalidExtension");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
ADialog.error(m_WindowNo, parent, "Error", e.getLocalizedMessage());
|
||||||
|
if (CLogMgt.isLevelFinest())
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
parent.setCursor(Cursor.getDefaultCursor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createXLS(File outFile, GridTab tab)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
GridTabExcelExporter exporter = new GridTabExcelExporter(m_ctx, tab);
|
||||||
|
exporter.export(outFile, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -117,6 +117,7 @@ import org.compiere.util.Util;
|
||||||
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
* <li>BF [ 1824621 ] History button can't be canceled
|
* <li>BF [ 1824621 ] History button can't be canceled
|
||||||
* <li>BF [ 1941271 ] VTreePanel is modifying even if is save wasn't successfull
|
* <li>BF [ 1941271 ] VTreePanel is modifying even if is save wasn't successfull
|
||||||
|
* <li>FR [ 1943731 ] Window data export functionality
|
||||||
* <li>BF [ 1996056 ] Report error message is not displayed
|
* <li>BF [ 1996056 ] Report error message is not displayed
|
||||||
* <li>BF [ 1998575 ] Document Print is discarding any error
|
* <li>BF [ 1998575 ] Document Print is discarding any error
|
||||||
* @author victor.perez@e-evolution.com
|
* @author victor.perez@e-evolution.com
|
||||||
|
|
@ -279,6 +280,7 @@ public final class APanel extends CPanel
|
||||||
|
|
||||||
private AppsAction aPrevious, aNext, aParent, aDetail, aFirst, aLast,
|
private AppsAction aPrevious, aNext, aParent, aDetail, aFirst, aLast,
|
||||||
aNew, aCopy, aDelete, aPrint, aPrintPreview,
|
aNew, aCopy, aDelete, aPrint, aPrintPreview,
|
||||||
|
aExport,
|
||||||
aRefresh, aHistory, aAttachment, aChat, aMulti, aFind,
|
aRefresh, aHistory, aAttachment, aChat, aMulti, aFind,
|
||||||
aWorkflow, aZoomAcross, aRequest, aWinSize, aArchive;
|
aWorkflow, aZoomAcross, aRequest, aWinSize, aArchive;
|
||||||
/** Ignore Button */
|
/** Ignore Button */
|
||||||
|
|
@ -314,6 +316,10 @@ public final class APanel extends CPanel
|
||||||
aReport = addAction("Report", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0), false);
|
aReport = addAction("Report", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0), false);
|
||||||
aPrint = addAction("Print", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), false);
|
aPrint = addAction("Print", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), false);
|
||||||
aPrintPreview = addAction("PrintPreview", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.SHIFT_MASK+Event.ALT_MASK), false);
|
aPrintPreview = addAction("PrintPreview", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.SHIFT_MASK+Event.ALT_MASK), false);
|
||||||
|
if (MRole.getDefault().isCanExport())
|
||||||
|
{
|
||||||
|
aExport = addAction("Export", mFile, null, false);
|
||||||
|
}
|
||||||
mFile.addSeparator();
|
mFile.addSeparator();
|
||||||
aEnd = addAction("End", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.ALT_MASK), false);
|
aEnd = addAction("End", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.ALT_MASK), false);
|
||||||
aLogout = addAction("Logout", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.SHIFT_MASK+Event.ALT_MASK), false);
|
aLogout = addAction("Logout", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.SHIFT_MASK+Event.ALT_MASK), false);
|
||||||
|
|
@ -1492,6 +1498,8 @@ public final class APanel extends CPanel
|
||||||
cmd_print();
|
cmd_print();
|
||||||
else if (cmd.equals(aPrintPreview.getName()))
|
else if (cmd.equals(aPrintPreview.getName()))
|
||||||
cmd_print(true);
|
cmd_print(true);
|
||||||
|
else if (cmd.equals(aExport.getName()))
|
||||||
|
cmd_export();
|
||||||
else if (cmd.equals(aEnd.getName()))
|
else if (cmd.equals(aEnd.getName()))
|
||||||
cmd_end(false);
|
cmd_end(false);
|
||||||
else if (cmd.equals(aExit.getName()))
|
else if (cmd.equals(aExit.getName()))
|
||||||
|
|
@ -2190,7 +2198,11 @@ public final class APanel extends CPanel
|
||||||
win.setWindowSize(size);
|
win.setWindowSize(size);
|
||||||
win.save();
|
win.save();
|
||||||
} // cmdWinSize
|
} // cmdWinSize
|
||||||
|
|
||||||
|
private void cmd_export()
|
||||||
|
{
|
||||||
|
new AExport(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue