Example usage for org.apache.wicket.markup.html.list ListView ListView

List of usage examples for org.apache.wicket.markup.html.list ListView ListView

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.list ListView ListView.

Prototype

public ListView(final String id, final List<T> list) 

Source Link

Usage

From source file:com.evolveum.midpoint.web.component.prism.PrismPropertyPanel.java

License:Apache License

private void initLayout(final IModel<PropertyWrapper> model, final Form form) {
    final IModel<String> label = createDisplayName(model);
    add(new Label("label", label));

    final IModel<String> helpText = new LoadableModel<String>(false) {

        @Override//  w w  w . ja v  a2 s.c  om
        protected String load() {
            return loadHelpText(model);
        }
    };
    Label help = new Label(ID_HELP);
    help.add(AttributeModifier.replace("title", helpText));
    help.add(new InfoTooltipBehavior());
    help.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return StringUtils.isNotEmpty(helpText.getObject());
        }
    });
    add(help);

    WebMarkupContainer required = new WebMarkupContainer("required");
    required.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            PropertyWrapper wrapper = model.getObject();
            PrismProperty property = wrapper.getItem();
            PrismPropertyDefinition def = property.getDefinition();

            if (ObjectType.F_NAME.equals(def.getName())) {
                //fix for "name as required" MID-789
                return true;
            }

            return def.isMandatory();
        }
    });
    add(required);

    WebMarkupContainer hasOutbound = new WebMarkupContainer("hasOutbound");
    hasOutbound.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return hasOutbound(model);
        }
    });
    add(hasOutbound);

    WebMarkupContainer hasPendingModification = new WebMarkupContainer(ID_HAS_PENDING_MODIFICATION);
    hasPendingModification.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return hasPendingModification(model);
        }
    });
    add(hasPendingModification);

    ListView<ValueWrapper> values = new ListView<ValueWrapper>("values",
            new PropertyModel<List<ValueWrapper>>(model, "values")) {

        @Override
        protected void populateItem(final ListItem<ValueWrapper> item) {
            item.add(new PrismValuePanel("value", item.getModel(), label, form));
            item.add(AttributeModifier.append("class", createStyleClassModel(item.getModel())));

            item.add(new VisibleEnableBehaviour() {

                @Override
                public boolean isVisible() {
                    return isVisibleValue(item.getModel());
                }
            });
        }
    };
    values.setReuseItems(true);
    add(values);
}

From source file:com.evolveum.midpoint.web.component.prism.show.SceneItemPanel.java

License:Apache License

private void initLayout(final IModel<SceneItemDto> model) {
    ListView<SceneItemLineDto> items = new ListView<SceneItemLineDto>(ID_ITEM_LINES,
            new PropertyModel<List<SceneItemLineDto>>(model, SceneItemDto.F_LINES)) {

        @Override//from  w  w w .  ja  v a  2  s  . c  om
        protected void populateItem(ListItem<SceneItemLineDto> item) {
            SceneItemLinePanel panel = new SceneItemLinePanel(ID_ITEM_LINE, item.getModel());
            item.add(panel);
        }
    };
    items.setReuseItems(true);
    add(items);
}

From source file:com.evolveum.midpoint.web.component.prism.show.ScenePanel.java

License:Apache License

