/*
* $RCSfile: VAIProductModel.java,v $
* @modification $Date: 2001/09/28 19:27:49 $
* @version $Id: VAIProductModel.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
*
*/
package com.memoire.vainstall.builder;
import com.memoire.vainstall.builder.event.*;
import com.memoire.vainstall.builder.util.*;
import java.util.*;
import javax.swing.DefaultListModel;
import javax.swing.event.EventListenerList;
/**
* This is a VAIProduct data model
*
* @see javax.swing.event.EventListenerList
*
* @author Henrik Falk
* @version $Id: VAIProductModel.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
*/
public class VAIProductModel {
/**
* The list of listenere that are interested in changes in
* the data model
*/
EventListenerList listenerList = new EventListenerList();
/**
* The persistance class for this model
*/
ProductPersisterInterface productPersister;
/**
* Flag that indicated whether the data model needs to be saved
*/
boolean isDirty = false;
/**
* Master list of required fields/attributes for a product
* before an installation package can be generated
*/
Hashtable masterRequiredList = new Hashtable();
/**
* List of required fields/attributes for a product
* which still needs to be 'resolved'
* before an installation package can be generated
*/
Hashtable requiredList = new Hashtable();
DefaultListModel requiredListModel = new DefaultListModel();
/**
* list of properties in the format <name,String value>
*/
Hashtable propertyList = new Hashtable();
/**
*
*/
LinkedList stepsList = new LinkedList();
/**
*
*/
LinkedList targetList = new LinkedList();
/**
*
*/
LinkedList languageList = new LinkedList();
/**
* Default constructor
*/
public VAIProductModel() {
super();
try {
if( System.getProperty("java.version").indexOf("1.4.") != -1 ) {
productPersister = (ProductPersisterInterface)Class.forName("com.memoire.vainstall.builder.util.JavaProductPersister").newInstance();
} else {
productPersister = (ProductPersisterInterface)Class.forName("com.memoire.vainstall.builder.util.NanoProductPersister").newInstance();
}
productPersister.initialize(this);
// add proper exception handling
} catch (InstantiationException exc) {
} catch (ClassNotFoundException exc) {
} catch (IllegalAccessException exc) {
}
buildRequiredFieldsList();
}
/**
* Returns whether the data model needs to be saved or not.
* @return true if the datamodel needs to be saved
*/
public boolean isDirty() {
return isDirty;
}
/**
* @param e VAIProductEvent
*/
public void fireVAIProductEvent(VAIProductEvent e) {
// guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == com.memoire.vainstall.builder.event.VAIProductListener.class) {
((com.memoire.vainstall.builder.event.VAIProductListener)listeners[i+1]).productChanged(e);
}
}
}
/**
* @param l com.memoire.vainstall.builder.event.VAIProductListener
*/
public void addVAIProductListener(com.memoire.vainstall.builder.event.VAIProductListener l) {
listenerList.add(com.memoire.vainstall.builder.event.VAIProductListener.class,l);
}
/**
* @param l com.memoire.vainstall.builder.event.VAIProductListener
*/
public void removeVAIProductListener(com.memoire.vainstall.builder.event.VAIProductListener l) {
listenerList.remove(com.memoire.vainstall.builder.event.VAIProductListener.class,l);
}
/**
* Load project data from datastore
* @throws com.memoire.vainstall.builder.util.VAIBuilderException
*/
public void load() throws VAIBuilderException {
productPersister.load();
isDirty = false;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_LOADED));
}
/**
* Store project data in datastore
* @throws com.memoire.vainstall.builder.util.VAIBuilderException
*/
public void save() throws VAIBuilderException {
productPersister.save();
isDirty = false;
if(requiredList.size() == 0) {
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_REQUIREMENTS_MET));
}
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_SAVED));
}
/**
* Returns the name of the product
* @return The name of the product
*/
public String getProductName() {
return (String)getPropertyList().get("vainstall.product.name");
}
/**
* Set the product name
* @param productName The name of the product
*/
public void setProductName(String value) {
if(value.equals(getProductName()) == true) {
return;
}
if (value != null) {
getPropertyList().put("vainstall.product.name", value);
} else {
getPropertyList().remove("vainstall.product.name");
}
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECTNAME_CHANGED));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
}
/**
* Returns the version of the product
* @return The version of the product
*/
public String getProductVersion() {
return (String)getPropertyList().get("vainstall.product.version");
}
/**
* Set the product version
* @param productVersion The version of the product
*/
public void setProductVersion(String value) {
if(value.equals(getProductVersion()) == true) {
return;
}
if (value != null) {
getPropertyList().put("vainstall.product.version", value);
} else {
getPropertyList().remove("vainstall.product.version");
}
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECTVERSION_CHANGED));
}
/**
* Returns the the product work directory
* @return The product work directory
*/
public String getProductDirectory() {
return (String)getPropertyList().get("vainstall.product.directory");
}
/**
* Set the product work directory
* @param productDirectory The work directory of the project
*/
public void setProductDirectory(String value) {
if(value.equals(getProductDirectory()) == true) {
return;
}
if (value != null) {
getPropertyList().put("vainstall.product.directory", value);
} else {
getPropertyList().remove("vainstall.product.directory");
}
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECTDIRECTORY_CHANGED));
}
public String getProductType() {
return (String)getPropertyList().get("vainstall.product.type");
}
public void setProductType(String value) {
if(value.equals(getProductType()) == true) {
return;
}
if (value != null) {
getPropertyList().put("vainstall.product.type", value);
} else {
getPropertyList().remove("vainstall.product.type");
}
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
}
private void buildRequiredFieldsList() {
ProductRequirement requirement = null;
// Name of install class
// vainstall.archive.installClassName
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>");
masterRequiredList.put("Install Filename",requirement);
requiredList.put("Install Filename",requirement);
getRequiredListModel().addElement(requirement);
// Required steps for an install
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>");
masterRequiredList.put("Required Steps",requirement);
requiredList.put("Required Steps",requirement);
getRequiredListModel().addElement(requirement);
/*
// Required steps for an install
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>");
masterRequiredList.put("Required Steps",requirement);
requiredList.put("Required Steps",requirement);
getRequiredListModel().addElement(requirement);
*/
}
public Hashtable getRequiredList() {
return requiredList;
}
public DefaultListModel getRequiredListModel() {
return requiredListModel;
}
public void addRequirement(String name) {
Object obj = masterRequiredList.get(name);
if (obj != null) {
requiredList.put(name,obj);
getRequiredListModel().addElement(obj);
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_REQUIREMENTS_NOTMET));
}
}
public void removeRequirement(String name) {
ProductRequirement req = (ProductRequirement)requiredList.remove(name);
if (req != null) {
try {
if(getRequiredListModel().contains(req) == true) {
getRequiredListModel().removeElement(req);
}
} catch(Exception exc) {
// Due to bug (?) in 1.4beta. OK, fixed
// System.out.println(exc.getMessage());
}
}
if(requiredList.size() == 0) {
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_REQUIREMENTS_MET));
}
}
/**
* Convenience method to access properties directly
* @return a list of builder properties
*/
public Hashtable getPropertyList() {
return propertyList;
}
public void putProperty(String name, String value) {
if (getPropertyList().containsKey(name) == false) {
getPropertyList().put(name,value);
} else {
if (((String)getPropertyList().get(name)).equals(value) == true ||
value.length() == 0) {
return;
} else {
getPropertyList().put(name,value);
}
}
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,name));
}
public String getProperty(String name) {
return (String)getPropertyList().get(name);
}
public void removeProperty(String name) {
if (getPropertyList().containsKey(name) == false) {
return;
}
getPropertyList().remove(name);
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,name));
}
public LinkedList getStepsList() {
return stepsList;
}
/**
* Wee need to do something in the future because some
* new step types could be added more than once
*/
public void addStep(String type) {
getStepsList().add(type);
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
}
public String getPackageName() {
return (String)getPropertyList().get("vainstall.archiver.package.name");
}
public void setPackageName(String value) {
if(value.equals(getPackageName()) == true) {
return;
}
if (value != null) {
getPropertyList().put("vainstall.archiver.package.name", value);
} else {
getPropertyList().remove("vainstall.archiver.package.name");
}
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
}
public String getLicenseName() {
return (String)getPropertyList().get("vainstall.archiver.license.name");
}
public void setLicenseName(String value) {
if(value.equals(getLicenseName()) == true) {
return;
}
if (value != null) {
getPropertyList().put("vainstall.archiver.license.name", value);
} else {
getPropertyList().remove("vainstall.archiver.license.name");
}
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
}
public String getLicenseEncoding() {
return (String)getPropertyList().get("vainstall.archiver.license.encoding");
}
public void setLicenseEncoding(String value) {
if(value.equals(getLicenseEncoding()) == true) {
return;
}
if (value != null) {
getPropertyList().put("vainstall.archiver.license.encoding", value);
} else {
getPropertyList().remove("vainstall.archiver.license.encoding");
}
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
}
public String getReadmeName() {
return (String)getPropertyList().get("vainstall.archiver.readme.name");
}
public void setReadmeName(String value) {
if(value.equals(getReadmeName()) == true) {
return;
}
if (value != null) {
getPropertyList().put("vainstall.archiver.readme.name", value);
} else {
getPropertyList().remove("vainstall.archiver.readme.name");
}
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
}
public String getReadmeEncoding() {
return (String)getPropertyList().get("vainstall.archiver.readme.encoding");
}
public void setReadmeEncoding(String value) {
if(value.equals(getReadmeEncoding()) == true) {
return;
}
if (value != null) {
getPropertyList().put("vainstall.archiver.readme.encoding", value);
} else {
getPropertyList().remove("vainstall.archiver.readme.encoding");
}
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROPERTIES_CHANGED,value));
}
public LinkedList getTargetList() {
return targetList;
}
public void addTarget(String value) {
if (targetList.contains(value) == false) {
targetList.add(value);
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
}
}
public void removeTarget(String value) {
if (targetList.contains(value) == true) {
targetList.remove(value);
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
}
}
public LinkedList getLanguageList() {
return languageList;
}
public void addLanguage(String value) {
if (languageList.contains(value) == false) {
languageList.add(value);
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
}
}
public void removeLanguage(String value) {
if (languageList.contains(value) == true) {
languageList.remove(value);
isDirty = true;
fireVAIProductEvent(new VAIProductEvent(this,VAIProductEvent.PROJECT_DIRTY));
}
}
}
|