Search in sources :

Example 66 with PropertyModel

use of org.apache.wicket.model.PropertyModel in project midpoint by Evolveum.

the class PrismValuePanel method createTypedInputComponent.

// normally this method returns an InputPanel;
// however, for some special readonly types (like ObjectDeltaType) it will return a Panel
private Panel createTypedInputComponent(String id) {
    //        ValueWrapper valueWrapper = model.getObject();
    //        ItemWrapper itemWrapper =
    final Item item = valueWrapperModel.getObject().getItem().getItem();
    Panel panel = null;
    if (item instanceof PrismProperty) {
        final PrismProperty property = (PrismProperty) item;
        PrismPropertyDefinition definition = property.getDefinition();
        final QName valueType = definition.getTypeName();
        //pointing to prism property real value
        final String baseExpression = "value.value";
        //now it works only in description
        if (ObjectType.F_DESCRIPTION.equals(definition.getName())) {
            return new TextAreaPanel(id, new PropertyModel(valueWrapperModel, baseExpression), null);
        }
        if (ActivationType.F_ADMINISTRATIVE_STATUS.equals(definition.getName())) {
            return WebComponentUtil.createEnumPanel(ActivationStatusType.class, id, new PropertyModel<ActivationStatusType>(valueWrapperModel, baseExpression), this);
        } else if (ActivationType.F_LOCKOUT_STATUS.equals(definition.getName())) {
            return new LockoutStatusPanel(id, valueWrapperModel.getObject(), new PropertyModel<LockoutStatusType>(valueWrapperModel, baseExpression));
        } else {
            if (definition.getTypeName().getLocalPart().equals(ActivationStatusType.class.getSimpleName())) {
                return WebComponentUtil.createEnumPanel(ActivationStatusType.class, id, new PropertyModel<ActivationStatusType>(valueWrapperModel, baseExpression), this);
            }
        }
        if (DOMUtil.XSD_DATETIME.equals(valueType)) {
            panel = new DatePanel(id, new PropertyModel<XMLGregorianCalendar>(valueWrapperModel, baseExpression));
        } else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
            panel = new PasswordPanel(id, new PropertyModel<ProtectedStringType>(valueWrapperModel, baseExpression), valueWrapperModel.getObject().isReadonly());
        } else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
            panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(valueWrapperModel, baseExpression));
        } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
            InputPanel inputPanel;
            PrismPropertyDefinition def = property.getDefinition();
            if (def.getValueEnumerationRef() != null) {
                PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
                String lookupTableUid = valueEnumerationRef.getOid();
                Task task = pageBase.createSimpleTask("loadLookupTable");
                OperationResult result = task.getResult();
                Collection<SelectorOptions<GetOperationOptions>> options = WebModelServiceUtils.createLookupTableRetrieveOptions();
                final PrismObject<LookupTableType> lookupTable = WebModelServiceUtils.loadObject(LookupTableType.class, lookupTableUid, options, pageBase, task, result);
                if (lookupTable != null) {
                    inputPanel = new AutoCompleteTextPanel<String>(id, new LookupPropertyModel<String>(valueWrapperModel, baseExpression + ".orig", lookupTable.asObjectable()), String.class) {

                        @Override
                        public Iterator<String> getIterator(String input) {
                            return prepareAutoCompleteList(input, lookupTable).iterator();
                        }
                    };
                } else {
                    inputPanel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"), String.class);
                }
            } else {
                inputPanel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"), String.class);
            }
            if (ObjectType.F_NAME.equals(def.getName()) || UserType.F_FULL_NAME.equals(def.getName())) {
                inputPanel.getBaseFormComponent().setRequired(true);
            }
            panel = inputPanel;
        } else if (DOMUtil.XSD_BASE64BINARY.equals(valueType)) {
            panel = new UploadDownloadPanel(id, valueWrapperModel.getObject().isReadonly()) {

                @Override
                public InputStream getStream() {
                    Object object = ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue();
                    return object != null ? new ByteArrayInputStream((byte[]) object) : new ByteArrayInputStream(new byte[0]);
                //                		return super.getStream();
                }

                @Override
                public void updateValue(byte[] file) {
                    ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).setValue(file);
                }

                @Override
                public void uploadFilePerformed(AjaxRequestTarget target) {
                    super.uploadFilePerformed(target);
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                }

                @Override
                public void removeFilePerformed(AjaxRequestTarget target) {
                    super.removeFilePerformed(target);
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                }

                @Override
                public void uploadFileFailed(AjaxRequestTarget target) {
                    super.uploadFileFailed(target);
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                    target.add(((PageBase) getPage()).getFeedbackPanel());
                }
            };
        } else if (ObjectDeltaType.COMPLEX_TYPE.equals(valueType)) {
            panel = new ModificationsPanel(id, new AbstractReadOnlyModel<DeltaDto>() {

                @Override
                public DeltaDto getObject() {
                    if (valueWrapperModel.getObject() == null || valueWrapperModel.getObject().getValue() == null || ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue() == null) {
                        return null;
                    }
                    PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
                    ObjectDeltaType objectDeltaType = (ObjectDeltaType) ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue();
                    try {
                        ObjectDelta delta = DeltaConvertor.createObjectDelta(objectDeltaType, prismContext);
                        return new DeltaDto(delta);
                    } catch (SchemaException e) {
                        throw new IllegalStateException("Couldn't convert object delta: " + objectDeltaType);
                    }
                }
            });
        } else if (QueryType.COMPLEX_TYPE.equals(valueType) || CleanupPoliciesType.COMPLEX_TYPE.equals(valueType)) {
            return new TextAreaPanel(id, new AbstractReadOnlyModel() {

                @Override
                public Object getObject() {
                    if (valueWrapperModel.getObject() == null || valueWrapperModel.getObject().getValue() == null) {
                        return null;
                    }
                    PrismPropertyValue ppv = (PrismPropertyValue) valueWrapperModel.getObject().getValue();
                    if (ppv == null || ppv.getValue() == null) {
                        return null;
                    }
                    QName name = property.getElementName();
                    if (name == null && property.getDefinition() != null) {
                        name = property.getDefinition().getName();
                    }
                    if (name == null) {
                        name = SchemaConstants.C_VALUE;
                    }
                    PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
                    try {
                        return prismContext.xmlSerializer().serializeAnyData(ppv.getValue(), name);
                    } catch (SchemaException e) {
                        throw new SystemException("Couldn't serialize property value of type: " + valueType + ": " + e.getMessage(), e);
                    }
                }
            }, 10);
        } else {
            Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
            if (type != null && type.isPrimitive()) {
                type = ClassUtils.primitiveToWrapper(type);
            }
            if (isEnum(property)) {
                return WebComponentUtil.createEnumPanel(definition, id, new PropertyModel<>(valueWrapperModel, baseExpression), this);
            }
            //                  // default QName validation is a bit weird, so let's treat QNames as strings [TODO finish this - at the parsing side]
            //                  if (type == QName.class) {
            //                      type = String.class;
            //                  }
            PrismPropertyDefinition def = property.getDefinition();
            if (def.getValueEnumerationRef() != null) {
                PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
                String lookupTableUid = valueEnumerationRef.getOid();
                Task task = pageBase.createSimpleTask("loadLookupTable");
                OperationResult result = task.getResult();
                Collection<SelectorOptions<GetOperationOptions>> options = WebModelServiceUtils.createLookupTableRetrieveOptions();
                final PrismObject<LookupTableType> lookupTable = WebModelServiceUtils.loadObject(LookupTableType.class, lookupTableUid, options, pageBase, task, result);
                if (lookupTable != null) {
                    panel = new AutoCompleteTextPanel<String>(id, new LookupPropertyModel<String>(valueWrapperModel, baseExpression, lookupTable == null ? null : lookupTable.asObjectable()), type) {

                        @Override
                        public Iterator<String> getIterator(String input) {
                            return prepareAutoCompleteList(input, lookupTable).iterator();
                        }

                        @Override
                        public void checkInputValue(AutoCompleteTextField input, AjaxRequestTarget target, LookupPropertyModel model) {
                            Iterator<String> lookupTableValuesIterator = prepareAutoCompleteList("", lookupTable).iterator();
                            String value = input.getInput();
                            boolean isValueExist = false;
                            if (value != null) {
                                if (value.trim().equals("")) {
                                    isValueExist = true;
                                } else {
                                    while (lookupTableValuesIterator.hasNext()) {
                                        String lookupTableValue = lookupTableValuesIterator.next();
                                        if (value.trim().equals(lookupTableValue)) {
                                            isValueExist = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            if (isValueExist) {
                                input.setModelValue(new String[] { value });
                                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                            } else {
                                input.error("Entered value doesn't match any of available values and will not be saved.");
                                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                            }
                        }
                    };
                } else {
                    panel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
                }
            } else {
                panel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
            }
        }
    } else if (item instanceof PrismReference) {
        PrismContext prismContext = item.getPrismContext();
        if (prismContext == null) {
            prismContext = pageBase.getPrismContext();
        }
        QName targetTypeName = ((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName();
        Class targetClass = null;
        if (targetTypeName != null && prismContext != null) {
            targetClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeName);
        }
        final Class typeClass = targetClass != null ? targetClass : (item.getDefinition().getTypeClassIfKnown() != null ? item.getDefinition().getTypeClassIfKnown() : FocusType.class);
        Collection typeClasses = new ArrayList();
        // HACK HACK MID-3201 MID-3231
        if (isUserOrgItem(item, typeClass)) {
            typeClasses.add(UserType.class);
            typeClasses.add(OrgType.class);
        } else {
            typeClasses.add(typeClass);
        }
        panel = new ValueChoosePanel(id, new PropertyModel<>(valueWrapperModel, "value"), item.getValues(), false, typeClasses);
    } else if (item instanceof PrismContainer<?>) {
        AssociationWrapper itemWrapper = (AssociationWrapper) valueWrapperModel.getObject().getItem();
        final PrismContainer container = (PrismContainer) item;
        PrismContainerDefinition definition = container.getDefinition();
        QName valueType = definition.getTypeName();
        if (ShadowAssociationType.COMPLEX_TYPE.equals(valueType)) {
            PrismContext prismContext = item.getPrismContext();
            if (prismContext == null) {
                prismContext = pageBase.getPrismContext();
            }
            ShadowType shadowType = ((ShadowType) itemWrapper.getContainer().getObject().getObject().asObjectable());
            PrismObject<ResourceType> resource = shadowType.getResource().asPrismObject();
            // of resources.
            try {
                resource.revive(prismContext);
            } catch (SchemaException e) {
                throw new SystemException(e.getMessage(), e);
            }
            RefinedResourceSchema refinedSchema;
            CompositeRefinedObjectClassDefinition rOcDef;
            try {
                refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
                rOcDef = refinedSchema.determineCompositeObjectClassDefinition(shadowType.asPrismObject());
            } catch (SchemaException e) {
                throw new SystemException(e.getMessage(), e);
            }
            RefinedAssociationDefinition assocDef = itemWrapper.getRefinedAssociationDefinition();
            RefinedObjectClassDefinition assocTargetDef = assocDef.getAssociationTarget();
            ObjectQuery query = getAssociationsSearchQuery(prismContext, resource, assocTargetDef.getTypeName(), assocTargetDef.getKind());
            List values = item.getValues();
            return new AssociationValueChoicePanel(id, valueWrapperModel, values, false, ShadowType.class, query, assocTargetDef);
        }
    }
    return panel;
}
Also used : LockoutStatusPanel(com.evolveum.midpoint.web.component.LockoutStatusPanel) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) List(java.util.List) ArrayList(java.util.ArrayList) ValueChoosePanel(com.evolveum.midpoint.web.component.form.ValueChoosePanel) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) DeltaDto(com.evolveum.midpoint.web.component.model.delta.DeltaDto) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ByteArrayInputStream(java.io.ByteArrayInputStream) Collection(java.util.Collection) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ModificationsPanel(com.evolveum.midpoint.web.component.model.delta.ModificationsPanel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SystemException(com.evolveum.midpoint.util.exception.SystemException) AssociationValueChoicePanel(com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoicePanel) Iterator(java.util.Iterator) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) QName(javax.xml.namespace.QName) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) LookupPropertyModel(com.evolveum.midpoint.web.model.LookupPropertyModel) PropertyModel(org.apache.wicket.model.PropertyModel) LockoutStatusPanel(com.evolveum.midpoint.web.component.LockoutStatusPanel) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) ValueChoosePanel(com.evolveum.midpoint.web.component.form.ValueChoosePanel) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) ModificationsPanel(com.evolveum.midpoint.web.component.model.delta.ModificationsPanel) Panel(org.apache.wicket.markup.html.panel.Panel) AssociationValueChoicePanel(com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoicePanel) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) LookupPropertyModel(com.evolveum.midpoint.web.model.LookupPropertyModel)

