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

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

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public final List<T> getModelObject() 

Source Link

Document

Gets model object

Usage

From source file:org.syncope.console.pages.panels.UserManagementResultPanel.java

License:Apache License

/**
 * Panel constructor.//from  w w  w  .  jav  a  2  s.  c  om
 *
 * @param id panel id.
 * @param window guest modal window.
 * @param mode operation mode.
 * @param userTO User TO.
 */
public UserManagementResultPanel(final String id, final ModalWindow window, final UserModalPage.Mode mode,
        final UserTO userTO) {

    super(id);

    // shortcut to retrieve fragments inside inner classes
    final Panel panel = this;

    final WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupId(true);
    add(container);

    final Fragment fragment = new Fragment("userModalResultFrag",
            mode == UserModalPage.Mode.SELF ? "userModalSelfResultFrag" : "userModalPropagationResultFrag",
            this);

    fragment.setOutputMarkupId(true);
    container.add(fragment);

    if (mode == UserModalPage.Mode.ADMIN) {

        // add Syncope propagation status
        PropagationTO syncope = new PropagationTO();
        syncope.setResourceName("Syncope");
        syncope.setStatus(PropagationTaskExecStatus.SUCCESS);

        List<PropagationTO> propagations = new ArrayList<PropagationTO>();
        propagations.add(syncope);
        propagations.addAll(userTO.getPropagationTOs());

        fragment.add(new Label("userInfo",
                userTO.getUsername() != null ? userTO.getUsername() : String.valueOf(userTO.getId())));

        final ListView<PropagationTO> propRes = new ListView<PropagationTO>("resources", propagations) {

            private static final long serialVersionUID = -1020475259727720708L;

            @Override
            protected void populateItem(final ListItem item) {
                final PropagationTO propTO = (PropagationTO) item.getDefaultModelObject();

                final ListView attributes = getConnObjectView(propTO);

                final Fragment attrhead;

                if (attributes.getModelObject() != null && !attributes.getModelObject().isEmpty()) {
                    attrhead = new Fragment("attrhead", "attrHeadFrag", panel);
                } else {
                    attrhead = new Fragment("attrhead", "emptyAttrHeadFrag", panel);
                }

                item.add(attrhead);
                item.add(attributes);

                attrhead.add(new Label("resource", propTO.getResourceName()));

                attrhead.add(new Label("propagation",
                        propTO.getStatus() != null ? propTO.getStatus().toString() : "UNDEFINED"));

                final Image image;
                final String alt, title;

                switch (propTO.getStatus()) {
                case SUCCESS:
                case SUBMITTED:
                case CREATED:
                    image = new Image("icon", "statuses/active.png");
                    alt = "success icon";
                    title = "success";
                    break;
                default:
                    image = new Image("icon", "statuses/inactive.png");
                    alt = "failure icon";
                    title = "failure";
                }

                image.add(new Behavior() {

                    private static final long serialVersionUID = 1469628524240283489L;

                    @Override
                    public void onComponentTag(final Component component, final ComponentTag tag) {
                        tag.put("alt", alt);
                        tag.put("title", title);
                    }
                });

                attrhead.add(image);
            }
        };
        fragment.add(propRes);
    }

    final AjaxLink close = new IndicatingAjaxLink("close") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            window.close(target);
        }
    };
    container.add(close);
}

From source file:ro.nextreports.server.web.dashboard.DashboardNavigationPanel.java

License:Apache License

public DashboardNavigationPanel(String id) {
    super(id);//from   w ww.ja va  2  s.c o m

    setOutputMarkupPlaceholderTag(true);

    addToolbar();

    WebMarkupContainer container = new WebMarkupContainer("navigation");
    ListView<Object> listView = new ListView<Object>("dashboardList", new DashboardsAndLinksModel()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<Object> item) {
            Tab tab = new Tab("dashboard", item.getModel(), item.getIndex());
            item.add(tab);

            //                item.add(new WiQueryEventBehavior(new Event(MouseEvent.MOUSEOVER) {
            //
            //                    private static final long serialVersionUID = 1L;
            //
            //                    @Override
            //                    public JsScope callback() {
            //                        return JsScope.quickScope("$(this).find('.actions-col').show()");
            //                    }
            //
            //                }));
            //                item.add(new WiQueryEventBehavior(new Event(MouseEvent.MOUSEOUT) {
            //
            //                    private static final long serialVersionUID = 1L;
            //
            //                    @Override
            //                    public JsScope callback() {
            //                        return JsScope.quickScope("$(this).find('.actions-col').hide()");
            //                    }
            //
            //                }));

            item.add(new DashboardActionPanel("actions", item.getModel()));

            // TODO getId, setId -> Identifiable
            Object object = item.getModelObject();
            String dashboardId = getDashboardId(object);
            if (getSelectedDashboardId().equals(dashboardId)) {
                item.add(AttributeModifier.append("class", "selected"));
            }
            item.setOutputMarkupId(true);
        }

    };
    listView.setOutputMarkupId(true);

    container.add(listView);
    add(container);

    // we select default dashboard only at first login, then we may select other dashboard
    // and we want that dashboard to remain selected when we move between UI tabs
    SectionContext sectionContext = NextServerSession.get().getSectionContext(DashboardSection.ID);
    boolean found = false;
    if (sectionContext.getData().get(SectionContextConstants.SELECTED_DASHBOARD_ID) == null) {

        String dashboardId = "";
        try {
            dashboardId = dashboardService.getDefaultDashboardId();
        } catch (Exception ex) {
            // at first startup (no data folder) and getDefaultDashboardId() is called before 'My' dashboard is created
            // see getMyDashboards() from default dashboard service
            LOG.error("Get default dashboard : " + ex.getMessage(), ex);
        }
        if (!"".equals(dashboardId)) {
            for (Object obj : listView.getModelObject()) {
                if (obj instanceof Dashboard) {
                    if (dashboardId.equals(((Dashboard) obj).getId())) {
                        found = true;
                    }
                } else {
                    if (dashboardId.equals(((Link) obj).getReference())) {
                        found = true;
                    }
                }
                if (found) {
                    sectionContext.getData().put(SectionContextConstants.SELECTED_DASHBOARD_ID, dashboardId);
                    break;
                }
            }
            if (!found) {
                sectionContext.getData().put(SectionContextConstants.SELECTED_DASHBOARD_ID,
                        dashboardService.getMyDashboards().get(0).getId());
            }
        }

    }
}