Coverage details for net.sourceforge.demetrix.ui.ProcessChainExcelWriter

LineHitsSource
1 /*******************************************************************************
2  
3  * Demetrix process modelling system
4  
5  *
6  
7  * Copyright (c) 2003, 2004 Dimitri A. Pissarenko
8  
9  *
10  
11  * This file is part of Demetrix.
12  
13  *
14  
15  * Demetrix is free software; you can redistribute it and/or modify
16  
17  * it under the terms of the GNU General Public License as published by
18  
19  * the Free Software Foundation; either version 2.1 of the License, or
20  
21  * (at your option) any later version.
22  
23  *
24  
25  * Demetrix is distributed in the hope that it will be useful,
26  
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  
31  * GNU General Public License for more details.
32  
33  *
34  
35  * You should have received a copy of the GNU General Public License
36  
37  * along with Demetrix; if not, write to the Free Software
38  
39  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40  
41  *
42  
43  * For further information you may
44  
45  *
46  
47  * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net
48  
49  * - look at http://sourceforge.net/projects/demetrix/
50  
51  * - look at http://demetrix.sourceforge.net/
52  
53  * - look at http://members.inode.at/d.pissarenko/
54  
55  *
56  
57  *****************************************************************************/
58  
59  
60  
61  package net.sourceforge.demetrix.ui;
62  
63  
64  
65 import java.io.File;
66  
67 import java.io.FileOutputStream;
68  
69 import java.io.IOException;
70  
71 import java.util.Iterator;
72  
73 import java.util.Vector;
74  
75  
76  
77 import org.apache.log4j.Logger;
78  
79 import org.apache.poi.hssf.usermodel.HSSFCell;
80  
81 import org.apache.poi.hssf.usermodel.HSSFRow;
82  
83 import org.apache.poi.hssf.usermodel.HSSFSheet;
84  
85 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
86  
87  
88  
89 import net.sourceforge.demetrix.model.ProcessChain;
90  
91 import net.sourceforge.demetrix.properties.DemetrixPropertiesHolder;
92  
93 import net.sourceforge.demetrix.properties.DemetrixPropertiesStorage;
94  
95 import net.sourceforge.demetrix.properties.DemetrixProperty;
96  
97 import net.sourceforge.demetrix.properties.DoubleProperty;
98  
99  
100  
101 /**
102  
103  * @author Dimitri Pissarenko
104  
105  *
106  
107  */
108  
109 public class ProcessChainExcelWriter {
110  
111     public static final String LINKS_SHEET_NAME = "Links";
112  
113     public static final String RESOURCES_SHEET_NAME = "Resources";
114  
115     public static final String TASKS_SHEET_NAME = "Tasks";
116  
117     private Logger logger=Logger.getLogger(getClass());
118  
119     private File targetFile;
120  
121     private ProcessChain processChain;
122  
123     public ProcessChainExcelWriter(File targetFile, ProcessChain processChain)
124  
1250    {
126  
1270        this.targetFile=targetFile;
128  
1290        this.processChain=processChain;
130  
1310    }
132  
133     public void write() throws IOException
134  
135     {
136  
1370        FileOutputStream fileOutputStream=null;
138  
1390        HSSFWorkbook workBook=null;
140  
141         
142  
1430        this.targetFile.delete();
144  
1450        this.targetFile.createNewFile();
146  
147         
148  
1490        workBook=new HSSFWorkbook();
150  
151     
152  
1530        ProcessChainExcelWriter.writeDemetrixPropertiesHolder(workBook.createSheet(ProcessChainExcelWriter.TASKS_SHEET_NAME), this.processChain.getTasks());
154  
1550        ProcessChainExcelWriter.writeDemetrixPropertiesHolder(workBook.createSheet(ProcessChainExcelWriter.RESOURCES_SHEET_NAME), this.processChain.getResources());
156  
1570        ProcessChainExcelWriter.writeDemetrixPropertiesHolder(workBook.createSheet(ProcessChainExcelWriter.LINKS_SHEET_NAME), this.processChain.getLinks());
158  
159  
160  
1610        fileOutputStream=new FileOutputStream(this.targetFile);
162  
1630        workBook.write(fileOutputStream);
164  
1650        fileOutputStream.close();
166  
167         
168  
1690    }
170  
171     public static void writeDemetrixPropertiesHolder(HSSFSheet sheet, Vector propertiesHolders)
172  
173     {
174  
1750        Iterator holders=null;
176  
1770        DemetrixPropertiesHolder holder=null;
178  
1790        Vector allPropertiesNames=null;
180  
1810        Iterator properties=null;
182  
1830        HSSFRow row=null;
184  
1850        HSSFCell cell=null;
186  
1870        DemetrixProperty currentProperty=null;
188  
1890        short currentRowNumber=0;
190  
1910        short currentColNumber=0;
192  
193         
194  
1950        allPropertiesNames=DemetrixPropertiesStorage.getAllPropertyNames(propertiesHolders);
196  
197         
198  
1990        ProcessChainExcelWriter.writePropertyNamesHeader(sheet, allPropertiesNames);
200  
2010        currentRowNumber=(short)(sheet.getLastRowNum()+1);
202  
203         
204  
2050        holders=propertiesHolders.iterator();
206  
2070        while (holders.hasNext())
208  
209         {
210  
2110            row=sheet.createRow(currentRowNumber++);
212  
2130            holder=(DemetrixPropertiesHolder)holders.next();
214  
2150            properties=allPropertiesNames.iterator();
216  
2170            currentColNumber=0;
218  
2190            while (properties.hasNext())
220  
221             {
222  
2230                cell=row.createCell(currentColNumber++);
224  
2250                currentProperty=holder.getProperty(properties.next().toString());
226  
2270                if (currentProperty!=null)
228  
229                 {
230  
2310                    ProcessChainExcelWriter.writeProperty(cell, currentProperty);
232  
233                 }
234  
235             }
236  
237         }
238  
239         
240  
2410    }
242  
243     public static void writePropertyNamesHeader(HSSFSheet sheet, Vector allPropertiesNames)
244  
245     {
246  
2470        HSSFRow row=null;
248  
2490        HSSFCell cell=null;
250  
2510        Iterator propertiesNames=null;
252  
2530        short curColNum=0;
254  
255         
256  
2570        row=sheet.createRow((short)(sheet.getLastRowNum()+1));
258  
2590        propertiesNames=allPropertiesNames.iterator();
260  
2610        curColNum=0;
262  
2630        while (propertiesNames.hasNext())
264  
265         {
266  
2670            cell=row.createCell(curColNum++);
268  
2690            cell.setCellValue(propertiesNames.next().toString());
270  
271         }
272  
2730    }
274  
275     public static void writeProperty(HSSFCell cell, DemetrixProperty property)
276  
277     {
278  
2790        DoubleProperty doubleProperty=null;
280  
2810        if (property instanceof DoubleProperty)
282  
283         {
284  
2850            doubleProperty=(DoubleProperty)property;
286  
287             
288  
2890            cell.setCellValue(((Double)doubleProperty.getValue()).doubleValue());
290  
291         }
292  
293         else
294  
295         {
296  
2970            cell.setCellValue(property.getValue().toString());
298  
299         }
300  
3010    }
302  
303     
304  
305  
306  
307 }
308  

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.