//---------------------------------/
//- notifyPropertyChangeListeners -/
//---------------------------------/
JMethod jMethod = new JMethod(null,"notifyPropertyChangeListeners");
jMethod.getModifiers().makeProtected();
String desc = "Notifies all registered "+
"PropertyChangeListeners when a bound property's value "+
"changes.";
JDocComment jdc = jMethod.getJDocComment();
JDocDescriptor jdDesc = null;
jdc.appendComment(desc);
jMethod.addParameter(new JParameter(SGTypes.String, "fieldName"));
jdDesc = jdc.getParamDescriptor("fieldName");
jdDesc.setDescription("the name of the property that has changed.");
jMethod.addParameter(new JParameter(SGTypes.Object, "oldValue"));
jdDesc = jdc.getParamDescriptor("oldValue");
jdDesc.setDescription("the old value of the property.");
jMethod.addParameter(new JParameter(SGTypes.Object, "newValue"));
jdDesc = jdc.getParamDescriptor("newValue");
jdDesc.setDescription("the new value of the property.");
parent.addMethod(jMethod);
jsc = jMethod.getSourceCode();
//--fix for bug 1026
jsc.add("if (");
jsc.append(vName);
jsc.append(" == null) return;");
jsc.add("java.beans.PropertyChangeEvent event = new ");
jsc.append("java.beans.PropertyChangeEvent");
jsc.append("(this, fieldName, oldValue, newValue);");
jsc.add("");
jsc.add("for (int i = 0; i < ");
jsc.append(vName);
jsc.append(".size(); i++) {");
jsc.indent();
jsc.add("((java.beans.PropertyChangeListener) ");
jsc.append(vName);
jsc.append(".elementAt(i)).");
jsc.append("propertyChange(event);");
jsc.unindent();
jsc.add("}");
//-----------------------------/
//- addPropertyChangeListener -/
//-----------------------------/
JType jType = new JClass("java.beans.PropertyChangeListener");
jMethod = new JMethod(null,"addPropertyChangeListener");
desc = "Registers a PropertyChangeListener with this class.";
jdc = jMethod.getJDocComment();
jdc.appendComment(desc);
jMethod.addParameter(new JParameter(jType, "pcl"));
desc = "The PropertyChangeListener to register.";
jdDesc = jdc.getParamDescriptor("pcl");
jdDesc.setDescription(desc);
parent.addMethod(jMethod);
jsc = jMethod.getSourceCode();
jsc.add(vName);
jsc.append(".addElement(pcl);");
//--------------------------------/
//- removePropertyChangeListener -/
//--------------------------------/
jMethod = new JMethod(JType.Boolean,"removePropertyChangeListener");
desc = "Removes the given PropertyChangeListener "+
"from this classes list of ProperyChangeListeners.";
jdc = jMethod.getJDocComment();
jdc.appendComment(desc);
jMethod.addParameter(new JParameter(jType, "pcl"));
desc = "The PropertyChangeListener to remove.";
jdDesc = jdc.getParamDescriptor("pcl");
jdDesc.setDescription(desc);
desc = "true if the given PropertyChangeListener was removed.";
jdc.addDescriptor(JDocDescriptor.createReturnDesc(desc));
parent.addMethod(jMethod);
jsc = jMethod.getSourceCode();
jsc.add("return ");
jsc.append(vName);
jsc.append(".removeElement(pcl);");
} //-- createPropertyChangeMethods