private void initLayout() {
    final IModel<SceneDto> model = getModel();

    WebMarkupContainer box = new WebMarkupContainer(ID_BOX);
    box.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() {

        @Override// w ww. ja  v a 2s . c  o  m
        public String getObject() {
            SceneDto dto = model.getObject();

            if (dto.getBoxClassOverride() != null) {
                return dto.getBoxClassOverride();
            }

            if (dto.getChangeType() == null) {
                return null;
            }

            switch (dto.getChangeType()) {
            case ADD:
                return "box-success";
            case DELETE:
                return "box-danger";
            case MODIFY:
                return "box-info";
            default:
                return null;
            }
        }
    }));
    add(box);

    WebMarkupContainer headerPanel = new WebMarkupContainer(ID_HEADER_PANEL);
    box.add(headerPanel);

    headerPanel.add(new SceneButtonPanel(ID_OPTION_BUTTONS, model) {
        @Override
        public void minimizeOnClick(AjaxRequestTarget target) {
            headerOnClickPerformed(target, model);
        }
    });

    Label headerChangeType = new Label(ID_HEADER_CHANGE_TYPE, new ChangeTypeModel());
    //headerChangeType.setRenderBodyOnly(true);
    Label headerObjectType = new Label(ID_HEADER_OBJECT_TYPE, new ObjectTypeModel());
    //headerObjectType.setRenderBodyOnly(true);

    IModel<String> nameModel = new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            return model.getObject().getName(ScenePanel.this);
        }
    };
    Label headerNameLabel = new Label(ID_HEADER_NAME_LABEL, nameModel);
    LinkPanel headerNameLink = new LinkPanel(ID_HEADER_NAME_LINK, nameModel) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            PrismContainerValue<?> value = getModelObject().getScene().getSourceValue();
            if (value != null && value.getParent() instanceof PrismObject) {
                PrismObject<? extends ObjectType> object = (PrismObject<? extends ObjectType>) value
                        .getParent();
                WebComponentUtil.dispatchToObjectDetailsPage(ObjectTypeUtil.createObjectRef(object),
                        getPageBase(), false);
            }
        }
    };
    Label headerDescription = new Label(ID_HEADER_DESCRIPTION, new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            return model.getObject().getDescription(ScenePanel.this);
        }
    });
    Label headerWrapperDisplayName = new Label(ID_HEADER_WRAPPER_DISPLAY_NAME,
            new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    String key = ((WrapperScene) getModelObject().getScene()).getDisplayNameKey();
                    Object[] parameters = ((WrapperScene) getModelObject().getScene())
                            .getDisplayNameParameters();
                    return new StringResourceModel(key, this).setModel(null).setDefaultValue(key)
                            .setParameters(parameters).getObject();
                }
            });

    headerPanel.add(headerChangeType);
    headerPanel.add(headerObjectType);
    headerPanel.add(headerNameLabel);
    headerPanel.add(headerNameLink);
    headerPanel.add(headerDescription);
    headerPanel.add(headerWrapperDisplayName);

    headerChangeType.add(createHeaderOnClickBehaviour(model));
    headerObjectType.add(createHeaderOnClickBehaviour(model));
    headerNameLabel.add(createHeaderOnClickBehaviour(model));
    headerDescription.add(createHeaderOnClickBehaviour(model));
    headerWrapperDisplayName.add(createHeaderOnClickBehaviour(model));

    VisibleEnableBehaviour visibleIfNotWrapper = new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return !getModelObject().isWrapper();
        }
    };
    VisibleEnableBehaviour visibleIfWrapper = new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return getModelObject().isWrapper();
        }
    };
    VisibleEnableBehaviour visibleIfExistingObject = new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            if (getModelObject().isWrapper()) {
                return false;
            }
            return isExistingViewableObject();
        }
    };
    VisibleEnableBehaviour visibleIfNotWrapperAndNotExistingObject = new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            if (getModelObject().isWrapper()) {
                return false;
            }
            return !isExistingViewableObject();
        }
    };
    headerChangeType.add(visibleIfNotWrapper);
    headerObjectType.add(visibleIfNotWrapper);
    headerNameLabel.add(visibleIfNotWrapperAndNotExistingObject);
    headerNameLink.add(visibleIfExistingObject);
    headerDescription.add(visibleIfNotWrapper);
    headerWrapperDisplayName.add(visibleIfWrapper);

    WebMarkupContainer body = new WebMarkupContainer(ID_BODY);
    body.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            SceneDto wrapper = model.getObject();
            return !wrapper.isMinimized();
        }
    });
    box.add(body);

    WebMarkupContainer itemsTable = new WebMarkupContainer(ID_ITEMS_TABLE);
    itemsTable.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return !model.getObject().getItems().isEmpty();
        }
    });
    WebMarkupContainer oldValueLabel = new WebMarkupContainer(ID_OLD_VALUE_LABEL);
    oldValueLabel.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return model.getObject().containsDeltaItems();
        }
    });
    itemsTable.add(oldValueLabel);
    WebMarkupContainer newValueLabel = new WebMarkupContainer(ID_NEW_VALUE_LABEL);
    newValueLabel.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return model.getObject().containsDeltaItems();
        }
    });
    itemsTable.add(newValueLabel);
    WebMarkupContainer valueLabel = new WebMarkupContainer(ID_VALUE_LABEL);
    valueLabel.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return !model.getObject().containsDeltaItems();
        }
    });
    itemsTable.add(valueLabel);
    ListView<SceneItemDto> items = new ListView<SceneItemDto>(ID_ITEMS,
            new PropertyModel<List<SceneItemDto>>(model, SceneDto.F_ITEMS)) {

        @Override
        protected void populateItem(ListItem<SceneItemDto> item) {
            SceneItemPanel panel = new SceneItemPanel(ID_ITEM, item.getModel());
            panel.setRenderBodyOnly(true);
            item.add(panel);
        }
    };
    items.setReuseItems(true);
    itemsTable.add(items);
    body.add(itemsTable);

    ListView<SceneDto> partialScenes = new ListView<SceneDto>(ID_PARTIAL_SCENES,
            new PropertyModel<List<SceneDto>>(model, SceneDto.F_PARTIAL_SCENES)) {

        @Override
        protected void populateItem(ListItem<SceneDto> item) {
            ScenePanel panel = new ScenePanel(ID_PARTIAL_SCENE, item.getModel());
            panel.setOutputMarkupPlaceholderTag(true);
            item.add(panel);
        }
    };
    partialScenes.setReuseItems(true);
    body.add(partialScenes);
}

From source file:com.evolveum.midpoint.web.component.progress.ProgressPanel.java

License:Apache License

