private void saveChanges(boolean modal, ArrayList<LocalizableMessage> errors) { for (JLabel label : labels) { setPrimaryValid(label); } String n = getObjectClassName(); LocalizableMessageBuilder err = new LocalizableMessageBuilder(); if (n.length() == 0) { errors.add(ERR_CTRL_PANEL_OBJECTCLASS_NAME_REQUIRED.get()); setPrimaryInvalid(lName); } else if (!n.equalsIgnoreCase(objectClass.getNameOrOID())) { if (!StaticUtils.isValidSchemaElement(n, 0, n.length(), err)) { errors.add(ERR_CTRL_PANEL_INVALID_OBJECTCLASS_NAME.get(err)); setPrimaryInvalid(lName); err = new LocalizableMessageBuilder(); } else { LocalizableMessage elementType = NewAttributePanel.getSchemaElementType(n, schema); if (elementType != null) { errors.add(ERR_CTRL_PANEL_OBJECTCLASS_NAME_ALREADY_IN_USE.get(n, elementType)); setPrimaryInvalid(lName); } } } n = oid.getText().trim(); if (n.length() > 0 && !n.equalsIgnoreCase(objectClass.getOID())) { if (!StaticUtils.isValidSchemaElement(n, 0, n.length(), err)) { errors.add(ERR_CTRL_PANEL_OID_NOT_VALID.get(err)); setPrimaryInvalid(lOID); err = new LocalizableMessageBuilder(); } else { LocalizableMessage elementType = NewAttributePanel.getSchemaElementType(n, schema); if (elementType != null) { errors.add(ERR_CTRL_PANEL_OID_ALREADY_IN_USE.get(n, elementType)); setPrimaryInvalid(lOID); } } } Collection<String> aliases = getAliases(); Collection<String> oldAliases = getAliases(objectClass); if (!aliases.equals(oldAliases)) { for (String alias : aliases) { if (alias.trim().length() == 0) { errors.add(ERR_CTRL_PANEL_EMPTY_ALIAS.get()); setPrimaryInvalid(lAliases); } else { boolean notPreviouslyDefined = true; for (String oldAlias : oldAliases) { if (oldAlias.equalsIgnoreCase(alias)) { notPreviouslyDefined = false; break; } } if (notPreviouslyDefined) { LocalizableMessage elementType = NewAttributePanel.getSchemaElementType(alias, schema); if (elementType != null) { errors.add(ERR_CTRL_PANEL_ALIAS_ALREADY_IN_USE.get(n, elementType)); setPrimaryInvalid(lAliases); } } } } } // validate the superiority. for (ObjectClass superior : getObjectClassSuperiors()) { validateSuperiority(superior, errors); } checkCompatibleSuperiors(getObjectClassSuperiors(), getObjectClassType(), errors); if (errors.isEmpty()) { ProgressDialog dlg = new ProgressDialog( Utilities.createFrame(), Utilities.getParentDialog(this), INFO_CTRL_PANEL_MODIFY_ATTRIBUTE_TITLE.get(), getInfo()); ModifyObjectClassTask newTask = new ModifyObjectClassTask(getInfo(), dlg, objectClass, getNewObjectClass()); for (ConfigurationElementCreatedListener listener : getConfigurationElementCreatedListeners()) { newTask.addConfigurationElementCreatedListener(listener); } for (Task task : getInfo().getTasks()) { task.canLaunch(newTask, errors); } if (errors.isEmpty()) { launchOperation( newTask, INFO_CTRL_PANEL_MODIFYING_OBJECTCLASS_SUMMARY.get(ocName), INFO_CTRL_PANEL_MODIFYING_OBJECTCLASS_COMPLETE.get(), INFO_CTRL_PANEL_MODIFYING_OBJECTCLASS_SUCCESSFUL.get(ocName), ERR_CTRL_PANEL_MODIFYING_OBJECTCLASS_ERROR_SUMMARY.get(), ERR_CTRL_PANEL_MODIFYING_OBJECTCLASS_ERROR_DETAILS.get(ocName), null, dlg); dlg.setVisible(true); } } if (!errors.isEmpty()) { displayErrorDialog(errors); } }
/** * Updates the contents of the panel with the provided object class. * * @param oc the object class. * @param schema the schema. */ public void update(ObjectClass oc, Schema schema) { ignoreChangeEvents = true; objectClass = oc; if (oc == null || schema == null) { // Ignore: this is called to get an initial panel size. return; } String n = oc.getPrimaryName(); if (n == null) { n = NOT_APPLICABLE.toString(); } titlePanel.setDetails(LocalizableMessage.raw(n)); name.setText(n); SortableListModel<AttributeType> modelRequired = attributes.getSelectedListModel1(); SortableListModel<AttributeType> modelAvailable = attributes.getSelectedListModel2(); SortableListModel<AttributeType> availableModel = attributes.getAvailableListModel(); availableModel.addAll(modelRequired.getData()); availableModel.addAll(modelAvailable.getData()); modelRequired.clear(); modelAvailable.clear(); superiors.setSelectedSuperiors(oc.getSuperiorClasses()); superiors.setObjectClassesToExclude(Collections.singleton(oc)); if (oc.getSuperiorClasses().size() > 1) { lSuperior.setText(INFO_CTRL_PANEL_OBJECTCLASS_PARENTS_LABEL.get().toString()); } else { lSuperior.setText(INFO_CTRL_PANEL_OBJECTCLASS_PARENT_LABEL.get().toString()); } updateAttributesWithParent(false); for (AttributeType attr : oc.getRequiredAttributes()) { availableModel.remove(attr); modelRequired.add(attr); } for (AttributeType attr : oc.getOptionalAttributes()) { availableModel.remove(attr); modelAvailable.add(attr); } notifyAttributesChanged(); oid.setText(oc.getOID()); n = oc.getDescription(); if (n == null) { n = ""; } description.setText(n); Set<String> aliases = getAliases(oc); lastAliases.clear(); lastAliases.addAll(aliases); this.aliases.setText(Utilities.getStringFromCollection(aliases, ", ")); String sOrigin = Utilities.getOrigin(oc); if (sOrigin == null) { sOrigin = ""; } origin.setText(sOrigin); String sFile = getSchemaFile(oc); if (sFile == null) { sFile = ""; } file.setText(sFile); type.setSelectedItem(oc.getObjectClassType()); obsolete.setSelected(oc.isObsolete()); ocName = objectClass.getNameOrOID(); scrollListener.updateBorder(); for (JLabel label : labels) { setPrimaryValid(label); } saveChanges.setEnabled(false); ignoreChangeEvents = false; }