Example 67 with PropertyModel

use of org.apache.wicket.model.PropertyModel in project midpoint by Evolveum.

the class PrismContainerPanel method addOrReplaceProperties.

private void addOrReplaceProperties(IModel<ContainerWrapper> model, final Form form, boolean isToBeReplaced) {
    ListView<ItemWrapper> properties = new ListView<ItemWrapper>("properties", new PropertyModel(model, "properties")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<ItemWrapper> item) {
            item.add(new PrismPropertyPanel("property", item.getModel(), form, pageBase));
            item.add(new VisibleEnableBehaviour() {

                private static final long serialVersionUID = 1L;

                @Override
                public boolean isVisible() {
                    return item.getModel().getObject().isVisible();
                }
            });
            item.add(AttributeModifier.append("class", createStyleClassModel(item.getModel())));
        }
    };
    properties.setReuseItems(true);
    if (isToBeReplaced) {
        replace(properties);
    } else {
        add(properties);
    }
}
Also used : ListView(org.apache.wicket.markup.html.list.ListView) PropertyModel(org.apache.wicket.model.PropertyModel) ListItem(org.apache.wicket.markup.html.list.ListItem) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 68 with PropertyModel

use of org.apache.wicket.model.PropertyModel in project midpoint by Evolveum.

the class LoggingConfigPanel method initLoggerColumns.

private List<IColumn<LoggerConfiguration, String>> initLoggerColumns() {
    List<IColumn<LoggerConfiguration, String>> columns = new ArrayList<>();
    IColumn column = new CheckBoxHeaderColumn<LoggerConfiguration>();
    columns.add(column);
    //name editing column
    columns.add(new EditableLinkColumn<LoggerConfiguration>(createStringResource("LoggingConfigPanel.logger"), "name") {

        @Override
        protected Component createInputPanel(String componentId, final IModel<LoggerConfiguration> model) {
            if (model.getObject() instanceof StandardLogger) {
                DropDownChoicePanel dropDownChoicePanel = new DropDownChoicePanel(componentId, new PropertyModel(model, "logger"), WebComponentUtil.createReadonlyModelFromEnum(StandardLoggerType.class), new EnumChoiceRenderer<StandardLoggerType>());
                FormComponent<StandardLoggerType> input = dropDownChoicePanel.getBaseFormComponent();
                input.add(new NotNullValidator<StandardLoggerType>("logger.emptyLogger"));
                input.add(new AttributeAppender("style", "width: 100%"));
                input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
                addAjaxFormComponentUpdatingBehavior(input);
                return dropDownChoicePanel;
            } else if (model.getObject() instanceof ComponentLogger) {
                DropDownChoicePanel dropDownChoicePanel = new DropDownChoicePanel(componentId, new PropertyModel(model, "component"), WebComponentUtil.createReadonlyModelFromEnum(LoggingComponentType.class), new EnumChoiceRenderer<LoggingComponentType>());
                FormComponent<LoggingComponentType> input = dropDownChoicePanel.getBaseFormComponent();
                input.add(new NotNullValidator<LoggingComponentType>("logger.emptyLogger"));
                input.add(new AttributeAppender("style", "width: 100%"));
                input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
                addAjaxFormComponentUpdatingBehavior(input);
                return dropDownChoicePanel;
            } else {
                TextPanel textPanel = new TextPanel<>(componentId, new PropertyModel<String>(model, getPropertyExpression()));
                FormComponent input = textPanel.getBaseFormComponent();
                addAjaxFormComponentUpdatingBehavior(input);
                input.add(new AttributeAppender("style", "width: 100%"));
                input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
                input.add(new NotNullValidator<StandardLoggerType>("message.emptyString"));
                return textPanel;
            }
        }

        @Override
        public void onClick(AjaxRequestTarget target, IModel<LoggerConfiguration> rowModel) {
            loggerEditPerformed(target, rowModel);
        }
    });
    //level editing column
    columns.add(new EditableLinkColumn<LoggerConfiguration>(createStringResource("LoggingConfigPanel.loggersLevel"), "level") {

        @Override
        protected Component createInputPanel(String componentId, IModel<LoggerConfiguration> model) {
            DropDownChoicePanel dropDownChoicePanel = new DropDownChoicePanel(componentId, new PropertyModel(model, getPropertyExpression()), WebComponentUtil.createReadonlyModelFromEnum(LoggingLevelType.class));
            FormComponent<LoggingLevelType> input = dropDownChoicePanel.getBaseFormComponent();
            input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            input.add(new NotNullValidator<LoggingLevelType>("message.emptyLevel"));
            addAjaxFormComponentUpdatingBehavior(input);
            return dropDownChoicePanel;
        }

        @Override
        public void onClick(AjaxRequestTarget target, IModel<LoggerConfiguration> rowModel) {
            loggerEditPerformed(target, rowModel);
        }

        @Override
        protected IModel<String> createLinkModel(IModel<LoggerConfiguration> rowModel) {
            LoggerConfiguration configuration = rowModel.getObject();
            return WebComponentUtil.createLocalizedModelForEnum(configuration.getLevel(), getPageBase());
        }
    });
    //appender editing column
    columns.add(new EditableLinkColumn<LoggerConfiguration>(createStringResource("LoggingConfigPanel.loggersAppender"), "appenders") {

        @Override
        protected IModel<String> createLinkModel(IModel<LoggerConfiguration> rowModel) {
            final LoggerConfiguration configuration = rowModel.getObject();
            if (configuration.getAppenders().isEmpty()) {
                return createStringResource("LoggingConfigPanel.appenders.Inherit");
            } else {
                return new LoadableModel<String>() {

                    @Override
                    protected String load() {
                        StringBuilder builder = new StringBuilder();
                        for (String appender : configuration.getAppenders()) {
                            if (configuration.getAppenders().indexOf(appender) != 0) {
                                builder.append(", ");
                            }
                            builder.append(appender);
                        }
                        return builder.toString();
                    }
                };
            }
        }

        @Override
        protected InputPanel createInputPanel(String componentId, IModel<LoggerConfiguration> model) {
            IModel<Map<String, String>> options = new Model(null);
            Map<String, String> optionsMap = new HashMap<String, String>();
            optionsMap.put("nonSelectedText", createStringResource("LoggingConfigPanel.appenders.Inherit").getString());
            options.setObject(optionsMap);
            ListMultipleChoicePanel panel = new ListMultipleChoicePanel<>(componentId, new PropertyModel<List<String>>(model, getPropertyExpression()), createNewLoggerAppendersListModel(), new StringChoiceRenderer(null), options);
            FormComponent<AppenderConfigurationType> input = panel.getBaseFormComponent();
            input.add(new EmptyOnChangeAjaxFormUpdatingBehavior());
            addAjaxFormComponentUpdatingBehavior(input);
            return panel;
        }

        public void onClick(AjaxRequestTarget target, IModel<LoggerConfiguration> rowModel) {
            loggerEditPerformed(target, rowModel);
        }
    });
    return columns;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) EnumChoiceRenderer(org.apache.wicket.markup.html.form.EnumChoiceRenderer) ArrayList(java.util.ArrayList) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) ListMultipleChoicePanel(com.evolveum.midpoint.web.component.input.ListMultipleChoicePanel) CheckBoxHeaderColumn(com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) LoggerConfiguration(com.evolveum.midpoint.web.page.admin.configuration.dto.LoggerConfiguration) StandardLoggerType(com.evolveum.midpoint.web.page.admin.configuration.dto.StandardLoggerType) StandardLogger(com.evolveum.midpoint.web.page.admin.configuration.dto.StandardLogger) IModel(org.apache.wicket.model.IModel) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) PropertyModel(org.apache.wicket.model.PropertyModel) NotNullValidator(com.evolveum.midpoint.web.component.input.validator.NotNullValidator) ComponentLogger(com.evolveum.midpoint.web.page.admin.configuration.dto.ComponentLogger) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) StringChoiceRenderer(com.evolveum.midpoint.web.component.input.StringChoiceRenderer) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) IModel(org.apache.wicket.model.IModel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Model(org.apache.wicket.model.Model) PropertyModel(org.apache.wicket.model.PropertyModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) LoggingComponentType(com.evolveum.midpoint.xml.ns._public.common.common_3.LoggingComponentType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 69 with PropertyModel

use of org.apache.wicket.model.PropertyModel in project midpoint by Evolveum.

the class LoggingConfigPanel method initAppenderColumns.

private List<IColumn<AppenderConfiguration, String>> initAppenderColumns() {
    List<IColumn<AppenderConfiguration, String>> columns = new ArrayList<>();
    IColumn column = new CheckBoxHeaderColumn<AppenderConfiguration>();
    columns.add(column);
    //name columns (editable)
    column = new EditableLinkColumn<AppenderConfiguration>(createStringResource("LoggingConfigPanel.appenders.name"), "name") {

        @Override
        public void onClick(AjaxRequestTarget target, IModel<AppenderConfiguration> rowModel) {
            appenderEditPerformed(target, rowModel);
        }

        @Override
        protected Component createInputPanel(String componentId, IModel<AppenderConfiguration> model) {
            TextPanel<String> panel = new TextPanel<String>(componentId, new PropertyModel(model, getPropertyExpression()));
            panel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            panel.getBaseFormComponent().add(new NotNullValidator<String>("message.emptyString"));
            addAjaxFormComponentUpdatingBehavior(panel.getBaseFormComponent());
            return panel;
        }
    };
    columns.add(column);
    //pattern column (editable)
    column = new EditablePropertyColumn(createStringResource("LoggingConfigPanel.appenders.pattern"), "pattern") {

        @Override
        protected InputPanel createInputPanel(String componentId, IModel model) {
            InputPanel panel = super.createInputPanel(componentId, model);
            panel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            panel.getBaseFormComponent().add(new NotNullValidator<String>("message.emptyString"));
            addAjaxFormComponentUpdatingBehavior(panel.getBaseFormComponent());
            return panel;
        }
    };
    columns.add(column);
    //file path column (editable)
    column = new FileAppenderColumn(createStringResource("LoggingConfigPanel.appenders.filePath"), "filePath");
    columns.add(column);
    //file pattern column (editable)                                                                               jj
    column = new FileAppenderColumn(createStringResource("LoggingConfigPanel.appenders.filePattern"), "filePattern");
    columns.add(column);
    //max history column (editable)
    column = new FileAppenderColumn(createStringResource("LoggingConfigPanel.appenders.maxHistory"), "maxHistory") {

        @Override
        protected InputPanel createInputPanel(String componentId, IModel model) {
            TextPanel panel = new TextPanel<>(componentId, new PropertyModel<String>(model, getPropertyExpression()));
            FormComponent component = panel.getBaseFormComponent();
            component.add(new AttributeModifier("size", 5));
            component.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            addAjaxFormComponentUpdatingBehavior(component);
            return panel;
        }
    };
    columns.add(column);
    //max file size column (editable)
    column = new FileAppenderColumn(createStringResource("LoggingConfigPanel.appenders.maxFileSize"), "maxFileSize") {

        @Override
        protected InputPanel createInputPanel(String componentId, IModel model) {
            TextPanel<String> panel = new TextPanel<>(componentId, new PropertyModel<String>(model, getPropertyExpression()));
            FormComponent component = panel.getBaseFormComponent();
            component.add(new AttributeModifier("size", 5));
            component.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            component.add(new NotNullValidator<String>("message.emptyString"));
            addAjaxFormComponentUpdatingBehavior(component);
            return panel;
        }
    };
    columns.add(column);
    CheckBoxColumn check = new EditableCheckboxColumn(createStringResource("LoggingConfigPanel.appenders.appending"), "appending") {

        @Override
        protected InputPanel createInputPanel(String componentId, IModel model) {
            InputPanel panel = super.createInputPanel(componentId, model);
            panel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            panel.getBaseFormComponent().add(new NotNullValidator<String>("message.emptyString"));
            addAjaxFormComponentUpdatingBehavior(panel.getBaseFormComponent());
            return panel;
        }
    };
    check.setEnabled(false);
    columns.add(check);
    return columns;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) ArrayList(java.util.ArrayList) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) AppenderConfiguration(com.evolveum.midpoint.web.page.admin.configuration.dto.AppenderConfiguration) CheckBoxHeaderColumn(com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn) EditablePropertyColumn(com.evolveum.midpoint.web.component.data.column.EditablePropertyColumn) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IModel(org.apache.wicket.model.IModel) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) PropertyModel(org.apache.wicket.model.PropertyModel) NotNullValidator(com.evolveum.midpoint.web.component.input.validator.NotNullValidator) AttributeModifier(org.apache.wicket.AttributeModifier) CheckBoxColumn(com.evolveum.midpoint.web.component.data.column.CheckBoxColumn) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) EditableCheckboxColumn(com.evolveum.midpoint.web.component.data.column.EditableCheckboxColumn) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)

