Search in sources :

Example 51 with ListView

use of org.apache.wicket.markup.html.list.ListView 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 52 with ListView

use of org.apache.wicket.markup.html.list.ListView in project midpoint by Evolveum.

the class DashboardSearchPanel method initLayout.

@Override
protected void initLayout() {
    final Form searchForm = new Form(ID_SEARCH_FORM);
    add(searchForm);
    searchForm.setOutputMarkupId(true);
    final List<String> accessibleSearchTypes = new ArrayList<>();
    if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_USERS_ALL_URL, AuthorizationConstants.AUTZ_UI_USERS_URL)) {
        accessibleSearchTypes.add(SEARCH_TYPES.get(USER_INDEX));
    }
    if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_RESOURCES_ALL_URL, AuthorizationConstants.AUTZ_UI_RESOURCES_URL)) {
        accessibleSearchTypes.add(SEARCH_TYPES.get(RESOURCE_INDEX));
    }
    if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_TASKS_ALL_URL, AuthorizationConstants.AUTZ_UI_TASKS_URL)) {
        accessibleSearchTypes.add(SEARCH_TYPES.get(TASK_INDEX));
    }
    if (accessibleSearchTypes.size() == 0) {
        searchForm.setVisible(false);
    } else {
        final TextField searchInput = new TextField(ID_SEARCH_INPUT, Model.of("")) {

            @Override
            protected void onComponentTag(final ComponentTag tag) {
                super.onComponentTag(tag);
                tag.put("placeholder", createStringResource("SearchPanel.searchByName").getString());
            }
        };
        searchForm.add(searchInput);
        final Label buttonLabel = new Label(ID_BUTTON_LABEL, new Model<String>() {

            public String getObject() {
                return accessibleSearchTypes.get(selectedSearchType);
            }
        });
        buttonLabel.setOutputMarkupId(true);
        final AjaxSubmitLink searchButton = new AjaxSubmitLink(ID_SEARCH_BUTTON) {

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                String searchType = buttonLabel.getDefaultModel().getObject().toString();
                String searchText = searchInput.getValue();
                performSearch(searchType, searchText == null ? "" : searchText);
            }
        };
        searchButton.setOutputMarkupId(true);
        searchButton.add(buttonLabel);
        searchForm.add(searchButton);
        searchForm.setDefaultButton(searchButton);
        //            final WebMarkupContainer list = new WebMarkupContainer(ID_SEARCH_TYPES);
        //            list.setOutputMarkupId(true);
        ListView<String> li = new ListView<String>(ID_SEARCH_TYPES, new IModel<List<String>>() {

            @Override
            public void detach() {
            }

            @Override
            public List<String> getObject() {
                return accessibleSearchTypes;
            }

            @Override
            public void setObject(List<String> list) {
            }
        }) {

            @Override
            protected void populateItem(final ListItem<String> item) {
                final AjaxLink searchTypeLink = new AjaxLink(ID_SEARCH_TYPE_ITEM) {

                    @Override
                    public IModel<?> getBody() {
                        return new Model<String>(item.getModel().getObject());
                    }

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        selectedSearchType = accessibleSearchTypes.indexOf(item.getModelObject());
                        target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_BUTTON)));
                    }

                    @Override
                    protected void onComponentTag(final ComponentTag tag) {
                        super.onComponentTag(tag);
                        tag.put("value", item.getModelObject());
                    }
                };
                searchTypeLink.setOutputMarkupId(true);
                item.add(searchTypeLink);
            }
        };
        li.setOutputMarkupId(true);
        searchForm.add(li);
    //            final RepeatingView searchTypes = new RepeatingView(ID_SEARCH_TYPE_ITEM);
    //            searchTypes.setOutputMarkupId(true);
    //            if (accessibleSearchTypes.size() > 1) {
    //                for (int i = 0; i < accessibleSearchTypes.size(); i++) {
    //                    if (i == selectedSearchType){
    //                        continue;
    //                    }
    //                    final String searchTypeItem = accessibleSearchTypes.get(i);
    //                    final AjaxSubmitLink searchTypeLink = new AjaxSubmitLink(searchTypes.newChildId()) {
    //                        @Override
    //                        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
    //                                selectedSearchType = accessibleSearchTypes.indexOf(searchTypeItem);
    //                                target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_BUTTON)));
    //                                target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_TYPES)));
    ////                                target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_TYPES, ID_SEARCH_TYPE_ITEM)));
    //                        }
    //
    //                        @Override
    //                        protected void onComponentTag(final ComponentTag tag) {
    //                            super.onComponentTag(tag);
    //                            tag.put("value", searchTypeItem);
    //                        }
    //
    //                    };
    //                    searchTypeLink.setOutputMarkupId(true);
    //                    Label linkLabel = new Label(ID_LINK_LABEL, new Model<String>() {
    //                        public String getObject() {
    //                            return searchTypeItem;
    //                        }
    //                    });
    //                    linkLabel.setOutputMarkupId(true);
    //                    searchTypeLink.add(linkLabel);
    //                    searchTypes.add(searchTypeLink);
    //                }
    //            }
    //            list.add(searchTypes);
    //            if (accessibleSearchTypes.size() == 1){
    //                list.setVisible(false);
    //            }
    //            searchForm.add(list);
    }
}
Also used : Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListView(org.apache.wicket.markup.html.list.ListView) ComponentTag(org.apache.wicket.markup.ComponentTag) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) TextField(org.apache.wicket.markup.html.form.TextField) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 53 with ListView

