001: /*
002: * $RCSfile: VAIProductModel.java,v $
003: * @modification $Date: 2001/09/28 19:27:49 $
004: * @version $Id: VAIProductModel.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
005: *
006: */
007:
008: package com.memoire.vainstall.builder;
009:
010: import com.memoire.vainstall.builder.event.*;
011: import com.memoire.vainstall.builder.util.*;
012:
013: import java.util.*;
014:
015: import javax.swing.DefaultListModel;
016: import javax.swing.event.EventListenerList;
017:
018: /**
019: * This is a VAIProduct data model
020: *
021: * @see javax.swing.event.EventListenerList
022: *
023: * @author Henrik Falk
024: * @version $Id: VAIProductModel.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
025: */
026: public class VAIProductModel {
027:
028: /**
029: * The list of listenere that are interested in changes in
030: * the data model
031: */
032: EventListenerList listenerList = new EventListenerList();
033:
034: /**
035: * The persistance class for this model
036: */
037: ProductPersisterInterface productPersister;
038:
039: /**
040: * Flag that indicated whether the data model needs to be saved
041: */
042: boolean isDirty = false;
043:
044: /**
045: * Master list of required fields/attributes for a product
046: * before an installation package can be generated
047: */
048: Hashtable masterRequiredList = new Hashtable();
049:
050: /**
051: * List of required fields/attributes for a product
052: * which still needs to be 'resolved'
053: * before an installation package can be generated
054: */
055: Hashtable requiredList = new Hashtable();
056:
057: DefaultListModel requiredListModel = new DefaultListModel();
058:
059: /**
060: * list of properties in the format <name,String value>
061: */
062: Hashtable propertyList = new Hashtable();
063:
064: /**
065: *
066: */
067: LinkedList stepsList = new LinkedList();
068:
069: /**
070: *
071: */
072: LinkedList targetList = new LinkedList();
073:
074: /**
075: *
076: */
077: LinkedList languageList = new LinkedList();
078:
079: /**
080: * Default constructor
081: */
082: public VAIProductModel() {
083: super ();
084:
085: try {
086: if (System.getProperty("java.version").indexOf("1.4.") != -1) {
087: productPersister = (ProductPersisterInterface) Class
088: .forName(
089: "com.memoire.vainstall.builder.util.JavaProductPersister")
090: .newInstance();
091: } else {
092: productPersister = (ProductPersisterInterface) Class
093: .forName(
094: "com.memoire.vainstall.builder.util.NanoProductPersister")
095: .newInstance();
096: }
097:
098: productPersister.initialize(this );
099:
100: // add proper exception handling
101: } catch (InstantiationException exc) {
102: } catch (ClassNotFoundException exc) {
103: } catch (IllegalAccessException exc) {
104: }
105:
106: buildRequiredFieldsList();
107: }
108:
109: /**
110: * Returns whether the data model needs to be saved or not.
111: * @return true if the datamodel needs to be saved
112: */
113: public boolean isDirty() {
114: return isDirty;
115: }
116:
117: /**
118: * @param e VAIProductEvent
119: */
120: public void fireVAIProductEvent(VAIProductEvent e) {
121:
122: // guaranteed to return a non-null array
123: Object[] listeners = listenerList.getListenerList();
124:
125: // process the listeners last to first, notifying
126: // those that are interested in this event
127: for (int i = listeners.length - 2; i >= 0; i -= 2) {
128: if (listeners[i] == com.memoire.vainstall.builder.event.VAIProductListener.class) {
129: ((com.memoire.vainstall.builder.event.VAIProductListener) listeners[i + 1])
130: .productChanged(e);
131: }
132: }
133: }
134:
135: /**
136: * @param l com.memoire.vainstall.builder.event.VAIProductListener
137: */
138: public void addVAIProductListener(
139: com.memoire.vainstall.builder.event.VAIProductListener l) {
140: listenerList
141: .add(
142: com.memoire.vainstall.builder.event.VAIProductListener.class,
143: l);
144: }
145:
146: /**
147: * @param l com.memoire.vainstall.builder.event.VAIProductListener
148: */
149: public void removeVAIProductListener(
150: com.memoire.vainstall.builder.event.VAIProductListener l) {
151: listenerList
152: .remove(
153: com.memoire.vainstall.builder.event.VAIProductListener.class,
154: l);
155: }
156:
157: /**
158: * Load project data from datastore
159: * @throws com.memoire.vainstall.builder.util.VAIBuilderException
160: */
161: public void load() throws VAIBuilderException {
162:
163: productPersister.load();
164:
165: isDirty = false;
166: fireVAIProductEvent(new VAIProductEvent(this ,
167: VAIProductEvent.PROJECT_LOADED));
168: }
169:
170: /**
171: * Store project data in datastore
172: * @throws com.memoire.vainstall.builder.util.VAIBuilderException
173: */
174: public void save() throws VAIBuilderException {
175: productPersister.save();
176:
177: isDirty = false;
178:
179: if (requiredList.size() == 0) {
180: fireVAIProductEvent(new VAIProductEvent(this ,
181: VAIProductEvent.PROJECT_REQUIREMENTS_MET));
182: }
183:
184: fireVAIProductEvent(new VAIProductEvent(this ,
185: VAIProductEvent.PROJECT_SAVED));
186: }
187:
188: /**
189: * Returns the name of the product
190: * @return The name of the product
191: */
192: public String getProductName() {
193: return (String) getPropertyList().get("vainstall.product.name");
194: }
195:
196: /**
197: * Set the product name
198: * @param productName The name of the product
199: */
200: public void setProductName(String value) {
201: if (value.equals(getProductName()) == true) {
202: return;
203: }
204: if (value != null) {
205: getPropertyList().put("vainstall.product.name", value);
206: } else {
207: getPropertyList().remove("vainstall.product.name");
208: }
209:
210: isDirty = true;
211: fireVAIProductEvent(new VAIProductEvent(this ,
212: VAIProductEvent.PROJECTNAME_CHANGED));
213: fireVAIProductEvent(new VAIProductEvent(this ,
214: VAIProductEvent.PROJECT_DIRTY));
215: }
216:
217: /**
218: * Returns the version of the product
219: * @return The version of the product
220: */
221: public String getProductVersion() {
222: return (String) getPropertyList().get(
223: "vainstall.product.version");
224: }
225:
226: /**
227: * Set the product version
228: * @param productVersion The version of the product
229: */
230: public void setProductVersion(String value) {
231: if (value.equals(getProductVersion()) == true) {
232: return;
233: }
234: if (value != null) {
235: getPropertyList().put("vainstall.product.version", value);
236: } else {
237: getPropertyList().remove("vainstall.product.version");
238: }
239:
240: isDirty = true;
241: fireVAIProductEvent(new VAIProductEvent(this ,
242: VAIProductEvent.PROJECT_DIRTY));
243: fireVAIProductEvent(new VAIProductEvent(this ,
244: VAIProductEvent.PROJECTVERSION_CHANGED));
245: }
246:
247: /**
248: * Returns the the product work directory
249: * @return The product work directory
250: */
251: public String getProductDirectory() {
252: return (String) getPropertyList().get(
253: "vainstall.product.directory");
254: }
255:
256: /**
257: * Set the product work directory
258: * @param productDirectory The work directory of the project
259: */
260: public void setProductDirectory(String value) {
261: if (value.equals(getProductDirectory()) == true) {
262: return;
263: }
264: if (value != null) {
265: getPropertyList().put("vainstall.product.directory", value);
266: } else {
267: getPropertyList().remove("vainstall.product.directory");
268: }
269:
270: isDirty = true;
271: fireVAIProductEvent(new VAIProductEvent(this ,
272: VAIProductEvent.PROJECT_DIRTY));
273: fireVAIProductEvent(new VAIProductEvent(this ,
274: VAIProductEvent.PROJECTDIRECTORY_CHANGED));
275: }
276:
277: public String getProductType() {
278: return (String) getPropertyList().get("vainstall.product.type");
279: }
280:
281: public void setProductType(String value) {
282: if (value.equals(getProductType()) == true) {
283: return;
284: }
285: if (value != null) {
286: getPropertyList().put("vainstall.product.type", value);
287: } else {
288: getPropertyList().remove("vainstall.product.type");
289: }
290:
291: isDirty = true;
292: fireVAIProductEvent(new VAIProductEvent(this ,
293: VAIProductEvent.PROJECT_DIRTY));
294: fireVAIProductEvent(new VAIProductEvent(this ,
295: VAIProductEvent.PROPERTIES_CHANGED, value));
296: }
297:
298: private void buildRequiredFieldsList() {
299:
300: ProductRequirement requirement = null;
301:
302: // Name of install class
303: // vainstall.archive.installClassName
304: requirement = new ProductRequirement(
305: "Install Filename",
306: "<html><b><font color=black size=7><center>Install Filename:</center></font></b><br>The name of the install file without file extension.</html>");
307: masterRequiredList.put("Install Filename", requirement);
308: requiredList.put("Install Filename", requirement);
309: getRequiredListModel().addElement(requirement);
310:
311: // Required steps for an install
312: requirement = new ProductRequirement(
313: "Required Steps",
314: "<html><b><font color=black size=7><center>Required Steps:</center></font></b><br>Required steps who needs configured for an installation package.</html>");
315: masterRequiredList.put("Required Steps", requirement);
316: requiredList.put("Required Steps", requirement);
317: getRequiredListModel().addElement(requirement);
318: /*
319: // Required steps for an install
320: 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>");
321: masterRequiredList.put("Required Steps",requirement);
322: requiredList.put("Required Steps",requirement);
323: getRequiredListModel().addElement(requirement);
324: */
325: }
326:
327: public Hashtable getRequiredList() {
328: return requiredList;
329: }
330:
331: public DefaultListModel getRequiredListModel() {
332: return requiredListModel;
333: }
334:
335: public void addRequirement(String name) {
336: Object obj = masterRequiredList.get(name);
337: if (obj != null) {
338: requiredList.put(name, obj);
339: getRequiredListModel().addElement(obj);
340:
341: fireVAIProductEvent(new VAIProductEvent(this ,
342: VAIProductEvent.PROJECT_REQUIREMENTS_NOTMET));
343: }
344: }
345:
346: public void removeRequirement(String name) {
347:
348: ProductRequirement req = (ProductRequirement) requiredList
349: .remove(name);
350: if (req != null) {
351: try {
352: if (getRequiredListModel().contains(req) == true) {
353: getRequiredListModel().removeElement(req);
354: }
355: } catch (Exception exc) {
356: // Due to bug (?) in 1.4beta. OK, fixed
357: // System.out.println(exc.getMessage());
358: }
359: }
360:
361: if (requiredList.size() == 0) {
362: fireVAIProductEvent(new VAIProductEvent(this ,
363: VAIProductEvent.PROJECT_REQUIREMENTS_MET));
364: }
365: }
366:
367: /**
368: * Convenience method to access properties directly
369: * @return a list of builder properties
370: */
371: public Hashtable getPropertyList() {
372: return propertyList;
373: }
374:
375: public void putProperty(String name, String value) {
376: if (getPropertyList().containsKey(name) == false) {
377: getPropertyList().put(name, value);
378: } else {
379: if (((String) getPropertyList().get(name)).equals(value) == true
380: || value.length() == 0) {
381: return;
382: } else {
383: getPropertyList().put(name, value);
384: }
385: }
386: isDirty = true;
387: fireVAIProductEvent(new VAIProductEvent(this ,
388: VAIProductEvent.PROJECT_DIRTY));
389: fireVAIProductEvent(new VAIProductEvent(this ,
390: VAIProductEvent.PROPERTIES_CHANGED, name));
391: }
392:
393: public String getProperty(String name) {
394: return (String) getPropertyList().get(name);
395: }
396:
397: public void removeProperty(String name) {
398: if (getPropertyList().containsKey(name) == false) {
399: return;
400: }
401: getPropertyList().remove(name);
402: isDirty = true;
403: fireVAIProductEvent(new VAIProductEvent(this ,
404: VAIProductEvent.PROJECT_DIRTY));
405: fireVAIProductEvent(new VAIProductEvent(this ,
406: VAIProductEvent.PROPERTIES_CHANGED, name));
407: }
408:
409: public LinkedList getStepsList() {
410: return stepsList;
411: }
412:
413: /**
414: * Wee need to do something in the future because some
415: * new step types could be added more than once
416: */
417: public void addStep(String type) {
418: getStepsList().add(type);
419: isDirty = true;
420: fireVAIProductEvent(new VAIProductEvent(this ,
421: VAIProductEvent.PROJECT_DIRTY));
422: }
423:
424: public String getPackageName() {
425: return (String) getPropertyList().get(
426: "vainstall.archiver.package.name");
427: }
428:
429: public void setPackageName(String value) {
430: if (value.equals(getPackageName()) == true) {
431: return;
432: }
433: if (value != null) {
434: getPropertyList().put("vainstall.archiver.package.name",
435: value);
436: } else {
437: getPropertyList().remove("vainstall.archiver.package.name");
438: }
439:
440: isDirty = true;
441: fireVAIProductEvent(new VAIProductEvent(this ,
442: VAIProductEvent.PROJECT_DIRTY));
443: fireVAIProductEvent(new VAIProductEvent(this ,
444: VAIProductEvent.PROPERTIES_CHANGED, value));
445: }
446:
447: public String getLicenseName() {
448: return (String) getPropertyList().get(
449: "vainstall.archiver.license.name");
450: }
451:
452: public void setLicenseName(String value) {
453: if (value.equals(getLicenseName()) == true) {
454: return;
455: }
456: if (value != null) {
457: getPropertyList().put("vainstall.archiver.license.name",
458: value);
459: } else {
460: getPropertyList().remove("vainstall.archiver.license.name");
461: }
462:
463: isDirty = true;
464: fireVAIProductEvent(new VAIProductEvent(this ,
465: VAIProductEvent.PROJECT_DIRTY));
466: fireVAIProductEvent(new VAIProductEvent(this ,
467: VAIProductEvent.PROPERTIES_CHANGED, value));
468: }
469:
470: public String getLicenseEncoding() {
471: return (String) getPropertyList().get(
472: "vainstall.archiver.license.encoding");
473: }
474:
475: public void setLicenseEncoding(String value) {
476: if (value.equals(getLicenseEncoding()) == true) {
477: return;
478: }
479: if (value != null) {
480: getPropertyList().put(
481: "vainstall.archiver.license.encoding", value);
482: } else {
483: getPropertyList().remove(
484: "vainstall.archiver.license.encoding");
485: }
486:
487: isDirty = true;
488: fireVAIProductEvent(new VAIProductEvent(this ,
489: VAIProductEvent.PROJECT_DIRTY));
490: fireVAIProductEvent(new VAIProductEvent(this ,
491: VAIProductEvent.PROPERTIES_CHANGED, value));
492: }
493:
494: public String getReadmeName() {
495: return (String) getPropertyList().get(
496: "vainstall.archiver.readme.name");
497: }
498:
499: public void setReadmeName(String value) {
500: if (value.equals(getReadmeName()) == true) {
501: return;
502: }
503: if (value != null) {
504: getPropertyList().put("vainstall.archiver.readme.name",
505: value);
506: } else {
507: getPropertyList().remove("vainstall.archiver.readme.name");
508: }
509:
510: isDirty = true;
511: fireVAIProductEvent(new VAIProductEvent(this ,
512: VAIProductEvent.PROJECT_DIRTY));
513: fireVAIProductEvent(new VAIProductEvent(this ,
514: VAIProductEvent.PROPERTIES_CHANGED, value));
515: }
516:
517: public String getReadmeEncoding() {
518: return (String) getPropertyList().get(
519: "vainstall.archiver.readme.encoding");
520: }
521:
522: public void setReadmeEncoding(String value) {
523: if (value.equals(getReadmeEncoding()) == true) {
524: return;
525: }
526: if (value != null) {
527: getPropertyList().put("vainstall.archiver.readme.encoding",
528: value);
529: } else {
530: getPropertyList().remove(
531: "vainstall.archiver.readme.encoding");
532: }
533:
534: isDirty = true;
535: fireVAIProductEvent(new VAIProductEvent(this ,
536: VAIProductEvent.PROJECT_DIRTY));
537: fireVAIProductEvent(new VAIProductEvent(this ,
538: VAIProductEvent.PROPERTIES_CHANGED, value));
539: }
540:
541: public LinkedList getTargetList() {
542: return targetList;
543: }
544:
545: public void addTarget(String value) {
546: if (targetList.contains(value) == false) {
547: targetList.add(value);
548: isDirty = true;
549: fireVAIProductEvent(new VAIProductEvent(this ,
550: VAIProductEvent.PROJECT_DIRTY));
551: }
552: }
553:
554: public void removeTarget(String value) {
555: if (targetList.contains(value) == true) {
556: targetList.remove(value);
557: isDirty = true;
558: fireVAIProductEvent(new VAIProductEvent(this ,
559: VAIProductEvent.PROJECT_DIRTY));
560: }
561: }
562:
563: public LinkedList getLanguageList() {
564: return languageList;
565: }
566:
567: public void addLanguage(String value) {
568: if (languageList.contains(value) == false) {
569: languageList.add(value);
570: isDirty = true;
571: fireVAIProductEvent(new VAIProductEvent(this ,
572: VAIProductEvent.PROJECT_DIRTY));
573: }
574: }
575:
576: public void removeLanguage(String value) {
577: if (languageList.contains(value) == true) {
578: languageList.remove(value);
579: isDirty = true;
580: fireVAIProductEvent(new VAIProductEvent(this,
581: VAIProductEvent.PROJECT_DIRTY));
582: }
583: }
584:
585: }
|