ClassPool classPool) throws InvalidComponentClassException, InvalidComponentFieldException,
ClassNotFoundException, CannotCompileException, NotFoundException, SecurityException, NoSuchFieldException,
InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
NoSuchMethodException {
Component componentAnnotation = (Component) componentClass.getAnnotation(Component.class);
/*
* Get dialog title
*/
String dialogTitle = componentAnnotation.value();
/*
* Setup Tabs from Component tab list
*/
List<TabHolder> tabsList = new ArrayList<TabHolder>();
if (componentAnnotation.tabs().length == 0) {
TabHolder tabHolder = new TabHolder();
tabHolder.setTitle(dialogTitle);
tabsList.add(tabHolder);
} else {
for (com.citytechinc.cq.component.annotations.Tab tab : componentAnnotation.tabs()) {
if (StringUtils.isNotEmpty(tab.title()) && StringUtils.isNotEmpty(tab.path())) {
throw new InvalidComponentClassException("Tabs can have only a path or a title");
}
TabHolder tabHolder = new TabHolder();
if (StringUtils.isNotEmpty(tab.title())) {
tabHolder.setTitle(tab.title());
}
if (StringUtils.isNotEmpty(tab.path())) {
CQIncludeParameters params = new CQIncludeParameters();
params.setFieldName(DEFAULT_TAB_FIELD_NAME + tabsList.size());
params.setPath(tab.path());
CQInclude cqincludes = new CQInclude(params);
tabHolder.addElement(cqincludes);
}
tabsList.add(tabHolder);
}
}
List<CtMember> fieldsAndMethods = new ArrayList<CtMember>();
fieldsAndMethods.addAll(ComponentMojoUtil.collectFields(componentClass));
fieldsAndMethods.addAll(ComponentMojoUtil.collectMethods(componentClass));
// Load the true class
Class<?> trueComponentClass = classLoader.loadClass(componentClass.getName());
/*
* Iterate through all fields establishing proper widgets for each
*/
for (CtMember member : fieldsAndMethods) {
DialogField dialogProperty = (DialogField) member.getAnnotation(DialogField.class);
if (dialogProperty != null) {
WidgetMakerParameters parameters = new WidgetMakerParameters(dialogProperty, member,
trueComponentClass, classLoader, classPool, widgetRegistry, null, true);
DialogElement builtFieldWidget = WidgetFactory.make(parameters, -1);
builtFieldWidget.setRanking(dialogProperty.ranking());
int tabIndex = dialogProperty.tab();
if (tabIndex < 1 || tabIndex > tabsList.size()) {
throw new InvalidComponentFieldException("Invalid tab index " + tabIndex + " for field "
+ dialogProperty.fieldName());
}
tabsList.get(tabIndex - 1).addElement(builtFieldWidget);
}
}
List<DialogElement> tabList = new ArrayList<DialogElement>();
for (TabHolder tab : tabsList) {
tabList.add(buildTabForDialogElementSet(tab));
}
Integer width = null;
Integer height = null;
if (componentAnnotation.dialogWidth() > 0) {
width = componentAnnotation.dialogWidth();
}
if (componentAnnotation.dialogHeight() > 0) {
height = componentAnnotation.dialogHeight();
}
DialogParameters dialogParams = new DialogParameters();
dialogParams.setContainedElements(Dialog.buildTabPanel(tabList));
dialogParams.setTitle(dialogTitle);
dialogParams.setFileName(componentAnnotation.fileName());
dialogParams.setWidth(width);
dialogParams.setHeight(height);
return new Dialog(dialogParams);
}