Example usage for org.apache.wicket.markup.html WebComponent add

List of usage examples for org.apache.wicket.markup.html WebComponent add

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html WebComponent add.

Prototype

public Component add(final Behavior... behaviors) 

Source Link

Document

Adds a behavior modifier to the component.

Usage

From source file:de.inren.frontend.storehouse.picture.SimplePicturePanel.java

License:Apache License

@Override
protected void onInitialize() {
    super.onInitialize();
    final String url;
    final String css;
    switch (variant) {
    case THUMBNAIL:
        url = ((InRenApplication) getApplication()).getThumbnailUrl(picture.getDigest(), RequestCycle.get());
        css = "thumbnail";
        break;/*  w  ww .ja v  a  2  s. co  m*/
    case PREVIEW:
        url = ((InRenApplication) getApplication()).getPreviewUrl(picture.getDigest(), RequestCycle.get());
        css = "preview";
        break;
    case LAYOUT:
        url = ((InRenApplication) getApplication()).getLayoutUrl(picture.getDigest(), RequestCycle.get());
        css = "layout";
        break;
    default:
        throw new RuntimeException("Unknown dimension " + variant);
    }
    final WebComponent wc = new WebComponent("pic");
    wc.add(AttributeModifier.replace("alt", picture.getTitle()));
    wc.add(AttributeModifier.replace("title", picture.getTitle()));
    wc.add(AttributeModifier.replace("src", url));
    wc.add(AttributeModifier.replace("class", css));
    add(wc);
}

From source file:dk.frankbille.scoreboard.components.menu.MenuItemsPanel.java

License:Open Source License

public MenuItemsPanel(String id, IModel<List<MenuItem>> itemsModel,
        final IModel<MenuItemType> activeMenuItemModel) {
    super(id, itemsModel);

    add(new ListView<MenuItem>("menuItems", itemsModel) {
        private static final long serialVersionUID = 1L;

        @Override//from  ww  w. j a va  2  s. co m
        protected void populateItem(final ListItem<MenuItem> listItem) {
            listItem.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    MenuItemType activeMenuType = activeMenuItemModel.getObject();
                    MenuItemType menuItemType = listItem.getModelObject().getMenuItemType();

                    return activeMenuType == menuItemType ? "active" : null;
                }
            }));

            final WebMarkupContainer link;

            final MenuItem menuItem = listItem.getModelObject();
            if (menuItem instanceof MenuItemPageLink) {
                final MenuItemPageLink menuItemLink = (MenuItemPageLink) menuItem;

                link = new BookmarkablePageLink<Void>("menuLink", menuItemLink.getPageClass(),
                        menuItemLink.getPageParameters());
                listItem.add(link);

                link.add(new Label("menuLabel", menuItemLink.getLabel()).setRenderBodyOnly(true));
                link.add(new WebMarkupContainer("downIcon").setVisible(false));

                listItem.add(new WebComponent("subMenu").setVisible(false));
            } else if (menuItem instanceof MenuItemContainer) {
                MenuItemContainer menuItemContainer = (MenuItemContainer) menuItem;

                listItem.add(AttributeModifier.append("class", "dropdown"));

                link = new WebMarkupContainer("menuLink");
                link.setOutputMarkupId(true);
                link.add(AttributeModifier.replace("href", "#"));
                link.add(AttributeModifier.replace("class", "dropdown-toggle"));
                link.add(AttributeModifier.replace("data-toggle", "dropdown"));
                link.add(AttributeModifier.replace("role", "button"));
                listItem.add(link);

                link.add(new Label("menuLabel", menuItemContainer.getLabel()).setRenderBodyOnly(true));
                link.add(new WebMarkupContainer("downIcon").setRenderBodyOnly(true));

                MenuItemsPanel subMenu = new MenuItemsPanel("subMenu",
                        new PropertyModel<List<MenuItem>>(menuItemContainer, "subMenuItems"),
                        new Model<MenuItemType>());
                subMenu.add(AttributeModifier.replace("class", "dropdown-menu"));
                subMenu.add(AttributeModifier.replace("role", "menu"));
                subMenu.add(AttributeModifier.replace("aria-labelledby", new AbstractReadOnlyModel<String>() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public String getObject() {
                        return link.getMarkupId();
                    }
                }));
                listItem.add(subMenu);
            } else {
                throw new IllegalStateException("Unknown menuItem type: " + menuItem);
            }

            // Icon
            WebComponent icon = new WebComponent("icon") {
                private static final long serialVersionUID = 1L;

                @Override
                public boolean isVisible() {
                    return menuItem.getIconName() != null;
                }
            };
            icon.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return "icon-" + menuItem.getIconName();
                }
            }));
            link.add(icon);
        }
    });
}

From source file:dk.frankbille.scoreboard.components.PlayerStatisticsPanel.java

License:Open Source License

public PlayerStatisticsPanel(String id, final IModel<Player> selectedPlayerModel, final League league,
        final RatingCalculator rating) {
    super(id);/*from   w w w . j  a va  2 s .com*/

    IModel<List<PlayerResult>> playerResultsModel = new LoadableDetachableModel<List<PlayerResult>>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected List<PlayerResult> load() {
            List<PlayerResult> playerResults = scoreBoardService.getPlayerResults(league);

            Collections.sort(playerResults, new Comparator<PlayerResult>() {
                @Override
                public int compare(PlayerResult o1, PlayerResult o2) {
                    double rating1 = rating.getPlayerRating(o1.getPlayer().getId()).getRating();
                    Double rating2 = rating.getPlayerRating(o2.getPlayer().getId()).getRating();
                    int compare = rating2.compareTo(rating1);

                    if (compare == 0) {
                        compare = new Double(o2.getGamesWonRatio()).compareTo(o1.getGamesWonRatio());
                    }

                    if (compare == 0) {
                        compare = new Integer(o2.getGamesWon()).compareTo(o1.getGamesWon());
                    }

                    if (compare == 0) {
                        compare = new Integer(o1.getGamesLost()).compareTo(o2.getGamesLost());
                    }

                    if (compare == 0) {
                        compare = new Integer(o1.getGamesCount()).compareTo(o2.getGamesCount());
                    }

                    if (compare == 0) {
                        compare = o1.getPlayer().getName().compareTo(o2.getPlayer().getName());
                    }

                    if (compare == 0) {
                        compare = o1.getPlayer().getId().compareTo(o2.getPlayer().getId());
                    }

                    return compare;
                }
            });

            return playerResults;
        }
    };

    add(new ListView<PlayerResult>("players", playerResultsModel) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<PlayerResult> item) {
            final PlayerResult playerResult = item.getModelObject();
            Player player = playerResult.getPlayer();
            Player selectedPlayer = selectedPlayerModel.getObject();

            item.add(new TooltipBehavior(new AbstractReadOnlyModel<CharSequence>() {
                private static final long serialVersionUID = 1L;

                @Override
                public CharSequence getObject() {
                    StringBuilder b = new StringBuilder();
                    Localizer localizer = Application.get().getResourceSettings().getLocalizer();
                    b.append(localizer.getString("won", item)).append(": ").append(playerResult.getGamesWon());
                    b.append(", ");
                    b.append(localizer.getString("lost", item)).append(": ")
                            .append(playerResult.getGamesLost());
                    return b;
                }
            }));

            item.add(RowColorModifier.create(item));
            if (selectedPlayer != null && player.getId().equals(selectedPlayer.getId())) {
                item.add(new AttributeAppender("class", new Model<String>("highlighted"), " "));
            }
            item.add(new Label("number", "" + (item.getIndex() + 1)));
            PageParameters pp = new PageParameters();
            pp.set(0, player.getId());
            BookmarkablePageLink<Void> playerLink = new BookmarkablePageLink<Void>("playerLink",
                    PlayerPage.class, pp);
            item.add(playerLink);
            playerLink.add(new Label("name", new PropertyModel<Integer>(item.getModel(), "player.name")));
            WebComponent medal = new WebComponent("medal") {
                private static final long serialVersionUID = 1L;

                @Override
                public boolean isVisible() {
                    return item.getIndex() < 3;
                }
            };
            medal.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    if (item.getIndex() == 0) {
                        return "gold";
                    } else if (item.getIndex() == 1) {
                        return "silver";
                    } else if (item.getIndex() == 2) {
                        return "bronze";
                    }

                    return null;
                }
            }));
            item.add(medal);
            item.add(new Label("gamesCount", new PropertyModel<Integer>(item.getModel(), "gamesCount")));
            item.add(new Label("winRatio", new FormatModel(new DecimalFormat("0.00"),
                    new PropertyModel<Double>(item.getModel(), "gamesWonRatio"))));
            item.add(new Label("rating", new FormatModel(new DecimalFormat("#"),
                    rating.getPlayerRating(player.getId()).getRating())));
            item.add(new Label("trend",
                    new StringResourceModel(item.getModelObject().getTrend().name().toLowerCase(), null)));
        }
    });
}

From source file:dk.frankbille.scoreboard.components.TeamStatisticsPanel.java

License:Open Source License

public TeamStatisticsPanel(String id, final League league, final RatingCalculator rating) {
    super(id);/*from   w  w  w  .  j  a v  a  2  s  . com*/

    IModel<List<TeamResult>> teamResultsModel = new LoadableDetachableModel<List<TeamResult>>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected List<TeamResult> load() {
            List<TeamResult> teamResults = scoreBoardService.getTeamResults(league);

            Collections.sort(teamResults, new Comparator<TeamResult>() {
                @Override
                public int compare(TeamResult o1, TeamResult o2) {
                    double rating1 = rating.getTeamRating(o1.getTeam()).getRating();
                    Double rating2 = rating.getTeamRating(o2.getTeam()).getRating();
                    int compare = rating2.compareTo(rating1);

                    if (compare == 0) {
                        compare = new Double(o2.getGamesWonRatio()).compareTo(o1.getGamesWonRatio());
                    }

                    if (compare == 0) {
                        compare = new Integer(o2.getGamesWon()).compareTo(o1.getGamesWon());
                    }

                    if (compare == 0) {
                        compare = new Integer(o1.getGamesLost()).compareTo(o2.getGamesLost());
                    }

                    if (compare == 0) {
                        compare = new Integer(o1.getGamesCount()).compareTo(o2.getGamesCount());
                    }

                    return compare;
                }
            });

            return teamResults;
        }
    };

    add(new ListView<TeamResult>("teams", teamResultsModel) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<TeamResult> item) {
            final TeamResult teamResult = item.getModelObject();

            item.add(new TooltipBehavior(new AbstractReadOnlyModel<CharSequence>() {
                private static final long serialVersionUID = 1L;

                @Override
                public CharSequence getObject() {
                    StringBuilder b = new StringBuilder();
                    Localizer localizer = Application.get().getResourceSettings().getLocalizer();
                    b.append(localizer.getString("won", item)).append(": ").append(teamResult.getGamesWon());
                    b.append(", ");
                    b.append(localizer.getString("lost", item)).append(": ").append(teamResult.getGamesLost());
                    return b;
                }
            }));

            item.add(RowColorModifier.create(item));
            item.add(new Label("number", "" + (item.getIndex() + 1)));
            item.add(new Label("name", new PropertyModel<Integer>(item.getModel(), "name")));
            WebComponent medal = new WebComponent("medal") {
                private static final long serialVersionUID = 1L;

                @Override
                public boolean isVisible() {
                    return item.getIndex() < 3;
                }
            };
            medal.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    if (item.getIndex() == 0) {
                        return "gold";
                    } else if (item.getIndex() == 1) {
                        return "silver";
                    } else if (item.getIndex() == 2) {
                        return "bronze";
                    }

                    return null;
                }
            }));
            item.add(medal);
            item.add(new Label("gamesCount", new PropertyModel<Integer>(item.getModel(), "gamesCount")));
            item.add(new Label("winRatio", new FormatModel(new DecimalFormat("0.00"),
                    new PropertyModel<Double>(item.getModel(), "gamesWonRatio"))));
            item.add(new Label("rating", new FormatModel(new DecimalFormat("#"),
                    rating.getTeamRating(teamResult.getTeam()).getRating())));
            item.add(new Label("trend",
                    new StringResourceModel(item.getModelObject().getTrend().name().toLowerCase(), null)));
        }
    });
}

From source file:dk.frankbille.scoreboard.security.LogoutPage.java

License:Open Source License

public LogoutPage() {
    ScoreBoardSession.get().logout();/*from  w  ww  .  java  2 s  . c o  m*/

    WebComponent refresh = new WebComponent("refresh"); //$NON-NLS-1$
    StringBuilder content = new StringBuilder();
    content.append("1; url="); //$NON-NLS-1$
    content.append(getRequestCycle().urlFor(Application.get().getHomePage(), null));
    refresh.add(AttributeModifier.replace("content", content)); //$NON-NLS-1$
    add(refresh);
}

From source file:dk.teachus.frontend.components.menu.MenuItemsPanel.java

License:Apache License

public MenuItemsPanel(String id, IModel<List<MenuItem>> itemsModel,
        final IModel<PageCategory> activeMenuItemModel) {
    super(id, itemsModel);

    add(new ListView<MenuItem>("menuItems", itemsModel) {
        private static final long serialVersionUID = 1L;

        @Override//from  w w w  . j a  v  a2  s  .co m
        protected void populateItem(final ListItem<MenuItem> listItem) {
            listItem.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    PageCategory activeMenuType = activeMenuItemModel.getObject();
                    PageCategory menuItemType = listItem.getModelObject().getMenuItemType();

                    return activeMenuType == menuItemType ? "active" : null;
                }
            }));

            final WebMarkupContainer link;

            final MenuItem menuItem = listItem.getModelObject();
            if (menuItem instanceof MenuItemPageLink) {
                final MenuItemPageLink menuItemLink = (MenuItemPageLink) menuItem;

                link = new BookmarkablePageLink<Void>("menuLink", menuItemLink.getPageClass(),
                        menuItemLink.getPageParameters());
                listItem.add(link);

                link.add(new Label("menuLabel", menuItemLink.getLabel()).setRenderBodyOnly(true));
                link.add(new WebMarkupContainer("downIcon").setVisible(false));

                listItem.add(new WebComponent("subMenu").setVisible(false));
            } else if (menuItem instanceof MenuItemContainer) {
                MenuItemContainer menuItemContainer = (MenuItemContainer) menuItem;

                listItem.add(AttributeModifier.append("class", "dropdown"));

                link = new WebMarkupContainer("menuLink");
                link.setOutputMarkupId(true);
                link.add(AttributeModifier.replace("href", "#"));
                link.add(AttributeModifier.replace("class", "dropdown-toggle"));
                link.add(AttributeModifier.replace("data-toggle", "dropdown"));
                link.add(AttributeModifier.replace("role", "button"));
                listItem.add(link);

                link.add(new Label("menuLabel", menuItemContainer.getLabel()).setRenderBodyOnly(true));
                link.add(new WebMarkupContainer("downIcon").setRenderBodyOnly(true));

                MenuItemsPanel subMenu = new MenuItemsPanel("subMenu",
                        new PropertyModel<List<MenuItem>>(menuItemContainer, "subMenuItems"),
                        new AbstractReadOnlyModel<PageCategory>() {
                            private static final long serialVersionUID = 1L;

                            @Override
                            public PageCategory getObject() {
                                return null;
                            }
                        });
                subMenu.add(AttributeModifier.replace("class", "dropdown-menu"));
                subMenu.add(AttributeModifier.replace("role", "menu"));
                subMenu.add(AttributeModifier.replace("aria-labelledby", new AbstractReadOnlyModel<String>() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public String getObject() {
                        return link.getMarkupId();
                    }
                }));
                listItem.add(subMenu);
            } else {
                throw new IllegalStateException("Unknown menuItem type: " + menuItem);
            }

            // Icon
            WebComponent icon = new WebComponent("icon") {
                private static final long serialVersionUID = 1L;

                @Override
                public boolean isVisible() {
                    return menuItem.getIconName() != null;
                }
            };
            icon.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return "icon-" + menuItem.getIconName();
                }
            }));
            link.add(icon);
        }
    });
}

From source file:dk.teachus.frontend.components.PaidPanel.java

License:Apache License

public PaidPanel(String id, final IModel<PupilBooking> model) {
    super(id, model);

    AjaxFallbackLink<PupilBooking> link = new BlockingAjaxLink<PupilBooking>("link", model) { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override//from  ww  w. j a v a  2s.  c  o m
        public void onClick(AjaxRequestTarget target) {
            PupilBooking pupilBooking = getModelObject();

            BookingDAO bookingDAO = TeachUsApplication.get().getBookingDAO();
            bookingDAO.changePaidStatus(pupilBooking);

            if (target != null) {
                target.add(this);
            }
        }
    };
    link.setOutputMarkupId(true);
    WebComponent image = new WebComponent("icon"); //$NON-NLS-1$
    image.add(AttributeModifier.replace("class", new IconModel(model))); //$NON-NLS-1$
    link.add(image);
    add(link);
}

From source file:dk.teachus.frontend.pages.SignedOutPage.java

License:Apache License

public SignedOutPage() {
    TeachUsSession.get().signOut();/*w w  w  .java2s  . c om*/

    WebComponent refresh = new WebComponent("refresh"); //$NON-NLS-1$
    StringBuilder content = new StringBuilder();
    content.append("1; url="); //$NON-NLS-1$
    content.append(getRequestCycle().urlFor(Application.get().getHomePage(), null));
    refresh.add(AttributeModifier.replace("content", content)); //$NON-NLS-1$
    add(refresh);

    add(new Label("signedOutText", //$NON-NLS-1$
            TeachUsSession.get().getString("SignedOutPage.youAreNowLoggedOutOfTheSystem"))); //$NON-NLS-1$

    Link<Void> homePageLink = new BookmarkablePageLink<Void>("homePageLink", Application.get().getHomePage()); //$NON-NLS-1$
    add(homePageLink);
    homePageLink.add(
            new Label("homePageLabel", TeachUsSession.get().getString("SignedOutPage.clickToGoToFrontPage"))); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:ee.pri.rl.blog.web.page.BasePage.java

License:Open Source License

public BasePage() {
    super();//from   w w  w.jav  a 2  s.  c  o m
    add(new Label("pageTitle", new PropertyModel<Void>(this, "pageTitle")));

    WebComponent styleLink = new WebComponent("styleLink");
    styleLink.add(new AttributeModifier("href", new Model<String>(getStyleAndJSPath() + "/style.css")));
    add(styleLink);

    WebComponent scriptLocation = new WebComponent("scriptLocation");
    scriptLocation.add(new AttributeModifier("src", new Model<String>(getStyleAndJSPath() + "/script.js")));
    add(scriptLocation);

    add(new GlobalFeedbackPanel("pageFeedback") {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !getCurrentMessages().isEmpty();
        }
    });
}

From source file:eu.esdihumboldt.hale.server.projects.war.components.ProjectList.java

License:Open Source License

/**
 * Constructor//  w w w .j av a  2  s .com
 * 
 * @param id the panel id
 * @param showCaption if the caption shall be shown
 */
public ProjectList(String id, boolean showCaption) {
    super(id);

    // projects list
    final IModel<? extends List<String>> projectsModel = new LoadableDetachableModel<List<String>>() {

        private static final long serialVersionUID = 7277175702043541004L;

        @Override
        protected List<String> load() {
            return new ArrayList<String>(projects.getResources());
        }

    };

    final ListView<String> projectList = new ListView<String>("projects", projectsModel) {

        private static final long serialVersionUID = -6740090246572869212L;

        /**
         * @see ListView#populateItem(ListItem)
         */
        @Override
        protected void populateItem(ListItem<String> item) {
            final boolean odd = item.getIndex() % 2 != 0;
            if (odd) {
                item.add(AttributeModifier.replace("class", "odd"));
            }

            final String id = item.getModelObject();

            // identifier
            item.add(new Label("identifier", id));

            // status
            Status status = projects.getStatus(id);
            String statusImagePath;
            String statusTitle;
            switch (status) {
            case ACTIVE:
                statusImagePath = "images/ok.png";
                statusTitle = "Active";
                break;
            case INACTIVE:
                statusImagePath = "images/sleeping.gif";
                statusTitle = "Inactive";
                break;
            case BROKEN:
                statusImagePath = "images/error.gif";
                statusTitle = "Project cannot be loaded";
                break;
            case NOT_AVAILABLE:
            default:
                statusImagePath = "images/unknown.gif";
                statusTitle = "Project file missing or not set";
            }
            WebComponent statusImage = new WebComponent("status");
            statusImage.add(AttributeModifier.replace("src", statusImagePath));
            statusImage.add(AttributeModifier.replace("title", statusTitle));
            item.add(statusImage);

            // action
            String actionImagePath;
            String actionTitle;
            boolean showAction;
            Link<?> actionLink;
            switch (status) {
            case ACTIVE:
                actionTitle = "Stop";
                actionImagePath = "images/stop.gif";
                showAction = true;
                actionLink = new Link<Void>("action") {

                    private static final long serialVersionUID = 393941411843332519L;

                    @Override
                    public void onClick() {
                        projects.deactivate(id);
                    }

                };
                break;
            case BROKEN:
            case NOT_AVAILABLE:
                actionTitle = "Rescan";
                actionImagePath = "images/refresh.gif";
                showAction = true;
                actionLink = new Link<Void>("action") {

                    private static final long serialVersionUID = -4403828305588875839L;

                    @Override
                    public void onClick() {
                        projects.triggerScan();
                    }

                };
                break;
            case INACTIVE:
            default:
                actionTitle = "Start";
                actionImagePath = "images/start.gif";
                showAction = status.equals(Status.INACTIVE);
                actionLink = new Link<Void>("action") {

                    private static final long serialVersionUID = 393941411843332519L;

                    @Override
                    public void onClick() {
                        projects.activate(id);
                    }

                };
                break;
            }
            WebComponent actionImage = new WebComponent("image");
            actionImage.add(AttributeModifier.replace("src", actionImagePath));
            actionImage.add(AttributeModifier.replace("title", actionTitle));
            actionLink.add(actionImage);
            actionLink.setVisible(showAction);
            item.add(actionLink);

            // name
            String projectName = "";
            ProjectInfo info = projects.getInfo(id);
            if (info != null) {
                projectName = info.getName();
            }
            item.add(new Label("name", projectName));

            // download log
            File logFile = projects.getLoadReports(id);
            DownloadLink log = new DownloadLink("log", logFile, id + ".log");
            log.setVisible(logFile != null && logFile.exists());
            WebComponent logImage = new WebComponent("image");
            if (status == Status.BROKEN) {
                logImage.add(AttributeModifier.replace("src", "images/error_log.gif"));
            }
            log.add(logImage);
            item.add(log);
        }

    };
    add(projectList);

    boolean noProjects = projectsModel.getObject().isEmpty();

    // caption
    WebMarkupContainer caption = new WebMarkupContainer("caption");
    caption.setVisible(showCaption && !noProjects);
    add(caption);

    add(new WebMarkupContainer("noprojects").setVisible(noProjects));
}