* @param existing -
* null or an existing tree item being edited
*/
private boolean addNewOrEditExistingGroup(String names, TreeItem existing) {
valueChanged = true; // preset
ConfigGroup mcg = null;
String[] oldGroupNames = stringArray0;
String[] newGroupNames = groupNamesToArray(names);
String[] groupNamesToAdd;
String[] groupNamesToDrop = stringArray0;
if (null != existing) {
mcg = getCorrespondingModelGroup(existing);
oldGroupNames = mcg.getNameArray();
groupNamesToDrop = setDiff(oldGroupNames, newGroupNames);
groupNamesToAdd = setDiff(newGroupNames, oldGroupNames);
} else {
groupNamesToAdd = newGroupNames;
}
// it is legal to define a group name more than once, but the same set of group names
// shouldn't be defined more than once
if (groupNameAlreadyDefined(newGroupNames)) {
Utility.popMessage("Group Already Defined",
"This set of group names has already been defined." + "\n\nGroup: " + names,
MessageDialog.ERROR);
return false;
}
TreeItem item;
if (existing == null) {
ConfigurationGroup cg = new ConfigurationGroup_impl();
cg.setConfigurationParameters(configurationParameterArray0);
cg.setNames(groupNamesToArray(names));
item = addGroupToGUI(names, cg);
addGroupToModel(cg);
} else { // editing existing group
valueChanged = groupNamesToDrop.length != 0 || groupNamesToAdd.length != 0;
item = existing;
setGroupText(item, names);
for (int i = 0; i < groupNamesToDrop.length; i++) {
removeIncludedParmSettingsFromSingleGroup(groupNamesToDrop[i], mcg.getConfigParms());
}
mcg.setNameArray(groupNamesToArray(names));
if (null != settings) {
for (int i = 0; i < groupNamesToAdd.length; i++) {
TreeItem settingsItem = getSettingsTreeGroup(groupNamesToAdd[i]);
if (null == settingsItem) {
settingsItem = new TreeItem(settingsTree, SWT.NONE);
setGroupText(settingsItem, groupNamesToAdd[i]);
settingsItem.setData(null);
fill(mcg.getConfigParms(), settingsItem);
fill(commonParms, settingsItem);
} else {
fillInFrontOfCommon(mcg.getConfigParms(), settingsItem);
}
}
}
}