Example 70 with PropertyModel

use of org.apache.wicket.model.PropertyModel in project midpoint by Evolveum.

the class LiveSyncHandlerPanel method initLayout.

private void initLayout(final PageTaskEdit parentPage) {
    WebMarkupContainer tokenContainer = new WebMarkupContainer(ID_TOKEN_CONTAINER);
    tokenContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            //TODO
            return true;
        }
    });
    tokenContainer.add(new Label(ID_TOKEN, new PropertyModel<>(getModel(), LiveSyncHandlerDto.F_TOKEN)));
    LinkIconPanel deleteTokenPanel = new LinkIconPanel(ID_DELETE_TOKEN, new Model("fa fa-fw fa-trash-o fa-lg text-danger"), createStringResource("LiveSyncHandlerPanel.deleteToken")) {

        @Override
        protected void onClickPerformed(AjaxRequestTarget target) {
            parentPage.getController().deleteSyncTokenPerformed(target);
        }
    };
    deleteTokenPanel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            // TODO ... and security
            return !parentPage.isEdit() && getModelObject().hasToken();
        }
    });
    deleteTokenPanel.setRenderBodyOnly(true);
    tokenContainer.add(deleteTokenPanel);
    add(tokenContainer);
    WebMarkupContainer retryContainer = new WebMarkupContainer(ID_TOKEN_RETRY_CONTAINER);
    add(retryContainer);
    WebMarkupContainer retryCheckboxContainer = new WebMarkupContainer(ID_TOKEN_RETRY_CHECKBOX_CONTAINER);
    retryContainer.add(retryCheckboxContainer);
    CheckBox retryCheckbox = new CheckBox(ID_TOKEN_RETRY_CHECKBOX, new PropertyModel<Boolean>(getModel(), ResourceRelatedHandlerDto.F_TOKEN_RETRY_UNHANDLED_ERR));
    retryCheckbox.add(enabledIfEdit);
    retryCheckboxContainer.add(retryCheckbox);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CheckBox(org.apache.wicket.markup.html.form.CheckBox) Label(org.apache.wicket.markup.html.basic.Label) PropertyModel(org.apache.wicket.model.PropertyModel) PropertyModel(org.apache.wicket.model.PropertyModel) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) LinkIconPanel(com.evolveum.midpoint.web.component.data.column.LinkIconPanel)

Aggregations

PropertyModel (org.apache.wicket.model.PropertyModel)70 Label (org.apache.wicket.markup.html.basic.Label)38 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)37 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)32 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)29 ArrayList (java.util.ArrayList)22 List (java.util.List)21 IModel (org.apache.wicket.model.IModel)21 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)20 ListItem (org.apache.wicket.markup.html.list.ListItem)17 ListView (org.apache.wicket.markup.html.list.ListView)15 Model (org.apache.wicket.model.Model)13 DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)10 TextField (org.apache.wicket.markup.html.form.TextField)10 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)9 QName (javax.xml.namespace.QName)8 Form (org.apache.wicket.markup.html.form.Form)8 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)6 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)6 MultiValueTextEditPanel (com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextEditPanel)5