IDEMPIERE-234 Configurable Toolbar / Bring back export action button

This commit is contained in:
Carlos Ruiz 2012-10-29 11:51:14 -05:00
parent 14f2125874
commit c621e93fe3
4 changed files with 235 additions and 1 deletions

View File

@ -91,6 +91,7 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
private ToolBarButton btnCustomize;
private ToolBarButton btnExport;
private ToolBarButton btnFileImport;
private ToolBarButton btnProcess;
@ -188,6 +189,10 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
btnArchive.setDisabled(false); // Elaine 2008/07/28
btnLock.setDisabled(!isPersonalLock); // Elaine 2008/12/04
if (MRole.getDefault().isCanExport())
{
btnExport = createButton("Export", "Export", "Export");
}
btnFileImport = createButton("FileImport", "FileImport", "FileImport");
configureKeyMap();
@ -543,6 +548,15 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
this.windowNo = windowNo;
}
/**
* Enable/disable export button
* @param b
*/
public void enableExport(boolean b) {
if (btnExport != null)
btnExport.setDisabled(!b);
}
/**
* Enable/disable file import button
* @param b

View File

@ -59,6 +59,7 @@ import org.adempiere.webui.panel.ADForm;
import org.adempiere.webui.panel.InfoPanel;
import org.adempiere.webui.panel.WAttachment;
import org.adempiere.webui.panel.WDocActionPanel;
import org.adempiere.webui.panel.action.ExportAction;
import org.adempiere.webui.panel.action.FileImportAction;
import org.adempiere.webui.panel.action.ReportAction;
import org.adempiere.webui.part.AbstractUIPart;
@ -1341,6 +1342,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
toolbar.enablePrint(adTabbox.getSelectedGridTab().isPrinted());
toolbar.enableReport(true);
toolbar.enableExport(!adTabbox.getSelectedGridTab().isSortTab());
toolbar.enableFileImport(!changed && !adTabbox.getSelectedGridTab().isSortTab() && adTabbox.getSelectedGridTab().isInsertRecord());
//Deepak-Enabling customize button IDEMPIERE-364
@ -2155,6 +2157,12 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
//
@Override
public void onExport() {
ExportAction action = new ExportAction(this);
action.export();
}
@Override
public void onFileImport() {
FileImportAction action = new FileImportAction(this);

View File

@ -160,6 +160,11 @@ public interface ToolbarListener
*/
public void onCopy();
/**
* Export grid data
*/
public void onExport();
/**
* File import data
*/

View File

@ -0,0 +1,207 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2010 Heng Sin Low *
* 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.webui.panel.action;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.adempiere.base.IGridTabExporter;
import org.adempiere.base.Service;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.webui.adwindow.AbstractADWindowContent;
import org.adempiere.webui.adwindow.IADTabbox;
import org.adempiere.webui.adwindow.IADTabpanel;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Checkbox;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.Label;
import org.adempiere.webui.component.ListItem;
import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.window.FDialog;
import org.compiere.model.GridTab;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.zkoss.util.media.AMedia;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Div;
import org.zkoss.zul.Filedownload;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Vbox;
/**
*
* @author hengsin
*
*/
public class ExportAction implements EventListener<Event>
{
private AbstractADWindowContent panel;
private Map<String, IGridTabExporter> exporterMap = null;
private Map<String, String> extensionMap = null;
private Window winExportFile = null;
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
private Listbox cboType = new Listbox();
private Checkbox chkCurrentRow = new Checkbox();
/**
* @param panel
*/
public ExportAction(AbstractADWindowContent panel)
{
this.panel = panel;
}
/**
* execute export action
*/
public void export()
{
exporterMap = new HashMap<String, IGridTabExporter>();
extensionMap = new HashMap<String, String>();
List<IGridTabExporter> exporterList = Service.list(IGridTabExporter.class);
for(IGridTabExporter exporter : exporterList)
{
String extension = exporter.getFileExtension();
if (!extensionMap.containsKey(extension))
{
extensionMap.put(extension, exporter.getFileExtensionLabel());
exporterMap.put(extension, exporter);
}
}
if(winExportFile == null)
{
winExportFile = new Window();
winExportFile.setTitle(Msg.getMsg(Env.getCtx(), "Export") + ": " + panel.getActiveGridTab().getName());
winExportFile.setWidth("450px");
winExportFile.setClosable(true);
winExportFile.setBorder("normal");
winExportFile.setStyle("position:absolute");
cboType.setMold("select");
cboType.getItems().clear();
for(Map.Entry<String, String> entry : extensionMap.entrySet())
{
cboType.appendItem(entry.getKey() + " - " + entry.getValue(), entry.getKey());
}
cboType.setSelectedIndex(0);
Vbox vb = new Vbox();
vb.setWidth("100%");
winExportFile.appendChild(vb);
Hbox hb = new Hbox();
Div div = new Div();
div.setAlign("right");
div.appendChild(new Label("Files of Type: "));
hb.appendChild(div);
hb.appendChild(cboType);
cboType.setWidth("100%");
vb.appendChild(hb);
hb = new Hbox();
chkCurrentRow.setLabel(Msg.getMsg(Env.getCtx(), "ExportCurrentRowOnly"));
chkCurrentRow.setSelected(true);
hb.appendChild(chkCurrentRow);
vb.appendChild(hb);
vb.appendChild(confirmPanel);
confirmPanel.addActionListener(this);
}
winExportFile.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED);
AEnv.showWindow(winExportFile);
}
@Override
public void onEvent(Event event) throws Exception {
if(event.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
winExportFile.onClose();
else if(event.getTarget().getId().equals(ConfirmPanel.A_OK))
exportFile();
}
private void exportFile() {
try {
ListItem li = cboType.getSelectedItem();
if(li == null || li.getValue() == null)
{
FDialog.error(0, winExportFile, "FileInvalidExtension");
return;
}
String ext = li.getValue().toString();
IGridTabExporter exporter = exporterMap.get(ext);
if (exporter == null)
{
FDialog.error(0, winExportFile, "FileInvalidExtension");
return;
}
boolean currentRowOnly = chkCurrentRow.isSelected();
File file = File.createTempFile("Export", "."+ext);
IADTabbox adTab = panel.getADTab();
int selected = adTab.getSelectedIndex();
int tabLevel = panel.getActiveGridTab().getTabLevel();
Set<String> tables = new HashSet<String>();
List<GridTab> childs = new ArrayList<GridTab>();
List<GridTab> includedList = panel.getActiveGridTab().getIncludedTabs();
for(GridTab included : includedList)
{
String tableName = included.getTableName();
if (tables.contains(tableName))
continue;
tables.add(tableName);
childs.add(included);
}
for(int i = selected+1; i < adTab.getTabCount(); i++)
{
IADTabpanel adTabPanel = adTab.getADTabpanel(i);
if (adTabPanel.getGridTab().isSortTab())
continue;
if (adTabPanel.getGridTab().getTabLevel() <= tabLevel)
break;
String tableName = adTabPanel.getGridTab().getTableName();
if (tables.contains(tableName))
continue;
tables.add(tableName);
childs.add(adTabPanel.getGridTab());
}
exporter.export(panel.getActiveGridTab(), childs, currentRowOnly, file);
winExportFile.onClose();
winExportFile = null;
AMedia media = null;
media = new AMedia(panel.getActiveGridTab().getName() + "." + ext, null, exporter.getContentType(), file, true);
Filedownload.save(media, panel.getActiveGridTab().getName() + "." + ext);
} catch (Exception e) {
throw new AdempiereException(e);
} finally {
if (winExportFile != null)
winExportFile.onClose();
}
}
}