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

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

Introduction

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

Prototype

@Override
    public MarkupContainer setDefaultModel(final IModel<?> model) 

Source Link

Usage

From source file:org.apache.syncope.client.console.pages.ReportletConfModalPage.java

License:Apache License

private ListView<String> buildPropView() {
    LoadableDetachableModel<List<String>> propViewModel = new LoadableDetachableModel<List<String>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override//w  ww  .  j  av  a  2s  .  c  o  m
        protected List<String> load() {
            List<String> result = new ArrayList<String>();
            if (ReportletConfModalPage.this.reportletConf != null) {
                for (Field field : ReportletConfModalPage.this.reportletConf.getClass().getDeclaredFields()) {
                    if (!ArrayUtils.contains(EXCLUDE_PROPERTIES, field.getName())) {
                        result.add(field.getName());
                    }
                }
            }

            return result;
        }
    };

    propView = new ListView<String>("propView", propViewModel) {

        private static final long serialVersionUID = 9101744072914090143L;

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

            Label label = new Label("key", fieldName);
            item.add(label);

            Field field = null;
            try {
                field = ReportletConfModalPage.this.reportletConf.getClass().getDeclaredField(fieldName);
            } catch (Exception e) {
                LOG.error("Could not find field {} in class {}", fieldName,
                        ReportletConfModalPage.this.reportletConf.getClass(), e);
            }
            if (field == null) {
                return;
            }

            FormAttributeField annotation = field.getAnnotation(FormAttributeField.class);

            BeanWrapper wrapper = PropertyAccessorFactory
                    .forBeanPropertyAccess(ReportletConfModalPage.this.reportletConf);

            Panel panel;

            if (String.class.equals(field.getType()) && annotation != null && annotation.userSearch()) {
                panel = new UserSearchPanel.Builder("value").fiql((String) wrapper.getPropertyValue(fieldName))
                        .required(false).build();
                // This is needed in order to manually update this.reportletConf with search panel selections
                panel.setDefaultModel(new Model<String>(fieldName));
            } else if (String.class.equals(field.getType()) && annotation != null && annotation.groupSearch()) {
                panel = new GroupSearchPanel.Builder("value").fiql((String) wrapper.getPropertyValue(fieldName))
                        .required(false).build();
                // This is needed in order to manually update this.reportletConf with search panel selections
                panel.setDefaultModel(new Model<String>(fieldName));
            } 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) && annotation != null) {
                    List<String> choices;
                    switch (annotation.schema()) {
                    case UserPlainSchema:
                        choices = schemaRestClient.getPlainSchemaNames(AttributableType.USER);
                        break;

                    case UserDerivedSchema:
                        choices = schemaRestClient.getDerSchemaNames(AttributableType.USER);
                        break;

                    case UserVirtualSchema:
                        choices = schemaRestClient.getVirSchemaNames(AttributableType.USER);
                        break;

                    case GroupPlainSchema:
                        choices = schemaRestClient.getPlainSchemaNames(AttributableType.GROUP);
                        break;

                    case GroupDerivedSchema:
                        choices = schemaRestClient.getDerSchemaNames(AttributableType.GROUP);
                        break;

                    case GroupVirtualSchema:
                        choices = schemaRestClient.getVirSchemaNames(AttributableType.GROUP);
                        break;

                    case MembershipPlainSchema:
                        choices = schemaRestClient.getPlainSchemaNames(AttributableType.MEMBERSHIP);
                        break;

                    case MembershipDerivedSchema:
                        choices = schemaRestClient.getDerSchemaNames(AttributableType.MEMBERSHIP);
                        break;

                    case MembershipVirtualSchema:
                        choices = schemaRestClient.getVirSchemaNames(AttributableType.MEMBERSHIP);
                        break;

                    default:
                        choices = Collections.emptyList();
                    }

                    panel = new AjaxPalettePanel("value",
                            new PropertyModel<List<String>>(ReportletConfModalPage.this.reportletConf,
                                    fieldName),
                            new ListModel<String>(choices), true);
                } else if (listItemType.isEnum()) {
                    panel = new CheckBoxMultipleChoiceFieldPanel("value",
                            new PropertyModel(ReportletConfModalPage.this.reportletConf, fieldName),
                            new ListModel(Arrays.asList(listItemType.getEnumConstants())));
                } else {
                    if (((List) wrapper.getPropertyValue(fieldName)).isEmpty()) {
                        ((List) wrapper.getPropertyValue(fieldName)).add(null);
                    }

                    panel = new MultiFieldPanel("value",
                            new PropertyModel<List>(ReportletConfModalPage.this.reportletConf, fieldName),
                            buildSinglePanel(field.getType(), fieldName, "panel"));
                }
            } else {
                panel = buildSinglePanel(field.getType(), fieldName, "value");
            }

            item.add(panel);
        }
    };

    return propView;
}

