Search in sources :

Example 56 with AbstractReadOnlyModel

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

the class SceneItemLinePanel method initLayout.

private void initLayout() {
    WebMarkupContainer nameCell = new WebMarkupContainer(ID_NAME_CONTAINER);
    nameCell.add(new AttributeModifier("rowspan", new PropertyModel<Integer>(getModel(), SceneItemLineDto.F_NUMBER_OF_LINES)));
    Label label = new Label("name", new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            final SceneItemLineDto lineDto = getModel().getObject();
            if (lineDto == null || lineDto.getName() == null) {
                return null;
            }
            String key = lineDto.getName();
            return getLocalizer().getString(key, SceneItemLinePanel.this, key);
        }
    });
    nameCell.add(label);
    nameCell.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModelObject().isFirst();
        }
    });
    add(nameCell);
    WebMarkupContainer oldValueCell = new WebMarkupContainer(ID_OLD_VALUE_CONTAINER);
    oldValueCell.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModelObject().isDelta();
        }
    });
    SceneItemValuePanel sivp = new SceneItemValuePanel(ID_OLD_VALUE, new PropertyModel<SceneItemValue>(getModel(), SceneItemLineDto.F_OLD_VALUE));
    sivp.setRenderBodyOnly(true);
    oldValueCell.add(sivp);
    ImagePanel oldValueImagePanel = new ImagePanel(ID_OLD_VALUE_IMAGE, Model.of(GuiStyleConstants.CLASS_MINUS_CIRCLE_DANGER), createStringResource("SceneItemLinePanel.removedValue"));
    oldValueImagePanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return getModelObject().getOldValue() != null && getModelObject().getOldValue().getSourceValue() != null;
        }
    });
    oldValueCell.add(oldValueImagePanel);
    add(oldValueCell);
    WebMarkupContainer newValueCell = new WebMarkupContainer(ID_NEW_VALUE_CONTAINER);
    sivp = new SceneItemValuePanel(ID_NEW_VALUE, new PropertyModel<SceneItemValue>(getModel(), SceneItemLineDto.F_NEW_VALUE));
    sivp.setRenderBodyOnly(true);
    newValueCell.add(sivp);
    newValueCell.add(new AttributeModifier("colspan", new AbstractReadOnlyModel<Integer>() {

        @Override
        public Integer getObject() {
            return !getModelObject().isDelta() && getModelObject().isDeltaScene() ? 2 : 1;
        }
    }));
    newValueCell.add(new AttributeModifier("align", new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            return !getModelObject().isDelta() && getModelObject().isDeltaScene() ? "center" : null;
        }
    }));
    ImagePanel newValueImagePanel = new ImagePanel(ID_NEW_VALUE_IMAGE, !getModelObject().isDelta() && getModelObject().isDeltaScene() ? Model.of(GuiStyleConstants.CLASS_CIRCLE_FULL) : Model.of(GuiStyleConstants.CLASS_PLUS_CIRCLE_SUCCESS), !getModelObject().isDelta() && getModelObject().isDeltaScene() ? createStringResource("SceneItemLinePanel.unchangedValue") : createStringResource("SceneItemLinePanel.addedValue"));
    newValueImagePanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return getModelObject().getNewValue() != null && getModelObject().getNewValue().getSourceValue() != null;
        }
    });
    newValueImagePanel.add(new AttributeAppender("style", !getModelObject().isDelta() && getModelObject().isDeltaScene() ? "float: left; margin-right: 5px; width: 30%; position: absolute;" : "float: left; margin-right: 5px;"));
    newValueCell.add(newValueImagePanel);
    add(newValueCell);
}
Also used : SceneItemValue(com.evolveum.midpoint.model.api.visualizer.SceneItemValue) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) PropertyModel(org.apache.wicket.model.PropertyModel) Label(org.apache.wicket.markup.html.basic.Label) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) ImagePanel(com.evolveum.midpoint.web.component.data.column.ImagePanel)

Example 57 with AbstractReadOnlyModel

use of org.apache.wicket.model.AbstractReadOnlyModel in project ocvn 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)

Example 58 with AbstractReadOnlyModel

use of org.apache.wicket.model.AbstractReadOnlyModel in project ocvn by devgateway.

the class BootstrapPagingNavigation method populateItem.

@Override
protected void populateItem(final LoopItem loopItem) {
    super.populateItem(loopItem);
    final long pageIndex = getStartIndex() + loopItem.getIndex();
    // Add disabled class to enclosing list item.
    loopItem.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            if (pageable.getCurrentPage() == pageIndex) {
                return "active";
            } else {
                return "";
            }
        }
    }));
// Do not mask disabled link by em tag.
// ((AbstractLink)
// loopItem.get("pageLink")).setBeforeDisabledLink("").setAfterDisabledLink("");
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) AttributeModifier(org.apache.wicket.AttributeModifier)

Example 59 with AbstractReadOnlyModel

use of org.apache.wicket.model.AbstractReadOnlyModel in project ocvn by devgateway.

the class VietnamImportPage method addLogText.

protected void addLogText() {
    importContainer = new TransparentWebMarkupContainer("importContainer");
    importContainer.setOutputMarkupId(true);
    importForm.add(importContainer);
    AbstractReadOnlyModel<String> logTextModel = new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return vnExcelImportService.getMsgBuffer().toString();
        }
    };
    logText = new LogLabel("logText", logTextModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onPostProcessTarget(final AjaxRequestTarget target) {
            if (threadPoolTaskExecutor.getActiveCount() == 0) {
                getSelfUpdatingBehavior().stop(target);
                spinner.setVisibilityAllowed(false);
                target.add(spinner);
            }
        }
    };
    importContainer.add(logText);
    spinner = new WebMarkupContainer("spinner");
    spinner.setOutputMarkupId(true);
    importContainer.add(spinner);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) TransparentWebMarkupContainer(org.apache.wicket.markup.html.TransparentWebMarkupContainer) LogLabel(org.devgateway.ocvn.forms.wicket.components.LogLabel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) TransparentWebMarkupContainer(org.apache.wicket.markup.html.TransparentWebMarkupContainer)

Example 60 with AbstractReadOnlyModel

use of org.apache.wicket.model.AbstractReadOnlyModel in project oc-explorer 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)

Aggregations

AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)105 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)60 Label (org.apache.wicket.markup.html.basic.Label)59 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)54 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)41 ArrayList (java.util.ArrayList)34 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)29 ListItem (org.apache.wicket.markup.html.list.ListItem)29 IModel (org.apache.wicket.model.IModel)26 ListView (org.apache.wicket.markup.html.list.ListView)25 List (java.util.List)23 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)23 AttributeModifier (org.apache.wicket.AttributeModifier)21 PropertyModel (org.apache.wicket.model.PropertyModel)20 Model (org.apache.wicket.model.Model)16 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)13 TextField (org.apache.wicket.markup.html.form.TextField)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 Form (org.apache.wicket.markup.html.form.Form)9 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)8