use of org.apache.wicket.markup.html.list.ListView in project ocvn by devgateway.

the class FileInputBootstrapFormComponentWrapper method addAlreadyUploadedFilesComponent.

/**
     * already uploaded files section
     */
private void addAlreadyUploadedFilesComponent() {
    alreadyUploadedFiles = new WebMarkupContainer("alreadyUploadedFiles") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onInitialize() {
            super.onInitialize();
            setVisibilityAllowed(isVisibleAlreadyUploadedFiles());
        }
    };
    alreadyUploadedFiles.setOutputMarkupPlaceholderTag(true);
    alreadyUploadedFiles.setOutputMarkupId(true);
    add(alreadyUploadedFiles);
    alreadyUploadedFiles.add(new Label("uploadedFilesTitle", new StringResourceModel("uploadedFilesTitle", this, null)));
    AbstractReadOnlyModel<List<FileMetadata>> alreadyUploadedFilesModel = new AbstractReadOnlyModel<List<FileMetadata>>() {

        private static final long serialVersionUID = 1L;

        @Override
        public List<FileMetadata> getObject() {
            List<FileMetadata> fileObject = new ArrayList<>();
            // get only the already uploaded files
            for (FileMetadata file : filesModel) {
                if (!file.isNew()) {
                    fileObject.add(file);
                }
            }
            return fileObject;
        }
    };
    ListView<FileMetadata> list = new ListView<FileMetadata>("list", alreadyUploadedFilesModel) {

        private static final long serialVersionUID = 1L;

        private List<IndicatingAjaxLink<Void>> deleteButtons = new ArrayList<>();

        @Override
        protected void populateItem(final ListItem<FileMetadata> item) {
            // make file name clickable
            Link<FileMetadata> downloadLink = new Link<FileMetadata>("downloadLink", item.getModel()) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick() {
                    final FileMetadata modelObject = getModelObject();
                    AbstractResourceStreamWriter rstream = new AbstractResourceStreamWriter() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void write(final OutputStream output) throws IOException {
                            output.write(modelObject.getContent().getBytes());
                        }

                        @Override
                        public String getContentType() {
                            return modelObject.getContentType();
                        }
                    };
                    ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(rstream, modelObject.getName());
                    handler.setContentDisposition(ContentDisposition.ATTACHMENT);
                    getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
                }
            };
            downloadLink.add(new Label("downloadText", item.getModelObject().getName()));
            downloadLink.add(new TooltipBehavior(new StringResourceModel("downloadUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
            item.add(downloadLink);
            Link<FileMetadata> download = new CustomDownloadLink("download", item.getModel());
            item.add(download);
            IndicatingAjaxLink<Void> delete = new IndicatingAjaxLink<Void>("delete") {

                private static final long serialVersionUID = 1L;

                @SuppressWarnings("unchecked")
                @Override
                public void onClick(final AjaxRequestTarget target) {
                    filesModel.remove(item.getModelObject());
                    FileInputBootstrapFormComponentWrapper.this.getModel().setObject((T) filesModel);
                    target.add(alreadyUploadedFiles);
                }
            };
            delete.add(new IconBehavior(GlyphIconType.remove));
            delete.add(new TooltipBehavior(new StringResourceModel("removeUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
            delete.setVisible(true);
            item.add(delete);
            deleteButtons.add(delete);
            // only to admins
            if (visibleOnlyToAdmin) {
                MetaDataRoleAuthorizationStrategy.authorize(delete, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
            }
            if (disableDeleteButton) {
                delete.setVisibilityAllowed(false);
            }
        }

        @Override
        public void onEvent(final IEvent<?> event) {
            /*
                 * disable 'delete' buttons based on the form state
                 */
            if (event.getPayload() instanceof EditingDisabledEvent) {
                for (IndicatingAjaxLink<?> del : deleteButtons) {
                    del.setVisibilityAllowed(false);
                }
            }
            if (event.getPayload() instanceof EditingEnabledEvent) {
                for (IndicatingAjaxLink<?> del : deleteButtons) {
                    del.setVisibilityAllowed(true);
                }
            }
        }
    };
    alreadyUploadedFiles.add(list);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) IEvent(org.apache.wicket.event.IEvent) OutputStream(java.io.OutputStream) Label(org.apache.wicket.markup.html.basic.Label) FileMetadata(org.devgateway.toolkit.persistence.dao.FileMetadata) ArrayList(java.util.ArrayList) AbstractResourceStreamWriter(org.apache.wicket.util.resource.AbstractResourceStreamWriter) CustomDownloadLink(org.devgateway.toolkit.forms.wicket.components.util.CustomDownloadLink) IconBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.image.IconBehavior) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ResourceStreamRequestHandler(org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler) TooltipBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior) ListView(org.apache.wicket.markup.html.list.ListView) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) ArrayList(java.util.ArrayList) List(java.util.List) EditingDisabledEvent(org.devgateway.toolkit.forms.wicket.events.EditingDisabledEvent) StringResourceModel(org.apache.wicket.model.StringResourceModel) EditingEnabledEvent(org.devgateway.toolkit.forms.wicket.events.EditingEnabledEvent) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListItem(org.apache.wicket.markup.html.list.ListItem) CustomDownloadLink(org.devgateway.toolkit.forms.wicket.components.util.CustomDownloadLink) Link(org.apache.wicket.markup.html.link.Link) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink)

