Search in sources :

Example 6 with AbstractReadOnlyModel

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

the class BoxedTablePanel method initLayout.

private void initLayout(List<IColumn<T, String>> columns, ISortableDataProvider provider, int pageSize) {
    setOutputMarkupId(true);
    WebMarkupContainer box = new WebMarkupContainer(ID_BOX);
    box.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            String boxCssClasses = getAdditionalBoxCssClasses();
            if (boxCssClasses == null) {
                return "";
            } else {
                return " " + boxCssClasses;
            }
        }
    }));
    add(box);
    WebMarkupContainer tableContainer = new WebMarkupContainer(ID_TABLE_CONTAINER);
    tableContainer.setOutputMarkupId(true);
    DataTable<T, String> table = new SelectableDataTable<T>(ID_TABLE, columns, provider, pageSize) {

        @Override
        protected Item<T> newRowItem(String id, int index, IModel<T> rowModel) {
            Item<T> item = super.newRowItem(id, index, rowModel);
            return customizeNewRowItem(item, rowModel);
        }
    };
    table.setOutputMarkupId(true);
    tableContainer.add(table);
    box.add(tableContainer);
    TableHeadersToolbar headersTop = new TableHeadersToolbar(table, provider);
    headersTop.setOutputMarkupId(true);
    table.addTopToolbar(headersTop);
    box.add(createHeader(ID_HEADER));
    box.add(createFooter(ID_FOOTER));
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) IModel(org.apache.wicket.model.IModel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 7 with AbstractReadOnlyModel

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

the class SystemInfoPanel method createUptimeModel.

private IModel<String> createUptimeModel() {
    return new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            SystemInfoDto dto = getModelObject();
            PrettyTime time = new PrettyTime();
            return time.format(new Date(System.currentTimeMillis() - dto.uptime));
        }
    };
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) PrettyTime(org.ocpsoft.prettytime.PrettyTime) Date(java.util.Date)

Example 8 with AbstractReadOnlyModel

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

the class OrgTreePanel method initLayout.

