Search in sources :

Example 26 with ReadOnlyModel

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

the class LinkedReferencePanel method initLayout.

private void initLayout() {
    setOutputMarkupId(true);
    IModel<DisplayType> displayModel = new ReadOnlyModel<>(() -> {
        PrismReferenceValue ref = referenceModel.getObject();
        if (ref == null) {
            return null;
        }
        DisplayType displayType = GuiDisplayTypeUtil.getDisplayTypeForObject(ref.getObject(), null, getPageBase());
        if (displayType == null) {
            displayType = new DisplayType();
        }
        if (displayType.getIcon() == null) {
            displayType.setIcon(WebComponentUtil.createIconType(WebComponentUtil.createDefaultBlackIcon(ref.getTargetType())));
        }
        return displayType;
    });
    ImagePanel imagePanel = new ImagePanel(ID_ICON, displayModel);
    imagePanel.setOutputMarkupId(true);
    add(imagePanel);
    AjaxLink<PrismReferenceValue> nameLink = new AjaxLink<PrismReferenceValue>(ID_NAME, referenceModel) {

        @Override
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            WebComponentUtil.dispatchToObjectDetailsPage(referenceModel.getObject(), LinkedReferencePanel.this, false);
        }
    };
    nameLink.add(new EnableBehaviour(() -> {
        PrismReferenceValue ref = referenceModel.getObject();
        if (ref == null) {
            return false;
        }
        return ref.getObject() != null;
    }));
    nameLink.setOutputMarkupId(true);
    add(nameLink);
    Label nameLinkText = new Label(ID_NAME_TEXT, new ReadOnlyModel<>(() -> {
        PrismReferenceValue ref = referenceModel.getObject();
        if (ref == null) {
            return "";
        }
        return WebComponentUtil.getReferencedObjectDisplayNameAndName(ref.asReferencable(), false, getPageBase());
    }));
    nameLinkText.setOutputMarkupId(true);
    nameLink.add(nameLinkText);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) DisplayType(com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) ImagePanel(com.evolveum.midpoint.web.component.data.column.ImagePanel) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Example 27 with ReadOnlyModel

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

the class CountIconPanel method initLayout.

private void initLayout() {
    getModelObject().sort((d1, d2) -> {
        if (d1 == null || d1.getIcon() == null || d1.getIcon().getCssClass() == null || d2 == null || d2.getIcon() == null || d2.getIcon().getCssClass() == null) {
            return 0;
        }
        return d1.getIcon().getCssClass().compareTo(d2.getIcon().getCssClass());
    });
    ListView<DisplayType> iconsPanel = new ListView<DisplayType>(ID_ICONS, getModel()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<DisplayType> item) {
            Label icon = new Label(ID_ICON);
            icon.add(AttributeModifier.replace("class", new PropertyModel<>(item.getModel(), "icon.cssClass")));
            if (item.getModelObject() != null && item.getModelObject().getTooltip() != null) {
                icon.add(AttributeModifier.replace("title", getPageBase().createStringResource(item.getModelObject().getTooltip().getOrig())));
            }
            icon.add(AttributeAppender.append("style", new ReadOnlyModel<>(() -> StringUtils.isNotBlank(getColor(item.getModelObject())) ? "color: " + getColor(item.getModelObject()) + ";" : "")));
            icon.setOutputMarkupId(true);
            icon.add(new VisibleBehaviour(() -> item.getModelObject() != null && item.getModelObject().getIcon() != null && StringUtils.isNotEmpty(item.getModelObject().getIcon().getCssClass())));
            item.add(icon);
            Integer count = icons.get(item.getModelObject());
            Label countPanel = new Label(ID_COUNT, Model.of(count));
            item.add(countPanel);
        }
    };
    add(iconsPanel);
}
Also used : ListView(org.apache.wicket.markup.html.list.ListView) DisplayType(com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Label(org.apache.wicket.markup.html.basic.Label) PropertyModel(org.apache.wicket.model.PropertyModel) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 28 with ReadOnlyModel

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

the class ResourceDetailsTabPanel method createSchemaStatusInfoBoxModel.

private ReadOnlyModel<InfoBoxType> createSchemaStatusInfoBoxModel() {
    return new ReadOnlyModel<>(() -> {
        String backgroundColor = "bg-gray";
        String icon = "fa fa-times";
        String numberMessage;
        String description = null;
        Integer progress = null;
        ResourceSchema refinedSchema;
        try {
            refinedSchema = getObjectDetailsModels().getRefinedSchema();
            if (refinedSchema != null) {
                backgroundColor = "bg-purple";
                icon = "fa fa-cubes";
                // TODO is this correct?
                int numObjectTypes = refinedSchema.getObjectTypeDefinitions().size();
                int numAllDefinitions = numObjectTypes + refinedSchema.getObjectClassDefinitions().size();
                numberMessage = numObjectTypes + " " + getPageBase().getString("PageResource.resource.objectTypes");
                if (numAllDefinitions != 0) {
                    progress = numObjectTypes * 100 / numAllDefinitions;
                    if (progress > 100) {
                        progress = 100;
                    }
                }
                description = numAllDefinitions + " " + getPageBase().getString("PageResource.resource.schemaDefinitions");
            } else {
                numberMessage = getPageBase().getString("PageResource.resource.noSchema");
            }
        } catch (SchemaException e) {
            backgroundColor = "bg-danger";
            icon = "fa fa-warning";
            numberMessage = getPageBase().getString("PageResource.resource.schemaError");
        }
        InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, icon, getPageBase().getString("PageResource.resource.schema"));
        infoBoxType.setNumber(numberMessage);
        infoBoxType.setProgress(progress);
        infoBoxType.setDescription(description);
        return infoBoxType;
    });
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) InfoBoxType(com.evolveum.midpoint.web.component.box.InfoBoxType) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel)

