IDEMPIERE-2052:make export csv function can export multi detail tab
This commit is contained in:
parent
6790fa1570
commit
bb3e0460d3
|
@ -53,4 +53,11 @@ public interface IGridTabExporter {
|
||||||
* @return suggested file name
|
* @return suggested file name
|
||||||
*/
|
*/
|
||||||
public String getSuggestedFileName(GridTab gridTab);
|
public String getSuggestedFileName(GridTab gridTab);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check a tab (detail tab) is support to export in this exporter
|
||||||
|
* @param gridTab
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isExportableTab (GridTab gridTab);
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,24 +135,25 @@ public class GridTabCSVExporter implements IGridTabExporter
|
||||||
//Details up to tab level 1
|
//Details up to tab level 1
|
||||||
if(childs.size() > 0){
|
if(childs.size() > 0){
|
||||||
int specialDetDispayType = 0;
|
int specialDetDispayType = 0;
|
||||||
int numOfTabs=0;
|
//int numOfTabs=0;
|
||||||
for(GridTab detail: childs){
|
for(GridTab detail: childs){
|
||||||
|
|
||||||
if(indxDetailSelected != detail.getTabNo())
|
//if(indxDetailSelected != detail.getTabNo())
|
||||||
continue;
|
//continue;
|
||||||
|
|
||||||
if(!detail.isDisplayed())
|
if(!detail.isDisplayed())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(detail.getDisplayLogic()!=null){
|
if(detail.getDisplayLogic()!=null){
|
||||||
if(!currentRowOnly)
|
//if(!currentRowOnly)
|
||||||
numOfTabs--;
|
//numOfTabs--;
|
||||||
else if(!Evaluator.evaluateLogic(detail,detail.getDisplayLogic()))
|
//TODO: it's need? DisplayLogic is evaluated when call detail.isDisplayed()
|
||||||
|
if(currentRowOnly && !Evaluator.evaluateLogic(detail,detail.getDisplayLogic()))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//comment this line if you want to export all tabs
|
//comment this line if you want to export all tabs
|
||||||
if(numOfTabs > 0)
|
//if(numOfTabs > 0)
|
||||||
break;
|
//break;
|
||||||
|
|
||||||
if(detail.getTabLevel()>1)
|
if(detail.getTabLevel()>1)
|
||||||
continue;
|
continue;
|
||||||
|
@ -196,7 +197,7 @@ public class GridTabCSVExporter implements IGridTabExporter
|
||||||
specialDetDispayType = 0;
|
specialDetDispayType = 0;
|
||||||
}
|
}
|
||||||
tabMapDetails.put(detail,gridFields);
|
tabMapDetails.put(detail,gridFields);
|
||||||
numOfTabs++;
|
//numOfTabs++;
|
||||||
}
|
}
|
||||||
gridFields = null;
|
gridFields = null;
|
||||||
}
|
}
|
||||||
|
@ -593,4 +594,23 @@ public class GridTabCSVExporter implements IGridTabExporter
|
||||||
return "Export_" + gridTab.getTableName() + "." + getFileExtension();
|
return "Export_" + gridTab.getTableName() + "." + getFileExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* just export display tab, one level deep, not read only and not account tab
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isExportableTab(GridTab detail) {
|
||||||
|
if(!detail.isDisplayed())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(detail.getTabLevel()>1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (isValidTabToExport(detail) != null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,4 +182,13 @@ public class GridTabExcelExporter extends AbstractExcelExporter implements IGrid
|
||||||
public String getSuggestedFileName(GridTab gridTab) {
|
public String getSuggestedFileName(GridTab gridTab) {
|
||||||
return gridTab.getName() + "." + getFileExtension();
|
return gridTab.getName() + "." + getFileExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* no detail tab is support to export with excel
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isExportableTab(GridTab gridTab) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,4 +154,13 @@ public class GridTab2PackExporter implements IGridTabExporter {
|
||||||
public String getSuggestedFileName(GridTab gridTab) {
|
public String getSuggestedFileName(GridTab gridTab) {
|
||||||
return gridTab.getName() + "." + getFileExtension();
|
return gridTab.getName() + "." + getFileExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* With 2Pack, everry tab is support to export
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isExportableTab(GridTab gridTab) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ import org.compiere.util.Msg;
|
||||||
import org.zkoss.util.media.AMedia;
|
import org.zkoss.util.media.AMedia;
|
||||||
import org.zkoss.zk.ui.event.Event;
|
import org.zkoss.zk.ui.event.Event;
|
||||||
import org.zkoss.zk.ui.event.EventListener;
|
import org.zkoss.zk.ui.event.EventListener;
|
||||||
|
import org.zkoss.zk.ui.event.Events;
|
||||||
import org.zkoss.zul.Filedownload;
|
import org.zkoss.zul.Filedownload;
|
||||||
import org.zkoss.zul.Space;
|
import org.zkoss.zul.Space;
|
||||||
import org.zkoss.zul.Vbox;
|
import org.zkoss.zul.Vbox;
|
||||||
|
@ -70,7 +71,11 @@ public class ExportAction implements EventListener<Event>
|
||||||
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
|
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
|
||||||
private Listbox cboType = new Listbox();
|
private Listbox cboType = new Listbox();
|
||||||
private Checkbox chkCurrentRow = new Checkbox();
|
private Checkbox chkCurrentRow = new Checkbox();
|
||||||
|
private int indxDetailSelected = 0;
|
||||||
|
private List<GridTab> childs;
|
||||||
|
private Row selectionTabRow = null;
|
||||||
|
private List<Checkbox> chkSelectionTabForExport = null;
|
||||||
|
private IGridTabExporter exporter;
|
||||||
/**
|
/**
|
||||||
* @param panel
|
* @param panel
|
||||||
*/
|
*/
|
||||||
|
@ -117,6 +122,7 @@ public class ExportAction implements EventListener<Event>
|
||||||
}
|
}
|
||||||
|
|
||||||
cboType.setSelectedIndex(0);
|
cboType.setSelectedIndex(0);
|
||||||
|
cboType.addActionListener(this);
|
||||||
|
|
||||||
Vbox vb = new Vbox();
|
Vbox vb = new Vbox();
|
||||||
vb.setWidth("100%");
|
vb.setWidth("100%");
|
||||||
|
@ -154,15 +160,68 @@ public class ExportAction implements EventListener<Event>
|
||||||
chkCurrentRow.setSelected(true);
|
chkCurrentRow.setSelected(true);
|
||||||
row.appendChild(chkCurrentRow);
|
row.appendChild(chkCurrentRow);
|
||||||
|
|
||||||
|
selectionTabRow = new Row();
|
||||||
|
rows.appendChild(selectionTabRow);
|
||||||
|
|
||||||
LayoutUtils.addSclass("dialog-footer", confirmPanel);
|
LayoutUtils.addSclass("dialog-footer", confirmPanel);
|
||||||
vb.appendChild(confirmPanel);
|
vb.appendChild(confirmPanel);
|
||||||
confirmPanel.addActionListener(this);
|
confirmPanel.addActionListener(this);
|
||||||
}
|
}
|
||||||
|
displayExportTabSelection();
|
||||||
panel.getComponent().getParent().appendChild(winExportFile);
|
panel.getComponent().getParent().appendChild(winExportFile);
|
||||||
panel.showBusyMask(winExportFile);
|
panel.showBusyMask(winExportFile);
|
||||||
LayoutUtils.openOverlappedWindow(panel.getComponent(), winExportFile, "middle_center");
|
LayoutUtils.openOverlappedWindow(panel.getComponent(), winExportFile, "middle_center");
|
||||||
winExportFile.addEventListener(DialogEvents.ON_WINDOW_CLOSE, this);
|
winExportFile.addEventListener(DialogEvents.ON_WINDOW_CLOSE, this);
|
||||||
|
winExportFile.addEventListener("onExporterException", this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show list tab can export for user selection
|
||||||
|
*/
|
||||||
|
protected void displayExportTabSelection() {
|
||||||
|
initTabInfo ();
|
||||||
|
|
||||||
|
exporter = getExporter ();
|
||||||
|
if (exporter == null){
|
||||||
|
Events.echoEvent("onExporterException", winExportFile, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear list checkbox selection to recreate with new reporter
|
||||||
|
selectionTabRow.getChildren().clear();
|
||||||
|
Vlayout vlayout = new Vlayout();
|
||||||
|
selectionTabRow.appendChild(new Space());
|
||||||
|
selectionTabRow.appendChild(vlayout);
|
||||||
|
vlayout.appendChild(new Label(Msg.getMsg(Env.getCtx(), "SelectTabToExport")));
|
||||||
|
|
||||||
|
chkSelectionTabForExport = new ArrayList<Checkbox> ();
|
||||||
|
boolean isHasSelectionTab = false;
|
||||||
|
boolean isSelectTabDefault = false;
|
||||||
|
// with 2Pack, default is export all child tab
|
||||||
|
if (exporter.getClass().getName().equals("org.adempiere.pipo2.GridTab2PackExporter")){
|
||||||
|
isSelectTabDefault = true;
|
||||||
|
}
|
||||||
|
// for to make each export tab with one checkbox
|
||||||
|
for (GridTab child : childs){
|
||||||
|
Checkbox chkSelectionTab = new Checkbox();
|
||||||
|
chkSelectionTab.setLabel(child.getName());
|
||||||
|
// just allow selection tab can export
|
||||||
|
if (!exporter.isExportableTab(child)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (child.getTabNo() == indxDetailSelected || isSelectTabDefault){
|
||||||
|
chkSelectionTab.setSelected(true);
|
||||||
|
}
|
||||||
|
chkSelectionTab.setAttribute("tabBinding", child);
|
||||||
|
vlayout.appendChild(chkSelectionTab);
|
||||||
|
chkSelectionTabForExport.add(chkSelectionTab);
|
||||||
|
isHasSelectionTab = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// in case no child tab can export. clear selection area
|
||||||
|
if (isHasSelectionTab == false){
|
||||||
|
selectionTabRow.getChildren().clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -173,33 +232,24 @@ public class ExportAction implements EventListener<Event>
|
||||||
exportFile();
|
exportFile();
|
||||||
else if (event.getName().equals(DialogEvents.ON_WINDOW_CLOSE)) {
|
else if (event.getName().equals(DialogEvents.ON_WINDOW_CLOSE)) {
|
||||||
panel.hideBusyMask();
|
panel.hideBusyMask();
|
||||||
}
|
}else if (event.getTarget().equals(cboType) && event.getName().equals(Events.ON_SELECT)) {
|
||||||
}
|
displayExportTabSelection();
|
||||||
|
}else if (event.getName().equals("onExporterException")){
|
||||||
private void exportFile() {
|
|
||||||
try {
|
|
||||||
ListItem li = cboType.getSelectedItem();
|
|
||||||
if(li == null || li.getValue() == null)
|
|
||||||
{
|
|
||||||
FDialog.error(0, winExportFile, "FileInvalidExtension");
|
FDialog.error(0, winExportFile, "FileInvalidExtension");
|
||||||
return;
|
winExportFile.onClose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String ext = li.getValue().toString();
|
/**
|
||||||
IGridTabExporter exporter = exporterMap.get(ext);
|
* get info of window export,
|
||||||
if (exporter == null)
|
* index of active tab, list child tab
|
||||||
{
|
*/
|
||||||
FDialog.error(0, winExportFile, "FileInvalidExtension");
|
protected void initTabInfo() {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean currentRowOnly = chkCurrentRow.isSelected();
|
|
||||||
File file = File.createTempFile("Export", "."+ext);
|
|
||||||
IADTabbox adTab = panel.getADTab();
|
IADTabbox adTab = panel.getADTab();
|
||||||
int selected = adTab.getSelectedIndex();
|
int selected = adTab.getSelectedIndex();
|
||||||
int tabLevel = panel.getActiveGridTab().getTabLevel();
|
int tabLevel = panel.getActiveGridTab().getTabLevel();
|
||||||
Set<String> tables = new HashSet<String>();
|
Set<String> tables = new HashSet<String>();
|
||||||
List<GridTab> childs = new ArrayList<GridTab>();
|
childs = new ArrayList<GridTab>();
|
||||||
List<GridTab> includedList = panel.getActiveGridTab().getIncludedTabs();
|
List<GridTab> includedList = panel.getActiveGridTab().getIncludedTabs();
|
||||||
for(GridTab included : includedList)
|
for(GridTab included : includedList)
|
||||||
{
|
{
|
||||||
|
@ -223,10 +273,39 @@ public class ExportAction implements EventListener<Event>
|
||||||
childs.add(adTabPanel.getGridTab());
|
childs.add(adTabPanel.getGridTab());
|
||||||
}
|
}
|
||||||
|
|
||||||
int indxDetailSelected = 0;
|
indxDetailSelected = 0;
|
||||||
if( adTab.getSelectedDetailADTabpanel()!=null )
|
if( adTab.getSelectedDetailADTabpanel()!=null )
|
||||||
indxDetailSelected = adTab.getSelectedDetailADTabpanel().getGridTab().getTabNo();
|
indxDetailSelected = adTab.getSelectedDetailADTabpanel().getGridTab().getTabNo();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get selected exporter
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected IGridTabExporter getExporter() {
|
||||||
|
ListItem li = cboType.getSelectedItem();
|
||||||
|
if(li == null || li.getValue() == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ext = li.getValue().toString();
|
||||||
|
IGridTabExporter exporter = exporterMap.get(ext);
|
||||||
|
return exporter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exportFile() {
|
||||||
|
try {
|
||||||
|
boolean currentRowOnly = chkCurrentRow.isSelected();
|
||||||
|
File file = File.createTempFile("Export", "."+cboType.getSelectedItem().getValue().toString());
|
||||||
|
childs.clear();
|
||||||
|
for (Checkbox chkSeletionTab : chkSelectionTabForExport){
|
||||||
|
if (chkSeletionTab.isChecked()){
|
||||||
|
childs.add((GridTab)chkSeletionTab.getAttribute("tabBinding"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exporter.export(panel.getActiveGridTab(), childs, currentRowOnly,file,indxDetailSelected);
|
exporter.export(panel.getActiveGridTab(), childs, currentRowOnly,file,indxDetailSelected);
|
||||||
|
|
||||||
winExportFile.onClose();
|
winExportFile.onClose();
|
||||||
|
|
Loading…
Reference in New Issue