| Line | Hits | Source |
|---|---|---|
| 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 | ||
| 125 | 0 | { |
| 126 | ||
| 127 | 0 | this.targetFile=targetFile; |
| 128 | ||
| 129 | 0 | this.processChain=processChain; |
| 130 | ||
| 131 | 0 | } |
| 132 | ||
| 133 | public void write() throws IOException | |
| 134 | ||
| 135 | { | |
| 136 | ||
| 137 | 0 | FileOutputStream fileOutputStream=null; |
| 138 | ||
| 139 | 0 | HSSFWorkbook workBook=null; |
| 140 | ||
| 141 | ||
| 142 | ||
| 143 | 0 | this.targetFile.delete(); |
| 144 | ||
| 145 | 0 | this.targetFile.createNewFile(); |
| 146 | ||
| 147 | ||
| 148 | ||
| 149 | 0 | workBook=new HSSFWorkbook(); |
| 150 | ||
| 151 | ||
| 152 | ||
| 153 | 0 | ProcessChainExcelWriter.writeDemetrixPropertiesHolder(workBook.createSheet(ProcessChainExcelWriter.TASKS_SHEET_NAME), this.processChain.getTasks()); |
| 154 | ||
| 155 | 0 | ProcessChainExcelWriter.writeDemetrixPropertiesHolder(workBook.createSheet(ProcessChainExcelWriter.RESOURCES_SHEET_NAME), this.processChain.getResources()); |
| 156 | ||
| 157 | 0 | ProcessChainExcelWriter.writeDemetrixPropertiesHolder(workBook.createSheet(ProcessChainExcelWriter.LINKS_SHEET_NAME), this.processChain.getLinks()); |
| 158 | ||
| 159 | ||
| 160 | ||
| 161 | 0 | fileOutputStream=new FileOutputStream(this.targetFile); |
| 162 | ||
| 163 | 0 | workBook.write(fileOutputStream); |
| 164 | ||
| 165 | 0 | fileOutputStream.close(); |
| 166 | ||
| 167 | ||
| 168 | ||
| 169 | 0 | } |
| 170 | ||
| 171 | public static void writeDemetrixPropertiesHolder(HSSFSheet sheet, Vector propertiesHolders) | |
| 172 | ||
| 173 | { | |
| 174 | ||
| 175 | 0 | Iterator holders=null; |
| 176 | ||
| 177 | 0 | DemetrixPropertiesHolder holder=null; |
| 178 | ||
| 179 | 0 | Vector allPropertiesNames=null; |
| 180 | ||
| 181 | 0 | Iterator properties=null; |
| 182 | ||
| 183 | 0 | HSSFRow row=null; |
| 184 | ||
| 185 | 0 | HSSFCell cell=null; |
| 186 | ||
| 187 | 0 | DemetrixProperty currentProperty=null; |
| 188 | ||
| 189 | 0 | short currentRowNumber=0; |
| 190 | ||
| 191 | 0 | short currentColNumber=0; |
| 192 | ||
| 193 | ||
| 194 | ||
| 195 | 0 | allPropertiesNames=DemetrixPropertiesStorage.getAllPropertyNames(propertiesHolders); |
| 196 | ||
| 197 | ||
| 198 | ||
| 199 | 0 | ProcessChainExcelWriter.writePropertyNamesHeader(sheet, allPropertiesNames); |
| 200 | ||
| 201 | 0 | currentRowNumber=(short)(sheet.getLastRowNum()+1); |
| 202 | ||
| 203 | ||
| 204 | ||
| 205 | 0 | holders=propertiesHolders.iterator(); |
| 206 | ||
| 207 | 0 | while (holders.hasNext()) |
| 208 | ||
| 209 | { | |
| 210 | ||
| 211 | 0 | row=sheet.createRow(currentRowNumber++); |
| 212 | ||
| 213 | 0 | holder=(DemetrixPropertiesHolder)holders.next(); |
| 214 | ||
| 215 | 0 | properties=allPropertiesNames.iterator(); |
| 216 | ||
| 217 | 0 | currentColNumber=0; |
| 218 | ||
| 219 | 0 | while (properties.hasNext()) |
| 220 | ||
| 221 | { | |
| 222 | ||
| 223 | 0 | cell=row.createCell(currentColNumber++); |
| 224 | ||
| 225 | 0 | currentProperty=holder.getProperty(properties.next().toString()); |
| 226 | ||
| 227 | 0 | if (currentProperty!=null) |
| 228 | ||
| 229 | { | |
| 230 | ||
| 231 | 0 | ProcessChainExcelWriter.writeProperty(cell, currentProperty); |
| 232 | ||
| 233 | } | |
| 234 | ||
| 235 | } | |
| 236 | ||
| 237 | } | |
| 238 | ||
| 239 | ||
| 240 | ||
| 241 | 0 | } |
| 242 | ||
| 243 | public static void writePropertyNamesHeader(HSSFSheet sheet, Vector allPropertiesNames) | |
| 244 | ||
| 245 | { | |
| 246 | ||
| 247 | 0 | HSSFRow row=null; |
| 248 | ||
| 249 | 0 | HSSFCell cell=null; |
| 250 | ||
| 251 | 0 | Iterator propertiesNames=null; |
| 252 | ||
| 253 | 0 | short curColNum=0; |
| 254 | ||
| 255 | ||
| 256 | ||
| 257 | 0 | row=sheet.createRow((short)(sheet.getLastRowNum()+1)); |
| 258 | ||
| 259 | 0 | propertiesNames=allPropertiesNames.iterator(); |
| 260 | ||
| 261 | 0 | curColNum=0; |
| 262 | ||
| 263 | 0 | while (propertiesNames.hasNext()) |
| 264 | ||
| 265 | { | |
| 266 | ||
| 267 | 0 | cell=row.createCell(curColNum++); |
| 268 | ||
| 269 | 0 | cell.setCellValue(propertiesNames.next().toString()); |
| 270 | ||
| 271 | } | |
| 272 | ||
| 273 | 0 | } |
| 274 | ||
| 275 | public static void writeProperty(HSSFCell cell, DemetrixProperty property) | |
| 276 | ||
| 277 | { | |
| 278 | ||
| 279 | 0 | DoubleProperty doubleProperty=null; |
| 280 | ||
| 281 | 0 | if (property instanceof DoubleProperty) |
| 282 | ||
| 283 | { | |
| 284 | ||
| 285 | 0 | doubleProperty=(DoubleProperty)property; |
| 286 | ||
| 287 | ||
| 288 | ||
| 289 | 0 | cell.setCellValue(((Double)doubleProperty.getValue()).doubleValue()); |
| 290 | ||
| 291 | } | |
| 292 | ||
| 293 | else | |
| 294 | ||
| 295 | { | |
| 296 | ||
| 297 | 0 | cell.setCellValue(property.getValue().toString()); |
| 298 | ||
| 299 | } | |
| 300 | ||
| 301 | 0 | } |
| 302 | ||
| 303 | ||
| 304 | ||
| 305 | ||
| 306 | ||
| 307 | } | |
| 308 |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |