Example usage for org.apache.wicket.markup.repeater.data GridView setColumns

List of usage examples for org.apache.wicket.markup.repeater.data GridView setColumns

Introduction

In this page you can find the example usage for org.apache.wicket.markup.repeater.data GridView setColumns.

Prototype

public GridView<T> setColumns(int cols) 

Source Link

Document

Sets number of columns

Usage

From source file:com.evolveum.midpoint.web.component.assignment.GridViewComponent.java

License:Apache License

private void initLayout() {
    GridView gridView = new GridView(ID_ROWS, getModelObject()) {
        private static final long serialVersionUID = 1L;

        @Override//ww w.j a v  a2s.  co m
        protected void populateEmptyItem(Item item) {
            GridViewComponent.this.populateEmptyItem(item);
        }

        @Override
        protected void populateItem(Item item) {
            GridViewComponent.this.populateItem(item);
            item.add(AttributeAppender.append("class", getGridItemStyleClass(item.getModel())));
        }

    };
    gridView.add(new VisibleEnableBehaviour() {
        public boolean isVisible() {
            BaseSortableDataProvider p = (BaseSortableDataProvider) GridViewComponent.this.getModelObject();
            List<AssignmentEditorDto> l = p.getAvailableData();

            if (l != null) {
            }
            return true;
        }
    });
    gridView.setRows(getRowsCount());
    gridView.setColumns(getColsCount());
    gridView.setOutputMarkupId(true);
    gridView.setItemsPerPage(getColsCount() * getRowsCount());
    add(gridView);

    add(createFooter());
}

From source file:com.locke.library.web.wow.layout.layouts.ColumnLayout.java

License:Apache License

/**
 * Construct.//www . ja v  a2  s . co m
 * 
 * @param id
 *            Component id
 * @param panels
 *            Source of panels
 * @param columnCount
 *            Number of columns in the grid
 */
public ColumnLayout(final String id, final IPanelSource panels, final int columnCount) {
    super(id, panels);

    if (columnCount < 1) {
        throw new IllegalArgumentException("Invalid column count: " + columnCount);
    }

    final GridView<Panel> grid = new GridView<Panel>("rows", getProvider()) {

        private static final long serialVersionUID = -5420713157033336965L;

        @Override
        protected void populateEmptyItem(Item<Panel> item) {
            item.add(new EmptyPanel(CHILD_ID));
        }

        @Override
        protected void populateItem(Item<Panel> item) {
            item.add(item.getModelObject());
        }
    };
    grid.setRows(Integer.MAX_VALUE);
    grid.setColumns(columnCount);
    add(grid);
}

From source file:de.inren.frontend.storehouse.FolderContentPanel.java

License:Apache License

@Override
protected void onInitialize() {
    super.onInitialize();
    GridView<AuthorizedDomainObject> gridView = new GridView<AuthorizedDomainObject>("gridView",
            createDataProvider()) {// w  w  w. ja  va 2  s .  c  o  m

        @Override
        protected void populateEmptyItem(Item<AuthorizedDomainObject> item) {
            item.add(new Label("id", ""));
        }

        @Override
        protected void populateItem(Item<AuthorizedDomainObject> item) {
            AuthorizedDomainObject object = item.getModel().getObject();
            if (object instanceof Picture) {
                item.add(createPreviewThumbnail("id", (Picture) object));

            } else {
                if (object instanceof Folder) {
                    final String title = object.getClass().getSimpleName() + "\n" + ((Folder) object).getName();
                    item.add(new TextImagePicturePanel("id", new TextImageResource(100, 100, title)));

                } else {
                    final String title = object.getClass().getSimpleName() + "\n" + object.getId();
                    item.add(new TextImagePicturePanel("id", new TextImageResource(100, 100, title)));
                }
            }
        }
    };
    gridView.setColumns(5);
    add(gridView);
}

From source file:org.dcm4chee.web.war.tc.TCDetailsImagesTab.java

License:LGPL

