Example usage for org.apache.wicket.markup.html.panel Panel setRenderBodyOnly

List of usage examples for org.apache.wicket.markup.html.panel Panel setRenderBodyOnly

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.panel Panel setRenderBodyOnly.

Prototype

public final Component setRenderBodyOnly(final boolean renderTag) 

Source Link

Document

If false the component's tag will be printed as well as its body (which is default).

Usage

From source file:org.apache.syncope.client.console.panels.BeanPanel.java

License:Apache License

public BeanPanel(final String id, final IModel<T> bean,
        final Map<String, Pair<AbstractFiqlSearchConditionBuilder, List<SearchClause>>> sCondWrapper,
        final String... excluded) {
    super(id, bean);
    setOutputMarkupId(true);//w w w .  ja  v  a  2 s .c o  m

    this.sCondWrapper = sCondWrapper;

    this.excluded = new ArrayList<>(Arrays.asList(excluded));
    this.excluded.add("serialVersionUID");
    this.excluded.add("class");

    final LoadableDetachableModel<List<String>> model = new LoadableDetachableModel<List<String>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override
        protected List<String> load() {
            List<String> result = new ArrayList<>();

            if (BeanPanel.this.getDefaultModelObject() != null) {
                for (Field field : BeanPanel.this.getDefaultModelObject().getClass().getDeclaredFields()) {
                    if (!BeanPanel.this.excluded.contains(field.getName())) {
                        result.add(field.getName());
                    }
                }
            }

            return result;
        }
    };

    add(new ListView<String>("propView", model) {

        private static final long serialVersionUID = 9101744072914090143L;

        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        protected void populateItem(final ListItem<String> item) {
            final String fieldName = item.getModelObject();

            item.add(new Label("fieldName", new ResourceModel(fieldName, fieldName)));

            Field field = null;
            try {
                field = bean.getObject().getClass().getDeclaredField(fieldName);
            } catch (NoSuchFieldException | SecurityException e) {
                LOG.error("Could not find field {} in class {}", fieldName, bean.getObject().getClass(), e);
            }

            if (field == null) {
                return;
            }

            final SearchCondition scondAnnot = field.getAnnotation(SearchCondition.class);
            final Schema schemaAnnot = field.getAnnotation(Schema.class);

            BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean.getObject());

            Panel panel;

            if (scondAnnot != null) {
                final String fiql = (String) wrapper.getPropertyValue(fieldName);

                final List<SearchClause> clauses;
                if (StringUtils.isEmpty(fiql)) {
                    clauses = new ArrayList<>();
                } else {
                    clauses = SearchUtils.getSearchClauses(fiql);
                }

                final AbstractFiqlSearchConditionBuilder builder;

                switch (scondAnnot.type()) {
                case "USER":
                    panel = new UserSearchPanel.Builder(new ListModel<>(clauses)).required(false)
                            .build("value");
                    builder = SyncopeClient.getUserSearchConditionBuilder();
                    break;
                case "GROUP":
                    panel = new GroupSearchPanel.Builder(new ListModel<>(clauses)).required(false)
                            .build("value");
                    builder = SyncopeClient.getGroupSearchConditionBuilder();
                    break;
                default:
                    panel = new AnyObjectSearchPanel.Builder(scondAnnot.type(), new ListModel<>(clauses))
                            .required(false).build("value");
                    builder = SyncopeClient.getAnyObjectSearchConditionBuilder(null);
                }

                if (BeanPanel.this.sCondWrapper != null) {
                    BeanPanel.this.sCondWrapper.put(fieldName, Pair.of(builder, clauses));
                }
            } else if (List.class.equals(field.getType())) {
                Class<?> listItemType = String.class;
                if (field.getGenericType() instanceof ParameterizedType) {
                    listItemType = (Class<?>) ((ParameterizedType) field.getGenericType())
                            .getActualTypeArguments()[0];
                }

                if (listItemType.equals(String.class) && schemaAnnot != null) {
                    SchemaRestClient schemaRestClient = new SchemaRestClient();

                    final List<AbstractSchemaTO> choices = new ArrayList<>();

                    for (SchemaType type : schemaAnnot.type()) {
                        switch (type) {
                        case PLAIN:
                            choices.addAll(
                                    schemaRestClient.getSchemas(SchemaType.PLAIN, schemaAnnot.anyTypeKind()));
                            break;

                        case DERIVED:
                            choices.addAll(
                                    schemaRestClient.getSchemas(SchemaType.DERIVED, schemaAnnot.anyTypeKind()));
                            break;

                        case VIRTUAL:
                            choices.addAll(
                                    schemaRestClient.getSchemas(SchemaType.VIRTUAL, schemaAnnot.anyTypeKind()));
                            break;

                        default:
                        }
                    }

                    panel = new AjaxPalettePanel.Builder<String>().setName(fieldName)
                            .build("value", new PropertyModel<List<String>>(bean.getObject(), fieldName),
                                    new ListModel<>(CollectionUtils.collect(choices,
                                            new Transformer<AbstractSchemaTO, String>() {

                                                @Override
                                                public String transform(final AbstractSchemaTO input) {
                                                    return input.getKey();
                                                }
                                            }, new ArrayList<String>())))
                            .hideLabel();
                } else if (listItemType.isEnum()) {
                    panel = new AjaxPalettePanel.Builder<String>().setName(fieldName)
                            .build("value", new PropertyModel<List<String>>(bean.getObject(), fieldName),
                                    new ListModel(Arrays.asList(listItemType.getEnumConstants())))
                            .hideLabel();
                } else {
                    if (((List) wrapper.getPropertyValue(fieldName)).isEmpty()) {
                        ((List) wrapper.getPropertyValue(fieldName)).add(null);
                    }

                    panel = new MultiFieldPanel.Builder<>(
                            new PropertyModel<List<String>>(bean.getObject(), fieldName)).build("value",
                                    fieldName,
                                    buildSinglePanel(bean.getObject(), field.getType(), fieldName, "panel"))
                                    .hideLabel();
                }
            } else {
                panel = buildSinglePanel(bean.getObject(), field.getType(), fieldName, "value").hideLabel();
            }

            item.add(panel.setRenderBodyOnly(true));
        }

    }.setReuseItems(true).setOutputMarkupId(true));
}