List of usage examples for org.apache.wicket.markup.html.list ListView setVisible
public final Component setVisible(final boolean visible)
From source file:ch.qos.mistletoe.wicket.TreeExpansionLink.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from www.j ava 2s.co m public void onClick(AjaxRequestTarget target) { TestReportPanel nodePanel = (TestReportPanel) getParent(); if (nodePanel == null || nodePanel.testReport == null) { warn("Failed to find node panel"); return; } if (nodePanel.testReport.isSuite()) { expanded = !expanded; System.out.println("expanded=" + expanded); TreeExpansionLink link = (TreeExpansionLink) nodePanel.get(Constants.TREE_CONTROL_ID); target.add(link.getParent()); Image image = (Image) link.get(Constants.TREE_CONTROL_SYMBOL_ID); ResourceReference ref = getControlSymbolResourceReference(expanded); image.setImageResourceReference(ref); ListView<Node> payloadNode = (ListView<Node>) nodePanel.get(Constants.PAYLOAD_ID); payloadNode.setVisible(expanded); // can't update a ListView target.add(payloadNode.getParent()); } }
From source file:com.axway.ats.testexplorer.pages.machines.MachinesPage.java
License:Apache License
private Form<Object> getMachinesForm(final Label noMachinesLabel) { final Form<Object> machinesForm = new Form<Object>("machinesForm"); machinesForm.setOutputMarkupId(true); machineModels = new HashMap<Integer, IModel<String>>(); ListView<Machine> machinesTable = new ListView<Machine>("machine", machines) { private static final long serialVersionUID = 1L; @Override// www .j a v a2s.c o m protected void populateItem(final ListItem<Machine> item) { if (item.getIndex() % 2 != 0) { item.add(AttributeModifier.replace("class", "oddRow")); } IModel<String> aliasModel = new Model<String>(item.getModelObject().alias); machineModels.put(item.getModelObject().machineId, aliasModel); item.add(new TextField<String>("machineAlias", aliasModel)); item.add(new Label("machineName", item.getModelObject().name).setEscapeModelStrings(false)); final Machine machine = item.getModelObject(); item.add(new AjaxButton("machineInfo") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { if (machine.alias == null || machine.alias.trim().length() == 0) { machineInfoDialogTitle.setDefaultModelObject(machine.name); } else { machineInfoDialogTitle.setDefaultModelObject(machine.alias + " (" + machine.name + ")"); } machineInfoDialog.setVisible(true); machineForEdit = machine; machineInfoText.setModelObject(getMachineInformation(machine)); target.add(machineInfoDialogForm); } }); } }; machinesForm.add(machinesTable); AjaxButton saveMachineAliasesButton = new AjaxButton("saveMachineAliasesButton") { private static final long serialVersionUID = 1L; @Override public void onSubmit(AjaxRequestTarget target, Form<?> form) { if (!form.isSubmitted()) { return; } for (Machine machine : machines) { String newMachineAlias = machineModels.get(machine.machineId).getObject(); if (newMachineAlias != null) { newMachineAlias = newMachineAlias.trim(); } if ((newMachineAlias == null && machine.alias != null) || (newMachineAlias != null && !newMachineAlias.equals(machine.alias))) { machine.alias = newMachineAlias; try { getTESession().getDbWriteConnection().updateMachineAlias(machine); } catch (DatabaseAccessException e) { LOG.error("Can't update alias of machine '" + machine.name + "'", e); target.appendJavaScript( "alert('There was an error while updating the machine aliases!');"); return; } } } target.appendJavaScript("alert('The machine aliases were successfully updated.');"); } }; boolean hasMachines = machines.size() > 0; machinesTable.setVisible(hasMachines); saveMachineAliasesButton.setVisible(hasMachines); noMachinesLabel.setVisible(!hasMachines); machinesForm.add(saveMachineAliasesButton); machinesForm.add(noMachinesLabel); return machinesForm; }
From source file:com.axway.ats.testexplorer.pages.testcase.loadqueues.LoadQueuesPanel.java
License:Apache License
public LoadQueuesPanel(String id, final String testcaseId) { super(id);//from w ww . j a v a 2 s . c om List<ComplexLoadQueue> loadQueues = getLoadQueues(testcaseId); ListView<ComplexLoadQueue> loadQueuesContainer = new ListView<ComplexLoadQueue>("loadQueuesContainer", loadQueues) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<ComplexLoadQueue> item) { final ComplexLoadQueue loadQueue = item.getModelObject(); if (item.getIndex() % 2 != 0) { item.add(AttributeModifier.replace("class", "oddRow")); } item.add(new Label("name", loadQueue.getName())); item.add(new Label("threadingPattern", loadQueue.getThreadingPattern()) .setEscapeModelStrings(false)); item.add(new Label("state", loadQueue.getState()) .add(AttributeModifier.replace("class", loadQueue.getState().toLowerCase() + "State"))); item.add(new Label("dateStart", loadQueue.getDateStart())); item.add(new Label("dateEnd", loadQueue.getDateEnd())); item.add(new Label("duration", String.valueOf(loadQueue.getDuration()))); item.add(new ListView<ComplexAction>("checkpoint_summary_info", loadQueue.getCheckpointsSummary()) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<ComplexAction> item) { if (item.getIndex() % 2 != 0) { item.add(AttributeModifier.replace("class", "oddRow")); } final ComplexAction checkpointSummary = item.getModelObject(); item.add(new Label("name", checkpointSummary.getName())); item.add(new Label("numTotal", String.valueOf(checkpointSummary.getNumTotal()))); item.add(new Label("numRunning", String.valueOf(checkpointSummary.getNumRunning()))); item.add(new Label("numPassed", String.valueOf(checkpointSummary.getNumPassed()))); item.add(new Label("numFailed", String.valueOf(checkpointSummary.getNumFailed()))); item.add(new Label("minResponseTime", checkpointSummary.getMinResponseTime())); item.add(new Label("avgResponseTime", checkpointSummary.getAvgResponseTime())); item.add(new Label("maxResponseTime", checkpointSummary.getMaxResponseTime())); String transferRateUnit = checkpointSummary.getTransferRateUnit(); if (StringUtils.isNullOrEmpty(transferRateUnit)) { // this action does not transfer data item.add(new Label("minTransferRate", "")); item.add(new Label("avgTransferRate", "")); item.add(new Label("maxTransferRate", "")); item.add(new Label("transferRateUnit", "")); } else { // this action transfers data item.add(new Label("minTransferRate", checkpointSummary.getMinTransferRate())); item.add(new Label("avgTransferRate", checkpointSummary.getAvgTransferRate())); item.add(new Label("maxTransferRate", checkpointSummary.getMaxTransferRate())); item.add(new Label("transferRateUnit", transferRateUnit)); } } }); } }; loadQueuesContainer.setVisible(!loadQueues.isEmpty()); WebMarkupContainer noLoadQueuesContainer = new WebMarkupContainer("noLoadQueuesContainer"); noLoadQueuesContainer.setVisible(loadQueues.isEmpty()); add(loadQueuesContainer); add(noLoadQueuesContainer); }
From source file:com.evolveum.midpoint.web.component.wf.ApprovalProcessExecutionInformationPanel.java
License:Apache License
protected void initLayout() { // TODO clean this code up!!! ListView<ApprovalStageExecutionInformationDto> stagesList = new ListView<ApprovalStageExecutionInformationDto>( ID_STAGES, new PropertyModel<>(getModel(), ApprovalProcessExecutionInformationDto.F_STAGES)) { @Override// w w w. j a va 2 s.c o m protected void populateItem(ListItem<ApprovalStageExecutionInformationDto> stagesListItem) { ApprovalProcessExecutionInformationDto process = ApprovalProcessExecutionInformationPanel.this .getModelObject(); ApprovalStageExecutionInformationDto stage = stagesListItem.getModelObject(); int stageNumber = stage.getStageNumber(); int numberOfStages = process.getNumberOfStages(); int currentStageNumber = process.getCurrentStageNumber(); WebMarkupContainer arrow = new WebMarkupContainer(ID_ARROW); arrow.add(new VisibleBehaviour(() -> stageNumber > 1)); stagesListItem.add(arrow); WebMarkupContainer currentStageMarker = new WebMarkupContainer(ID_CURRENT_STAGE_MARKER); currentStageMarker .add(new VisibleBehaviour(() -> stageNumber == currentStageNumber && process.isRunning())); stagesListItem.add(currentStageMarker); ListView<ApproverEngagementDto> approversList = new ListView<ApproverEngagementDto>(ID_APPROVERS, new PropertyModel<>(stagesListItem.getModel(), ApprovalStageExecutionInformationDto.F_APPROVER_ENGAGEMENTS)) { @Override protected void populateItem(ListItem<ApproverEngagementDto> approversListItem) { ApproverEngagementDto ae = approversListItem.getModelObject(); // original approver name approversListItem.add(createApproverLabel(ID_APPROVER_NAME, "ApprovalProcessExecutionInformationPanel.approver", ae.getApproverRef(), true)); // outcome WorkItemOutcomeType outcome = ae.getOutput() != null ? ApprovalUtils.fromUri(ae.getOutput().getOutcome()) : null; ApprovalOutcomeIcon outcomeIcon; if (outcome != null) { switch (outcome) { case APPROVE: outcomeIcon = ApprovalOutcomeIcon.APPROVED; break; case REJECT: outcomeIcon = ApprovalOutcomeIcon.REJECTED; break; default: outcomeIcon = ApprovalOutcomeIcon.UNKNOWN; break; // perhaps should throw AssertionError instead } } else { if (stageNumber < currentStageNumber) { outcomeIcon = ApprovalOutcomeIcon.EMPTY; // history: do not show anything for work items with no outcome } else if (stageNumber == currentStageNumber) { outcomeIcon = process.isRunning() && stage.isReachable() ? ApprovalOutcomeIcon.IN_PROGRESS : ApprovalOutcomeIcon.CANCELLED; // currently open } else { outcomeIcon = process.isRunning() && stage.isReachable() ? ApprovalOutcomeIcon.FUTURE : ApprovalOutcomeIcon.CANCELLED; } } ImagePanel outcomePanel = new ImagePanel(ID_OUTCOME, Model.of(outcomeIcon.getIcon()), Model.of(getString(outcomeIcon.getTitle()))); outcomePanel.add(new VisibleBehaviour(() -> outcomeIcon != ApprovalOutcomeIcon.EMPTY)); approversListItem.add(outcomePanel); // content (incl. performer) WebMarkupContainer approvalBoxContent = new WebMarkupContainer(ID_APPROVAL_BOX_CONTENT); approversListItem.add(approvalBoxContent); approvalBoxContent.setVisible(performerVisible(ae) || attorneyVisible(ae)); approvalBoxContent.add(createApproverLabel(ID_PERFORMER_NAME, "ApprovalProcessExecutionInformationPanel.performer", ae.getCompletedBy(), performerVisible(ae))); approvalBoxContent.add(createApproverLabel(ID_ATTORNEY_NAME, "ApprovalProcessExecutionInformationPanel.attorney", ae.getAttorney(), attorneyVisible(ae))); // junction Label junctionLabel = new Label(ID_JUNCTION, stage.isFirstDecides() ? "" : " & "); // or "+" for first decides? probably not junctionLabel.setVisible(!stage.isFirstDecides() && !ae.isLast()); // not showing "" to save space (if aligned vertically) approversListItem.add(junctionLabel); } }; approversList.setVisible(stage.getAutomatedCompletionReason() == null); stagesListItem.add(approversList); String autoCompletionKey; if (stage.getAutomatedCompletionReason() != null) { switch (stage.getAutomatedCompletionReason()) { case AUTO_COMPLETION_CONDITION: autoCompletionKey = "DecisionDto.AUTO_COMPLETION_CONDITION"; break; case NO_ASSIGNEES_FOUND: autoCompletionKey = "DecisionDto.NO_ASSIGNEES_FOUND"; break; default: autoCompletionKey = null; // or throw an exception? } } else { autoCompletionKey = null; } Label automatedOutcomeLabel = new Label(ID_AUTOMATED_OUTCOME, autoCompletionKey != null ? getString(autoCompletionKey) : ""); automatedOutcomeLabel.setVisible(stage.getAutomatedCompletionReason() != null); stagesListItem.add(automatedOutcomeLabel); stagesListItem.add(new Label(ID_STAGE_NAME, getStageNameLabel(stage, stageNumber, numberOfStages))); ApprovalLevelOutcomeType stageOutcome = stage.getOutcome(); ApprovalOutcomeIcon stageOutcomeIcon; if (stageOutcome != null) { switch (stageOutcome) { case APPROVE: stageOutcomeIcon = ApprovalOutcomeIcon.APPROVED; break; case REJECT: stageOutcomeIcon = ApprovalOutcomeIcon.REJECTED; break; case SKIP: stageOutcomeIcon = ApprovalOutcomeIcon.SKIPPED; break; default: stageOutcomeIcon = ApprovalOutcomeIcon.UNKNOWN; break; // perhaps should throw AssertionError instead } } else { if (stageNumber < currentStageNumber) { stageOutcomeIcon = ApprovalOutcomeIcon.EMPTY; // history: do not show anything (shouldn't occur, as historical stages are filled in) } else if (stageNumber == currentStageNumber) { stageOutcomeIcon = process.isRunning() && stage.isReachable() ? ApprovalOutcomeIcon.IN_PROGRESS : ApprovalOutcomeIcon.CANCELLED; // currently open } else { stageOutcomeIcon = process.isRunning() && stage.isReachable() ? ApprovalOutcomeIcon.FUTURE : ApprovalOutcomeIcon.CANCELLED; } } ImagePanel stageOutcomePanel = new ImagePanel(ID_STAGE_OUTCOME, Model.of(stageOutcomeIcon.getIcon()), Model.of(getString(stageOutcomeIcon.getTitle()))); stageOutcomePanel.add(new VisibleBehaviour(() -> stageOutcomeIcon != ApprovalOutcomeIcon.EMPTY)); stagesListItem.add(stageOutcomePanel); } }; add(stagesList); }
From source file:com.swordlord.gozer.components.wicket.action.button.detail.GWDetailPanelActionToolbar.java
License:Open Source License
public GWDetailPanelActionToolbar(String name, IModel<GWContext> model, GDetail detail, final Form<?> form) { super(name, model); _detail = detail;//from w w w .ja v a2 s .c o m final GWContext context = getGWContext(); final GozerController gc = context.getFrameExtension().getGozerController(); List<GActionBase> actions = getKnownActions(); ListView<GActionBase> listView = new ListView<GActionBase>("eachAction", actions) { @Override protected void populateItem(ListItem<GActionBase> item) { GActionBase ob = item.getModelObject(); if (ob.getClass().equals(GNewAction.class)) { item.add(new GWNewButton(ACTION_WICKET_ID, gc, ob, form)); } else if (ob.getClass().equals(GDeleteAction.class)) { item.add(new GWDeleteButton(ACTION_WICKET_ID, gc, ob, form)); } else if (ob.getClass().equals(GAddAction.class)) { item.add(new GWAddButton(ACTION_WICKET_ID, gc, ob, form)); } else if (ob.getClass().equals(GRemoveAction.class)) { item.add(new GWRemoveButton(ACTION_WICKET_ID, gc, ob, form)); } else if (ob.getClass().equals(GToggleAction.class)) { item.add(new GWSwitchToListButton(ACTION_WICKET_ID, gc, ob)); } else if (ob.getClass().equals(GFirstAction.class)) { item.add(new GWFirstButton(ACTION_WICKET_ID, gc, ob)); } else if (ob.getClass().equals(GPrevAction.class)) { item.add(new GWPrevButton(ACTION_WICKET_ID, gc, ob)); } else if (ob.getClass().equals(GNextAction.class)) { item.add(new GWNextButton(ACTION_WICKET_ID, gc, ob)); } else if (ob.getClass().equals(GLastAction.class)) { item.add(new GWLastButton(ACTION_WICKET_ID, gc, ob)); } else if (ob.getClass().equals(GOtherAction.class)) { item.add(new GWOtherButton(ACTION_WICKET_ID, gc, ob, form)); } } }; listView.setReuseItems(true); add(listView); if (actions.size() == 0) { listView.setVisible(false); this.setVisible(false); } }
From source file:com.swordlord.gozer.components.wicket.box.GWFrame.java
License:Open Source License
/** * @param id//from w ww . j ava 2s .c o m * @param model * @param gozerForm */ public GWFrame(String id, final IModel<?> model, ObjectBase gozerForm) { super(id, model); GWContext context = getGWContext(); context.setFormPanel(this); final SecureForm<Object> form = new SecureForm<Object>("gozerForm"); add(form); final FeedbackPanel feedback = new FeedbackPanel("feedback"); form.add(feedback); // filteredErrorLevels will not be shown in the FeedbackPanel // int[] filteredErrorLevels = new int[]{FeedbackMessage.ERROR}; // feedback.setFilter(new ErrorLevelFeedbackMessageFilter(filteredErrorLevels)); ObjectBase formRoot = gozerForm; ListView<ObjectBase> listView = new ListView<ObjectBase>("eachGuiElem", formRoot.getChildren()) { @Override protected void populateItem(ListItem<ObjectBase> item) { ObjectBase ob = item.getModelObject(); item.add(getPanelFromObjectBase("cell", ob, model, form)); } }; listView.setReuseItems(true); if (formRoot.getChildren().size() == 0) { listView.setVisible(false); } form.add(listView); }
From source file:com.tysanclan.site.projectewok.pages.member.AcceptanceVotePage.java
License:Open Source License
/** * /* ww w .j a v a 2 s . c om*/ */ public AcceptanceVotePage() { super("Acceptance votes"); add(new ListView<AcceptanceVote>("members", ModelMaker.wrap(acceptanceVoteDAO.findAll())) { private static final long serialVersionUID = 1L; @SpringBean private ForumPostDAO forumPostDAO; @SpringBean private ForumService forumService; @Override protected void populateItem(ListItem<AcceptanceVote> item) { AcceptanceVote vote = item.getModelObject(); User trialMember = vote.getTrialMember(); AcceptanceVoteVerdict myVote = null; AcceptanceVoteVerdict mentorVote = null; for (AcceptanceVoteVerdict verdict : vote.getVerdicts()) { if (verdict.getCaster().equals(verdict.getVote().getTrialMember().getMentor())) { mentorVote = verdict; } if (verdict.getCaster().equals(getUser())) { myVote = verdict; } } item.add(new Label("username", trialMember.getUsername())); item.add(new ContextImage("ihaznotvoted", "images/icons/error.png").setVisible(myVote == null)); PageParameters params = new PageParameters(); params.add("userid", trialMember.getId().toString()); BookmarkablePageLink<User> profileLink = new BookmarkablePageLink<User>("profile", MemberPage.class, params); WebMarkupContainer mentorWarning = new WebMarkupContainer("mentorWarning"); User mentor = vote.getTrialMember().getMentor(); if (mentor != null) { mentorWarning.add(new MemberListItem("mentor", mentor)); mentorWarning.add(new ContextImage("warningIcon1", "images/icons/exclamation.png")); mentorWarning.add(new ContextImage("warningIcon2", "images/icons/exclamation.png")); mentorWarning.add(new ContextImage("warningIcon3", "images/icons/exclamation.png")); mentorWarning.add(new ContextImage("warningIcon4", "images/icons/exclamation.png")); mentorWarning.add(new ContextImage("warningIcon5", "images/icons/exclamation.png")); mentorWarning.add(new ContextImage("warningIcon6", "images/icons/exclamation.png")); } else { mentorWarning.add(new WebMarkupContainer("mentor").setVisible(false)); mentorWarning.add(new WebMarkupContainer("warningIcon1").setVisible(false)); mentorWarning.add(new WebMarkupContainer("warningIcon2").setVisible(false)); mentorWarning.add(new WebMarkupContainer("warningIcon3").setVisible(false)); mentorWarning.add(new WebMarkupContainer("warningIcon4").setVisible(false)); mentorWarning.add(new WebMarkupContainer("warningIcon5").setVisible(false)); mentorWarning.add(new WebMarkupContainer("warningIcon6").setVisible(false)); } mentorWarning.setVisible(mentorVote != null && !mentorVote.isInFavor()); item.add(mentorWarning); profileLink.add(new Label("username", trialMember.getUsername())); item.add(profileLink); item.add(new IconLink.Builder("images/icons/tick.png", new DefaultClickResponder<AcceptanceVote>(ModelMaker.wrap(vote)) { private static final long serialVersionUID = 1L; @SpringBean private DemocracyService democracyService; /** * @see com.tysanclan.site.projectewok.components.IconLink.DefaultClickResponder#onClick() */ @Override public void onClick() { AcceptanceVote av = getModelObject(); User caster = getUser(); democracyService.castAcceptanceVote(av, caster, true); setResponsePage(new AcceptanceVotePage()); } }).setText("Yes, I want to accept " + trialMember.getUsername() + " as a member") .newInstance("yes")); item.add(new IconLink.Builder("images/icons/cross.png", new DefaultClickResponder<AcceptanceVote>(ModelMaker.wrap(vote)) { private static final long serialVersionUID = 1L; @SpringBean private DemocracyService democracyService; /** * @see com.tysanclan.site.projectewok.components.IconLink.DefaultClickResponder#onClick() */ @Override public void onClick() { AcceptanceVote av = getModelObject(); User caster = getUser(); democracyService.castAcceptanceVote(av, caster, false); setResponsePage(new AcceptanceVotePage()); } }).setText("No, I would prefer it if " + trialMember.getUsername() + " would no longer remain a member" + (getUser().equals(mentor) ? ". WARNING: AS MENTOR OF THIS APPLICANT YOUR VOTE WILL BE VISIBLE IF YOU VOTE AGAINST YOUR OWN PUPIL" : "")) .newInstance("no")); item.add(new Label("count", new Model<Integer>(vote.getVerdicts().size()))); ForumPostFilter filter = new ForumPostFilter(); filter.setShadow(false); filter.setUser(trialMember); filter.addOrderBy("time", false); List<ForumPost> posts = forumPostDAO.findByFilter(filter); posts = forumService.filterPosts(getUser(), false, posts); List<ForumPost> topPosts = new LinkedList<ForumPost>(); for (int i = 0; i < Math.min(posts.size(), 5); i++) { topPosts.add(posts.get(i)); } ListView<ForumPost> lastPosts = new ListView<ForumPost>("lastposts", ModelMaker.wrap(topPosts)) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<ForumPost> item1) { ForumPost post = item1.getModelObject(); item1.add(new AutoThreadLink("thread", post.getThread())); item1.add(new DateTimeLabel("time", post.getTime())); } }; item.add(lastPosts.setVisible(!topPosts.isEmpty())); item.add(new WebMarkupContainer("noPosts").setVisible(!lastPosts.isVisible())); WebMarkupContainer vacation = new WebMarkupContainer("vacation"); vacation.add(new Label("username", trialMember.getUsername())); vacation.setVisible(trialMember.isVacation()); item.add(vacation); String text = "You have not yet voted"; if (myVote != null) { if (myVote.isInFavor()) { text = "You have voted in favor of " + trialMember.getUsername(); } else { text = "You have voted against " + trialMember.getUsername(); } } item.add(new Label("current", text)); } }); }
From source file:com.tysanclan.site.projectewok.pages.MemberPage.java
License:Open Source License
private void initComponents(User u) { super.setPageTitle(u.getUsername() + " - Member"); TimeZone tz = TimeZone.getTimeZone("America/New_York"); SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy", Locale.US); sdf.setTimeZone(tz);/*from w w w . j ava 2s . c o m*/ add(new Label("membersince", new Model<String>(sdf.format(u.getJoinDate())))); add(new Label("lastlogin", new Model<String>(u.getLastAction() != null ? sdf.format(u.getLastAction()) : null))); Profile profile = u.getProfile(); add(new Label("realname", profile != null && profile.getRealName() != null ? profile.getRealName() : "") .setVisible(profile != null && profile.getRealName() != null && getUser() != null && MemberUtil.isMember(getUser()))); WebMarkupContainer photo = new WebMarkupContainer("photo"); photo.setVisible(false); add(photo); if (profile != null && profile.getPhotoURL() != null) { photo.add(AttributeModifier.replace("src", profile.getPhotoURL())); photo.setVisible(profile.isPhotoPublic() || (getUser() != null && MemberUtil.isMember(getUser()))); } add(new Label("age", profile != null && profile.getBirthDate() != null ? Integer.toString(DateUtil.calculateAge(profile.getBirthDate())) : "Unknown").setVisible( profile != null && profile.getBirthDate() != null && u.getRank() != Rank.HERO)); add(new Label("username", u.getUsername())); WebMarkupContainer aboutMe = new WebMarkupContainer("aboutme"); aboutMe.add(new Label("publicDescription", profile != null && profile.getPublicDescription() != null ? profile.getPublicDescription() : "") .setEscapeModelStrings(false) .setVisible(profile != null && profile.getPublicDescription() != null)); aboutMe.add(new Label("privateDescription", profile != null && profile.getPrivateDescription() != null ? profile.getPrivateDescription() : "") .setEscapeModelStrings(false) .setVisible(profile != null && profile.getPrivateDescription() != null && getUser() != null && MemberUtil.isMember(getUser()))); add(aboutMe.setVisible(profile != null && (profile.getPublicDescription() != null || (profile.getPrivateDescription() != null && getUser() != null && MemberUtil.isMember(getUser()))))); GroupFilter gfilter = new GroupFilter(); gfilter.addIncludedMember(u); List<Group> groups = groupDAO.findByFilter(gfilter); add(new ListView<Group>("groups", ModelMaker.wrap(groups)) { private static final long serialVersionUID = 1L; /** * @see org.apache.wicket.markup.html.list.ListView#populateItem(org.apache.wicket.markup.html.list.ListItem) */ @Override protected void populateItem(ListItem<Group> item) { Group group = item.getModelObject(); item.add(new AutoGroupLink("name", group)); } }.setVisible(!groups.isEmpty())); RoleFilter rfilter = new RoleFilter(); rfilter.setUser(u); add(new Label("usernameroles", u.getUsername())); List<Role> roles = roleDAO.findByFilter(rfilter); add(new ListView<Role>("roles", ModelMaker.wrap(roles)) { private static final long serialVersionUID = 1L; /** * @see org.apache.wicket.markup.html.list.ListView#populateItem(org.apache.wicket.markup.html.list.ListItem) */ @Override protected void populateItem(ListItem<Role> item) { Role role = item.getModelObject(); item.add(new Label("name", role.getName())); item.add(new Label("description", role.getDescription()).setEscapeModelStrings(false)); } }.setVisible(!roles.isEmpty())); add(new RankIcon("rank", u.getRank())); add(new Label("rankName", u.getRank().toString())); if (u.getRank() == Rank.CHANCELLOR || u.getRank() == Rank.SENATOR) { if (u.getRank() == Rank.CHANCELLOR) { add(new ChancellorElectedSincePanel("electionDatePanel", u)); } else { add(new SenateElectedSincePanel("electionDatePanel", u)); } } else { add(new WebMarkupContainer("electionDatePanel").setVisible(false)); } ForumPostFilter filter = new ForumPostFilter(); filter.setShadow(false); filter.setUser(u); filter.addOrderBy("time", false); List<ForumPost> posts = forumPostDAO.findByFilter(filter); posts = forumService.filterPosts(getUser(), true, posts); List<ForumPost> topPosts = new LinkedList<ForumPost>(); for (int i = 0; i < Math.min(posts.size(), 5); i++) { topPosts.add(posts.get(i)); } ListView<ForumPost> lastPosts = new ListView<ForumPost>("lastposts", ModelMaker.wrap(topPosts)) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<ForumPost> item) { ForumPost post = item.getModelObject(); item.add(new AutoThreadLink("thread", post.getThread())); item.add(new DateTimeLabel("time", post.getTime())); } }; add(lastPosts.setVisible(!topPosts.isEmpty())); WebMarkupContainer container = new WebMarkupContainer("gamescontainer"); List<UserGameRealm> played = new LinkedList<UserGameRealm>(); played.addAll(u.getPlayedGames()); Collections.sort(played, new Comparator<UserGameRealm>() { /** * @see java.util.Comparator#compare(java.lang.Object, * java.lang.Object) */ @Override public int compare(UserGameRealm o1, UserGameRealm o2) { return o1.getGame().getName().compareToIgnoreCase(o2.getGame().getName()); } }); container.add(new ListView<UserGameRealm>("games", ModelMaker.wrap(played)) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<UserGameRealm> item) { UserGameRealm ugr = item.getModelObject(); item.add(new Label("game", ugr.getGame().getName())); item.add(new Label("realm", ugr.getRealm().getName())); StringBuilder builder = new StringBuilder(); for (GameAccount account : ugr.getAccounts()) { if (builder.length() > 0) { builder.append(", "); } builder.append(account.getName()); } if (builder.length() == 0) { builder.append('-'); } item.add(new Label("accounts", builder.toString())); } }); add(container); boolean twitviz = profile != null && profile.getTwitterUID() != null; add(new Label("twitterhead", u.getUsername() + " on Twitter").setVisible(twitviz)); String url = "http://twitter.com/" + (twitviz && profile != null ? profile.getTwitterUID() : ""); add(new Label("twitterprofile", url).add(AttributeModifier.replace("href", url))); add(new AchievementsPanel("achievements", u)); add(new IconLink.Builder("images/icons/email_add.png", new DefaultClickResponder<User>(ModelMaker.wrap(u)) { private static final long serialVersionUID = 1L; @Override public void onClick() { setResponsePage(new MessageListPage(getModelObject())); } }).setText("Send Message").newInstance("sendMessage") .setVisible(getUser() != null && MemberUtil.isMember(getUser()))); }
From source file:de.alpharogroup.wicket.dialogs.examples.HomePage.java
License:Apache License
/** * Constructor that is invoked when page is invoked without a session. * * @param parameters/* w ww . ja v a 2 s . com*/ * Page parameters */ public HomePage(final PageParameters parameters) { final WebMarkupContainer wmc = new WebMarkupContainer("comments"); wmc.setOutputMarkupId(true); final List<MessageBean> noteList = new ArrayList<MessageBean>(); final MessageBean messageBean = new MessageBean(); messageBean.setMessageContent("hello"); final IModel<MessageBean> dialogModel = new CompoundPropertyModel<MessageBean>(messageBean); final ModalWindow modalWindow = new BaseModalWindow<MessageBean>("baseModalWindow", dialogModel, "Title", 350, 160) { /** * The serialVersionUID. */ private static final long serialVersionUID = 1L; @Override public void onCancel(final AjaxRequestTarget target) { target.add(wmc); close(target); } @Override public void onSelect(final AjaxRequestTarget target, final MessageBean object) { final MessageBean clone = (MessageBean) WicketObjects.cloneObject(object); noteList.add(clone); // Clear the content from textarea in the dialog. object.setMessageContent(""); target.add(wmc); close(target); } }; modalWindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY); modalWindow.setResizable(false); add(modalWindow); final AjaxLink<String> linkToModalWindow = new AjaxLink<String>("linkToModalWindow") { /** * The serialVersionUID. */ private static final long serialVersionUID = 1L; @Override public void onClick(final AjaxRequestTarget target) { modalWindow.show(target); } }; // Add the WebMarkupContainer... add(wmc); final Label linkToModalWindowLabel = new Label("linkToModalWindowLabel", "show modal dialog"); linkToModalWindow.add(linkToModalWindowLabel); // The AjaxLink to open the modal window add(linkToModalWindow); // here we have to set the message content from the bean in a repeater... final ListView<MessageBean> repliesAndNotesListView = new ListView<MessageBean>("repliesAndNotesListView", noteList) { /** * The serialVersionUID. */ private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<MessageBean> item) { final MessageBean repliesandnotes = item.getModelObject(); item.add(new RepliesandnotesPanel("repliesandnotesPanel", repliesandnotes)); } }; repliesAndNotesListView.setVisible(true); wmc.add(repliesAndNotesListView); @SuppressWarnings("rawtypes") final Link showUploadPage = new Link("showUploadPage") { /** * */ private static final long serialVersionUID = 1L; @Override public void onClick() { setResponsePage(new UploadPage(getPageParameters())); } }; add(showUploadPage); add(new ModalDialogWithStylePanel("modalDialogWithStylePanel", Model.of("bla"))); }
From source file:edu.colorado.phet.website.panels.simulation.SimulationMainPanel.java
public SimulationMainPanel(String id, final LocalizedSimulation simulation, final PageContext context) { super(id, context); String simulationVersionString = simulation.getSimulation().getProject().getVersionString(); add(new Label("simulation-main-title", simulation.getTitle())); //add( HeaderContributor.forCss( CSS.SIMULATION_MAIN ) ); if (simulation.getLocale().equals(context.getLocale())) { add(new InvisibleComponent("untranslated-sim-text")); } else {//from www . ja va 2s . com add(new LocalizedText("untranslated-sim-text", "simulationMainPanel.untranslatedMessage")); } RawLink link = simulation.getRunLink("simulation-main-link-run-main"); WebImage image = (simulation.getSimulation().isHTML()) ? simulation.getSimulation().getHTMLImage() : simulation.getSimulation().getImage(); link.add(new StaticImage("simulation-main-screenshot", image, StringUtils.messageFormat(getPhetLocalizer().getString("simulationMainPanel.screenshot.alt", this), new Object[] { encode(simulation.getTitle()) }))); if (simulation.getSimulation().isHTML()) { WebMarkupContainer html5Badge = new WebMarkupContainer("html5-badge"); link.add(html5Badge); html5Badge.add(new SimpleAttributeModifier("class", "sim-badge-html")); html5Badge.add(new SimpleAttributeModifier("style", "left: 284px")); } else { link.add(new InvisibleComponent("html5-badge")); } add(link); //add( new Label( "simulation-main-description", simulation.getDescription() ) ); add(new LocalizedText("simulation-main-description", simulation.getSimulation().getDescriptionKey())); add(new LocalizedText("simulationMainPanel.version", "simulationMainPanel.version", new Object[] { HtmlUtils.encode(simulationVersionString), })); { String name = simulation.getSimulation().getName(); if (HTML_SIM_LINK_MAP.containsKey(name)) { WebMarkupContainer container = new WebMarkupContainer("html-button"); // TODO: isolate specific HTML5 sim links out! container.add(new RawLink("html-link", HTML_SIM_LINK_MAP.get(name))); add(container); } else { add(new InvisibleComponent("html-button")); } } add(DonatePanel.getLinker().getLink("donate-link", context, getPhetCycle())); // SmallOrangeButtonBorder orangeButton = new SmallOrangeButtonBorder( "orange-button", context ); // add( orangeButton ); // orangeButton.add( DonatePanel.getLinker().getLink( "support-link", context, getPhetCycle() ) ); /*---------------------------------------------------------------------------* * rating icons *----------------------------------------------------------------------------*/ if (simulation.getSimulation().isUnderConstruction()) { Link uclink = AboutLegendPanel.getLinker().getLink("rating-under-construction-link", context, getPhetCycle()); uclink.add(new StaticImage("rating-under-construction-image", Images.UNDER_CONSTRUCTION_SMALL, getPhetLocalizer().getString("tooltip.legend.underConstruction", this))); add(uclink); } else { add(new InvisibleComponent("rating-under-construction-link")); } if (simulation.getSimulation().isGuidanceRecommended()) { Link uclink = AboutLegendPanel.getLinker().getLink("rating-guidance-recommended-link", context, getPhetCycle()); uclink.add(new StaticImage("rating-guidance-recommended-image", Images.GUIDANCE_RECOMMENDED_SMALL, getPhetLocalizer().getString("tooltip.legend.guidanceRecommended", this))); add(uclink); } else { add(new InvisibleComponent("rating-guidance-recommended-link")); } if (simulation.getSimulation().isClassroomTested()) { Link uclink = AboutLegendPanel.getLinker().getLink("rating-classroom-tested-link", context, getPhetCycle()); uclink.add(new StaticImage("rating-classroom-tested-image", Images.CLASSROOM_TESTED_SMALL, getPhetLocalizer().getString("tooltip.legend.classroomTested", this))); add(uclink); } else { add(new InvisibleComponent("rating-classroom-tested-link")); } /*---------------------------------------------------------------------------* * teacher's guide *----------------------------------------------------------------------------*/ final List<TeachersGuide> guides = new LinkedList<TeachersGuide>(); HibernateUtils.wrapTransaction(getHibernateSession(), new HibernateTask() { public boolean run(Session session) { List li = session.createQuery("select tg from TeachersGuide as tg where tg.simulation = :sim") .setEntity("sim", simulation.getSimulation()).list(); if (!li.isEmpty()) { guides.add((TeachersGuide) li.get(0)); } return true; } }); if (!guides.isEmpty()) { add(new LocalizedText("guide-text", "simulationMainPanel.teachersGuide", new Object[] { guides.get(0).getLinker().getHref(context, getPhetCycle()) })); // Label visLabel = new Label( "tips-for-teachers-visible", "" ); // visLabel.setRenderBodyOnly( true ); // don't make anything appear // add( visLabel ); hasTeacherTips = true; } else { // make the teachers guide text (and whole section) invisible add(new InvisibleComponent("guide-text")); // add( new InvisibleComponent( "tips-for-teachers-visible" ) ); hasTeacherTips = false; } /*---------------------------------------------------------------------------* * contributions *----------------------------------------------------------------------------*/ if (DistributionHandler.displayContributions(getPhetCycle())) { final List<Contribution> contributions = new LinkedList<Contribution>(); HibernateUtils.wrapTransaction(getHibernateSession(), new HibernateTask() { public boolean run(Session session) { List list = session.createQuery( "select c from Contribution as c where :simulation member of c.simulations and c.approved = true") .setEntity("simulation", simulation.getSimulation()).list(); for (Object o : list) { Contribution contribution = (Contribution) o; contributions.add(contribution); // we need to read levels contribution.getLevels(); // we also need to read the types contribution.getTypes(); for (Object x : contribution.getSimulations()) { Simulation sim = (Simulation) x; // we need to be able to read these to determine the localized simulation title later sim.getLocalizedSimulations(); } } return true; } }); add(new ContributionBrowsePanel("contributions-panel", context, contributions, false)); // Label visLabel = new Label( "teacher-ideas-visible", "" ); // visLabel.setRenderBodyOnly( true ); // don't make anything appear // add( visLabel ); } else { add(new InvisibleComponent("contributions-panel")); // add( new InvisibleComponent( "teacher-ideas-visible" ) ); } /*---------------------------------------------------------------------------* * translations *----------------------------------------------------------------------------*/ List<LocalizedSimulation> simulations = HibernateUtils.getLocalizedSimulationsMatching( getHibernateSession(), null, simulation.getSimulation().getName(), null); HibernateUtils.orderSimulations(simulations, context.getLocale()); List<LocalizedSimulation> otherLocalizedSimulations = new LinkedList<LocalizedSimulation>(); // TODO: improve model? for (final LocalizedSimulation sim : simulations) { if (!sim.getLocale().equals(simulation.getLocale())) { otherLocalizedSimulations.add(sim); } } // TODO: allow localization of locale display names ListView simulationList = new ListView<LocalizedSimulation>("simulation-main-translation-list", otherLocalizedSimulations) { protected void populateItem(ListItem<LocalizedSimulation> item) { LocalizedSimulation simulation = item.getModelObject(); Locale simLocale = simulation.getLocale(); RawLink runLink = simulation.getRunLink("simulation-main-translation-link"); RawLink downloadLink = simulation.getDownloadLink("simulation-main-translation-download"); String defaultLanguageName = simLocale.getDisplayName(context.getLocale()); String languageName = ((PhetLocalizer) getLocalizer()).getString( "language.names." + LocaleUtils.localeToString(simLocale), this, null, defaultLanguageName, false); item.add(runLink); if (DistributionHandler.displayJARLink(getPhetCycle(), simulation)) { item.add(downloadLink); } else { item.add(new InvisibleComponent("simulation-main-translation-download")); } item.add(new Label("simulation-main-translation-title", simulation.getTitle())); Link lang1 = TranslatedSimsPage.getLinker(simLocale).getLink("language-link-1", context, getPhetCycle()); item.add(lang1); Link lang2 = TranslatedSimsPage.getLinker(simLocale).getLink("language-link-2", context, getPhetCycle()); item.add(lang2); lang1.add(new Label("simulation-main-translation-locale-name", languageName)); lang2.add(new Label("simulation-main-translation-locale-translated-name", simLocale.getDisplayName(simLocale))); WicketUtils.highlightListItem(item); } }; add(simulationList); /*---------------------------------------------------------------------------* * run / download links *----------------------------------------------------------------------------*/ // TODO: move from direct links to page redirections, so bookmarkables will be minimized RawLink runOnlineLink = simulation.getRunLink("run-online-link"); add(runOnlineLink); RawLink downloadLink = simulation.getDownloadLink("run-offline-link"); add(downloadLink); if (getPhetCycle().isInstaller()) { add(new InvisibleComponent("embed-button")); } else { add(new WebMarkupContainer("embed-button")); } final String directEmbedText = simulation.getDirectEmbeddingSnippet(); String indirectEmbedText = simulation .getClickToLaunchSnippet(getPhetLocalizer().getString("embed.clickToLaunch", this)); if (directEmbedText != null) { add(new Label("direct-embed-text", directEmbedText)); } else { add(new InvisibleComponent("direct-embed-text")); } add(new Label("indirect-embed-text", indirectEmbedText) { { if (directEmbedText == null) { // if we can't directly embed, set our markup ID so that this text is automatically selected setMarkupId("embeddable-text"); setOutputMarkupId(true); } } }); /*---------------------------------------------------------------------------* * keywords / topics *----------------------------------------------------------------------------*/ List<Keyword> keywords = new LinkedList<Keyword>(); List<Keyword> topics = new LinkedList<Keyword>(); // TODO: improve handling here Transaction tx = null; try { Session session = getHibernateSession(); tx = session.beginTransaction(); Simulation sim = (Simulation) session.load(Simulation.class, simulation.getSimulation().getId()); //System.out.println( "Simulation keywords for " + sim.getName() ); for (Object o : sim.getKeywords()) { Keyword keyword = (Keyword) o; keywords.add(keyword); //System.out.println( keyword.getKey() ); } for (Object o : sim.getTopics()) { Keyword keyword = (Keyword) o; topics.add(keyword); //System.out.println( keyword.getKey() ); } tx.commit(); } catch (RuntimeException e) { logger.warn("Exception: " + e); if (tx != null && tx.isActive()) { try { tx.rollback(); } catch (HibernateException e1) { logger.error("ERROR: Error rolling back transaction", e1); } throw e; } } ListView topicList = new ListView<Keyword>("topic-list", topics) { protected void populateItem(ListItem<Keyword> item) { Keyword keyword = item.getModelObject(); item.add(new RawLabel("topic-label", new ResourceModel(keyword.getKey()))); } }; add(topicList); if (topics.isEmpty()) { topicList.setVisible(false); } ListView keywordList = new ListView<Keyword>("keyword-list", keywords) { protected void populateItem(ListItem<Keyword> item) { Keyword keyword = item.getModelObject(); Link link = SimsByKeywordPage.getLinker(keyword.getSubKey()).getLink("keyword-link", context, getPhetCycle()); // Link link = new StatelessLink( "keyword-link" ) { // public void onClick() { // // TODO: fill in keyword links! // } // }; link.add(new RawLabel("keyword-label", new ResourceModel(keyword.getKey()))); item.add(link); } }; add(keywordList); if (keywords.isEmpty()) { keywordList.setVisible(false); } /*---------------------------------------------------------------------------* * system requirements *----------------------------------------------------------------------------*/ /* * Requirements are laid out in 3 columns for java/flash sims and 4 columns for * HTML sims. Depending on the sim type, different content gets added to each * column. */ List<String> column1 = new LinkedList<String>(); List<String> column2 = new LinkedList<String>(); List<String> column3 = new LinkedList<String>(); List<String> column4 = new LinkedList<String>(); // column headers for java/flash sims if (!simulation.getSimulation().isHTML()) { add(new Label("column1-header", "Windows")); add(new Label("column2-header", "Macintosh")); add(new Label("column3-header", "Linux")); add(new InvisibleComponent("column4-header")); column1.add("Microsoft Windows"); column1.add("XP/Vista/7"); column2.add("OS 10.5 or later"); } // column headers for HTML sims else { add(new Label("column1-header", "Windows 7+ PCs")); add(new Label("column2-header", "Mac OS 10.7+ PCs")); add(new Label("column3-header", "iPad and iPad Mini with iOS")); add(new Label("column4-header", "Chromebook with Chrome OS")); } // column content for different sim types if (simulation.getSimulation().isJava()) { column1.add("Sun Java 1.5.0_15 or later"); column2.add("Sun Java 1.5.0_19 or later"); column3.add("Sun Java 1.5.0_15 or later"); } else if (simulation.getSimulation().isFlash()) { column1.add("Macromedia Flash 9 or later"); column2.add("Macromedia Flash 9 or later"); column3.add("Macromedia Flash 9 or later"); } else if (simulation.getSimulation().isHTML()) { column1.add("Internet Explorer 10+"); column1.add("latest versions of Chrome and Firefox"); column2.add("Safari 6.1 and up"); column2.add("latest versions of Chrome and Firefox"); column3.add("latest version of Safari"); column4.add("latest version of Chrome"); } // Add a list view for each column ListView column1View = new ListView<String>("column1-list", column1) { protected void populateItem(ListItem<String> item) { String str = item.getModelObject(); item.add(new Label("column1-item", str)); } }; add(column1View); ListView column2View = new ListView<String>("column2-list", column2) { protected void populateItem(ListItem<String> item) { String str = item.getModelObject(); item.add(new Label("column2-item", str)); } }; add(column2View); ListView column3View = new ListView<String>("column3-list", column3) { protected void populateItem(ListItem<String> item) { String str = item.getModelObject(); item.add(new Label("column3-item", str)); } }; add(column3View); // show column4 only for HTML sims if (simulation.getSimulation().isHTML()) { ListView column4View = new ListView<String>("column4-list", column4) { protected void populateItem(ListItem<String> item) { String str = item.getModelObject(); item.add(new Label("column4-item", str)); } }; add(column4View); } else { // column 4 is invisible for legacy sims add(new InvisibleComponent("column4-list")); } // so we don't emit an empty <table></table> that isn't XHTML Strict compatible if (otherLocalizedSimulations.isEmpty()) { simulationList.setVisible(false); } PhetLocalizer localizer = (PhetLocalizer) getLocalizer(); /*---------------------------------------------------------------------------* * title *----------------------------------------------------------------------------*/ // we initialize the title in the panel. then whatever page that wants to adopt this panel's "title" as the page // title can List<String> titleParams = new LinkedList<String>(); titleParams.add(simulation.getEncodedTitle()); for (Keyword keyword : keywords) { titleParams.add(localizer.getString(keyword.getKey(), this)); } if (keywords.size() < 3) { title = simulation.getEncodedTitle(); } else { try { title = StringUtils.messageFormat(localizer.getString("simulationPage.title", this), titleParams.toArray()); } catch (RuntimeException e) { e.printStackTrace(); title = simulation.getEncodedTitle(); } } addCacheParameter("title", title); /*---------------------------------------------------------------------------* * related simulations *----------------------------------------------------------------------------*/ List<LocalizedSimulation> relatedSimulations = getRelatedSimulations(simulation); if (relatedSimulations.isEmpty()) { add(new InvisibleComponent("related-simulations-panel")); add(new InvisibleComponent("related-simulations-visible")); } else { add(new SimulationDisplayPanel("related-simulations-panel", context, relatedSimulations)); add(new RawBodyLabel("related-simulations-visible", "")); // visible but shows nothing, so the related simulations "see below" shows up } /*---------------------------------------------------------------------------* * more info (design team, libraries, thanks, etc *----------------------------------------------------------------------------*/ List<String> designTeam = new LinkedList<String>(); List<String> libraries = new LinkedList<String>(); List<String> thanks = new LinkedList<String>(); List<String> learningGoals = new LinkedList<String>(); String rawDesignTeam = simulation.getSimulation().getDesignTeam(); if (rawDesignTeam != null) { for (String item : rawDesignTeam.split("<br/>")) { if (item != null && item.length() > 0) { designTeam.add(item); } } } String rawLibraries = simulation.getSimulation().getLibraries(); if (rawLibraries != null) { for (String item : rawLibraries.split("<br/>")) { if (item != null && item.length() > 0) { libraries.add(item); } } } String rawThanks = simulation.getSimulation().getThanksTo(); if (rawThanks != null) { for (String item : rawThanks.split("<br/>")) { if (item != null && item.length() > 0) { thanks.add(item); } } } String rawLearningGoals = getLocalizer().getString(simulation.getSimulation().getLearningGoalsKey(), this); if (rawLearningGoals != null) { for (String item : rawLearningGoals.split("<br/>")) { if (item != null && item.length() > 0) { learningGoals.add(item); } } } ListView designView = new ListView<String>("design-list", designTeam) { protected void populateItem(ListItem<String> item) { String str = item.getModelObject(); item.add(new Label("design-item", str)); } }; if (designTeam.isEmpty()) { designView.setVisible(false); } add(designView); ListView libraryView = new ListView<String>("library-list", libraries) { protected void populateItem(ListItem<String> item) { String str = item.getModelObject(); item.add(new Label("library-item", str)); } }; if (libraries.isEmpty()) { libraryView.setVisible(false); } add(libraryView); ListView thanksView = new ListView<String>("thanks-list", thanks) { protected void populateItem(ListItem<String> item) { String str = item.getModelObject(); item.add(new Label("thanks-item", str)); } }; if (thanks.isEmpty()) { thanksView.setVisible(false); } add(thanksView); // TODO: consolidate common behavior for these lists ListView learningGoalsView = new ListView<String>("learning-goals", learningGoals) { protected void populateItem(ListItem<String> item) { String str = item.getModelObject(); item.add(new RawLabel("goal", str)); } }; if (learningGoals.isEmpty()) { learningGoalsView.setVisible(false); } add(learningGoalsView); addDependency(new EventDependency() { private IChangeListener projectListener; private IChangeListener stringListener; private IChangeListener teacherGuideListener; @Override protected void addListeners() { projectListener = new AbstractChangeListener() { public void onUpdate(Object object, PostUpdateEvent event) { if (HibernateEventListener.getSafeHasChanged(event, "visible")) { invalidate(); } } }; teacherGuideListener = new AbstractChangeListener() { @Override public void onInsert(Object object, PostInsertEvent event) { TeachersGuide guide = (TeachersGuide) object; if (guide.getSimulation().getId() == simulation.getSimulation().getId()) { invalidate(); } } @Override public void onUpdate(Object object, PostUpdateEvent event) { TeachersGuide guide = (TeachersGuide) object; if (guide.getSimulation().getId() == simulation.getSimulation().getId()) { invalidate(); } } @Override public void onCollectionUpdate(Object object, PostCollectionUpdateEvent event) { TeachersGuide guide = (TeachersGuide) object; if (guide.getSimulation().getId() == simulation.getSimulation().getId()) { invalidate(); } } @Override public void onDelete(Object object, PostDeleteEvent event) { TeachersGuide guide = (TeachersGuide) object; if (guide.getSimulation().getId() == simulation.getSimulation().getId()) { invalidate(); } } }; stringListener = createTranslationChangeInvalidator(context.getLocale()); HibernateEventListener.addListener(Project.class, projectListener); HibernateEventListener.addListener(TranslatedString.class, stringListener); HibernateEventListener.addListener(Simulation.class, getAnyChangeInvalidator()); HibernateEventListener.addListener(LocalizedSimulation.class, getAnyChangeInvalidator()); } @Override protected void removeListeners() { HibernateEventListener.removeListener(Project.class, projectListener); HibernateEventListener.removeListener(TranslatedString.class, stringListener); HibernateEventListener.removeListener(Simulation.class, getAnyChangeInvalidator()); HibernateEventListener.removeListener(LocalizedSimulation.class, getAnyChangeInvalidator()); } }); if (DistributionHandler.showSimSponsor(getPhetCycle())) { // this gets cached, so it will stay the same for the sim (but will be different for different sims) add(new SimSponsorPanel("pearson-sponsor", context, Sponsor.chooseRandomSimSponsor())); } else { add(new InvisibleComponent("pearson-sponsor")); } if (getPhetCycle().isInstaller()) { add(new WebMarkupContainer("sim-sponsor-installer-js")); } else { add(new InvisibleComponent("sim-sponsor-installer-js")); } add(new LocalizedText("submit-a", "simulationMainPanel.submitActivities", new Object[] { ContributionCreatePage.getLinker().getHref(context, getPhetCycle()) })); /*---------------------------------------------------------------------------* * FAQ *----------------------------------------------------------------------------*/ if (simulation.getSimulation().isFaqVisible() && simulation.getSimulation().getFaqList() != null) { add(new LocalizedText("faq-text", "simulationMainPanel.simulationHasFAQ", new Object[] { SimulationFAQPage.getLinker(simulation).getHref(context, getPhetCycle()), simulation.getSimulation().getFaqList().getPDFLinker(getMyLocale()).getHref(context, getPhetCycle()) })); } else { add(new InvisibleComponent("faq-text")); } /*---------------------------------------------------------------------------* * metadata *----------------------------------------------------------------------------*/ // add the necessary license meta tags for our license list add(new ListView<String>("license-list", simulation.getSimulation().getLicenseURLs()) { @Override protected void populateItem(final ListItem<String> item) { item.add(new WebMarkupContainer("license-meta-tag") { { add(new AttributeModifier("content", true, new Model<String>(item.getModelObject()))); } }); } }); add(new WebMarkupContainer("schema-thumbnail") { { add(new AttributeModifier("content", true, new Model<String>( StringUtils.makeUrlAbsoluteProduction(simulation.getSimulation().getThumbnailUrl())))); } }); if (simulation.getSimulation().getCreateTime() != null) { add(new WebMarkupContainer("schema-date-created") { { add(new AttributeModifier("content", true, new Model<String>( WebsiteConstants.ISO_8601.format(simulation.getSimulation().getCreateTime())))); } }); } else { add(new InvisibleComponent("schema-date-created")); } if (simulation.getSimulation().getUpdateTime() != null) { add(new WebMarkupContainer("schema-date-modified") { { add(new AttributeModifier("content", true, new Model<String>( WebsiteConstants.ISO_8601.format(simulation.getSimulation().getUpdateTime())))); } }); } else { add(new InvisibleComponent("schema-date-modified")); } List<Alignment> alignments = new ArrayList<Alignment>(); alignments.addAll(simulation.getSimulation().getAlignments()); alignments.addAll(simulation.getSimulation().getSecondaryAlignments()); add(new ListView<Alignment>("alignment-list", alignments) { @Override protected void populateItem(final ListItem<Alignment> item) { item.add(new WebMarkupContainer("alignment") { { add(new AttributeModifier("content", true, new Model<String>(item.getModelObject().getUrl()))); } }); } }); add(new WebMarkupContainer("schema-inLanguage") { { // currently, we fake BCP 47 somewhat by replacing the underscore with a dash if necessary add(new AttributeModifier("content", true, new Model<String>(simulation.getLocaleString().replace('_', '-')))); } }); }