public TCDetailsImagesTab(final String id, TCAttributeVisibilityStrategy attrVisibilityStrategy) {
    super(id, attrVisibilityStrategy);

    WadoImage.setDefaultWadoBaseUrl(WADODelegate.getInstance().getWadoBaseUrl());

    final IModel<Integer> width = new Model<Integer>(64);
    final int cols = 5;
    final int rows = 5;

    final ReferencedImageProvider imageProvider = new ReferencedImageProvider();
    GridView<TCReferencedImage> view = new GridView<TCReferencedImage>("details-image-row", imageProvider) {

        private static final long serialVersionUID = 1L;

        @Override/*from  ww  w . ja  v a2s  . c o  m*/
        protected void populateItem(final Item<TCReferencedImage> item) {
            TCReferencedInstance ref = item.getModelObject();

            if (WADODelegate.getInstance().getRenderType(ref.getClassUID()) == WADODelegate.IMAGE) {
                item.add(new WadoImage("image", ref.getInstanceUID(), ref.getSeriesUID(), ref.getStudyUID(),
                        width)).setOutputMarkupId(true);
            } else {
                item.add(new Image("image", ImageManager.IMAGE_TC_IMAGE_PLACEHOLDER).setOutputMarkupId(true));
            }
        }

        @Override
        protected void populateEmptyItem(final Item<TCReferencedImage> item) {
            item.add(new Image("image", ImageManager.IMAGE_TC_IMAGE_PLACEHOLDER).setOutputMarkupId(true));
        }
    };

    view.setColumns(cols);
    view.setRows(rows);

    navWmc = new WebMarkupContainer("details-images-nav-container") {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            int nImages = imageProvider.size();
            return nImages > cols * rows;
        }
    };
    navWmc.add(new PagingNavigator("details-images-nav", view));
    navWmc.setOutputMarkupPlaceholderTag(true);
    navWmc.setOutputMarkupId(true);
    navWmc.setMarkupId("details-images-nav-container");

    add(navWmc);
    add(view);
}

From source file:org.devproof.portal.core.module.right.panel.RightGridPanel.java

License:Apache License

private GridView<Right> createRightGridView() {
    ListDataProvider<Right> ldp = new ListDataProvider<Right>(allRights);
    GridView<Right> gridView = newRightGridView(ldp);
    gridView.setColumns(3);
    gridView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
    return gridView;
}

From source file:org.sakaiproject.myconnections.ui.components.ConnectionsGrid.java

License:Educational Community License

@Override
public void onInitialize() {
    super.onInitialize();

    @SuppressWarnings("unchecked")
    final List<WidgetPage.GridPerson> connections = (List<WidgetPage.GridPerson>) getDefaultModelObject();

    final int nUsers = connections.size();
    int rows = (nUsers + cols - 1) / cols; /* round up number of rows */

    final ListDataProvider<WidgetPage.GridPerson> dataProvider = new ListDataProvider<WidgetPage.GridPerson>(
            connections);/*from  ww  w  .j  a  va  2s . c  o m*/

    final GridView<WidgetPage.GridPerson> gridView = new GridView<WidgetPage.GridPerson>("rows", dataProvider) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<WidgetPage.GridPerson> item) {
            final WidgetPage.GridPerson connection = item.getModelObject();
            final String connection_uuid = connection.uuid;
            final ProfileThumbnail img = new ProfileThumbnail("img", Model.of(connection_uuid));

            final String url = "javascript:;";

            img.add(new AttributeModifier("href", url));
            img.add(new AttributeModifier("target", "_top"));
            img.add(new AttributeModifier("data-user-id", connection_uuid));
            item.add(img);

            //name link
            ExternalLink l = new ExternalLink("name", url, connection.displayName);
            l.add(new AttributeModifier("data-user-id", connection_uuid));
            item.add(l);

            //role
            if (connection.role == "request") {
                ResourceModel rm = new ResourceModel("heading.request");
                item.add(new Label("role", rm.getObject()));
            } else {
                item.add(new EmptyPanel("role"));
            }

            String t = "online-status";
            if (connection.onlineStatus == ProfileConstants.ONLINE_STATUS_ONLINE) {
                t += " online";
            } else if (connection.onlineStatus == ProfileConstants.ONLINE_STATUS_AWAY) {
                t += " away";
            } else {
                t += " offline";
            }

            Label lbl = new Label("online_status", "");
            lbl.add(new AttributeModifier("class", t));

            item.add(lbl);
        }

        @Override
        protected void populateEmptyItem(final Item<WidgetPage.GridPerson> item) {
            item.add(new EmptyPanel("img"));
            item.add(new EmptyPanel("name"));
            item.add(new EmptyPanel("role"));
            item.setVisible(false);
        }
    };

    /* handle case where nUsers=0 */
    if (rows <= 0) {
        rows = 1;
    }
    gridView.setRows(rows);
    gridView.setColumns(cols);

    add(gridView);
}

From source file:org.sakaiproject.profile2.tool.pages.panels.FriendsFeed.java

License:Educational Community License

public FriendsFeed(String id, final String ownerUserId, final String viewingUserId) {
    super(id);/*from w w w. j  a  v a  2 s . c  o  m*/

    log.debug("FriendsFeed()");

    //heading   
    Label heading = new Label("heading");

    if (viewingUserId.equals(ownerUserId)) {
        heading.setDefaultModel(new ResourceModel("heading.widget.my.friends"));
    } else {
        String displayName = sakaiProxy.getUserDisplayName(ownerUserId);
        heading.setDefaultModel(
                new StringResourceModel("heading.widget.view.friends", null, new Object[] { displayName }));
    }
    add(heading);

    //get our list of friends as an IDataProvider
    //the FriendDataProvider takes care of the privacy associated with the associated list
    //so what it returns will always be clean
    FriendsFeedDataProvider provider = new FriendsFeedDataProvider(ownerUserId);

    GridView<Person> dataView = new GridView<Person>("rows", provider) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateEmptyItem(Item<Person> item) {
            Link friendItem = new Link("friendsFeedItem") {
                private static final long serialVersionUID = 1L;

                public void onClick() {
                }
            };

            ProfileImage friendPhoto = new ProfileImage("friendPhoto", new Model<String>(null));
            friendPhoto.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
            friendItem.add(friendPhoto);

            friendItem.add(new Label("friendName", "empty"));
            item.add(friendItem);
            friendItem.setVisible(false);
        }

        protected void populateItem(Item<Person> item) {
            final Person person = (Person) item.getDefaultModelObject();
            final String friendId = person.getUuid();

            //setup info
            String displayName = person.getDisplayName();
            boolean friend;

            //get friend status
            if (ownerUserId.equals(viewingUserId)) {
                friend = true; //viewing own list of friends so must be a friend
            } else {
                friend = connectionsLogic.isUserXFriendOfUserY(viewingUserId, friendId); //other person viewing, check if they are friends
            }

            //link to their profile
            Link<String> friendItem = new Link<String>("friendsFeedItem") {
                private static final long serialVersionUID = 1L;

                public void onClick() {
                    //link to own profile if link will point to self
                    if (viewingUserId.equals(friendId)) {
                        setResponsePage(new MyProfile());
                    } else {
                        setResponsePage(new ViewProfile(friendId));
                    }

                }
            };

            /* IMAGE */
            ProfileImage friendPhoto = new ProfileImage("friendPhoto", new Model<String>(friendId));
            friendPhoto.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
            friendItem.add(friendPhoto);

            //name (will be linked also)
            Label friendLinkLabel = new Label("friendName", displayName);
            friendItem.add(friendLinkLabel);

            item.add(friendItem);

        }
    };

    dataView.setColumns(3);
    add(dataView);

    /* NUM FRIENDS LABEL (can't just use provider as it only ever returns the number in the grid */
    final int numFriends = connectionsLogic.getConnectionsForUserCount(ownerUserId);
    Label numFriendsLabel = new Label("numFriendsLabel");
    add(numFriendsLabel);

    /* VIEW ALL FRIENDS LINK */
    Link<String> viewFriendsLink = new Link<String>("viewFriendsLink") {
        private static final long serialVersionUID = 1L;

        public void onClick() {
            //this could come from a bookmarkablelink, but this works for now
            if (numFriends == 0) {
                setResponsePage(new MySearch());
            } else {
                //if own FriendsFeed, link to own MyFriends, otherwise link to ViewFriends
                if (sakaiProxy.isSuperUserAndProxiedToUser(ownerUserId)) {
                    setResponsePage(new ViewFriends(ownerUserId));
                } else if (viewingUserId.equals(ownerUserId)) {
                    setResponsePage(new MyFriends());
                } else {
                    setResponsePage(new ViewFriends(ownerUserId));
                }
            }
        }
    };
    Label viewFriendsLabel = new Label("viewFriendsLabel");
    viewFriendsLink.add(viewFriendsLabel);
    add(viewFriendsLink);

    /* TESTS FOR THE ABOVE to change labels and links */
    if (numFriends == 0) {
        numFriendsLabel.setDefaultModel(new ResourceModel("text.friend.feed.num.none"));
        //numFriendsLabel.setVisible(false);
        //if own FriendsFeed, show search link, otherwise hide
        if (viewingUserId.equals(ownerUserId)) {
            if (sakaiProxy.isSearchEnabledGlobally()) {
                viewFriendsLabel.setDefaultModel(new ResourceModel("link.friend.feed.search"));
            }
        } else {
            viewFriendsLink.setVisible(false);
        }
    } else if (numFriends == 1) {
        numFriendsLabel.setDefaultModel(new ResourceModel("text.friend.feed.num.one"));
        viewFriendsLink.setVisible(false);
    } else {
        numFriendsLabel.setDefaultModel(
                new StringResourceModel("text.friend.feed.num.many", null, new Object[] { numFriends }));
        viewFriendsLabel.setDefaultModel(new ResourceModel("link.friend.feed.view"));
    }

}

