package com.vci.client.portal.NewUI; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import com.vci.corba.omd.btm.BtmItem; import com.vci.corba.portal.data.PLAction; import com.vci.corba.portal.data.PLCommandParameter; import com.vci.corba.portal.data.PLPageDefination; import com.vci.corba.portal.data.PLUILayout; import com.vci.corba.portal.data.PLTabButton; import com.vci.corba.portal.data.PLTabPage; import com.vci.client.LogonApplication; import com.vci.client.portal.utility.UITools; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.corba.common.VCIError; public class AllExpDialog { private String btname; private String plpageLayoutDefinationId= ""; List nodeList = new ArrayList(); HSSFWorkbook workbook; HSSFSheet sheet_btmName; HSSFSheet sheet_pagelayoutdefination; HSSFSheet sheet_pagedefination; HSSFSheet sheet_tabpage; HSSFSheet sheet_tabbutton; HSSFSheet sheet_commondParam; HSSFSheet sheet_action; int btmNameindex = 0; int pageLayoutDefinationindex = 0; int tabpageIndex = 0; int pagedefinationIndex = 0; int tabbuttonIndex = 0; int commondParamIndex = 0; int actionIndex = 0; /** * 记录action信息 */ List actionList = new ArrayList(); private String xfileName = ""; private BtmItem[] allBtItems; public AllExpDialog(BtmItem[] allBtItems) { this.allBtItems = allBtItems; init(); allExport(); } private void init() { workbook = new HSSFWorkbook(); sheet_btmName = workbook.createSheet(); workbook.setSheetName(0, "btmName"); sheet_pagelayoutdefination = workbook.createSheet(); workbook.setSheetName(1, "PlpageLayoutDefnation"); sheet_tabpage = workbook.createSheet(); workbook.setSheetName(2, "Pltabpage"); sheet_pagedefination = workbook.createSheet(); workbook.setSheetName(3, "Plpagedefination"); sheet_tabbutton = workbook.createSheet(); workbook.setSheetName(4, "Pltabbutton"); sheet_commondParam = workbook.createSheet(); workbook.setSheetName(5, "PlcommondParam"); sheet_action = workbook.createSheet(); workbook.setSheetName(6, "PlAction"); } public void allExport() { try{ btmNameindex = 0; pageLayoutDefinationindex = 0; tabpageIndex = 0; pagedefinationIndex = 0; tabbuttonIndex = 0; commondParamIndex = 0; if(allBtItems==null||(allBtItems!=null&&allBtItems.length==0)){ VCIOptionPane.showMessage(LogonApplication.frame, "没有要导出的数据!"); }else{ openFileChoser(); for(int abi = 0;abi < allBtItems.length;abi ++){ BtmItem btmItem = allBtItems[abi]; PLUILayout[] plpagelayoutdefinations = UITools.getService().getPLUILayoutsByRelatedType(btmItem.name); saveBtmName(btmItem.name); this.btname = btmItem.name; for(int i=0;i0){ // tabpageIndex++; // pageLayoutDefinationindex++; // } } if(writeFile()){ VCIOptionPane.showMessage(LogonApplication.frame, "导出成功"); } } }catch (Exception e) { e.printStackTrace(); VCIOptionPane.showMessage(LogonApplication.frame, "导出异常,退出!"); } } private void saveBtmName(String btmName) { // try { HSSFRow row = sheet_btmName.createRow(btmNameindex++); HSSFCell cell = row.createCell(0); cell.setCellValue(btmName); // Tool.getService().savePLUILayout(obj); // } catch (VCIError e) { // e.printStackTrace(); // } } private void savePlpageLayoutDefnation(Object object) { PLUILayout obj = (PLUILayout)object; plpageLayoutDefinationId = obj.plOId; // try { HSSFRow row = sheet_pagelayoutdefination.createRow(pageLayoutDefinationindex++); HSSFCell cell = row.createCell(0); cell.setCellValue(obj.plName); cell = row.createCell(1); cell.setCellValue(obj.plCode); cell = row.createCell(2); cell.setCellValue(obj.plOId); cell = row.createCell(3); cell.setCellValue(btname); cell = row.createCell(4); cell.setCellValue(obj.plRelatedType); cell = row.createCell(5); cell.setCellValue(obj.plIsShowNavigator); cell = row.createCell(6); cell.setCellValue(obj.plIsShowTab); cell = row.createCell(7); cell.setCellValue(obj.plIsShowForm); // Tool.getService().savePLUILayout(obj); // } catch (VCIError e) { // e.printStackTrace(); // } } private void savePlpageLayoutDefinationRelation(Object obj) { PLTabPage pt = (PLTabPage)obj; pt.plContextOId = plpageLayoutDefinationId; HSSFRow row = sheet_tabpage.createRow(tabpageIndex++); HSSFCell cell = row.createCell(0); cell.setCellValue(pt.plName); cell = row.createCell(1); cell.setCellValue(pt.plCode); cell = row.createCell(2); cell.setCellValue(pt.plSeq); cell = row.createCell(3); cell.setCellValue(pt.plContextOId); cell = row.createCell(4); cell.setCellValue(pt.plDesc); cell = row.createCell(5); cell.setCellValue(pt.plIsOpen); cell = row.createCell(6); cell.setCellValue(pt.plAreaType); cell = row.createCell(7); cell.setCellValue(pt.plOpenExpression); cell = row.createCell(8); cell.setCellValue(pt.plLicensOrs); cell = row.createCell(9); cell.setCellValue(pt.plLabel); cell = row.createCell(10); cell.setCellValue(pt.plOId); try { PLPageDefination[] pLPageDefinations = UITools.getService().getPLPageDefinationsByPageContextOId( pt.plOId); for(int j=0;j0){ commondParamIndex += pLCommandParameters.length; } } if(pLTabButtons.length>0){ tabbuttonIndex += pLTabButtons.length; } } if(pLPageDefinations.length>0){ pagedefinationIndex += pLPageDefinations.length; } } catch (VCIError e) { e.printStackTrace(); } } public void openFileChoser(){ JFileChooser jf = new JFileChooser(); jf.setDialogTitle("打开"); jf.removeChoosableFileFilter(jf.getFileFilter()); jf.setFileFilter(new FileFilter() { @Override public String getDescription() { return "xls"; } @Override public boolean accept(File f) { if(f.isDirectory()||f.getName().endsWith(".xls")){ return true; }else{ return false; } } }); int showOpenDialog = jf.showOpenDialog(LogonApplication.frame); if (showOpenDialog == JFileChooser.APPROVE_OPTION) { File file = jf.getSelectedFile(); xfileName = file.getAbsolutePath(); if(!xfileName.endsWith(".xls")){ xfileName = xfileName+".xls"; } } } public boolean writeFile(){ try { FileOutputStream fout = new FileOutputStream(xfileName); workbook.write(fout); fout.flush(); fout.close(); System.out.println("文件生成....."); return true; } catch (FileNotFoundException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } } }