@SuppressWarnings({ "unchecked", "rawtypes" })
public static void addNewLocalizedDescriptor(PropertyFileDescriptor descriptor, ProjectLocale locale) {
if (!descriptor.eIsSet(PropertiesPackage.Literals.PROPERTY_FILE_DESCRIPTOR__LOCATION))
throw new IllegalArgumentException("Property File Descriptor location is not set");
ProjectVersion version = locale.getParent();
ProjectLocale templateLocale = version.getTemplate();
URI templateResourceLocation = computeTemplateResourceLocation(locale.getLocale(), descriptor.getLocation(),
templateLocale.getLocale(),version);
Resolvable<?, ?> resolved = templateLocale.resolveChild(templateResourceLocation);
PropertyFileDescriptor template = null;
if (resolved instanceof PropertyFileDescriptor) {
template = (PropertyFileDescriptor) resolved;
}
if (template == null)
throw new IllegalArgumentException("Template property " + templateResourceLocation + " doesn't exist");
Resolvable container = getOrCreateFolder(locale, descriptor.getLocation().trimSegments(1).segments());
if (container.getChild(descriptor.getLocation().lastSegment()) != null) {
PropertyFileDescriptor child = (PropertyFileDescriptor) container.getChild(descriptor.getLocation().lastSegment());
child.setMaster(null);
container.getChildren().set(container.getChildren().indexOf(child), descriptor);
locale.getDescriptors().remove(child);
} else {
container.getChildren().add(descriptor);
}
descriptor.setMaster(template);
locale.getDescriptors().add(descriptor);
}