@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initializeUI(UIBuilder builder) throws Exception
{
UIContext context = builder.getUIContext();
Project project = getSelectedProject(context);
JPAFacet<PersistenceCommonDescriptor> persistenceFacet = project.getFacet(JPAFacet.class);
JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
List<JavaClassSource> allEntities = persistenceFacet.getAllEntities();
List<JavaClassSource> supportedEntities = new ArrayList<>();
for (JavaClassSource entity : allEntities)
{
if (isEntityWithSimpleKey(entity))
{
supportedEntities.add(entity);
}
}
targets.setValueChoices(supportedEntities);
targets.setItemLabelConverter(new Converter<JavaClassSource, String>()
{
@Override
public String convert(JavaClassSource source)
{
return source == null ? null : source.getQualifiedName();
}
});
List<String> persistenceUnits = new ArrayList<>();
List<PersistenceUnitCommon> allUnits = persistenceFacet.getConfig().getAllPersistenceUnit();
for (PersistenceUnitCommon persistenceUnit : allUnits)
{
persistenceUnits.add(persistenceUnit.getName());
}
if (!persistenceUnits.isEmpty())
{
persistenceUnit.setValueChoices(persistenceUnits).setDefaultValue(persistenceUnits.get(0));
}
// TODO: May detect where @Path resources are located
packageName.setDefaultValue(javaSourceFacet.getBasePackage() + ".rest");
contentType.setValueChoices(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML));
generator.setDefaultValue(defaultResourceGenerator);
if (context.getProvider().isGUI())
{
generator.setItemLabelConverter(new Converter<RestResourceGenerator, String>()
{
@Override
public String convert(RestResourceGenerator source)