Search in sources :

Example 21 with LoadableModel

use of com.evolveum.midpoint.gui.api.model.LoadableModel in project midpoint by Evolveum.

the class FocusPersonasTabPanel method loadModel.

private LoadableModel<List<PrismObject<FocusType>>> loadModel() {
    return new LoadableModel<List<PrismObject<FocusType>>>(false) {

        @Override
        protected List<PrismObject<FocusType>> load() {
            List<String> personaOidsList = getPersonasOidsList();
            List<PrismObject<FocusType>> personasList = new ArrayList<>();
            if (personaOidsList.size() > 0) {
                ObjectQuery query = ObjectQuery.createObjectQuery(InOidFilter.createInOid(personaOidsList));
                OperationResult result = new OperationResult(OPERATION_SEARCH_PERSONAS_OBJECTS);
                personasList = WebModelServiceUtils.searchObjects(FocusType.class, query, result, pageBase);
            }
            return personasList == null ? new ArrayList<>() : personasList;
        }
    };
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 22 with LoadableModel

use of com.evolveum.midpoint.gui.api.model.LoadableModel 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 23 with LoadableModel

use of com.evolveum.midpoint.gui.api.model.LoadableModel in project midpoint by Evolveum.

the class PageAccounts method createTotalsModel.

private LoadableModel<Integer> createTotalsModel(final SynchronizationSituationType situation) {
    return new LoadableModel<Integer>(false) {

        @Override
        protected Integer load() {
            ObjectFilter resourceFilter = createResourceQueryFilter();
            if (resourceFilter == null) {
                return 0;
            }
            ObjectFilter filter = createObjectQuery().getFilter();
            Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
            Task task = createSimpleTask(OPERATION_GET_TOTALS);
            OperationResult result = new OperationResult(OPERATION_GET_TOTALS);
            try {
                ObjectFilter situationFilter = QueryBuilder.queryFor(ShadowType.class, getPrismContext()).item(ShadowType.F_SYNCHRONIZATION_SITUATION).eq(situation).buildFilter();
                ObjectQuery query = ObjectQuery.createObjectQuery(AndFilter.createAnd(filter, situationFilter));
                return getModelService().countObjects(ShadowType.class, query, options, task, result);
            } catch (CommonException | RuntimeException ex) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't count shadows", ex);
            }
            return 0;
        }
    };
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 24 with LoadableModel

use of com.evolveum.midpoint.gui.api.model.LoadableModel in project midpoint by Evolveum.

the class PageAccounts method createFilesModel.

private LoadableModel<List<String>> createFilesModel() {
    return new LoadableModel<List<String>>(false) {

        @Override
        protected List<String> load() {
            String[] filesArray;
            try {
                MidpointConfiguration config = getMidpointConfiguration();
                File exportFolder = new File(config.getMidpointHome() + "/export");
                filesArray = exportFolder.list(new FilenameFilter() {

                    @Override
                    public boolean accept(java.io.File dir, String name) {
                        return name.endsWith("xml");
                    }
                });
            } catch (Exception ex) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't list files", ex);
                getSession().error("Couldn't list files, reason: " + ex.getMessage());
                throw new RestartResponseException(PageDashboard.class);
            }
            if (filesArray == null) {
                return new ArrayList<>();
            }
            List<String> list = Arrays.asList(filesArray);
            Collections.sort(list);
            return list;
        }
    };
}
Also used : FilenameFilter(java.io.FilenameFilter) RestartResponseException(org.apache.wicket.RestartResponseException) MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) ArrayList(java.util.ArrayList) PageDashboard(com.evolveum.midpoint.web.page.admin.home.PageDashboard) AjaxDownloadBehaviorFromFile(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile) File(org.apache.wicket.util.file.File) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)24 ArrayList (java.util.ArrayList)8 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)7 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)6 List (java.util.List)5 Model (org.apache.wicket.model.Model)5 PropertyModel (org.apache.wicket.model.PropertyModel)5 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)4 IModel (org.apache.wicket.model.IModel)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3 CommonException (com.evolveum.midpoint.util.exception.CommonException)3 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)3 Label (org.apache.wicket.markup.html.basic.Label)3 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)2 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)2 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 TabbedPanel (com.evolveum.midpoint.web.component.TabbedPanel)2