protected void initLayout() {
    contentsPanel = new WebMarkupContainer(ID_CONTENTS_PANEL);
    contentsPanel.setOutputMarkupId(true);
    add(contentsPanel);//from w w  w . ja va 2  s.  c  o m

    ListView statusItemsListView = new ListView<ProgressReportActivityDto>(ID_ACTIVITIES,
            new AbstractReadOnlyModel<List<ProgressReportActivityDto>>() {
                @Override
                public List<ProgressReportActivityDto> getObject() {
                    ProgressDto progressDto = ProgressPanel.this.getModelObject();
                    return progressDto.getProgressReportActivities();
                }
            }) {
        protected void populateItem(final ListItem<ProgressReportActivityDto> item) {
            item.add(new Label(ID_ACTIVITY_DESCRIPTION, new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    ProgressReportActivityDto si = item.getModelObject();
                    if (si.getActivityType() == RESOURCE_OBJECT_OPERATION
                            && si.getResourceShadowDiscriminator() != null) {
                        ResourceShadowDiscriminator rsd = si.getResourceShadowDiscriminator();
                        return createStringResource(rsd.getKind()).getString() + " (" + rsd.getIntent()
                                + ") on " + si.getResourceName(); // TODO correct i18n
                    } else {
                        return createStringResource(si.getActivityType()).getString();
                    }
                }
            }));
            item.add(createImageLabel(ID_ACTIVITY_STATE, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    OperationResultStatusType statusType = item.getModelObject().getStatus();
                    if (statusType == null) {
                        return null;
                    } else {
                        return OperationResultStatusIcon.parseOperationalResultStatus(statusType).getIcon();
                    }
                }
            }, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() { // TODO why this does not work???
                    OperationResultStatusType statusType = item.getModelObject().getStatus(); // TODO i18n
                    if (statusType == null) {
                        return null;
                    } else {
                        return statusType.toString();
                    }
                }
            }));
            item.add(new Label(ID_ACTIVITY_COMMENT, new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    ProgressReportActivityDto si = item.getModelObject();
                    if (si.getResourceName() != null || si.getResourceOperationResultList() != null) {
                        StringBuilder sb = new StringBuilder();
                        boolean first = true;
                        if (si.getResourceOperationResultList() != null) {
                            for (ResourceOperationResult ror : si.getResourceOperationResultList()) {
                                if (!first) {
                                    sb.append(", ");
                                } else {
                                    first = false;
                                }
                                sb.append(
                                        createStringResource("ChangeType." + ror.getChangeType()).getString());
                                sb.append(":");
                                sb.append(createStringResource(ror.getResultStatus()).getString());
                            }
                        }
                        if (si.getResourceObjectName() != null) {
                            if (!first) {
                                sb.append(" -> ");
                            }
                            sb.append(si.getResourceObjectName());
                        }
                        return sb.toString();
                    } else {
                        return null;
                    }
                }
            }));
        }

        private Label createImageLabel(String id, IModel<String> cssClass, IModel<String> title) {
            Label label = new Label(id);
            label.add(AttributeModifier.replace("class", cssClass));
            label.add(AttributeModifier.replace("title", title)); // does not work, currently

            return label;
        }

    };
    contentsPanel.add(statusItemsListView);

    ListView logItemsListView = new ListView(ID_LOG_ITEMS, new AbstractReadOnlyModel<List>() {
        @Override
        public List getObject() {
            ProgressDto progressDto = ProgressPanel.this.getModelObject();
            return progressDto.getLogItems();
        }
    }) {
        protected void populateItem(ListItem item) {
            item.add(new Label(ID_LOG_ITEM, item.getModel()));
        }
    };
    contentsPanel.add(logItemsListView);

    Label executionTime = new Label(ID_EXECUTION_TIME, new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            if (operationDurationTime > 0) {
                return createStringResource("ProgressPanel.ExecutionTimeWhenFinished", operationDurationTime)
                        .getString();
            } else if (operationStartTime > 0) {
                return createStringResource("ProgressPanel.ExecutionTimeWhenRunning",
                        (System.currentTimeMillis() - operationStartTime) / 1000).getString();
            } else {
                return null;
            }
        }
    });
    contentsPanel.add(executionTime);
}

From source file:com.evolveum.midpoint.web.component.progress.StatisticsPanel.java

License:Apache License

protected void initLayout() {
    contentsPanel = new WebMarkupContainer(ID_CONTENTS_PANEL);
    contentsPanel.setOutputMarkupId(true);
    add(contentsPanel);/*from ww  w.  j  a va 2 s .  co  m*/

    ListView provisioningLines = new ListView<ProvisioningStatisticsLineDto>(ID_PROVISIONING_STATISTICS_LINES,
            new PropertyModel<List<ProvisioningStatisticsLineDto>>(getModel(),
                    StatisticsDto.F_PROVISIONING_LINES)) {
        protected void populateItem(final ListItem<ProvisioningStatisticsLineDto> item) {
            item.add(new Label(ID_PROVISIONING_RESOURCE,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_RESOURCE)));
            item.add(new Label(ID_PROVISIONING_OBJECT_CLASS,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_OBJECT_CLASS)));
            item.add(new Label(ID_PROVISIONING_GET_SUCCESS,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_GET_SUCCESS)));
            item.add(new Label(ID_PROVISIONING_GET_FAILURE,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_GET_FAILURE)));
            item.add(new Label(ID_PROVISIONING_SEARCH_SUCCESS, new PropertyModel<String>(item.getModel(),
                    ProvisioningStatisticsLineDto.F_SEARCH_SUCCESS)));
            item.add(new Label(ID_PROVISIONING_SEARCH_FAILURE, new PropertyModel<String>(item.getModel(),
                    ProvisioningStatisticsLineDto.F_SEARCH_FAILURE)));
            item.add(new Label(ID_PROVISIONING_CREATE_SUCCESS, new PropertyModel<String>(item.getModel(),
                    ProvisioningStatisticsLineDto.F_CREATE_SUCCESS)));
            item.add(new Label(ID_PROVISIONING_CREATE_FAILURE, new PropertyModel<String>(item.getModel(),
                    ProvisioningStatisticsLineDto.F_CREATE_FAILURE)));
            item.add(new Label(ID_PROVISIONING_UPDATE_SUCCESS, new PropertyModel<String>(item.getModel(),
                    ProvisioningStatisticsLineDto.F_UPDATE_SUCCESS)));
            item.add(new Label(ID_PROVISIONING_UPDATE_FAILURE, new PropertyModel<String>(item.getModel(),
                    ProvisioningStatisticsLineDto.F_UPDATE_FAILURE)));
            item.add(new Label(ID_PROVISIONING_DELETE_SUCCESS, new PropertyModel<String>(item.getModel(),
                    ProvisioningStatisticsLineDto.F_DELETE_SUCCESS)));
            item.add(new Label(ID_PROVISIONING_DELETE_FAILURE, new PropertyModel<String>(item.getModel(),
                    ProvisioningStatisticsLineDto.F_DELETE_FAILURE)));
            item.add(new Label(ID_PROVISIONING_SYNC_SUCCESS,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_SYNC_SUCCESS)));
            item.add(new Label(ID_PROVISIONING_SYNC_FAILURE,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_SYNC_FAILURE)));
            item.add(new Label(ID_PROVISIONING_SCRIPT_SUCCESS, new PropertyModel<String>(item.getModel(),
                    ProvisioningStatisticsLineDto.F_SCRIPT_SUCCESS)));
            item.add(new Label(ID_PROVISIONING_SCRIPT_FAILURE, new PropertyModel<String>(item.getModel(),
                    ProvisioningStatisticsLineDto.F_SCRIPT_FAILURE)));
            item.add(new Label(ID_PROVISIONING_OTHER_SUCCESS,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_OTHER_SUCCESS)));
            item.add(new Label(ID_PROVISIONING_OTHER_FAILURE,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_OTHER_FAILURE)));
            item.add(new Label(ID_PROVISIONING_TOTAL_OPERATIONS_COUNT, new PropertyModel<String>(
                    item.getModel(), ProvisioningStatisticsLineDto.F_TOTAL_OPERATIONS_COUNT)));
            item.add(new Label(ID_PROVISIONING_AVERAGE_TIME,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_AVERAGE_TIME)));
            item.add(new Label(ID_PROVISIONING_MIN_TIME,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_MIN_TIME)));
            item.add(new Label(ID_PROVISIONING_MAX_TIME,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_MAX_TIME)));
            item.add(new Label(ID_PROVISIONING_TOTAL_TIME,
                    new PropertyModel<String>(item.getModel(), ProvisioningStatisticsLineDto.F_TOTAL_TIME)));
        }
    };
    contentsPanel.add(provisioningLines);

    ListView mappingsLines = new ListView<MappingsLineDto>(ID_MAPPINGS_STATISTICS_LINES,
            new PropertyModel<List<MappingsLineDto>>(getModel(), StatisticsDto.F_MAPPINGS_LINES)) {
        protected void populateItem(final ListItem<MappingsLineDto> item) {
            item.add(new Label(ID_MAPPINGS_OBJECT,
                    new PropertyModel<String>(item.getModel(), MappingsLineDto.F_OBJECT)));
            item.add(new Label(ID_MAPPINGS_COUNT,
                    new PropertyModel<String>(item.getModel(), MappingsLineDto.F_COUNT)));
            item.add(new Label(ID_MAPPINGS_AVERAGE_TIME,
                    new PropertyModel<String>(item.getModel(), MappingsLineDto.F_AVERAGE_TIME)));
            item.add(new Label(ID_MAPPINGS_MIN_TIME,
                    new PropertyModel<String>(item.getModel(), MappingsLineDto.F_MIN_TIME)));
            item.add(new Label(ID_MAPPINGS_MAX_TIME,
                    new PropertyModel<String>(item.getModel(), MappingsLineDto.F_MAX_TIME)));
            item.add(new Label(ID_MAPPINGS_TOTAL_TIME,
                    new PropertyModel<String>(item.getModel(), MappingsLineDto.F_TOTAL_TIME)));
        }
    };
    contentsPanel.add(mappingsLines);

    ListView notificationsLines = new ListView<NotificationsLineDto>(ID_NOTIFICATIONS_STATISTICS_LINES,
            new PropertyModel<List<NotificationsLineDto>>(getModel(), StatisticsDto.F_NOTIFICATIONS_LINES)) {
        protected void populateItem(final ListItem<NotificationsLineDto> item) {
            item.add(new Label(ID_NOTIFICATIONS_TRANSPORT,
                    new PropertyModel<String>(item.getModel(), NotificationsLineDto.F_TRANSPORT)));
            item.add(new Label(ID_NOTIFICATIONS_COUNT_SUCCESS,
                    new PropertyModel<String>(item.getModel(), NotificationsLineDto.F_COUNT_SUCCESS)));
            item.add(new Label(ID_NOTIFICATIONS_COUNT_FAILURE,
                    new PropertyModel<String>(item.getModel(), NotificationsLineDto.F_COUNT_FAILURE)));
            item.add(new Label(ID_NOTIFICATIONS_AVERAGE_TIME,
                    new PropertyModel<String>(item.getModel(), NotificationsLineDto.F_AVERAGE_TIME)));
            item.add(new Label(ID_NOTIFICATIONS_MIN_TIME,
                    new PropertyModel<String>(item.getModel(), NotificationsLineDto.F_MIN_TIME)));
            item.add(new Label(ID_NOTIFICATIONS_MAX_TIME,
                    new PropertyModel<String>(item.getModel(), NotificationsLineDto.F_MAX_TIME)));
            item.add(new Label(ID_NOTIFICATIONS_TOTAL_TIME,
                    new PropertyModel<String>(item.getModel(), NotificationsLineDto.F_TOTAL_TIME)));
        }
    };
    contentsPanel.add(notificationsLines);

    Label lastMessage = new Label(ID_LAST_MESSAGE,
            new PropertyModel<>(getModel(), StatisticsDto.F_LAST_MESSAGE));
    contentsPanel.add(lastMessage);

    //        Label source = new Label(ID_SOURCE, new AbstractReadOnlyModel<String>() {
    //            @Override
    //            public String getObject() {
    //                StatisticsDto dto = getModelObject();
    //                if (dto == null) {
    //                    return null;
    //                }
    //                EnvironmentalPerformanceInformationType info = dto.getEnvironmentalPerformanceInformationType();
    //                if (info == null) {
    //                    return null;
    //                }
    //                if (Boolean.TRUE.equals(info.isFromMemory())) {
    //                    return getString("Message.SourceMemory",
    //                            WebMiscUtil.formatDate(info.getTimestamp()));
    //                } else {
    //                    return getString("Message.SourceRepository",
    //                            WebMiscUtil.formatDate(info.getTimestamp()));
    //                }
    //            }
    //        });
    //        contentsPanel.add(source);
}

