Search in sources :

Example 1 with OrgStructurePanelStorage

use of com.evolveum.midpoint.web.session.OrgStructurePanelStorage in project midpoint by Evolveum.

the class AbstractOrgTabPanel method initLayout.

private void initLayout() {
    final IModel<List<ITab>> tabModel = new LoadableModel<>(true) {

        private static final long serialVersionUID = 1L;

        @Override
        protected List<ITab> load() {
            LOGGER.debug("Loading org. roots for tabs for tabbed panel.");
            roots = loadOrgRoots();
            final List<ITab> tabs = new ArrayList<>();
            for (PrismObject<OrgType> root : roots) {
                final String oid = root.getOid();
                tabs.add(new AbstractTab(createTabTitle(root)) {

                    private static final long serialVersionUID = 1L;

                    private final int tabId = tabs.size();

                    @Override
                    public WebMarkupContainer getPanel(String panelId) {
                        add(new AjaxEventBehavior("load") {

                            private static final long serialVersionUID = 1L;

                            protected void onEvent(final AjaxRequestTarget target) {
                                OrgStructurePanelStorage usersStorage = getOrgStructurePanelStorage();
                                if (usersStorage != null) {
                                    usersStorage.setSelectedTabId(tabId);
                                }
                            }
                        });
                        Panel panel = createTreePanel(panelId, new Model<>(oid), getPageBase());
                        panel.setOutputMarkupId(true);
                        return panel;
                    }
                });
            }
            LOGGER.debug("Tab count is {}", tabs.size());
            return tabs;
        }
    };
    List<ITab> tabsList = tabModel.getObject();
    OrgStructurePanelStorage orgStructurePanelStorage = getOrgStructurePanelStorage();
    int selectedTab = 0;
    if (orgStructurePanelStorage != null) {
        selectedTab = orgStructurePanelStorage.getSelectedTabId() == -1 ? 0 : orgStructurePanelStorage.getSelectedTabId();
        if (tabsList == null || (selectedTab > tabsList.size() - 1)) {
            orgStructurePanelStorage.setSelectedTabId(0);
        }
    }
    AjaxTabbedPanel<ITab> tabbedPanel = new AjaxTabbedPanel<>(ID_TABS, tabModel.getObject(), new Model<>(selectedTab), null) {

        private static final long serialVersionUID = 1L;

        @Override
        public TabbedPanel<ITab> setSelectedTab(int index) {
            changeTabPerformed(index);
            return super.setSelectedTab(index);
        }
    };
    tabbedPanel.setOutputMarkupId(true);
    if (tabsList == null || tabsList.size() == 0) {
        tabbedPanel.setVisible(false);
    }
    add(tabbedPanel);
}
Also used : AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) ArrayList(java.util.ArrayList) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ITab(org.apache.wicket.extensions.markup.html.tabs.ITab) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxTabbedPanel(com.evolveum.midpoint.web.component.AjaxTabbedPanel) Panel(org.apache.wicket.markup.html.panel.Panel) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) TabbedPanel(com.evolveum.midpoint.web.component.TabbedPanel) AjaxTabbedPanel(com.evolveum.midpoint.web.component.AjaxTabbedPanel) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) AbstractTab(org.apache.wicket.extensions.markup.html.tabs.AbstractTab) OrgStructurePanelStorage(com.evolveum.midpoint.web.session.OrgStructurePanelStorage) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with OrgStructurePanelStorage

use of com.evolveum.midpoint.web.session.OrgStructurePanelStorage in project midpoint by Evolveum.

the class OrgTreeAssignablePanel method initLayout.

