@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); }
private static void createMissingChildren(ProjectLocale template, ProjectLocale other) { EList<PropertyFileDescriptor> descriptors = template.getDescriptors(); for (PropertyFileDescriptor descriptor : descriptors) { URI derivedLocation = computeLocaleResourceLocation(other.getLocale(), other.getParent(), descriptor.getLocation()); Resolvable<?, ?> child = other.resolveChild(derivedLocation); if(child==null){ Resolvable<?, ?> folder = getOrCreateFolder(other, derivedLocation.trimSegments(1).segments()); PropertyFileDescriptor localeDescriptor = PropertiesFactory.eINSTANCE.createPropertyFileDescriptor(); localeDescriptor.setMaster(descriptor); localeDescriptor.setVariant(other.getLocale()); localeDescriptor.setLocation(derivedLocation); localeDescriptor.setProjectLocale(other); localeDescriptor.setParent(folder); localeDescriptor.setName(URI.decode(derivedLocation.lastSegment())); } } }