1 7 8 package com.memoire.vainstall.builder; 9 10 import com.memoire.vainstall.builder.event.*; 11 import com.memoire.vainstall.builder.util.*; 12 13 import java.util.*; 14 15 import javax.swing.DefaultListModel ; 16 import javax.swing.event.EventListenerList ; 17 18 26 public class VAIProductModel { 27 28 32 EventListenerList listenerList = new EventListenerList (); 33 34 37 ProductPersisterInterface productPersister; 38 39 42 boolean isDirty = false; 43 44 48 Hashtable masterRequiredList = new Hashtable(); 49 50 55 Hashtable requiredList = new Hashtable(); 56 57 DefaultListModel requiredListModel = new DefaultListModel (); 58 59 62 Hashtable propertyList = new Hashtable(); 63 64 67 LinkedList stepsList = new LinkedList(); 68 69 72 LinkedList targetList = new LinkedList(); 73 74 77 LinkedList languageList = new LinkedList(); 78 79 82 public VAIProductModel() { 83 super(); 84 85 try { 86 if( System.getProperty("java.version").indexOf("1.4.") != -1 ) { 87 productPersister = (ProductPersisterInterface)Class.forName("com.memoire.vainstall.builder.util.JavaProductPersister").newInstance(); 88 } else { 89 productPersister = (ProductPersisterInterface)Class.forName("com.memoire.vainstall.builder.util.NanoProductPersister").newInstance(); 90 } 91 92 productPersister.initialize(this); 93 94 } catch (InstantiationException exc) { 96 } catch (ClassNotFoundException exc) { 97 } catch (IllegalAccessException exc) { 98 } 99 100 buildRequiredFieldsList(); 101 } 102 103 107 public boolean isDirty() { 108 return isDirty; 109 } 110 111 114 public void fireVAIProductEvent(VAIProductEvent e) { 115 116 Object [] listeners = listenerList.getListenerList(); 118 119 for (int i = listeners.length - 2; i >= 0; i -= 2) { 122 if (listeners[i] == com.memoire.vainstall.builder.event.VAIProductListener.class) { 123 ((com.memoire.vainstall.builder.event.VAIProductListener)listeners[i+1]).productChanged(e); 124 } 125 } 126 } 127 128 131 public void addVAIProductListener(com.memoire.vainstall.builder.event.VAIProductListener l) { 132 listenerList.add(com.memoire.vainstall.builder.event.VAIProductListener.class,l); 133 } 134 135 138 public void removeVAIProductListener(com.memoire.vainstall.builder.event.VAIProductListener l) { 139 listenerList.remove(com.memoire.vainstall.builder.event.VAIProductListener.class,l); 140 } 141 142 146 public void load() throws VAIBuilderException { 147 148 productPersister.load(); 149 150 isDirty = false; 151 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_LOADED)); 152 } 153 154 158 public void save() throws VAIBuilderException { 159 productPersister.save(); 160 161 isDirty = false; 162 163 if(requiredList.size() == 0) { 164 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_REQUIREMENTS_MET)); 165 } 166 167 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_SAVED)); 168 } 169 170 174 public String getProductName() { 175 return (String )getPropertyList().get("vainstall.product.name"); 176 } 177 178 182 public void setProductName(String value) { 183 if(value.equals(getProductName()) == true) { 184 return; 185 } 186 if (value != null) { 187 getPropertyList().put("vainstall.product.name", value); 188 } else { 189 getPropertyList().remove("vainstall.product.name"); 190 } 191 192 isDirty = true; 193 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECTNAME_CHANGED)); 194 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 195 } 196 197 201 public String getProductVersion() { 202 return (String )getPropertyList().get("vainstall.product.version"); 203 } 204 205 209 public void setProductVersion(String value) { 210 if(value.equals(getProductVersion()) == true) { 211 return; 212 } 213 if (value != null) { 214 getPropertyList().put("vainstall.product.version", value); 215 } else { 216 getPropertyList().remove("vainstall.product.version"); 217 } 218 219 isDirty = true; 220 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 221 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECTVERSION_CHANGED)); 222 } 223 224 228 public String getProductDirectory() { 229 return (String )getPropertyList().get("vainstall.product.directory"); 230 } 231 232 236 public void setProductDirectory(String value) { 237 if(value.equals(getProductDirectory()) == true) { 238 return; 239 } 240 if (value != null) { 241 getPropertyList().put("vainstall.product.directory", value); 242 } else { 243 getPropertyList().remove("vainstall.product.directory"); 244 } 245 246 isDirty = true; 247 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 248 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECTDIRECTORY_CHANGED)); 249 } 250 251 public String getProductType() { 252 return (String )getPropertyList().get("vainstall.product.type"); 253 } 254 255 public void setProductType(String value) { 256 if(value.equals(getProductType()) == true) { 257 return; 258 } 259 if (value != null) { 260 getPropertyList().put("vainstall.product.type", value); 261 } else { 262 getPropertyList().remove("vainstall.product.type"); 263 } 264 265 isDirty = true; 266 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 267 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value)); 268 } 269 270 private void buildRequiredFieldsList() { 271 272 ProductRequirement requirement = null; 273 274 requirement = new ProductRequirement("Install Filename","<html><b><font color=black size=7><center>Install Filename:</center></font></b><br>The name of the install file without file extension.</html>"); 277 masterRequiredList.put("Install Filename",requirement); 278 requiredList.put("Install Filename",requirement); 279 getRequiredListModel().addElement(requirement); 280 281 requirement = new ProductRequirement("Required Steps","<html><b><font color=black size=7><center>Required Steps:</center></font></b><br>Required steps who needs configured for an installation package.</html>"); 283 masterRequiredList.put("Required Steps",requirement); 284 requiredList.put("Required Steps",requirement); 285 getRequiredListModel().addElement(requirement); 286 293 } 294 295 public Hashtable getRequiredList() { 296 return requiredList; 297 } 298 299 public DefaultListModel getRequiredListModel() { 300 return requiredListModel; 301 } 302 303 public void addRequirement(String name) { 304 Object obj = masterRequiredList.get(name); 305 if (obj != null) { 306 requiredList.put(name,obj); 307 getRequiredListModel().addElement(obj); 308 309 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_REQUIREMENTS_NOTMET)); 310 } 311 } 312 313 public void removeRequirement(String name) { 314 315 ProductRequirement req = (ProductRequirement)requiredList.remove(name); 316 if (req != null) { 317 try { 318 if(getRequiredListModel().contains(req) == true) { 319 getRequiredListModel().removeElement(req); 320 } 321 } catch(Exception exc) { 322 } 325 } 326 327 if(requiredList.size() == 0) { 328 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_REQUIREMENTS_MET)); 329 } 330 } 331 332 336 public Hashtable getPropertyList() { 337 return propertyList; 338 } 339 340 public void putProperty(String name, String value) { 341 if (getPropertyList().containsKey(name) == false) { 342 getPropertyList().put(name,value); 343 } else { 344 if (((String )getPropertyList().get(name)).equals(value) == true || 345 value.length() == 0) { 346 return; 347 } else { 348 getPropertyList().put(name,value); 349 } 350 } 351 isDirty = true; 352 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 353 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,name)); 354 } 355 356 public String getProperty(String name) { 357 return (String )getPropertyList().get(name); 358 } 359 360 public void removeProperty(String name) { 361 if (getPropertyList().containsKey(name) == false) { 362 return; 363 } 364 getPropertyList().remove(name); 365 isDirty = true; 366 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 367 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,name)); 368 } 369 370 public LinkedList getStepsList() { 371 return stepsList; 372 } 373 374 378 public void addStep(String type) { 379 getStepsList().add(type); 380 isDirty = true; 381 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 382 } 383 384 public String getPackageName() { 385 return (String )getPropertyList().get("vainstall.archiver.package.name"); 386 } 387 388 public void setPackageName(String value) { 389 if(value.equals(getPackageName()) == true) { 390 return; 391 } 392 if (value != null) { 393 getPropertyList().put("vainstall.archiver.package.name", value); 394 } else { 395 getPropertyList().remove("vainstall.archiver.package.name"); 396 } 397 398 isDirty = true; 399 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 400 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value)); 401 } 402 403 public String getLicenseName() { 404 return (String )getPropertyList().get("vainstall.archiver.license.name"); 405 } 406 407 public void setLicenseName(String value) { 408 if(value.equals(getLicenseName()) == true) { 409 return; 410 } 411 if (value != null) { 412 getPropertyList().put("vainstall.archiver.license.name", value); 413 } else { 414 getPropertyList().remove("vainstall.archiver.license.name"); 415 } 416 417 isDirty = true; 418 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 419 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value)); 420 } 421 422 public String getLicenseEncoding() { 423 return (String )getPropertyList().get("vainstall.archiver.license.encoding"); 424 } 425 426 public void setLicenseEncoding(String value) { 427 if(value.equals(getLicenseEncoding()) == true) { 428 return; 429 } 430 if (value != null) { 431 getPropertyList().put("vainstall.archiver.license.encoding", value); 432 } else { 433 getPropertyList().remove("vainstall.archiver.license.encoding"); 434 } 435 436 isDirty = true; 437 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 438 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value)); 439 } 440 441 public String getReadmeName() { 442 return (String )getPropertyList().get("vainstall.archiver.readme.name"); 443 } 444 445 public void setReadmeName(String value) { 446 if(value.equals(getReadmeName()) == true) { 447 return; 448 } 449 if (value != null) { 450 getPropertyList().put("vainstall.archiver.readme.name", value); 451 } else { 452 getPropertyList().remove("vainstall.archiver.readme.name"); 453 } 454 455 isDirty = true; 456 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 457 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value)); 458 } 459 460 public String getReadmeEncoding() { 461 return (String )getPropertyList().get("vainstall.archiver.readme.encoding"); 462 } 463 464 public void setReadmeEncoding(String value) { 465 if(value.equals(getReadmeEncoding()) == true) { 466 return; 467 } 468 if (value != null) { 469 getPropertyList().put("vainstall.archiver.readme.encoding", value); 470 } else { 471 getPropertyList().remove("vainstall.archiver.readme.encoding"); 472 } 473 474 isDirty = true; 475 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 476 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value)); 477 } 478 479 public LinkedList getTargetList() { 480 return targetList; 481 } 482 483 public void addTarget(String value) { 484 if (targetList.contains(value) == false) { 485 targetList.add(value); 486 isDirty = true; 487 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 488 } 489 } 490 491 public void removeTarget(String value) { 492 if (targetList.contains(value) == true) { 493 targetList.remove(value); 494 isDirty = true; 495 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 496 } 497 } 498 499 public LinkedList getLanguageList() { 500 return languageList; 501 } 502 503 public void addLanguage(String value) { 504 if (languageList.contains(value) == false) { 505 languageList.add(value); 506 isDirty = true; 507 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 508 } 509 } 510 511 public void removeLanguage(String value) { 512 if (languageList.contains(value) == true) { 513 languageList.remove(value); 514 isDirty = true; 515 fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY)); 516 } 517 } 518 519 } 520 | Popular Tags |