RadComponent (GuiEditor editor, ComponentItem item) { RadComponent result; final String id = FormEditingUtil.generateId(editor.getRootContainer()); final ClassLoader loader = LoaderFactory.getInstance(editor.getProject()).getLoader(editor.getFile()); RadComponentFactory factory = getRadComponentFactory(item.getClassName(), loader); if (factory != null) { try { result = factory.newInstance(editor, item.getClassName(), id); } catch (Exception e) { LOG.error(e); return null; } } else { PsiFile boundForm = item.getBoundForm(); if (boundForm != null) { final String formFileName = FormEditingUtil.buildResourceName(boundForm); try { result = new RadNestedForm(editor, formFileName, id); } catch (Exception ex) { String errorMessage = UIDesignerBundle.message("error.instantiating.nested.form", formFileName, (ex.getMessage() != null ? ex.getMessage() : ex.toString())); result = RadErrorComponent.create( editor, id, item.getClassName(), null, errorMessage ); } } else { try { final Class aClass = Class.forName(item.getClassName(), true, loader); if (item.isContainer()) { LOG.debug("Creating custom container instance"); result = new RadContainer(editor, aClass, id); } else { result = new RadAtomicComponent(editor, aClass, id); } } catch (final UnsupportedClassVersionError ucve) { result = RadErrorComponent.create(editor, id, item.getClassName(), null, UIDesignerBundle.message("unsupported.component.class.version") ); } catch (final Exception exc) { @NlsSafe String errorDescription = Utils.validateJComponentClass(loader, item.getClassName(), true); if (errorDescription == null) { errorDescription = UIDesignerBundle.message("error.class.cannot.be.instantiated", item.getClassName()); final String message = FormEditingUtil.getExceptionMessage(exc); if (message != null) { errorDescription += ": " + message; } } result = RadErrorComponent.create( editor, id, item.getClassName(), null, errorDescription ); } } } result.init(editor, item); return result; }