From source file:org.sakaiproject.profile2.tool.pages.panels.GalleryFeed.java

License:Educational Community License

@SuppressWarnings("unchecked")
public GalleryFeed(String id, final String ownerUserId, final String viewingUserId) {

    super(id);//from www. j  a  v a2s  .  com

    log.debug("GalleryFeed()");

    Label heading;
    if (viewingUserId.equals(ownerUserId)) {
        heading = new Label("heading", new ResourceModel("heading.widget.my.pictures"));
    } else {
        heading = new Label("heading", new StringResourceModel("heading.widget.view.pictures", null,
                new Object[] { sakaiProxy.getUserDisplayName(ownerUserId) }));
    }
    add(heading);

    IDataProvider dataProvider = new GalleryImageRandomizedDataProvider(ownerUserId);

    GridView dataView = new GridView("rows", dataProvider) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateEmptyItem(Item item) {
            // TODO make "fake" clickable
            Link emptyImageLink = new Link("galleryFeedItem") {
                public void onClick() {
                }

            };

            Label galleryFeedPicture = new Label("galleryImageThumbnailRenderer", "");
            emptyImageLink.add(galleryFeedPicture);

            item.add(emptyImageLink);
        }

        @Override
        protected void populateItem(Item item) {

            final GalleryImage image = (GalleryImage) item.getModelObject();

            GalleryImageRenderer galleryImageThumbnailRenderer = new GalleryImageRenderer(
                    "galleryImageThumbnailRenderer", image.getThumbnailResource());

            AjaxLink galleryFeedItem = new AjaxLink("galleryFeedItem") {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    // view-only (i.e. no edit functionality)
                    setResponsePage(new ViewPicture(image));
                }
            };
            galleryFeedItem.add(galleryImageThumbnailRenderer);

            item.add(galleryFeedItem);

        }

    };
    // limit gallery to 3x2 thumbnails
    dataView.setColumns(3);
    dataView.setRows(2);

    add(dataView);

    AjaxLink viewPicturesLink = new AjaxLink("viewPicturesLink") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {

            if (sakaiProxy.isSuperUserAndProxiedToUser(ownerUserId)) {
                setResponsePage(new ViewPictures(ownerUserId));
            } else if (viewingUserId.equals(ownerUserId)) {
                setResponsePage(new MyPictures());
            } else {
                setResponsePage(new ViewPictures(ownerUserId));
            }
        }

    };

    Label numPicturesLabel = new Label("numPicturesLabel");
    add(numPicturesLabel);

    Label viewPicturesLabel;

    if (dataView.getItemCount() == 0) {
        numPicturesLabel.setDefaultModel(new ResourceModel("text.gallery.feed.num.none"));
        viewPicturesLabel = new Label("viewPicturesLabel", new ResourceModel("link.gallery.feed.addnew"));

        if (!viewingUserId.equals(ownerUserId) || sakaiProxy.isSuperUserAndProxiedToUser(ownerUserId)) {
            viewPicturesLink.setVisible(false);
        }

    } else {
        numPicturesLabel.setVisible(false);
        viewPicturesLabel = new Label("viewPicturesLabel", new ResourceModel("link.gallery.feed.view"));
    }

    viewPicturesLink.add(viewPicturesLabel);

    add(viewPicturesLink);
}

