Implemented data grid export service for zk client.
This commit is contained in:
parent
95fdfa0208
commit
92ea2ef0bb
|
@ -58,7 +58,7 @@ public class CWindowToolbar extends FToolbar implements EventListener
|
|||
private static final String TOOLBAR_BUTTON_STYLE = "background-color: transparent; display:inline-block; margin-left: 1px; margin-right: 1px; width: 26px; height: 24px;";
|
||||
|
||||
private static final String EMBEDDED_TOOLBAR_BUTTON_STYLE = "background-color: transparent; display:inline-block; margin-left: 1px; margin-right: 1px; width: 20px; height: 18px;";
|
||||
|
||||
|
||||
private static CLogger log = CLogger.getCLogger(CWindowToolbar.class);
|
||||
|
||||
private ToolBarButton btnIgnore;
|
||||
|
@ -78,7 +78,9 @@ public class CWindowToolbar extends FToolbar implements EventListener
|
|||
private ToolBarButton btnZoomAcross, btnActiveWorkflows, btnRequests, btnProductInfo;
|
||||
|
||||
private ToolBarButton btnChat;
|
||||
|
||||
|
||||
private ToolBarButton btnExport;
|
||||
|
||||
private HashMap<String, ToolBarButton> buttons = new HashMap<String, ToolBarButton>();
|
||||
|
||||
// private ToolBarButton btnExit;
|
||||
|
@ -169,6 +171,11 @@ public class CWindowToolbar extends FToolbar implements EventListener
|
|||
btnArchive.setDisabled(false); // Elaine 2008/07/28
|
||||
btnLock.setDisabled(!isPersonalLock); // Elaine 2008/12/04
|
||||
|
||||
if (MRole.getDefault().isCanExport())
|
||||
{
|
||||
btnExport = createButton("Export", "Export", "Export");
|
||||
}
|
||||
|
||||
configureKeyMap();
|
||||
|
||||
if (embedded)
|
||||
|
@ -472,7 +479,7 @@ public class CWindowToolbar extends FToolbar implements EventListener
|
|||
{
|
||||
this.btnChat.setDisabled(!enabled);
|
||||
}
|
||||
|
||||
|
||||
public void enablePrint(boolean enabled)
|
||||
{
|
||||
this.btnPrint.setDisabled(!enabled);
|
||||
|
@ -590,4 +597,13 @@ public class CWindowToolbar extends FToolbar implements EventListener
|
|||
public void setWindowNo(int windowNo) {
|
||||
this.windowNo = windowNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable export button
|
||||
* @param b
|
||||
*/
|
||||
public void enableExport(boolean b) {
|
||||
if (btnExport != null)
|
||||
btnExport.setDisabled(!b);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,114 +29,119 @@ public interface ToolbarListener
|
|||
* Ignore user changes
|
||||
*/
|
||||
public void onIgnore();
|
||||
|
||||
|
||||
/**
|
||||
* Create new record
|
||||
*/
|
||||
public void onNew();
|
||||
|
||||
|
||||
/**
|
||||
* Navigate to first record
|
||||
*/
|
||||
public void onFirst();
|
||||
|
||||
|
||||
/**
|
||||
* Navigate to last record
|
||||
*/
|
||||
public void onLast();
|
||||
|
||||
|
||||
/**
|
||||
* Navigate to next record
|
||||
*/
|
||||
public void onNext();
|
||||
|
||||
|
||||
/**
|
||||
* Navigate to previous record
|
||||
*/
|
||||
public void onPrevious();
|
||||
|
||||
|
||||
/**
|
||||
* Navigate to parent record, i.e previous tab
|
||||
*/
|
||||
public void onParentRecord();
|
||||
|
||||
|
||||
/**
|
||||
* Navigate to detail record, i.e next tab
|
||||
*/
|
||||
public void onDetailRecord();
|
||||
|
||||
|
||||
/**
|
||||
* Refresh current record
|
||||
*/
|
||||
public void onRefresh();
|
||||
|
||||
|
||||
/**
|
||||
* Print document
|
||||
*/
|
||||
public void onPrint();
|
||||
|
||||
|
||||
/**
|
||||
* View available report for current tab
|
||||
*/
|
||||
public void onReport();
|
||||
|
||||
|
||||
/**
|
||||
* Toggle record presentation between free form and tabular
|
||||
* Toggle record presentation between free form and tabular
|
||||
*/
|
||||
public void onToggle();
|
||||
|
||||
|
||||
/**
|
||||
* Open the help window
|
||||
*/
|
||||
public void onHelp();
|
||||
|
||||
|
||||
/**
|
||||
* Delete current record
|
||||
*/
|
||||
public void onDelete();
|
||||
|
||||
|
||||
/**
|
||||
* Save current record
|
||||
*/
|
||||
public void onSave();
|
||||
|
||||
|
||||
/**
|
||||
* Open the find/search dialog
|
||||
*/
|
||||
public void onFind();
|
||||
|
||||
|
||||
/**
|
||||
* Open the attachment dialog
|
||||
*/
|
||||
public void onAttachment();
|
||||
|
||||
|
||||
/**
|
||||
* Open the history dialog
|
||||
*/
|
||||
public void onHistoryRecords();
|
||||
|
||||
|
||||
/**
|
||||
* Open the archive dialog
|
||||
*/
|
||||
public void onArchive();
|
||||
|
||||
|
||||
/**
|
||||
* Zoom to window where current record is use
|
||||
*/
|
||||
public void onZoomAcross();
|
||||
|
||||
|
||||
/**
|
||||
* Show active workflow for current record
|
||||
*/
|
||||
public void onActiveWorkflows();
|
||||
|
||||
|
||||
/**
|
||||
* Open the request menu where user can view available request or create a new request
|
||||
*/
|
||||
public void onRequests();
|
||||
|
||||
|
||||
/**
|
||||
* View product info
|
||||
*/
|
||||
public void onProductInfo();
|
||||
public void onProductInfo();
|
||||
|
||||
/**
|
||||
* Export grid data
|
||||
*/
|
||||
public void onExport();
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.adempiere.webui.event.ActionEvent;
|
|||
import org.adempiere.webui.event.ActionListener;
|
||||
import org.adempiere.webui.event.ToolbarListener;
|
||||
import org.adempiere.webui.exception.ApplicationException;
|
||||
import org.adempiere.webui.panel.action.ExportAction;
|
||||
import org.adempiere.webui.part.AbstractUIPart;
|
||||
import org.adempiere.webui.session.SessionManager;
|
||||
import org.adempiere.webui.window.FDialog;
|
||||
|
@ -265,7 +266,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
|||
checkad_user_id = (Integer)currSess.getAttribute("Check_AD_User_ID");
|
||||
if (checkad_user_id!=Env.getAD_User_ID(ctx))
|
||||
{
|
||||
String msg = "Timestamp=" + new Date()
|
||||
String msg = "Timestamp=" + new Date()
|
||||
+ ", Bug 2832968 SessionUser="
|
||||
+ checkad_user_id
|
||||
+ ", ContextUser="
|
||||
|
@ -885,13 +886,13 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
|||
break;
|
||||
}
|
||||
String description = infoName + ": " + infoDisplay;
|
||||
|
||||
|
||||
new WChat(curWindowNo, curTab.getCM_ChatID(), curTab.getAD_Table_ID(), recordId, description, null);
|
||||
curTab.loadChats();
|
||||
toolbar.getButton("Chat").setPressed(curTab.hasChat());
|
||||
focusToActivePanel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see ToolbarListener#onToggle()
|
||||
*/
|
||||
|
@ -1162,7 +1163,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
|||
{
|
||||
sb.replace(pos, pos+1, " - ");
|
||||
}
|
||||
boolean showPopup = e.isError()
|
||||
boolean showPopup = e.isError()
|
||||
|| (!GridTab.DEFAULT_STATUS_MESSAGE.equals(e.getAD_Message()) && !GridTable.DATA_REFRESH_MESSAGE.equals(e.getAD_Message()));
|
||||
statusBar.setStatusLine (sb.toString (), e.isError (), showPopup);
|
||||
}
|
||||
|
@ -1285,7 +1286,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
|||
{
|
||||
toolbar.enableChat(false);
|
||||
}
|
||||
|
||||
|
||||
toolbar.getButton("Find").setPressed(curTab.isQueryActive());
|
||||
|
||||
// Elaine 2008/12/05
|
||||
|
@ -1300,6 +1301,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
|||
|
||||
toolbar.enablePrint(curTab.isPrinted());
|
||||
toolbar.enableReport(true);
|
||||
toolbar.enableExport(!curTab.isSortTab());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1432,7 +1434,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
|||
{
|
||||
if (curTab == null)
|
||||
return;
|
||||
|
||||
|
||||
if (!onSave(false))
|
||||
return;
|
||||
|
||||
|
@ -1899,6 +1901,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
|||
}
|
||||
//
|
||||
|
||||
|
||||
// Elaine 2008/07/28
|
||||
/**
|
||||
* @see ToolbarListener#onArchive()
|
||||
|
@ -1916,6 +1919,12 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
|
|||
|
||||
//
|
||||
|
||||
@Override
|
||||
public void onExport() {
|
||||
ExportAction action = new ExportAction(this);
|
||||
action.export();
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Start Button Process
|
||||
* @param vButton button
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
/******************************************************************************
|
||||
* 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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.adempiere.base.IGridTabExporter;
|
||||
import org.adempiere.base.Service;
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.adempiere.webui.apps.AEnv;
|
||||
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.panel.AbstractADWindowPanel;
|
||||
import org.adempiere.webui.window.FDialog;
|
||||
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
|
||||
{
|
||||
private AbstractADWindowPanel 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();
|
||||
|
||||
/**
|
||||
* @param panel
|
||||
*/
|
||||
public ExportAction(AbstractADWindowPanel 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);
|
||||
|
||||
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%");
|
||||
|
||||
Vbox vb = new Vbox();
|
||||
vb.setWidth("390px");
|
||||
winExportFile.appendChild(vb);
|
||||
vb.appendChild(hb);
|
||||
vb.appendChild(confirmPanel);
|
||||
confirmPanel.addActionListener(this);
|
||||
}
|
||||
|
||||
AEnv.showCenterScreen(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;
|
||||
}
|
||||
|
||||
File file = File.createTempFile("Export", "."+ext);
|
||||
exporter.export(panel.getActiveGridTab(), 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue