@Override protected void initLayout() { final List<RichHyperlinkType> linksList = getModel().getObject(); RepeatingView rowView = new RepeatingView(ID_LINKS_ROW); int linksListSize = linksList == null ? 0 : linksList.size(); if (linksListSize > 0) { int currentColumn = 0; RepeatingView columnView = null; WebMarkupContainer row = null; boolean isRowAdded = false; for (int i = 0; i < linksListSize; i++) { final RichHyperlinkType link = linksList.get(i); if (WebMiscUtil.isAuthorized(link.getAuthorization())) { if (currentColumn == 0) { row = new WebMarkupContainer(rowView.newChildId()); isRowAdded = false; columnView = new RepeatingView(ID_LINKS_COLUMN); } WebMarkupContainer column = new WebMarkupContainer(columnView.newChildId()); Link linkItem = new Link(ID_LINK) { @Override public void onClick() {} @Override protected void onComponentTag(final ComponentTag tag) { super.onComponentTag(tag); String rootContext = ""; if (link.getTargetUrl() != null && !link.getTargetUrl().startsWith("http://") && !link.getTargetUrl().startsWith("https://") && !link.getTargetUrl().startsWith("www://") && !link.getTargetUrl().startsWith("//")) { WebApplication webApplication = WebApplication.get(); if (webApplication != null) { ServletContext servletContext = webApplication.getServletContext(); if (servletContext != null) { rootContext = servletContext.getContextPath(); } } } tag.put("href", rootContext + link.getTargetUrl()); } }; linkItem.add( new Label(ID_IMAGE) { @Override protected void onComponentTag(final ComponentTag tag) { super.onComponentTag(tag); String cssClass = ICON_DEFAULT_CSS_CLASS; if (link.getIcon() != null) { cssClass = link.getIcon().getCssClass(); } tag.put( "class", "info-box-icon " + (link.getColor() != null ? (link.getColor().startsWith("bg-") ? link.getColor() : "bg-" + link.getColor()) : "") + " " + cssClass); } }); linkItem.add( new Label( ID_LABEL, new Model<String>() { public String getObject() { return link.getLabel(); } })); Label description = new Label( ID_DESCRIPTION, new Model<String>() { public String getObject() { return link.getDescription(); } }); description.setEnabled(false); linkItem.add(description); column.add(linkItem); columnView.add(column); if (currentColumn == 1 || (linksList.indexOf(link) == linksListSize - 1)) { row.add(columnView); rowView.add(row); currentColumn = 0; isRowAdded = true; } else { currentColumn++; } } else { LOGGER.trace("Link {} not authorized, skipping", link); } } if (row != null && columnView != null && !isRowAdded) { row.add(columnView); rowView.add(row); } } add(rowView); }
public TCViewBibliographyTab( final String id, IModel<TCEditableObject> model, TCAttributeVisibilityStrategy attrVisibilityStrategy) { super(id, model, attrVisibilityStrategy); list = new ListView<String>("tc-view-bibliography-list", new ListModelWrapper()) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<String> item) { // textarea final TextArea<String> area = new SelfUpdatingTextArea("tc-view-bibliography-text", item.getModelObject()) { @Override protected void textUpdated(String text) { ((ListModelWrapper) list.getModel()).setReference(item.getIndex(), text); } }; area.setOutputMarkupId(true); area.setEnabled(isEditing()); area.add(createTextInputCssClassModifier()); // remove button final AbstractLink removeBtn = new AjaxLink<Void>("tc-view-bibliography-remove-btn") { @Override public void onClick(AjaxRequestTarget target) { try { ((ListModelWrapper) list.getModel()).removeReference(item.getIndex()); target.addComponent(title); target.addComponent(listContainer); target.appendJavascript("updateTCViewDialog();"); tabTitleChanged(target); if (tabTitleComponent != null) { target.addComponent(tabTitleComponent); } } catch (Exception e) { log.error("Removing bibliographic reference from teaching-file failed!", e); } } }; removeBtn.add( new Image("tc-view-bibliography-remove-img", ImageManager.IMAGE_TC_CANCEL_MONO) .add(new ImageSizeBehaviour("vertical-align: middle;"))); removeBtn.add(new TooltipBehaviour("tc.view.bibliography", "remove")); removeBtn.setOutputMarkupId(true); removeBtn.setVisible(isEditing()); removeBtn.add( new AttributeModifier( "onmouseover", true, new Model<String>( "$(this).children('img').attr('src','" + RequestCycle.get().urlFor(ImageManager.IMAGE_TC_CANCEL) + "');"))); removeBtn.add( new AttributeModifier( "onmouseout", true, new Model<String>( "$(this).children('img').attr('src','" + RequestCycle.get().urlFor(ImageManager.IMAGE_TC_CANCEL_MONO) + "');"))); item.setOutputMarkupId(true); item.add(area); item.add(removeBtn); } }; listContainer = new WebMarkupContainer("tc-view-bibliography-container"); listContainer.setOutputMarkupId(true); listContainer.setMarkupId("tc-view-bibliography-container"); listContainer.add(list); title = new Label( "tc-view-bibliography-title-text", new AbstractReadOnlyModel<String>() { @Override public String getObject() { String s = title.getString("tc.view.bibliography.number.text"); List<String> refs = list.getModelObject(); return MessageFormat.format(s, refs != null ? refs.size() : 0); } }); title.setOutputMarkupId(true); addBtn = new AjaxLink<Void>("tc-view-bibliography-add-btn") { @Override public void onClick(AjaxRequestTarget target) { try { ((ListModelWrapper) list.getModel()) .addReference(addBtn.getString("tc.view.bibliography.reference.defaulttext")); target.addComponent(title); target.addComponent(listContainer); target.appendJavascript("updateTCViewDialog();"); tabTitleChanged(target); if (tabTitleComponent != null) { target.addComponent(tabTitleComponent); } } catch (Exception e) { log.error("Adding new bibliographic reference to teachign-file failed!", e); } } }; addBtn.add( new Image("tc-view-bibliography-add-img", ImageManager.IMAGE_COMMON_ADD) .add(new ImageSizeBehaviour("vertical-align: middle;"))); addBtn.add( new Label( "tc-view-bibliography-add-text", new ResourceModel("tc.view.bibliography.add.text"))); addBtn.add(new TooltipBehaviour("tc.view.bibliography", "add")); addBtn.setMarkupId("tc-view-bibliography-add-btn"); title.setEnabled(isEditing()); addBtn.setVisible(isEditing()); listContainer.setEnabled(isEditing()); add(title); add(addBtn); add(listContainer); }