From source file:com.evolveum.midpoint.web.component.search.SearchItemPanel.java

License:Apache License

private void initPopover() {
    WebMarkupContainer popover = new WebMarkupContainer(ID_POPOVER);
    popover.setOutputMarkupId(true);/*w ww  . ja va 2  s  .  c o  m*/
    add(popover);

    WebMarkupContainer popoverBody = new WebMarkupContainer(ID_POPOVER_BODY);
    popoverBody.setOutputMarkupId(true);
    popover.add(popoverBody);

    ListView values = new ListView<DisplayableValue>(ID_VALUES,
            new PropertyModel<List<DisplayableValue>>(popoverModel, SearchItem.F_VALUES)) {

        @Override
        protected void populateItem(final ListItem<DisplayableValue> item) {
            item.add(AttributeModifier.replace("style", new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    return item.getIndex() != 0 ? "margin-top: 5px;" : null;
                }
            }));

            SearchPopupPanel fragment = createPopoverFragment(item.getModel());
            fragment.setRenderBodyOnly(true);
            item.add(fragment);
        }
    };
    popoverBody.add(values);

    AjaxSubmitButton update = new AjaxSubmitButton(ID_UPDATE, createStringResource("SearchItemPanel.update")) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            updateItemPerformed(target);
        }
    };
    popoverBody.add(update);

    AjaxButton close = new AjaxButton(ID_CLOSE, createStringResource("SearchItemPanel.close")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            closeEditPopoverPerformed(target);
        }
    };
    popoverBody.add(close);
}

From source file:com.evolveum.midpoint.web.component.search.SearchPanel.java

License:Apache License

private void initLayout() {
    moreDialogModel = new LoadableModel<MoreDialogDto>(false) {

        @Override/*from ww  w.  j  av  a 2  s  .  co  m*/
        protected MoreDialogDto load() {
            MoreDialogDto dto = new MoreDialogDto();
            dto.setProperties(createPropertiesList());

            return dto;
        }
    };

    Form form = new Form(ID_FORM);
    add(form);

    ListView items = new ListView<SearchItem>(ID_ITEMS,
            new PropertyModel<List<SearchItem>>(getModel(), Search.F_ITEMS)) {

        @Override
        protected void populateItem(ListItem<SearchItem> item) {
            SearchItemPanel searchItem = new SearchItemPanel(ID_ITEM, item.getModel());
            item.add(searchItem);
        }
    };
    items.add(createAdvancedVisibleBehaviour(false));
    form.add(items);

    WebMarkupContainer moreGroup = new WebMarkupContainer(ID_MORE_GROUP);
    moreGroup.add(createAdvancedVisibleBehaviour(false));
    form.add(moreGroup);

    AjaxLink more = new AjaxLink(ID_MORE) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            Component button = SearchPanel.this.get(createComponentPath(ID_FORM, ID_MORE_GROUP, ID_MORE));
            Component popover = SearchPanel.this.get(createComponentPath(ID_POPOVER));
            togglePopover(target, button, popover, 14);
        }
    };
    more.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            Search search = getModelObject();
            return !search.getAvailableDefinitions().isEmpty();
        }
    });
    more.setOutputMarkupId(true);
    moreGroup.add(more);

    WebMarkupContainer searchContainer = new WebMarkupContainer(ID_SEARCH_CONTAINER);
    searchContainer.setOutputMarkupId(true);
    form.add(searchContainer);

    AjaxSubmitButton searchSimple = new AjaxSubmitButton(ID_SEARCH_SIMPLE) {

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(form);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            searchPerformed(target);
        }
    };
    searchSimple.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isEnabled() {
            Search search = getModelObject();
            if (!search.isShowAdvanced()) {
                return true;
            }

            PrismContext ctx = getPageBase().getPrismContext();
            return search.isAdvancedQueryValid(ctx);
        }

        @Override
        public boolean isVisible() {
            return !getModelObject().isShowAdvanced() || !queryPlagroundAccessible;
        }
    });
    searchSimple.setOutputMarkupId(true);
    searchContainer.add(searchSimple);

    WebMarkupContainer searchDropdown = new WebMarkupContainer(ID_SEARCH_DROPDOWN);
    searchDropdown.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return getModelObject().isShowAdvanced() && queryPlagroundAccessible;
        }
    });
    searchContainer.add(searchDropdown);

    AjaxSubmitButton searchButtonBeforeDropdown = new AjaxSubmitButton(ID_SEARCH_BUTTON_BEFORE_DROPDOWN) {
        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(form);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            searchPerformed(target);
        }
    };
    searchButtonBeforeDropdown.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isEnabled() {
            Search search = getModelObject();
            if (!search.isShowAdvanced()) {
                return true;
            }
            PrismContext ctx = getPageBase().getPrismContext();
            return search.isAdvancedQueryValid(ctx);
        }
    });
    searchDropdown.add(searchButtonBeforeDropdown);

    List<InlineMenuItem> searchItems = new ArrayList<>();

    InlineMenuItem searchItem = new InlineMenuItem(createStringResource("SearchPanel.search"),
            new InlineMenuItemAction() {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    PrismContext ctx = getPageBase().getPrismContext();
                    if (getModelObject().isAdvancedQueryValid(ctx)) {
                        searchPerformed(target);
                    }
                }
            });
    searchItems.add(searchItem);

    searchItem = new InlineMenuItem(createStringResource("SearchPanel.debug"), new InlineMenuItemAction() {
        @Override
        public void onClick(AjaxRequestTarget target) {
            debugPerformed();
        }
    });
    searchItems.add(searchItem);

    ListView<InlineMenuItem> li = new ListView<InlineMenuItem>(ID_MENU_ITEM, Model.ofList(searchItems)) {
        @Override
        protected void populateItem(ListItem<InlineMenuItem> item) {
            WebMarkupContainer menuItemBody = new MenuLinkPanel(ID_MENU_ITEM_BODY, item.getModel());
            menuItemBody.setRenderBodyOnly(true);
            item.add(menuItemBody);
        }
    };
    searchDropdown.add(li);

    AjaxButton advanced = new AjaxButton(ID_ADVANCED, createAdvancedModel()) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            advancedPerformed(target);
        }
    };
    advanced.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return advancedSearch;
        }
    });
    form.add(advanced);

    initPopover();

    WebMarkupContainer advancedGroup = new WebMarkupContainer(ID_ADVANCED_GROUP);
    advancedGroup.add(createAdvancedVisibleBehaviour(true));
    advancedGroup.add(AttributeAppender.append("class", createAdvancedGroupStyle()));
    advancedGroup.setOutputMarkupId(true);
    form.add(advancedGroup);

    Label advancedCheck = new Label(ID_ADVANCED_CHECK);
    advancedCheck.add(AttributeAppender.append("class", createAdvancedGroupLabelStyle()));
    advancedGroup.add(advancedCheck);

    final TextArea advancedArea = new TextArea(ID_ADVANCED_AREA,
            new PropertyModel(getModel(), Search.F_ADVANCED_QUERY));
    advancedArea.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateAdvancedArea(advancedArea, target);
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);

            attributes.setThrottlingSettings(
                    new ThrottlingSettings(ID_ADVANCED_AREA, Duration.milliseconds(500), true));
        }
    });
    advancedGroup.add(advancedArea);

    Label advancedError = new Label(ID_ADVANCED_ERROR,
            new PropertyModel<String>(getModel(), Search.F_ADVANCED_ERROR));
    advancedError.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            Search search = getModelObject();

            if (!search.isShowAdvanced()) {
                return false;
            }

            return StringUtils.isNotEmpty(search.getAdvancedError());
        }
    });
    advancedGroup.add(advancedError);
}

From source file:com.evolveum.midpoint.web.component.search.SearchPanel.java

License:Apache License