From source file:org.apache.syncope.console.pages.ReportletConfModalPage.java

License:Apache License

private ListView<String> buildPropView() {
    LoadableDetachableModel<List<String>> propViewModel = new LoadableDetachableModel<List<String>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override/* w  w  w  .j a  v  a  2  s.  c  om*/
        protected List<String> load() {
            List<String> result = new ArrayList<String>();
            if (ReportletConfModalPage.this.reportletConf != null) {
                for (Field field : ReportletConfModalPage.this.reportletConf.getClass().getDeclaredFields()) {
                    if (!ArrayUtils.contains(EXCLUDE_PROPERTIES, field.getName())) {
                        result.add(field.getName());
                    }
                }
            }

            return result;
        }
    };

    propView = new ListView<String>("propView", propViewModel) {

        private static final long serialVersionUID = 9101744072914090143L;

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

            Label label = new Label("key", fieldName);
            item.add(label);

            Field field = null;
            try {
                field = ReportletConfModalPage.this.reportletConf.getClass().getDeclaredField(fieldName);
            } catch (Exception e) {
                LOG.error("Could not find field {} in class {}", fieldName,
                        ReportletConfModalPage.this.reportletConf.getClass(), e);
            }
            if (field == null) {
                return;
            }

            FormAttributeField annotation = field.getAnnotation(FormAttributeField.class);

            BeanWrapper wrapper = PropertyAccessorFactory
                    .forBeanPropertyAccess(ReportletConfModalPage.this.reportletConf);

            Panel panel;

            if (String.class.equals(field.getType()) && annotation != null && annotation.userSearch()) {
                panel = new UserSearchPanel.Builder("value").fiql((String) wrapper.getPropertyValue(fieldName))
                        .required(false).build();
                // This is needed in order to manually update this.reportletConf with search panel selections
                panel.setDefaultModel(new Model<String>(fieldName));
            } else if (String.class.equals(field.getType()) && annotation != null && annotation.roleSearch()) {
                panel = new RoleSearchPanel.Builder("value").fiql((String) wrapper.getPropertyValue(fieldName))
                        .required(false).build();
                // This is needed in order to manually update this.reportletConf with search panel selections
                panel.setDefaultModel(new Model<String>(fieldName));
            } 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) && annotation != null) {
                    List<String> choices;
                    switch (annotation.schema()) {
                    case UserSchema:
                        choices = schemaRestClient.getSchemaNames(AttributableType.USER);
                        break;

                    case UserDerivedSchema:
                        choices = schemaRestClient.getDerSchemaNames(AttributableType.USER);
                        break;

                    case UserVirtualSchema:
                        choices = schemaRestClient.getVirSchemaNames(AttributableType.USER);
                        break;

                    case RoleSchema:
                        choices = schemaRestClient.getSchemaNames(AttributableType.ROLE);
                        break;

                    case RoleDerivedSchema:
                        choices = schemaRestClient.getDerSchemaNames(AttributableType.ROLE);
                        break;

                    case RoleVirtualSchema:
                        choices = schemaRestClient.getVirSchemaNames(AttributableType.ROLE);
                        break;

                    case MembershipSchema:
                        choices = schemaRestClient.getSchemaNames(AttributableType.MEMBERSHIP);
                        break;

                    case MembershipDerivedSchema:
                        choices = schemaRestClient.getDerSchemaNames(AttributableType.MEMBERSHIP);
                        break;

                    case MembershipVirtualSchema:
                        choices = schemaRestClient.getVirSchemaNames(AttributableType.MEMBERSHIP);
                        break;

                    default:
                        choices = Collections.emptyList();
                    }

                    panel = new AjaxPalettePanel("value",
                            new PropertyModel<List<String>>(ReportletConfModalPage.this.reportletConf,
                                    fieldName),
                            new ListModel<String>(choices), true);
                } else if (listItemType.isEnum()) {
                    panel = new CheckBoxMultipleChoiceFieldPanel("value",
                            new PropertyModel(ReportletConfModalPage.this.reportletConf, fieldName),
                            new ListModel(Arrays.asList(listItemType.getEnumConstants())));
                } else {
                    if (((List) wrapper.getPropertyValue(fieldName)).isEmpty()) {
                        ((List) wrapper.getPropertyValue(fieldName)).add(null);
                    }

                    panel = new MultiFieldPanel("value",
                            new PropertyModel<List>(ReportletConfModalPage.this.reportletConf, fieldName),
                            buildSinglePanel(field.getType(), fieldName, "panel"));
                }
            } else {
                panel = buildSinglePanel(field.getType(), fieldName, "value");
            }

            item.add(panel);
        }
    };

    return propView;
}