private void initLayout() {
    if (getPreselectedOrgsList() != null) {
        allTabsSelectedOrgs.addAll(getPreselectedOrgsList());
    }
    AbstractOrgTabPanel tabbedPanel = new AbstractOrgTabPanel(ID_ORG_TABS, getPageBase()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Panel createTreePanel(String id, Model<String> model, PageBase pageBase) {
            OrgTreePanel panel = new OrgTreePanel(id, model, selectable, pageBase, "", allTabsSelectedOrgs) {

                private static final long serialVersionUID = 1L;

                private final OrgStructurePanelStorage storage = new OrgStructurePanelStorage();

                @Override
                protected IModel<Boolean> getCheckBoxValueModel(IModel<TreeSelectableBean<OrgType>> rowModel) {
                    return new LoadableModel<>(true) {

                        @Override
                        public Boolean load() {
                            for (OrgType org : allTabsSelectedOrgs) {
                                if (rowModel.getObject().getValue().getOid().equals(org.getOid())) {
                                    return true;
                                }
                            }
                            return false;
                        }
                    };
                }

                @Override
                protected void onOrgTreeCheckBoxSelectionPerformed(AjaxRequestTarget target, IModel<TreeSelectableBean<OrgType>> rowModel) {
                    if (rowModel != null && rowModel.getObject() != null) {
                        boolean isAlreadyInList = false;
                        Iterator<OrgType> it = allTabsSelectedOrgs.iterator();
                        while (it.hasNext()) {
                            OrgType org = it.next();
                            if (org.getOid().equals(rowModel.getObject().getValue().getOid())) {
                                isAlreadyInList = true;
                                it.remove();
                            }
                        }
                        if (!isAlreadyInList) {
                            allTabsSelectedOrgs.add(rowModel.getObject().getValue());
                        }
                    }
                    OrgTreeAssignablePanel.this.onOrgTreeCheckBoxSelectionPerformed(target, rowModel);
                }

                @Override
                protected void selectTreeItemPerformed(TreeSelectableBean<OrgType> selected, AjaxRequestTarget target) {
                    onItemSelect(selected, target);
                }

                @Override
                public OrgTreeStateStorage getOrgTreeStateStorage() {
                    return storage;
                }

                @Override
                protected ObjectFilter getCustomFilter() {
                    return OrgTreeAssignablePanel.this.getCustomFilter();
                }
            };
            panel.setOutputMarkupId(true);
            panel.setOutputMarkupPlaceholderTag(true);
            return panel;
        }

        @Override
        protected boolean isWarnMessageVisible() {
            return false;
        }

        @Override
        protected ObjectFilter getAssignableItemsFilter() {
            return OrgTreeAssignablePanel.this.getCustomFilter();
        }

        @Override
        protected OrgStructurePanelStorage getOrgStructurePanelStorage() {
            return null;
        }
    };
    tabbedPanel.setOutputMarkupId(true);
    tabbedPanel.setOutputMarkupPlaceholderTag(true);
    add(tabbedPanel);
    AjaxButton assignButton = new AjaxButton(ID_ASSIGN, getPageBase().createStringResource("userBrowserDialog.button.addButton")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            assignSelectedOrgPerformed(getAllTabPanelsSelectedOrgs(), target);
        }
    };
    assignButton.setOutputMarkupId(true);
    assignButton.setOutputMarkupPlaceholderTag(true);
    assignButton.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isAssignButtonVisible();
        }
    });
    add(assignButton);
}
Also used : IModel(org.apache.wicket.model.IModel) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) StringResourceModel(org.apache.wicket.model.StringResourceModel) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) OrgStructurePanelStorage(com.evolveum.midpoint.web.session.OrgStructurePanelStorage) TreeSelectableBean(com.evolveum.midpoint.web.component.util.TreeSelectableBean) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Aggregations

LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)2 OrgStructurePanelStorage (com.evolveum.midpoint.web.session.OrgStructurePanelStorage)2 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 IModel (org.apache.wicket.model.IModel)2 Model (org.apache.wicket.model.Model)2 BasePanel (com.evolveum.midpoint.gui.api.component.BasePanel)1 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 AjaxTabbedPanel (com.evolveum.midpoint.web.component.AjaxTabbedPanel)1 TabbedPanel (com.evolveum.midpoint.web.component.TabbedPanel)1 TreeSelectableBean (com.evolveum.midpoint.web.component.util.TreeSelectableBean)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AjaxEventBehavior (org.apache.wicket.ajax.AjaxEventBehavior)1 AbstractTab (org.apache.wicket.extensions.markup.html.tabs.AbstractTab)1 ITab (org.apache.wicket.extensions.markup.html.tabs.ITab)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1