private void initPopover() {
    WebMarkupContainer popover = new WebMarkupContainer(ID_POPOVER);
    popover.setOutputMarkupId(true);/*from   ww  w. j  av a  2 s .  c o  m*/
    add(popover);

    final WebMarkupContainer propList = new WebMarkupContainer(ID_PROP_LIST);
    propList.setOutputMarkupId(true);
    popover.add(propList);

    ListView properties = new ListView<Property>(ID_PROPERTIES,
            new PropertyModel<List<Property>>(moreDialogModel, MoreDialogDto.F_PROPERTIES)) {

        @Override
        protected void populateItem(final ListItem<Property> item) {
            CheckBox check = new CheckBox(ID_CHECK,
                    new PropertyModel<Boolean>(item.getModel(), Property.F_SELECTED));
            check.add(new AjaxFormComponentUpdatingBehavior("change") {

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    //nothing, just update model.
                }
            });
            item.add(check);

            AjaxLink propLink = new AjaxLink(ID_PROP_LINK) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    addOneItemPerformed(item.getModelObject(), target);
                }
            };
            item.add(propLink);

            Label name = new Label(ID_PROP_NAME, new PropertyModel<>(item.getModel(), Property.F_NAME));
            name.setRenderBodyOnly(true);
            propLink.add(name);

            item.add(new VisibleEnableBehaviour() {

                @Override
                public boolean isVisible() {
                    Property property = item.getModelObject();

                    Search search = SearchPanel.this.getModelObject();
                    if (!search.getAvailableDefinitions().contains(property.getDefinition())) {
                        return false;
                    }

                    MoreDialogDto dto = moreDialogModel.getObject();
                    String nameFilter = dto.getNameFilter();

                    String propertyName = property.getName().toLowerCase();
                    if (StringUtils.isNotEmpty(nameFilter)
                            && !propertyName.contains(nameFilter.toLowerCase())) {
                        return false;
                    }

                    return true;
                }
            });
        }
    };
    propList.add(properties);

    TextField addText = new TextField(ID_ADD_TEXT,
            new PropertyModel(moreDialogModel, MoreDialogDto.F_NAME_FILTER));
    addText.add(new Behavior() {
        @Override
        public void bind(Component component) {
            super.bind(component);

            component.add(AttributeModifier.replace("onkeydown",
                    Model.of("if(event.keyCode == 13) {event.preventDefault();}")));
        }
    });

    popover.add(addText);
    addText.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(propList);
        }
    });
    popover.add(addText);

    AjaxButton add = new AjaxButton(ID_ADD, createStringResource("SearchPanel.add")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addItemPerformed(target);
        }
    };
    popover.add(add);

    AjaxButton close = new AjaxButton(ID_CLOSE, createStringResource("SearchPanel.close")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            closeMorePopoverPerformed(target);
        }
    };
    popover.add(close);
}

From source file:com.evolveum.midpoint.web.component.wf.ApprovalProcessesPreviewPanel.java

License:Apache License

private void initLayout() {
    ListView<ApprovalProcessExecutionInformationDto> list = new ListView<ApprovalProcessExecutionInformationDto>(
            ID_PROCESSES, getModel()) {//from  ww  w.  j  a  v a  2  s.c  o m
        @Override
        protected void populateItem(ListItem<ApprovalProcessExecutionInformationDto> item) {
            item.add(new Label(ID_NAME, LoadableModel.create(() -> {
                String targetName = item.getModelObject().getTargetName();
                if (targetName != null) {
                    return ApprovalProcessesPreviewPanel.this
                            .getString("ApprovalProcessesPreviewPanel.processRelatedTo", targetName);
                } else {
                    return getString("ApprovalProcessesPreviewPanel.process");
                }
            }, false)));
            item.add(new ApprovalProcessExecutionInformationPanel(ID_PREVIEW, item.getModel()));
            item.add(new EvaluatedTriggerGroupPanel(ID_TRIGGERS,
                    new PropertyModel<>(item.getModel(), ApprovalProcessExecutionInformationDto.F_TRIGGERS)));
        }
    };
    add(list);
}

From source file:com.evolveum.midpoint.web.component.wf.ApprovalProcessExecutionInformationPanel.java

License:Apache License