From source file:org.sakaiproject.sitemembers.ui.components.ConnectionsGrid.java

License:Educational Community License

@Override
public void onInitialize() {
    super.onInitialize();

    @SuppressWarnings("unchecked")
    final List<WidgetPage.GridPerson> connections = (List<WidgetPage.GridPerson>) getDefaultModelObject();

    final int nUsers = connections.size();
    int rows = (nUsers + cols - 1) / cols; /* round up number of rows */

    final ListDataProvider<WidgetPage.GridPerson> dataProvider = new ListDataProvider<WidgetPage.GridPerson>(
            connections);/*ww w  .ja  va2s.  c  o  m*/

    final GridView<WidgetPage.GridPerson> gridView = new GridView<WidgetPage.GridPerson>("rows", dataProvider) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<WidgetPage.GridPerson> item) {
            final WidgetPage.GridPerson connection = item.getModelObject();
            final String connection_uuid = connection.uuid;
            final ProfileThumbnail img = new ProfileThumbnail("img", Model.of(connection_uuid));

            final String url = "javascript:;";

            img.add(new AttributeModifier("href", url));
            img.add(new AttributeModifier("target", "_top"));
            img.add(new AttributeModifier("data-user-id", connection_uuid));
            item.add(img);

            //name link
            ExternalLink l = new ExternalLink("name", url, connection.displayName);
            l.add(new AttributeModifier("data-user-id", connection_uuid));
            item.add(l);

            //role
            if (connection.role != "STUDENT") {
                ResourceModel rm = new ResourceModel(prefix + connection.role.toLowerCase());
                item.add(new Label("role", rm.getObject()));
            } else {
                item.add(new EmptyPanel("role"));
            }

            String t = "online-status";
            if (connection.onlineStatus == ProfileConstants.ONLINE_STATUS_ONLINE) {
                t += " online";
            } else if (connection.onlineStatus == ProfileConstants.ONLINE_STATUS_AWAY) {
                t += " away";
            } else {
                t += " offline";
            }

            Label lbl = new Label("online_status", "");
            lbl.add(new AttributeModifier("class", t));

            item.add(lbl);
        }

        @Override
        protected void populateEmptyItem(final Item<WidgetPage.GridPerson> item) {
            item.add(new EmptyPanel("img"));
            item.add(new EmptyPanel("name"));
            item.add(new EmptyPanel("role"));
            item.setVisible(false);
        }
    };

    /* handle case where nUsers=0 */
    if (rows <= 0) {
        rows = 1;
    }
    gridView.setRows(rows);
    gridView.setColumns(cols);

    add(gridView);
}

