From 3b60b8913d307ff28e27792a755ae65f4d14e1b2 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 10 Sep 2013 14:13:55 -0500 Subject: [PATCH] IDEMPIERE-1345 Allow Translation Export from webui --- .../oracle/201309091625_IDEMPIERE-1345.sql | 11 +++ .../201309091625_IDEMPIERE-1345.sql | 8 ++ org.adempiere.ui.zk/META-INF/MANIFEST.MF | 2 + .../webui/install/WTranslationDialog.java | 77 +++++++++++++++++-- 4 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 migration/i1.0c-release/oracle/201309091625_IDEMPIERE-1345.sql create mode 100644 migration/i1.0c-release/postgresql/201309091625_IDEMPIERE-1345.sql diff --git a/migration/i1.0c-release/oracle/201309091625_IDEMPIERE-1345.sql b/migration/i1.0c-release/oracle/201309091625_IDEMPIERE-1345.sql new file mode 100644 index 0000000000..bfdea45e1e --- /dev/null +++ b/migration/i1.0c-release/oracle/201309091625_IDEMPIERE-1345.sql @@ -0,0 +1,11 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Sep 9, 2013 4:25:23 PM COT +-- IDEMPIERE-1345 Allow Translation Export from webui +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('I','Export ZIP',200230,'D','d68b4fb8-d613-47a5-879b-c54aa9d3c415','ExportZIP','Y',TO_DATE('2013-09-09 16:25:22','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_DATE('2013-09-09 16:25:22','YYYY-MM-DD HH24:MI:SS'),0) +; + +SELECT register_migration_script('201309091625_IDEMPIERE-1345.sql') FROM dual +; + diff --git a/migration/i1.0c-release/postgresql/201309091625_IDEMPIERE-1345.sql b/migration/i1.0c-release/postgresql/201309091625_IDEMPIERE-1345.sql new file mode 100644 index 0000000000..b47b0eaa78 --- /dev/null +++ b/migration/i1.0c-release/postgresql/201309091625_IDEMPIERE-1345.sql @@ -0,0 +1,8 @@ +-- Sep 9, 2013 4:25:23 PM COT +-- IDEMPIERE-1345 Allow Translation Export from webui +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('I','Export ZIP',200230,'D','d68b4fb8-d613-47a5-879b-c54aa9d3c415','ExportZIP','Y',TO_TIMESTAMP('2013-09-09 16:25:22','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_TIMESTAMP('2013-09-09 16:25:22','YYYY-MM-DD HH24:MI:SS'),0) +; + +SELECT register_migration_script('201309091625_IDEMPIERE-1345.sql') FROM dual +; + diff --git a/org.adempiere.ui.zk/META-INF/MANIFEST.MF b/org.adempiere.ui.zk/META-INF/MANIFEST.MF index f8850cab9b..db3edefd22 100644 --- a/org.adempiere.ui.zk/META-INF/MANIFEST.MF +++ b/org.adempiere.ui.zk/META-INF/MANIFEST.MF @@ -11,6 +11,8 @@ Import-Package: javax.activation;version="1.1.1", org.apache.commons.codec.binary, org.apache.ecs, org.apache.ecs.xhtml, + org.apache.tools.ant, + org.apache.tools.ant.taskdefs, org.compiere.css, org.osgi.framework;version="1.5.0", org.osgi.service.event;version="1.3.0", diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/install/WTranslationDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/install/WTranslationDialog.java index 3e078fd993..237b4d6525 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/install/WTranslationDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/install/WTranslationDialog.java @@ -46,7 +46,11 @@ import org.adempiere.webui.panel.StatusBarPanel; import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.util.ReaderInputStream; import org.adempiere.webui.window.FDialog; +import org.adempiere.webui.window.MultiFileDownloadDialog; import org.apache.commons.io.FileUtils; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Target; +import org.apache.tools.ant.taskdefs.Zip; import org.compiere.install.Translation; import org.compiere.install.TranslationController; import org.compiere.util.Env; @@ -100,6 +104,7 @@ public class WTranslationDialog extends TranslationController implements IFormCo private Button bExport = new Button(); private Button bImport = new Button(); + private Button bExportZIP = new Button(); private Button bImportZIP = new Button(); private Label lClient = new Label(); @@ -128,6 +133,8 @@ public class WTranslationDialog extends TranslationController implements IFormCo bExport.setStyle("text-align: right;"); bImport.setLabel(Msg.getMsg(Env.getCtx(), "Import")); bImport.addActionListener(this); + bExportZIP.setLabel(Msg.getMsg(Env.getCtx(), "ExportZIP")); + bExportZIP.addActionListener(this); bImportZIP.setLabel(Msg.getMsg(Env.getCtx(), "ImportZIP")); bImportZIP.setUpload(AdempiereWebUI.getUploadSetting()); bImportZIP.addEventListener(Events.ON_UPLOAD, this); @@ -152,10 +159,16 @@ public class WTranslationDialog extends TranslationController implements IFormCo row.appendChild(div); div = new Div(); - div.setStyle("text-align: center;"); + div.setStyle("text-align: left;"); div.appendChild(bImport); row.appendChild(div); + row = rows.newRow(); + div = new Div(); + div.setStyle("text-align: right;"); + div.appendChild(bExportZIP); + row.appendChild(div); + div = new Div(); div.setStyle("text-align: left;"); div.appendChild(bImportZIP); @@ -247,13 +260,17 @@ public class WTranslationDialog extends TranslationController implements IFormCo return; } - final FolderBrowser directoryDialog = new FolderBrowser(true); - directoryDialog.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { - @Override - public void onEvent(Event event) throws Exception { - callImportProcess(directoryDialog.getPath()); - } - }); + if ((e.getTarget() == bImport || e.getTarget() == bExport)) { + final FolderBrowser directoryDialog = new FolderBrowser(true); + directoryDialog.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + callImportProcess(directoryDialog.getPath()); + } + }); + } else if (e.getTarget() == bExportZIP) { + processExportZIP(); + } } // onEvent private void callImportProcess(String directory) { @@ -408,4 +425,48 @@ public class WTranslationDialog extends TranslationController implements IFormCo out.close(); } + private void processExportZIP() { + File tempfolder; + try { + tempfolder = File.createTempFile(m_AD_Language.getValue(), ".trl"); + tempfolder.delete(); + tempfolder.mkdir(); + } catch (IOException e1) { + throw new AdempiereException("Problem creating temp folder", e1); + } + // export to temp folder + callImportProcess(tempfolder.getPath()); + + // and now zip the exported files + File destZipFile = null; + try { + destZipFile = File.createTempFile(m_AD_Language.getValue() + "_trlExport_", ".zip"); + } catch (Throwable e) { + throw new AdempiereException("Unable to create temp file", e); + } + destZipFile.delete(); + + Zip zipper = new Zip(); + zipper.setDestFile(destZipFile); + zipper.setBasedir(tempfolder); + zipper.setUpdate(false); + zipper.setCompress(true); + zipper.setCaseSensitive(false); + zipper.setFilesonly(true); + zipper.setTaskName("zip"); + zipper.setTaskType("zip"); + zipper.setProject(new Project()); + zipper.setOwningTarget(new Target()); + zipper.execute(); + + try { + FileUtils.deleteDirectory(tempfolder); + } catch (IOException e) {} + + MultiFileDownloadDialog downloadDialog = new MultiFileDownloadDialog(new File [] {destZipFile}); + downloadDialog.setPage(getForm().getPage()); + downloadDialog.setTitle(Msg.getMsg(Env.getCtx(), "ExportZIP")); + Events.postEvent(downloadDialog, new Event(MultiFileDownloadDialog.ON_SHOW)); + } + }