Example 29 with ReadOnlyModel

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

the class ResourceDetailsTabPanel method createSourceTargetInfoBoxModel.

private ReadOnlyModel<InfoBoxType> createSourceTargetInfoBoxModel() {
    return new ReadOnlyModel<>(() -> {
        PrismObjectWrapper<ResourceType> resource = getObjectDetailsModels().getObjectWrapper();
        String backgroundColor = "bg-aqua";
        SourceTarget sourceTarget = determineIfSourceOrTarget(resource);
        String numberKey;
        switch(sourceTarget) {
            case SOURCE:
                numberKey = "PageResource.resource.source";
                break;
            case TARGET:
                numberKey = "PageResource.resource.target";
                break;
            case SOURCE_TARGET:
                numberKey = "PageResource.resource.sourceAndTarget";
                break;
            default:
                backgroundColor = "bg-gray";
                numberKey = "PageResource.resource.noMappings";
                break;
        }
        InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, sourceTarget.getCssClass(), getPageBase().getString("PageResource.resource.mappings"));
        infoBoxType.setNumber(getPageBase().getString(numberKey));
        if (isSynchronizationDefined(resource)) {
            infoBoxType.setDescription(getPageBase().getString("PageResource.resource.sync"));
        }
        return infoBoxType;
    });
}
Also used : InfoBoxType(com.evolveum.midpoint.web.component.box.InfoBoxType) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel)

Example 30 with ReadOnlyModel

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

the class ResourceDetailsTabPanel method createResourceConfigListModel.

private ReadOnlyModel<List<ResourceConfigurationDto>> createResourceConfigListModel() {
    return new ReadOnlyModel<>(() -> {
        ResourceType resource = getObjectDetailsModels().getObjectType();
        OperationResult result = new OperationResult(OPERATION_SEARCH_TASKS_FOR_RESOURCE);
        List<PrismObject<TaskType>> tasks = WebModelServiceUtils.searchObjects(TaskType.class, getPageBase().getPrismContext().queryFor(TaskType.class).item(TaskType.F_OBJECT_REF).ref(resource.getOid()).and().item(TaskType.F_PARENT).isNull().build(), result, getPageBase());
        List<ResourceConfigurationDto> configs = new ArrayList<>();
        if (resource.getSchemaHandling() == null) {
            return configs;
        }
        List<ResourceObjectTypeDefinitionType> objectTypes = resource.getSchemaHandling().getObjectType();
        if (objectTypes == null) {
            return configs;
        }
        try {
            for (ResourceObjectTypeDefinitionType objectType : objectTypes) {
                ObjectSynchronizationType objectSynchronization = null;
                if (resource.getSynchronization() != null && resource.getSynchronization().getObjectSynchronization() != null) {
                    objectSynchronization = getSynchronizationFor(objectType, resource.getSynchronization().getObjectSynchronization(), resource.asPrismObject());
                }
                List<TaskType> syncTask = new ArrayList<>();
                if (objectSynchronization != null) {
                    syncTask = getTaskFor(tasks, objectSynchronization, resource.asPrismObject());
                }
                ResourceConfigurationDto resourceConfig = new ResourceConfigurationDto(objectType, objectSynchronization != null, syncTask);
                configs.add(resourceConfig);
            }
        } catch (SchemaException ex) {
            LoggingUtils.logUnexpectedException(LOGGER, "Could not determine resource configuration", ex);
        }
        return configs;
    });
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceConfigurationDto(com.evolveum.midpoint.web.page.admin.resources.dto.ResourceConfigurationDto) PrismObject(com.evolveum.midpoint.prism.PrismObject) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel)

Aggregations

ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)35 Label (org.apache.wicket.markup.html.basic.Label)14 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)13 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)10 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)9 IModel (org.apache.wicket.model.IModel)9 ListItem (org.apache.wicket.markup.html.list.ListItem)8 PropertyModel (org.apache.wicket.model.PropertyModel)8 ListView (org.apache.wicket.markup.html.list.ListView)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 ArrayList (java.util.ArrayList)5 QName (javax.xml.namespace.QName)5 List (java.util.List)4 StringResourceModel (org.apache.wicket.model.StringResourceModel)4 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)3 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)3 DisplayType (com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType)3 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)3