+ actualPort.getName(container) + "\" />");
}
// NOTE: the context is the composite entity containing
// the entity if possible
MoMLChangeRequest request = null;
if (composite != null) {
request = new MoMLChangeRequest(this, composite, moml
.toString());
} else {
request = new MoMLChangeRequest(this, container, moml
.toString());
}
request.setUndoable(true);
container.addChangeListener(this);
container.requestChange(request);
}
// Iterate over the table rows that represent ports. If a row
// corresponds to an actual port then look to see if that row
// is different from the actual port. If it is, then update
// that actual port. If a row does not correspond to an
// actual port then that row represents a new actual port
// which must be created.
StringBuffer moml = new StringBuffer("<group>");
boolean haveSomeUpdate = false;
for (int i = 0; i < _ports.size(); i++) {
Hashtable portInfo = (Hashtable) (_ports.elementAt(i));
portIterator = getTarget().portList().iterator();
// actualPort will be the Port found on the _target, if
// there is one.
actualPort = (Port) (portInfo.get(ColumnNames.COL_ACTUAL_PORT));
Hashtable updates = new Hashtable();
// FIXME is it necessary to add unchanged fields to hashtable ?
if (actualPort != null) {
// actualPort is a Port found on the _target. Check to
// see if the actualPort is different and needs to be
// updated.
boolean havePortUpdate = false;
if (_columnNames.contains(ColumnNames.COL_NAME)) {
String tableValue = (String) portInfo
.get(ColumnNames.COL_NAME);
if (!(actualPort.getName().equals(tableValue))) {
havePortUpdate = true;
updates.put(ColumnNames.COL_NAME, Boolean.TRUE);
}
}
if (actualPort instanceof IOPort) {
IOPort iop = (IOPort) actualPort;
if (_columnNames.contains(ColumnNames.COL_INPUT)) {
Boolean tableValue = (Boolean) portInfo
.get(ColumnNames.COL_INPUT);
if (iop.isInput() != tableValue.booleanValue()) {
havePortUpdate = true;
updates.put(ColumnNames.COL_INPUT, Boolean.TRUE);
}
}
if (_columnNames.contains(ColumnNames.COL_OUTPUT)) {
Boolean tableValue = (Boolean) portInfo
.get(ColumnNames.COL_OUTPUT);
if (iop.isOutput() != tableValue.booleanValue()) {
havePortUpdate = true;
updates.put(ColumnNames.COL_OUTPUT, Boolean.TRUE);
}
}
if (_columnNames.contains(ColumnNames.COL_MULTIPORT)) {
Boolean tableValue = (Boolean) portInfo
.get(ColumnNames.COL_MULTIPORT);
if (iop.isMultiport() != tableValue.booleanValue()) {
havePortUpdate = true;
updates
.put(ColumnNames.COL_MULTIPORT,
Boolean.TRUE);
}
}
}
if (_columnNames.contains(ColumnNames.COL_SHOW_NAME)) {
boolean isShowSet = _isPropertySet(actualPort, "_showName");
Boolean tableValue = (Boolean) portInfo
.get(ColumnNames.COL_SHOW_NAME);
if (isShowSet != tableValue.booleanValue()) {
havePortUpdate = true;
updates.put(ColumnNames.COL_SHOW_NAME, Boolean.TRUE);
}
}
if (_columnNames.contains(ColumnNames.COL_HIDE)) {
boolean isHideSet = _isPropertySet(actualPort, "_hide");
Boolean tableValue = (Boolean) portInfo
.get(ColumnNames.COL_HIDE);
if (isHideSet != tableValue.booleanValue()) {
havePortUpdate = true;
updates.put(ColumnNames.COL_HIDE, Boolean.TRUE);
}
}
if (actualPort instanceof TypedIOPort) {
TypedIOPort tiop = (TypedIOPort) actualPort;
if (_columnNames.contains(ColumnNames.COL_TYPE)) {
String _type = null;
TypeAttribute _typeAttribute = (TypeAttribute) tiop
.getAttribute("_type");
if (_typeAttribute != null) {
_type = _typeAttribute.getExpression();
}
String tableValue = (String) portInfo
.get(ColumnNames.COL_TYPE);
if (((_type == null) && (!tableValue.equals("")))
|| ((_type != null) && (!tableValue
.equals(_type)))) {
havePortUpdate = true;
updates.put(ColumnNames.COL_TYPE, Boolean.TRUE);
}
}
}
if (_columnNames.contains(ColumnNames.COL_DIRECTION)) {
// Look for a change in direction
String _direction = null;
String direction = (String) portInfo
.get(ColumnNames.COL_DIRECTION);
StringAttribute _cardinal = (StringAttribute) actualPort
.getAttribute("_cardinal");
if (_cardinal != null) {
_direction = _cardinal.getExpression().toUpperCase();
}
if (((_direction == null) && !direction.equals("DEFAULT"))
|| ((_direction != null) && (!direction
.equals(_direction)))) {
havePortUpdate = true;
updates.put(ColumnNames.COL_DIRECTION, Boolean.TRUE);
}
}
if (_columnNames.contains(ColumnNames.COL_UNITS)) {
String units = null;
UnitAttribute _unitsAttribute = (UnitAttribute) actualPort
.getAttribute("_units");
if (_unitsAttribute != null) {
units = _unitsAttribute.getExpression();
}
String tableValue = (String) portInfo
.get(ColumnNames.COL_UNITS);
// tableValue will not be null because we put ""
// into portInfo in the constructor of
// PortTableModel.
if (((units == null) && (!tableValue.equals("")))
|| ((units != null) && (!tableValue.equals(units)))) {
havePortUpdate = true;
updates.put(ColumnNames.COL_UNITS, Boolean.TRUE);
}
}
if (havePortUpdate) {
String currentPortName = ((Port) portInfo
.get(ColumnNames.COL_ACTUAL_PORT)).getName();
String newPortName = (String) portInfo
.get(ColumnNames.COL_NAME);
String momlString = _createMoMLUpdate(updates, portInfo,
currentPortName, newPortName);
moml.append(momlString);
haveSomeUpdate = true;
}
} else {
// actualPort is not found on the _target so make a new one.
// Initialize all columns to be updated for this port entry.
Iterator it = _columnNames.iterator();
while (it.hasNext()) {
String element = (String) it.next();
updates.put(element, Boolean.TRUE);
}
// FIXME is it necessary to remove unchanged fields
// from updates hashtable?
// Make this false, since this is a new port that does
// not have a pre-existing name. Note that "rename"
// is used for pre-existing ports with new names.
if (_columnNames.contains(ColumnNames.COL_NAME)) {
updates.put(ColumnNames.COL_NAME, Boolean.FALSE);
}
// Put this in the MoMLChangeRequest if the value is
// not the default of false.
if (_columnNames.contains(ColumnNames.COL_SHOW_NAME)) {
updates.put(ColumnNames.COL_SHOW_NAME, portInfo
.get(ColumnNames.COL_SHOW_NAME));
}
// Put this in the MoMLChangeRequest if the value is
// not the default of false.
if (_columnNames.contains(ColumnNames.COL_HIDE)) {
updates.put(ColumnNames.COL_HIDE, portInfo
.get(ColumnNames.COL_HIDE));
}
// FIXME: should we compare against "unknown" instead of ""?
if (_columnNames.contains(ColumnNames.COL_TYPE)) {
String type = (String) portInfo.get(ColumnNames.COL_TYPE);
if (!type.equals("")) {
updates.put(ColumnNames.COL_TYPE, Boolean.TRUE);
_portTableModel.fireTableDataChanged();
} else {
// Do not make this part of the
// MoMLChangeRequest if the value is equal to
// "".
updates.put(ColumnNames.COL_TYPE, Boolean.FALSE);
}
}
// Put this in the MoMLChangeRequest if the value is
// not the default.
if (_columnNames.contains(ColumnNames.COL_DIRECTION)) {
String direction = (String) portInfo
.get(ColumnNames.COL_DIRECTION);
if (!direction.equals("DEFAULT")) {
updates.put(ColumnNames.COL_DIRECTION, Boolean.TRUE);
_portTableModel.fireTableDataChanged();
} else {
updates.put(ColumnNames.COL_DIRECTION, Boolean.FALSE);
}
}
if (_columnNames.contains(ColumnNames.COL_UNITS)) {
String unit = (String) portInfo.get(ColumnNames.COL_UNITS);
if (!unit.equals("")) {
updates.put(ColumnNames.COL_UNITS, Boolean.TRUE);
_portTableModel.fireTableDataChanged();
} else {
// Do not make this part of the
// MoMLChangeRequest if the value is equal to
// "".
updates.put(ColumnNames.COL_UNITS, Boolean.FALSE);
}
}
moml.append(_createMoMLUpdate(updates, portInfo,
(String) portInfo.get(ColumnNames.COL_NAME), null));
haveSomeUpdate = true;
}
}
if (haveSomeUpdate) {
moml.append("</group>");
MoMLChangeRequest request = new MoMLChangeRequest(this,
getTarget(), moml.toString(), null);
request.setUndoable(true);
// NOTE: There is no need to listen for completion or
// errors in this change request, since, in theory, it
// will just work. Will someone report the error if one
// occurs? I hope so...