protected void initLayout() {

    // TODO clean this code up!!!

    ListView<ApprovalStageExecutionInformationDto> stagesList = new ListView<ApprovalStageExecutionInformationDto>(
            ID_STAGES, new PropertyModel<>(getModel(), ApprovalProcessExecutionInformationDto.F_STAGES)) {
        @Override/*from  ww  w . j a v  a  2  s.c o m*/
        protected void populateItem(ListItem<ApprovalStageExecutionInformationDto> stagesListItem) {
            ApprovalProcessExecutionInformationDto process = ApprovalProcessExecutionInformationPanel.this
                    .getModelObject();
            ApprovalStageExecutionInformationDto stage = stagesListItem.getModelObject();
            int stageNumber = stage.getStageNumber();
            int numberOfStages = process.getNumberOfStages();
            int currentStageNumber = process.getCurrentStageNumber();

            WebMarkupContainer arrow = new WebMarkupContainer(ID_ARROW);
            arrow.add(new VisibleBehaviour(() -> stageNumber > 1));
            stagesListItem.add(arrow);

            WebMarkupContainer currentStageMarker = new WebMarkupContainer(ID_CURRENT_STAGE_MARKER);
            currentStageMarker
                    .add(new VisibleBehaviour(() -> stageNumber == currentStageNumber && process.isRunning()));
            stagesListItem.add(currentStageMarker);

            ListView<ApproverEngagementDto> approversList = new ListView<ApproverEngagementDto>(ID_APPROVERS,
                    new PropertyModel<>(stagesListItem.getModel(),
                            ApprovalStageExecutionInformationDto.F_APPROVER_ENGAGEMENTS)) {
                @Override
                protected void populateItem(ListItem<ApproverEngagementDto> approversListItem) {
                    ApproverEngagementDto ae = approversListItem.getModelObject();

                    // original approver name
                    approversListItem.add(createApproverLabel(ID_APPROVER_NAME,
                            "ApprovalProcessExecutionInformationPanel.approver", ae.getApproverRef(), true));

                    // outcome
                    WorkItemOutcomeType outcome = ae.getOutput() != null
                            ? ApprovalUtils.fromUri(ae.getOutput().getOutcome())
                            : null;
                    ApprovalOutcomeIcon outcomeIcon;
                    if (outcome != null) {
                        switch (outcome) {
                        case APPROVE:
                            outcomeIcon = ApprovalOutcomeIcon.APPROVED;
                            break;
                        case REJECT:
                            outcomeIcon = ApprovalOutcomeIcon.REJECTED;
                            break;
                        default:
                            outcomeIcon = ApprovalOutcomeIcon.UNKNOWN;
                            break; // perhaps should throw AssertionError instead
                        }
                    } else {
                        if (stageNumber < currentStageNumber) {
                            outcomeIcon = ApprovalOutcomeIcon.EMPTY; // history: do not show anything for work items with no outcome
                        } else if (stageNumber == currentStageNumber) {
                            outcomeIcon = process.isRunning() && stage.isReachable()
                                    ? ApprovalOutcomeIcon.IN_PROGRESS
                                    : ApprovalOutcomeIcon.CANCELLED; // currently open
                        } else {
                            outcomeIcon = process.isRunning() && stage.isReachable()
                                    ? ApprovalOutcomeIcon.FUTURE
                                    : ApprovalOutcomeIcon.CANCELLED;
                        }
                    }
                    ImagePanel outcomePanel = new ImagePanel(ID_OUTCOME, Model.of(outcomeIcon.getIcon()),
                            Model.of(getString(outcomeIcon.getTitle())));
                    outcomePanel.add(new VisibleBehaviour(() -> outcomeIcon != ApprovalOutcomeIcon.EMPTY));
                    approversListItem.add(outcomePanel);

                    // content (incl. performer)
                    WebMarkupContainer approvalBoxContent = new WebMarkupContainer(ID_APPROVAL_BOX_CONTENT);
                    approversListItem.add(approvalBoxContent);
                    approvalBoxContent.setVisible(performerVisible(ae) || attorneyVisible(ae));
                    approvalBoxContent.add(createApproverLabel(ID_PERFORMER_NAME,
                            "ApprovalProcessExecutionInformationPanel.performer", ae.getCompletedBy(),
                            performerVisible(ae)));
                    approvalBoxContent.add(createApproverLabel(ID_ATTORNEY_NAME,
                            "ApprovalProcessExecutionInformationPanel.attorney", ae.getAttorney(),
                            attorneyVisible(ae)));

                    // junction
                    Label junctionLabel = new Label(ID_JUNCTION, stage.isFirstDecides() ? "" : " & "); // or "+" for first decides? probably not
                    junctionLabel.setVisible(!stage.isFirstDecides() && !ae.isLast()); // not showing "" to save space (if aligned vertically)
                    approversListItem.add(junctionLabel);
                }
            };
            approversList.setVisible(stage.getAutomatedCompletionReason() == null);
            stagesListItem.add(approversList);

            String autoCompletionKey;
            if (stage.getAutomatedCompletionReason() != null) {
                switch (stage.getAutomatedCompletionReason()) {
                case AUTO_COMPLETION_CONDITION:
                    autoCompletionKey = "DecisionDto.AUTO_COMPLETION_CONDITION";
                    break;
                case NO_ASSIGNEES_FOUND:
                    autoCompletionKey = "DecisionDto.NO_ASSIGNEES_FOUND";
                    break;
                default:
                    autoCompletionKey = null; // or throw an exception?
                }
            } else {
                autoCompletionKey = null;
            }
            Label automatedOutcomeLabel = new Label(ID_AUTOMATED_OUTCOME,
                    autoCompletionKey != null ? getString(autoCompletionKey) : "");
            automatedOutcomeLabel.setVisible(stage.getAutomatedCompletionReason() != null);
            stagesListItem.add(automatedOutcomeLabel);

            stagesListItem.add(new Label(ID_STAGE_NAME, getStageNameLabel(stage, stageNumber, numberOfStages)));

            ApprovalLevelOutcomeType stageOutcome = stage.getOutcome();
            ApprovalOutcomeIcon stageOutcomeIcon;
            if (stageOutcome != null) {
                switch (stageOutcome) {
                case APPROVE:
                    stageOutcomeIcon = ApprovalOutcomeIcon.APPROVED;
                    break;
                case REJECT:
                    stageOutcomeIcon = ApprovalOutcomeIcon.REJECTED;
                    break;
                case SKIP:
                    stageOutcomeIcon = ApprovalOutcomeIcon.SKIPPED;
                    break;
                default:
                    stageOutcomeIcon = ApprovalOutcomeIcon.UNKNOWN;
                    break; // perhaps should throw AssertionError instead
                }
            } else {
                if (stageNumber < currentStageNumber) {
                    stageOutcomeIcon = ApprovalOutcomeIcon.EMPTY; // history: do not show anything (shouldn't occur, as historical stages are filled in)
                } else if (stageNumber == currentStageNumber) {
                    stageOutcomeIcon = process.isRunning() && stage.isReachable()
                            ? ApprovalOutcomeIcon.IN_PROGRESS
                            : ApprovalOutcomeIcon.CANCELLED; // currently open
                } else {
                    stageOutcomeIcon = process.isRunning() && stage.isReachable() ? ApprovalOutcomeIcon.FUTURE
                            : ApprovalOutcomeIcon.CANCELLED;
                }
            }
            ImagePanel stageOutcomePanel = new ImagePanel(ID_STAGE_OUTCOME,
                    Model.of(stageOutcomeIcon.getIcon()), Model.of(getString(stageOutcomeIcon.getTitle())));
            stageOutcomePanel.add(new VisibleBehaviour(() -> stageOutcomeIcon != ApprovalOutcomeIcon.EMPTY));
            stagesListItem.add(stageOutcomePanel);
        }

    };
    add(stagesList);
}