private void initLayout() {
    WebMarkupContainer treeHeader = new WebMarkupContainer(ID_TREE_HEADER);
    treeHeader.setOutputMarkupId(true);
    add(treeHeader);
    String title = StringUtils.isEmpty(treeTitleKey) ? "TreeTablePanel.hierarchy" : treeTitleKey;
    Label treeTitle = new Label(ID_TREE_TITLE, createStringResource(title));
    treeHeader.add(treeTitle);
    InlineMenu treeMenu = new InlineMenu(ID_TREE_MENU, new Model<>((Serializable) createTreeMenuInternal()));
    treeHeader.add(treeMenu);
    ISortableTreeProvider provider = new OrgTreeProvider(this, getModel()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected List<InlineMenuItem> createInlineMenuItems(OrgType org) {
            return createTreeChildrenMenu(org);
        }
    };
    List<IColumn<SelectableBean<OrgType>, String>> columns = new ArrayList<>();
    if (selectable) {
        columns.add(new CheckBoxHeaderColumn<SelectableBean<OrgType>>());
    }
    columns.add(new TreeColumn<SelectableBean<OrgType>, String>(createStringResource("TreeTablePanel.hierarchy")));
    columns.add(new InlineMenuHeaderColumn(createTreeChildrenMenu(null)));
    WebMarkupContainer treeContainer = new WebMarkupContainer(ID_TREE_CONTAINER) {

        private static final long serialVersionUID = 1L;

        @Override
        public void renderHead(IHeaderResponse response) {
            super.renderHead(response);
            // method computes height based on document.innerHeight() -
            // screen height;
            Component form = OrgTreePanel.this.getParent().get("memberPanel");
            if (form != null) {
                response.render(OnDomReadyHeaderItem.forScript("updateHeight('" + getMarkupId() + "', ['#" + form.getMarkupId() + "'], ['#" + OrgTreePanel.this.get(ID_TREE_HEADER).getMarkupId() + "'])"));
            }
        }
    };
    add(treeContainer);
    TreeStateModel treeStateMode = new TreeStateModel(this, provider) {

        private static final long serialVersionUID = 1L;

        @Override
        public Set<SelectableBean<OrgType>> getExpandedItems() {
            return OrgTreePanel.this.getExpandedItems(getOrgTreeStateStorage());
        }

        @Override
        public SelectableBean<OrgType> getCollapsedItem() {
            return OrgTreePanel.this.getCollapsedItem(getOrgTreeStateStorage());
        }

        @Override
        public void setCollapsedItem(SelectableBean<OrgType> item) {
            OrgTreePanel.this.setCollapsedItem(null, getOrgTreeStateStorage());
        }
    };
    TableTree<SelectableBean<OrgType>, String> tree = new TableTree<SelectableBean<OrgType>, String>(ID_TREE, columns, provider, Integer.MAX_VALUE, treeStateMode) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Component newContentComponent(String id, IModel<SelectableBean<OrgType>> model) {
            return new SelectableFolderContent(id, this, model, selected) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onClick(AjaxRequestTarget target) {
                    super.onClick(target);
                    OrgTreePanel.this.setSelectedItem(selected.getObject(), getOrgTreeStateStorage());
                    selectTreeItemPerformed(selected.getObject(), target);
                }
            };
        }

        @Override
        protected Item<SelectableBean<OrgType>> newRowItem(String id, int index, final IModel<SelectableBean<OrgType>> model) {
            Item<SelectableBean<OrgType>> item = super.newRowItem(id, index, model);
            item.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() {

                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    SelectableBean<OrgType> itemObject = model.getObject();
                    if (itemObject != null && itemObject.equals(selected.getObject())) {
                        return "success";
                    }
                    return null;
                }
            }));
            return item;
        }

        @Override
        public void collapse(SelectableBean<OrgType> collapsedItem) {
            super.collapse(collapsedItem);
            Set<SelectableBean<OrgType>> items = OrgTreePanel.this.getExpandedItems(getOrgTreeStateStorage());
            if (items != null && items.contains(collapsedItem)) {
                items.remove(collapsedItem);
            }
            OrgTreePanel.this.setExpandedItems((TreeStateSet) items, getOrgTreeStateStorage());
            OrgTreePanel.this.setCollapsedItem(collapsedItem, getOrgTreeStateStorage());
        }

        @Override
        protected void onModelChanged() {
            super.onModelChanged();
            TreeStateSet<SelectableBean<OrgType>> items = (TreeStateSet) getModelObject();
            if (!items.isInverse()) {
                OrgTreePanel.this.setExpandedItems(items, getOrgTreeStateStorage());
            }
        }
    };
    tree.setItemReuseStrategy(new ReuseIfModelsEqualStrategy());
    tree.getTable().add(AttributeModifier.replace("class", "table table-striped table-condensed"));
    tree.add(new WindowsTheme());
    // tree.add(AttributeModifier.replace("class", "tree-midpoint"));
    treeContainer.add(tree);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Serializable(java.io.Serializable) InlineMenuHeaderColumn(com.evolveum.midpoint.web.component.data.column.InlineMenuHeaderColumn) TableTree(org.apache.wicket.extensions.markup.html.repeater.tree.TableTree) Label(org.apache.wicket.markup.html.basic.Label) WindowsTheme(org.apache.wicket.extensions.markup.html.repeater.tree.theme.WindowsTheme) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ReuseIfModelsEqualStrategy(org.apache.wicket.markup.repeater.ReuseIfModelsEqualStrategy) InlineMenu(com.evolveum.midpoint.web.component.menu.cog.InlineMenu) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) OrgTreeProvider(com.evolveum.midpoint.web.page.admin.users.component.OrgTreeProvider) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) Component(org.apache.wicket.Component) IModel(org.apache.wicket.model.IModel) SelectableFolderContent(com.evolveum.midpoint.web.page.admin.users.component.SelectableFolderContent) TreeStateSet(com.evolveum.midpoint.web.page.admin.users.dto.TreeStateSet) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) ISortableTreeProvider(org.apache.wicket.extensions.markup.html.repeater.tree.ISortableTreeProvider) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)

Example 9 with AbstractReadOnlyModel

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

the class RunReportPopupPanel method createUserAttributeListModel.