Example 54 with ListView

use of org.apache.wicket.markup.html.list.ListView in project oc-explorer by devgateway.

the class FileInputBootstrapFormComponentWrapper method addPendingFilesComponent.

/**
 * pending files section
 */
private void addPendingFilesComponent() {
    pendingFiles = new WebMarkupContainer("pendingFiles") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onConfigure() {
            if (filesModel != null && filesModel.size() > 0) {
                for (FileMetadata file : filesModel) {
                    if (file.isNew()) {
                        setVisibilityAllowed(true);
                        return;
                    }
                }
            }
            setVisibilityAllowed(false);
        }
    };
    pendingFiles.setOutputMarkupPlaceholderTag(true);
    pendingFiles.setOutputMarkupId(true);
    add(pendingFiles);
    pendingFiles.add(new Label("pendingFilesTitle", new StringResourceModel("pendingFilesTitle", this, null)));
    AbstractReadOnlyModel<List<FileMetadata>> pendingFilesModel = new AbstractReadOnlyModel<List<FileMetadata>>() {

        private static final long serialVersionUID = 1L;

        @Override
        public List<FileMetadata> getObject() {
            List<FileMetadata> fileObject = new ArrayList<>();
            // upload)
            for (FileMetadata file : filesModel) {
                if (file.isNew()) {
                    fileObject.add(file);
                }
            }
            return fileObject;
        }
    };
    ListView<FileMetadata> list = new ListView<FileMetadata>("list", pendingFilesModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<FileMetadata> item) {
            item.add(new Label("fileTitle", item.getModelObject().getName()));
            IndicatingAjaxLink<Void> delete = new IndicatingAjaxLink<Void>("delete") {

                private static final long serialVersionUID = 1L;

                @SuppressWarnings("unchecked")
                @Override
                public void onClick(final AjaxRequestTarget target) {
                    filesModel.remove(item.getModelObject());
                    FileInputBootstrapFormComponentWrapper.this.getModel().setObject((T) filesModel);
                    target.add(pendingFiles);
                }
            };
            delete.add(new IconBehavior(GlyphIconType.remove));
            delete.add(new TooltipBehavior(new StringResourceModel("removeUploadedFileTooltip", FileInputBootstrapFormComponentWrapper.this, null), TOOLTIP_CONFIG));
            delete.setVisible(true);
            item.add(delete);
        }
    };
    pendingFiles.add(list);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) FileMetadata(org.devgateway.toolkit.persistence.dao.FileMetadata) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) IconBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.image.IconBehavior) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) TooltipBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior) ListView(org.apache.wicket.markup.html.list.ListView) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Aggregations

ListView (org.apache.wicket.markup.html.list.ListView)54 ListItem (org.apache.wicket.markup.html.list.ListItem)51 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)39 Label (org.apache.wicket.markup.html.basic.Label)39 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)33 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)27 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)25 List (java.util.List)21 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)17 PropertyModel (org.apache.wicket.model.PropertyModel)15 ArrayList (java.util.ArrayList)14 TextField (org.apache.wicket.markup.html.form.TextField)13 Form (org.apache.wicket.markup.html.form.Form)10 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)9 AttributeModifier (org.apache.wicket.AttributeModifier)8 Model (org.apache.wicket.model.Model)8 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)7 IModel (org.apache.wicket.model.IModel)7 StringResourceModel (org.apache.wicket.model.StringResourceModel)6 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)5