From source file:org.yes.cart.web.page.component.ProductsCentralView.java

License:Apache License

/**
 * {@inheritDoc}/*  w  w w  .j  a va  2  s .  com*/
 */
@Override
protected void onBeforeRender() {

    final long configShopId = getCurrentShopId();
    final long categoryId = getCategoryId();
    final NavigationContext context = getNavigationContext();

    add(new TopCategories("topCategories"));
    add(new BrandProductFilter("brandFilter", categoryId, context));
    add(new AttributeProductFilter("attributeFilter", categoryId, context));
    add(new PriceProductFilter("priceFilter", categoryId, context));

    final List<String> itemsPerPageValues = categoryServiceFacade.getItemsPerPageOptionsConfig(categoryId,
            configShopId);
    final List<String> pageSortingValues = categoryServiceFacade.getPageSortingOptionsConfig(categoryId,
            configShopId);
    final Pair<String, String> widthHeight = categoryServiceFacade.getProductListImageSizeConfig(categoryId,
            configShopId);
    final int columns = categoryServiceFacade.getProductListColumnOptionsConfig(categoryId, configShopId);

    final PageParameters pageParameters = getPage().getPageParameters();
    final PaginationSupport pagination = getWicketSupportFacade().pagination();
    int currentPageIdx = pagination.getCurrentPage(pageParameters);
    if (currentPageIdx < 0) {
        // if we have gone overboard restart from 0 by redirect!
        final PageParameters params = new PageParameters(getPage().getPageParameters());
        getWicketSupportFacade().pagination().removePageParam(params);
        setResponsePage(getPage().getClass(), params);
        currentPageIdx = 0;
    }

    final int selectedItemPerPage = pagination.getCurrentItemsPerPage(pageParameters, itemsPerPageValues);
    final Pair<String, Boolean> sortResult = getSortField();

    ProductSearchResultPageDTO products = productServiceFacade.getListProducts(context,
            currentPageIdx * selectedItemPerPage, selectedItemPerPage, sortResult.getFirst(),
            sortResult.getSecond());

    if (currentPageIdx * selectedItemPerPage > products.getTotalHits()) {
        // if we have gone overboard restart from 0 by redirect!
        final PageParameters params = new PageParameters(getPage().getPageParameters());
        getWicketSupportFacade().pagination().removePageParam(params);
        setResponsePage(getPage().getClass(), params);
    }

    final boolean hasResults = products.getTotalHits() > 0L;

    final SortableProductDataProvider dataProvider = new SortableProductDataProvider(products);

    final GridView<ProductSearchResultDTO> productDataView = new GridView<ProductSearchResultDTO>(PRODUCT_LIST,
            dataProvider) {

        protected void populateItem(Item<ProductSearchResultDTO> productItem) {
            productItem.add(new ProductInListView(PRODUCT, productItem.getModelObject(), widthHeight));
        }

        protected void populateEmptyItem(Item<ProductSearchResultDTO> productItem) {
            productItem.add(new Label(PRODUCT, StringUtils.EMPTY).setVisible(false));

        }

    };

    productDataView.setColumns(columns);
    productDataView.setRows(selectedItemPerPage / columns);
    productDataView.setCurrentPage(currentPageIdx);

    add(new ProductSorter(SORTER, pageSortingValues).setVisible(hasResults));
    add(new URLPagingNavigator(PAGINATOR, productDataView, getPage().getPageParameters())
            .setVisible(hasResults));
    add(new URLPagingNavigator(PAGINATOR2, productDataView, getPage().getPageParameters())
            .setVisible(hasResults));
    add(new ProductPerPageListView(ITEMS_PER_PAGE_LIST, itemsPerPageValues).setVisible(hasResults));
    add(productDataView.setVisible(hasResults));

    if (!hasResults) {
        info(getLocalizer().getString("noResultsFound", this));
    }

    super.onBeforeRender();
}