private IModel<List<String>> createUserAttributeListModel(Class type) {
    final List<String> attrList = new ArrayList();
    PrismObjectDefinition<UserType> userDefinition = getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
    List<? extends ItemDefinition> itemDefs = userDefinition.getDefinitions();
    for (ItemDefinition id : itemDefs) {
        if (id instanceof PrismPropertyDefinition && ((((PrismPropertyDefinition) id).isIndexed() == null) || (((PrismPropertyDefinition) id).isIndexed() == true))) {
            if (id.getTypeClass() != null && id.getTypeClass().equals(type)) {
                attrList.add(id.getName().getLocalPart());
            }
        }
    }
    return new AbstractReadOnlyModel<List<String>>() {

        @Override
        public List<String> getObject() {
            return attrList;
        }
    };
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ArrayList(java.util.ArrayList) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 10 with AbstractReadOnlyModel

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

the class PageCreatedReports method initColumns.

//TODO - consider adding Author name, File Type and ReportType to columns
private List<IColumn<SelectableBean<ReportOutputType>, String>> initColumns(final AjaxDownloadBehaviorFromStream ajaxDownloadBehavior) {
    List<IColumn<SelectableBean<ReportOutputType>, String>> columns = new ArrayList<>();
    IColumn column;
    column = new CheckBoxHeaderColumn();
    columns.add(column);
    column = new PropertyColumn(createStringResource("pageCreatedReports.table.name"), "name", "value.name");
    columns.add(column);
    column = new PropertyColumn(createStringResource("pageCreatedReports.table.description"), "value.description");
    columns.add(column);
    column = new AbstractColumn<SelectableBean<ReportOutputType>, String>(createStringResource("pageCreatedReports.table.time"), "createTimestamp") {

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<ReportOutputType>>> cellItem, String componentId, final IModel<SelectableBean<ReportOutputType>> rowModel) {
            cellItem.add(new DateLabelComponent(componentId, new AbstractReadOnlyModel<Date>() {

                @Override
                public Date getObject() {
                    ReportOutputType object = rowModel.getObject().getValue();
                    MetadataType metadata = object != null ? object.getMetadata() : null;
                    if (metadata == null) {
                        return null;
                    }
                    return XmlTypeConverter.toDate(metadata.getCreateTimestamp());
                }
            }, DateLabelComponent.LONG_MEDIUM_STYLE));
        }
    };
    columns.add(column);
    column = new AbstractColumn<SelectableBean<ReportOutputType>, String>(new Model(), null) {

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<ReportOutputType>>> cellItem, String componentId, final IModel<SelectableBean<ReportOutputType>> model) {
            DownloadButtonPanel panel = new DownloadButtonPanel(componentId) {

                @Override
                protected void deletePerformed(AjaxRequestTarget target) {
                    deleteSelectedPerformed(target, ReportDeleteDialogDto.Operation.DELETE_SINGLE, model.getObject().getValue());
                }

                @Override
                protected void downloadPerformed(AjaxRequestTarget target) {
                    currentReport = model.getObject().getValue();
                    PageCreatedReports.this.downloadPerformed(target, model.getObject().getValue(), ajaxDownloadBehavior);
                }
            };
            cellItem.add(panel);
        }
    };
    columns.add(column);
    column = new InlineMenuHeaderColumn<InlineMenuable>(initInlineMenu()) {

        @Override
        public void populateItem(Item<ICellPopulator<InlineMenuable>> cellItem, String componentId, IModel<InlineMenuable> rowModel) {
            cellItem.add(new Label(componentId));
        }
    };
    columns.add(column);
    return columns;
}
Also used : PropertyColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn) Label(org.apache.wicket.markup.html.basic.Label) ReportOutputType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportOutputType) CheckBoxHeaderColumn(com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) MetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType) DateLabelComponent(com.evolveum.midpoint.web.component.DateLabelComponent) InlineMenuable(com.evolveum.midpoint.web.component.data.column.InlineMenuable) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DownloadButtonPanel(com.evolveum.midpoint.web.page.admin.reports.component.DownloadButtonPanel) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) IModel(org.apache.wicket.model.IModel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Model(org.apache.wicket.model.Model) PropertyModel(org.apache.wicket.model.PropertyModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel)

Aggregations

AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)52 ArrayList (java.util.ArrayList)22 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)22 Label (org.apache.wicket.markup.html.basic.Label)21 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)20 List (java.util.List)16 ListItem (org.apache.wicket.markup.html.list.ListItem)12 ListView (org.apache.wicket.markup.html.list.ListView)12 IModel (org.apache.wicket.model.IModel)12 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)10 PropertyModel (org.apache.wicket.model.PropertyModel)8 AttributeModifier (org.apache.wicket.AttributeModifier)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 Model (org.apache.wicket.model.Model)6 Task (com.evolveum.midpoint.task.api.Task)5 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)5 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 TooltipBehavior (de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior)4