List of usage examples for org.apache.wicket.ajax AjaxRequestTarget prependJavaScript
void prependJavaScript(CharSequence javascript);
From source file:org.artifactory.common.wicket.component.panel.sortedlist.OrderedListPanel.java
License:Open Source License
public void refresh(AjaxRequestTarget target) { target.add(get("items")); target.add(get("title")); target.add(get("listIndices")); target.add(get("moveDownLink")); target.add(get("moveUpLink")); target.add(get("initScript")); target.prependJavaScript("LinksColumn.hideCurrent();"); }
From source file:org.cast.isi.ISIXmlComponent.java
License:Open Source License
@Override public Component getDynamicComponent(final String wicketId, final Element elt) { if (wicketId.startsWith("object_")) { NodeList nodes = elt.getChildNodes(); String archive = null;//from www . ja v a 2 s . c o m String dataFile = null; for (int i = 0; i < nodes.getLength(); i++) { Node nextNode = nodes.item(i); if (nextNode instanceof Element) { Element next = (Element) nodes.item(i); if (next.getAttribute("name").equals("archive")) { archive = next.getAttribute("value"); } else if (next.getAttribute("name").equals("dataFile")) { dataFile = next.getAttribute("value"); } } } if (archive != null) { String jarUrl = RequestCycle.get().urlFor(getRelativeRef(archive + ".jar"), new PageParameters()) .toString(); String dataUrl = RequestCycle.get().urlFor(getRelativeRef(dataFile), new PageParameters()) .toString(); DeployJava dj = new DeployJava(wicketId); dj.setArchive(jarUrl); dj.setCode(elt.getAttribute("src")); dj.addParameter("dataFile", dataUrl); return dj; } return super.getDynamicComponent(wicketId, elt); // link to a short glossary definition modal or main glossary window } else if (wicketId.startsWith("glossaryLink_")) { IModel<String> wordModel = new Model<String>(elt.getAttribute("word")); String glossaryLinkType = ISIApplication.get().getGlossaryLinkType(); if (glossaryLinkType.equals(ISIApplication.GLOSSARY_TYPE_MODAL) && pageHasMiniGlossary() && miniGlossaryModal != null) { return new MiniGlossaryLink(wicketId, wordModel, miniGlossaryModal); } else if (glossaryLinkType.equals(ISIApplication.GLOSSARY_TYPE_INLINE)) { return new EmptyPanel(wicketId); } else { // Default case: glossary type is MAIN, or we wanted a modal but have no place to put it // (eg, we're in a popup window, or modal window) GlossaryLink glossaryLink = new GlossaryLink(wicketId, wordModel); ISIApplication.get().setLinkProperties(glossaryLink); return glossaryLink; } // inline glossary: linked word } else if (wicketId.startsWith("glossword")) { WebMarkupContainer glossaryWord = new WebMarkupContainer(wicketId); glossaryWord .setVisible(ISIApplication.get().glossaryLinkType.equals(ISIApplication.GLOSSARY_TYPE_INLINE)); return glossaryWord; // inline glossary: definition } else if (wicketId.startsWith("glossdef")) { // Span element, to be filled in with the glossary short def. String word = elt.getAttribute("word"); final String def = ISIApplication.get().getGlossary().getShortDefById(word); WebMarkupContainer container; container = new WebMarkupContainer(wicketId) { private static final long serialVersionUID = 1L; @Override public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { replaceComponentTagBody(markupStream, openTag, def); } }; container.add(new AttributeRemover("word")); container.setVisible(ISIApplication.get().glossaryLinkType.equals(ISIApplication.GLOSSARY_TYPE_INLINE)); return container; // inline glossary: "more" link to main glossary window } else if (wicketId.startsWith("glosslink")) { IModel<String> wordModel = new Model<String>(elt.getAttribute("word")); GlossaryLink glossaryLink = new GlossaryLink(wicketId, wordModel); ISIApplication.get().setLinkProperties(glossaryLink); glossaryLink .setVisible(ISIApplication.get().glossaryLinkType.equals(ISIApplication.GLOSSARY_TYPE_INLINE)); return glossaryLink; } else if (wicketId.startsWith("link_")) { String href = elt.getAttribute("href"); // According to NIMAS, href should be in the form "filename.xml#ID" or just "#ID" for within-file link // For authors' convenience, we accept simple "ID" as well. int hashLocation = href.indexOf('#'); if (hashLocation > 0) { // filename#ID case return new SectionLinkFactory().linkTo(wicketId, href.substring(0, hashLocation), href.substring(hashLocation + 1)); } // "#ID" or "ID" case: String file = getModel().getObject().getXmlDocument().getName(); // same file as we're currently viewing String id = href.substring(hashLocation + 1); // start at index 0 or 1 return new SectionLinkFactory().linkTo(wicketId, file, id); } else if (wicketId.startsWith("popupLink_")) { String href = elt.getAttribute("href"); // According to NIMAS, href should be in the form "filename.xml#ID" or just "#ID" for within-file link // For authors' convenience, we accept simple "ID" as well. int hashLocation = href.indexOf('#'); String file; if (hashLocation > 0) { file = href.substring(0, hashLocation); } else { // "#ID" or "ID" case: file = getModel().getObject().getXmlDocument().getName(); // same file as we're currently viewing } XmlDocument document = xmlService.getDocument(file); String xmlId = href.substring(hashLocation + 1); XmlSection section = document.getById(xmlId); XmlSectionModel mSection = new XmlSectionModel(section); return new AuthoredPopupLink(wicketId, xmlId, mSection); } else if (wicketId.startsWith("noteBackLink_")) { // Link back from a note to its (first) noteref. String idref = elt.getAttribute("idref"); // Find candidate noterefs in this chapter XmlSection sec = getModel().getObject(); XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setNamespaceContext(XmlService.get().getNamespaceContext()); XmlSection linkSection = null; String linkText = "?"; try { String path = String.format("//dtb:noteref[@idref='#%s']", idref); NodeList nl = (NodeList) xPath.evaluate(path, sec.getXmlDocument().getDocument().getDocumentElement(), XPathConstants.NODESET); if (nl.getLength() > 0) { Element node = null; node = (Element) nl.item(0); linkText = node.getTextContent(); // Scan parents until you find the smallest enclosing XML Section. while (linkSection == null && node.getParentNode() != null) { String id = node.getAttributeNS(null, "id"); if (id != null) { linkSection = sec.getXmlDocument().getById(id); } node = (Element) node.getParentNode(); } } } catch (XPathExpressionException e) { e.printStackTrace(); // malformed expression - shouldn't happen } if (linkSection != null) { BookmarkablePageLink<ISIStandardPage> link = new SectionLinkFactory().linkTo(wicketId, linkSection, "note_" + idref); link.add(new AttributeRemover("idref")); link.add(new Label("text", linkText)); return link; } else { log.debug("Could not find noteref for note: idref={}", idref); return new SectionLinkFactory().linkToPage(wicketId, null); } } else if (wicketId.startsWith("fileLink_")) { // link to file in content directory return new ResourceLink<Object>(wicketId, getRelativeRef(elt.getAttribute("href"))); } else if (wicketId.startsWith("sectionIcon_")) { WebComponent icon = ISIApplication.get().makeIcon(wicketId, elt.getAttribute("class")); icon.add(AttributeModifier.replace("class", new Model<String>("sectionIcon"))); return icon; } else if (wicketId.startsWith("thumbRating_")) { ContentLoc loc = new ContentLoc(getModel().getObject()); String thumbId = elt.getAttribute("id"); ThumbPanel thumbPanel = new ThumbPanel(wicketId, loc, thumbId); thumbPanel.add(new AttributeRemover("id")); return thumbPanel; } else if (wicketId.startsWith("thumbRatingDescription_")) { Label thumbRatingDescription = new Label(wicketId, new ResourceModel("thumbRatingPanel.ratingDescription", "Rate It:")); return thumbRatingDescription; } else if (wicketId.startsWith("mediaThumbImage_")) { String src = elt.getAttribute("src"); ResourceReference imgRef = getRelativeRef(src); Image image = new Image(wicketId, imgRef) { private static final long serialVersionUID = 1L; @Override protected void onComponentTag(final ComponentTag tag) { super.onComponentTag(tag); tag.put("width", elt.getAttribute("width")); tag.put("height", elt.getAttribute("height")); } }; return image; } else if (wicketId.startsWith("mediaThumbLink_")) { String videoId = elt.getAttributeNS(null, "videoId"); XmlSectionModel currentSectionModel = getModel(); VideoLink videoLink = new VideoLink(wicketId, videoId, currentSectionModel); videoLink.add(new AttributeRemover("videoId")); return videoLink; } else if (wicketId.startsWith("videoplayer_")) { String videoSrc = elt.getAttribute("src"); ResourceReference videoRef = getRelativeRef(videoSrc); String videoUrl = getRequestCycle().mapUrlFor(videoRef, null).toString(); Integer width = Integer.valueOf(elt.getAttribute("width")); Integer height = Integer.valueOf(elt.getAttribute("height")); String preview = elt.getAttribute("poster"); String captions = elt.getAttribute("captions"); String audioDescription = elt.getAttribute("audiodescription"); MediaPlayerPanel comp = new MediaPlayerPanel(wicketId, videoUrl, width, height) { private static final long serialVersionUID = 1L; @Override public void onPlay(String status) { if (cwmSessionService.isSignedIn()) eventService.saveEvent("video:view", "id=" + elt.getAttribute("videoId") + ",state=" + status, contentPage); } }; comp.setFullScreen(true); comp.setUseOnPlay(true); if (!Strings.isEmpty(preview)) comp.setPreview(getRelativeRef(preview)); if (!Strings.isEmpty(captions)) comp.setCaptionFile(getRelativeRef(captions)); if (!Strings.isEmpty(audioDescription)) comp.setAudioDescriptionFile(getRelativeRef(audioDescription)); comp.add(new AttributeRemover("src", "width", "height", "poster", "captions", "audiodescription", "videoId")); return comp; } else if (wicketId.startsWith("audioplayer_")) { String audioSrc = elt.getAttribute("src"); ResourceReference audioRef = getRelativeRef(audioSrc); String audioUrl = getRequestCycle().mapUrlFor(audioRef, null).toString(); int width = 400; if (!elt.getAttribute("width").equals("")) { try { width = Integer.parseInt(elt.getAttribute("width").trim()); } catch (Exception e) { log.debug("Can't get width for {}: {}", audioUrl, e); width = 400; } } AudioPlayerPanel player = new AudioPlayerPanel(wicketId, audioUrl, width, 20); player.setShowDownloadLink(false); player.setRenderBodyOnly(true); String preview = elt.getAttribute("poster"); if (!Strings.isEmpty(preview)) player.setPreview(getRelativeRef(preview)); return player; } else if (wicketId.startsWith("swf_")) { ResourceReference swfRef = getRelativeRef(elt.getAttribute("src")); return new FlashAppletPanel(wicketId, swfRef, Integer.valueOf(elt.getAttribute("width")), Integer.valueOf(elt.getAttribute("height")), ""); } else if (wicketId.startsWith("feedbackButton_")) { ContentLoc loc = new ContentLoc(getModel().getObject()); String responseGroupId = elt.getAttribute("rgid"); IModel<Prompt> pm = responseService.getOrCreatePrompt(PromptType.FEEDBACK, loc, responseGroupId); ResponseFeedbackButtonPanel component = new ResponseFeedbackButtonPanel(wicketId, pm, responseFeedbackPanel); String forRole = elt.getAttribute("for"); component.setVisibilityAllowed(isTeacher ? forRole.equals("teacher") : forRole.equals("student")); component.add(new AttributeRemover("rgid", "for")); return component; } else if (wicketId.startsWith("scoreButtons_")) { if (isGuest) return new EmptyPanel(wicketId); IModel<Prompt> promptModel = getPrompt(elt); IModel<User> studentModel = ISISession.get().getTargetUserModel(); ISortableDataProvider<Response> responseProvider = responseService .getResponseProviderForPrompt(promptModel, studentModel); TeacherScoreResponseButtonPanel component = new TeacherScoreResponseButtonPanel(wicketId, responseProvider); return component; } else if (wicketId.startsWith("showScore_")) { if (isGuest) return new EmptyPanel(wicketId); IModel<Prompt> promptModel = getPrompt(elt); IModel<User> studentModel = cwmSessionService.getUserModel(); ISortableDataProvider<Response> responseProvider = responseService .getResponseProviderForPrompt(promptModel, studentModel); ScorePanel component = new StudentScorePanel(wicketId, responseProvider); return component; // A container for a single-select form and whiteboard, notebook links } else if (wicketId.startsWith("responseContainer")) { return new WebMarkupContainer(wicketId); // A single-select, multiple choice form. MultipleChoiceItems will be added to a RadioGroup // child of this form. } else if (wicketId.startsWith("select1_immediate_")) { return makeImmediateResponseForm(wicketId, elt); // A single-select, multiple choice form. MultipleChoiceItems will be added to a RadioGroup // child of this form. } else if (wicketId.startsWith("select1_delay_")) { return makeDelayedResponseForm(wicketId, elt); // buttons for viewing in whiteboard and notebook } else if (wicketId.startsWith("viewActions")) { IModel<Prompt> mPrompt = getPrompt(elt, PromptType.SINGLE_SELECT); Long promptId = mPrompt.getObject().getId(); ResponseViewActionsPanel component = new ResponseViewActionsPanel(wicketId, promptId); component.add(new AttributeRemover("rgid", "title", "group", "type")); return component; // A single-select, multiple choice disabled form. MultipleChoiceItems will be added to a RadioGroup // child of this form. } else if (wicketId.startsWith("select1_view_immediate")) { return makeImmediateResponseView(wicketId, elt); // A single-select, multiple choice disabled form. MultipleChoiceItems will be added to a RadioGroup // child of this form. } else if (wicketId.startsWith("select1_view_delay")) { return makeDelayedResponseView(wicketId, elt); // A multiple choice radio button. Stores a "correct" value. This is // added to a generic RadioGroup in a SingleSelectForm. } else if (wicketId.startsWith("selectItem_")) { Component mcItem = new SingleSelectItem(wicketId, new Model<String>(wicketId.substring("selectItem_".length())), Boolean.valueOf(elt.getAttribute("correct"))); mcItem.add(new AttributeRemover("correct")); return mcItem; // A message associated with a wicketId.startsWith("selectItem_"). // The wicketId of the associated SingleSelectItem should be provided as a "for" attribute. // Visibility based on whether the corresponding radio button is selected in the enclosing form. } else if (wicketId.startsWith("selectMessage_")) { return new SingleSelectMessage(wicketId, elt.getAttribute("for")).add(new AttributeRemover("for")); // A delayed feedback message associated with a wicketId.startsWith("selectItem_"). // The wicketId of the associated SingleSelectItem should be provided as a "for" attribute. // Visibility based on whether the response has been reviewed. } else if (wicketId.startsWith("selectDelayMessage_")) { ISIXmlSection section = getISIXmlSection(); IModel<XmlSection> currentSectionModel = new XmlSectionModel(section); SingleSelectDelayMessage component = new SingleSelectDelayMessage(wicketId, currentSectionModel); return component.add(new AttributeRemover("for")); } else if (wicketId.startsWith("responseList_")) { if (isGuest) return new MessageBox(wicketId, "guestResponseArea"); ContentLoc loc = new ContentLoc(getModel().getObject()); String responseGroupId = elt.getAttribute("rgid"); ResponseMetadata metadata = getResponseMetadata(responseGroupId); IModel<Prompt> mPrompt = responseService.getOrCreatePrompt(PromptType.RESPONSEAREA, loc, responseGroupId, metadata.getCollection()); ResponseList dataView = new ResponseList(wicketId, mPrompt, metadata, loc, ISISession.get().getTargetUserModel()); dataView.setContext(getResponseListContext(false)); dataView.setAllowEdit(!isTeacher); dataView.setAllowNotebook(!inGlossary && !isTeacher && ISIApplication.get().isNotebookOn()); dataView.setAllowWhiteboard(!inGlossary && ISIApplication.get().isWhiteboardOn()); dataView.add(new AttributeRemover("rgid", "group")); return dataView; } else if (wicketId.startsWith("locking_responseList_")) { if (isGuest) return new EmptyPanel(wicketId); ContentLoc loc = new ContentLoc(getModel().getObject()); String responseGroupId = elt.getAttribute("rgid"); ResponseMetadata metadata = getResponseMetadata(responseGroupId); IModel<Prompt> mPrompt = responseService.getOrCreatePrompt(PromptType.RESPONSEAREA, loc, responseGroupId, metadata.getCollection()); ResponseList dataView = new LockingResponseList(wicketId, mPrompt, metadata, loc, ISISession.get().getTargetUserModel()); dataView.setContext(getResponseListContext(false)); dataView.setAllowEdit(!isTeacher); dataView.setAllowNotebook(!inGlossary && !isTeacher && ISIApplication.get().isNotebookOn()); dataView.setAllowWhiteboard(!inGlossary && ISIApplication.get().isWhiteboardOn()); dataView.add(new AttributeRemover("rgid", "group")); return dataView; } else if (wicketId.startsWith("period_responseList_")) { if (isGuest) return new MessageBox(wicketId, "guestResponseArea"); ContentLoc loc = new ContentLoc(getModel().getObject()); String responseGroupId = elt.getAttribute("rgid"); ResponseMetadata metadata = getResponseMetadata(responseGroupId); IModel<Prompt> mPrompt = responseService.getOrCreatePrompt(PromptType.RESPONSEAREA, loc, responseGroupId, metadata.getCollection()); PeriodResponseList dataView = new PeriodResponseList(wicketId, mPrompt, metadata, loc, ISISession.get().getCurrentPeriodModel()); dataView.setContext(getResponseListContext(true)); dataView.setAllowEdit(!isTeacher); dataView.setAllowNotebook(!inGlossary && !isTeacher && ISIApplication.get().isNotebookOn()); dataView.setAllowWhiteboard(!inGlossary && ISIApplication.get().isWhiteboardOn()); dataView.add(new AttributeRemover("rgid", "group")); return dataView; } else if (wicketId.startsWith("responseButtons_")) { ContentLoc loc = new ContentLoc(getModel().getObject()); String responseGroupId = elt.getAttribute("rgid"); Element xmlElement = getModel().getObject().getElement().getOwnerDocument() .getElementById(responseGroupId); ResponseMetadata metadata = new ResponseMetadata(xmlElement); if (!ISIApplication.get().isUseAuthoredResponseType()) { // set all the response types to the default per application configuration here metadata = adjustResponseTypes(metadata); } IModel<Prompt> mPrompt = responseService.getOrCreatePrompt(PromptType.RESPONSEAREA, loc, metadata.getId(), metadata.getCollection()); ResponseButtons buttons = new ResponseButtons(wicketId, mPrompt, metadata, loc); buttons.setVisible(!isTeacher); return buttons; } else if (wicketId.startsWith("locking_responseButtons_")) { ContentLoc loc = new ContentLoc(getModel().getObject()); String responseGroupId = elt.getAttribute("rgid"); Element xmlElement = getModel().getObject().getElement().getOwnerDocument() .getElementById(responseGroupId); ResponseMetadata metadata = new ResponseMetadata(xmlElement); if (!ISIApplication.get().isUseAuthoredResponseType()) { // set all the response types to the default per application configuration here metadata = adjustResponseTypes(metadata); } IModel<Prompt> mPrompt = responseService.getOrCreatePrompt(PromptType.RESPONSEAREA, loc, metadata.getId(), metadata.getCollection()); return new LockingResponseButtons(wicketId, mPrompt, metadata, loc, cwmSessionService.getUserModel()); } else if (wicketId.startsWith("ratePanel_")) { if (isGuest) return ISIApplication.get().getLoginMessageComponent(wicketId); ContentLoc loc = new ContentLoc(getModel().getObject()); String promptText = null; String ratingId = elt.getAttribute("id"); NodeList nodes = elt.getChildNodes(); // extract the prompt text authored - we might want to consider re-writing this // to use xsl instead of this - but this works for now - ldm for (int i = 0; i < nodes.getLength(); i++) { Node nextNode = nodes.item(i); if (nextNode instanceof Element) { Element next = (Element) nodes.item(i); if (next.getAttribute("class").equals("prompt")) { //get all the html under the prompt element promptText = new TransformResult(next).getString(); } } } RatePanel ratePanel = new RatePanel(wicketId, loc, ratingId, promptText); ratePanel.add(new AttributeRemover("id")); ratePanel.add(new AttributeRemover("type")); return ratePanel; } else if (wicketId.startsWith("teacherBar_")) { WebMarkupContainer teacherBar = new WebMarkupContainer(wicketId); teacherBar.setVisible(isTeacher && !inGlossary); return teacherBar; } else if (wicketId.startsWith("compareResponses_")) { IModel<Prompt> mPrompt = getPrompt(elt); BookmarkablePageLink<Page> bpl = new BookmarkablePageLink<Page>(wicketId, ISIApplication.get().getPeriodResponsePageClass()); bpl.getPageParameters().add("promptId", mPrompt.getObject().getId()); ISIApplication.get().setLinkProperties(bpl); bpl.setVisible(isTeacher); bpl.add(new AttributeRemover("rgid", "for", "type")); return bpl; } else if (wicketId.startsWith("agent_")) { String title = elt.getAttribute("title"); if (Strings.isEmpty(title)) title = new StringResourceModel("isi.defaultAgentButtonText", this, null, "Help").getObject(); AgentLink link = new AgentLink(wicketId, title, elt.getAttribute("responseAreaId")); link.add(new AttributeRemover("title", "responseAreaId")); return link; } else if (wicketId.startsWith("image_")) { String src = elt.getAttribute("src"); ResourceReference imgRef = getRelativeRef(src); return new Image(wicketId, imgRef); } else if (wicketId.startsWith("imageThumb_")) { String src = elt.getAttribute("src"); int ext = src.lastIndexOf('.'); src = src.substring(0, ext) + "_t" + src.substring(ext); ResourceReference imgRef = getRelativeRef(src); Image img = new Image(wicketId, imgRef); // FIXME these attributes were removed because indira was adding height and width of the detail image // not the thumbnail image - remove when indira gets removed img.add(new AttributeRemover("width", "height")); return img; } else if (wicketId.startsWith("imageDetailButton_")) { // for thumbnail images only - no longer for more info return new ImageDetailButtonPanel(wicketId, wicketId.substring("imageDetailButton_".length())); // We may want to put some of this back, but for now assuming that any time XSLT requests an image detail button we'll put one in. // if (contentPage == null && !inGlossary) // Don't do imageDetails on non-content pages (e.g. the Table of Contents) // return new WebMarkupContainer(wicketId).setVisible(false); } else if (wicketId.startsWith("imgToggleHeader") || wicketId.startsWith("imgDetailToggleHeader") || wicketId.startsWith("objectToggleHeader")) { // long description header for toggle area String src = elt.getAttribute("src"); // remove everything but the name of the media int lastIndex = src.lastIndexOf("/") + 1; src = src.substring(lastIndex, src.length()); Label label; String eventType = "ld"; String detail = null; if (wicketId.startsWith("img")) { label = new Label(wicketId, new ResourceModel("imageLongDescription.toggleHeading", "image information")); String imageId = elt.getAttribute("imageId"); detail = "imageId=" + imageId; label.add(new AttributeRemover("imageId")); if (wicketId.startsWith("imgDetailToggleHeader")) { label = new Label(wicketId, new ResourceModel("imageLongDescription.toggleHeading", "image information")); detail = detail + ",context=detail"; } } else { // video or mp3 files if (src.contains(".mp3")) { label = new Label(wicketId, new ResourceModel("audioLongDescription.toggleHeading", "more audio information")); } else { label = new Label(wicketId, new ResourceModel("videoLongDescription.toggleHeading", "more video information")); } detail = "src=" + src; } label.add( new CollapseBoxBehavior("onclick", eventType, ((ISIBasePage) getPage()).getPageName(), detail)); label.add(new AttributeRemover("src")); return label; } else if (wicketId.startsWith("annotatedImage_")) { // image with hotspots AnnotatedImageComponent annotatedImageComponent = new AnnotatedImageComponent(wicketId, elt, getModel()); annotatedImageComponent.add(new AttributeRemover("annotatedImageId")); return annotatedImageComponent; } else if (wicketId.startsWith("hotSpot_")) { // clickable areas on annotated images HotSpotComponent hotSpotComponent = new HotSpotComponent(wicketId, elt); hotSpotComponent.add(new AttributeRemover("annotatedImageId")); return hotSpotComponent; } else if (wicketId.startsWith("slideShow_")) { SlideShowComponent slideShowComponent = new SlideShowComponent(wicketId, elt); return slideShowComponent; } else if (wicketId.startsWith("collapseBox_")) { WebMarkupContainer collapseBox = new WebMarkupContainer(wicketId); return collapseBox; } else if (wicketId.startsWith("feedbackStatusIndicator_")) { FeedbackStatusIndicator feedbackStatusIndicator = new FeedbackStatusIndicator(wicketId); return feedbackStatusIndicator; } else if (wicketId.startsWith("collapseBoxControl-")) { String boxSequence = (wicketId.substring("collapseBoxControl-".length()).equals("") ? "0" : wicketId.substring("collapseBoxControl-".length())); CollapseBoxHeader collapseBoxHeader = new CollapseBoxHeader(wicketId, boxSequence); return collapseBoxHeader; } else if (wicketId.startsWith("iScienceLink-")) { return new AjaxFallbackLink<Object>(wicketId) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { target.prependJavaScript( "$('#iScienceVideo-" + wicketId.substring("iScienceLink-".length()) + "').jqmShow();"); eventService.saveEvent("iscience:view", "Video #" + wicketId.substring("iScienceLink-".length()), ((ISIBasePage) getPage()).getPageName()); } }; } else if (wicketId.startsWith("youtube_")) { int width = getWidth(elt, 640); int height = getHeight(elt, 385); String src = elt.getAttribute("src"); src = src.replace("youtube.com/watch?v=", "youtube.com/v/"); FlashAppletPanel panel = new FlashAppletPanel(wicketId, width, height); panel.add(new AttributeRemover("src", "width", "height")); panel.setAppletHRef(src); panel.setFullScreen(true); return panel; } else if (wicketId.startsWith("pageLinkPanel_")) { String id = elt.getAttribute("id"); IModel<XmlSection> currentSectionModel = new XmlSectionModel( getModel().getObject().getXmlDocument().getById(id)); PageLinkPanel panel = new PageLinkPanel(wicketId, currentSectionModel, null); panel.add(new AttributeRemover("id")); return panel; } else if (wicketId.startsWith("sectionStatusIcon_")) { String id = elt.getAttribute("id"); IModel<XmlSection> currentSectionModel = new XmlSectionModel( getModel().getObject().getXmlDocument().getById(id)); return new StudentSectionCompleteToggleImageLink(wicketId, currentSectionModel); } else if (wicketId.startsWith("inactiveSectionStatusIcon_")) { String id = elt.getAttribute("id"); IModel<XmlSection> currentSectionModel = new XmlSectionModel( getModel().getObject().getXmlDocument().getById(id)); return new SectionCompleteImageContainer(wicketId, currentSectionModel); } else if (wicketId.startsWith("itemSummary_")) { boolean noAnswer = Boolean.parseBoolean(elt.getAttributeNS(null, "noAnswer")); Component singleSelectComponent = new SingleSelectSummaryXmlComponentHandler().makeComponent(wicketId, elt, getModel(), noAnswer); singleSelectComponent.add(new AttributeRemover("noAnswer")); return singleSelectComponent; } else if (wicketId.startsWith("shy")) { return new ShyContainer(wicketId); } else { return super.getDynamicComponent(wicketId, elt); } }
From source file:org.cast.isi.page.Notebook.java
License:Open Source License
/** * Add a drop down choice of chapters.// w w w .j ava 2 s . c om */ protected void addChapterChoice(MarkupContainer container) { Form<Void> chapterSelectForm = new Form<Void>("chapterSelectForm") { private static final long serialVersionUID = 1L; @Override protected void onSubmit() { super.onSubmit(); // only reload the page if the user has selected a new chapter ContentLoc newLoc = new ContentLoc((ISIXmlSection) chapterChoice.getModelObject()); if (!newLoc.equals(currentChapterLoc)) { currentLoc = newLoc; PageParameters param = new PageParameters(); param.add("loc", currentLoc.getLocation()); setResponsePage(ISIApplication.get().getNotebookPageClass(), param); } } }; container.add(chapterSelectForm); // display only the titles in the dropdown ChoiceRenderer<XmlSection> renderer = new ChoiceRenderer<XmlSection>("title"); chapterChoice = new DropDownChoice<XmlSection>("chapterChoice", new XmlSectionModel(currentChapterLoc.getSection()), mChapterList, renderer); chapterChoice.add(new AttributeModifier("autocomplete", "off")); chapterChoice.add(new AttributeModifier("ignore", "true")); chapterSelectForm.add(chapterChoice); AjaxSubmitLink submitLink = new AjaxSubmitLink("submitLink", chapterSelectForm) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.prependJavaScript("AutoSaver.autoSaveMaybeSave(null);"); super.onSubmit(target, form); } }; String onClickString = "if (typeof AutoSaver !== 'undefined') { AutoSaver.autoSaveMaybeSave(null);}"; submitLink.add(new AttributePrepender("onclick", onClickString, ";")); chapterSelectForm.add(submitLink); }
From source file:org.efaps.ui.wicket.components.footer.AjaxSubmitCloseBehavior.java
License:Apache License
/** * Method is not used, but needed from the api. * * @param _target AjaxRequestTarget//from ww w . ja v a 2 s. c om */ @Override protected void onError(final AjaxRequestTarget _target) { final FeedbackCollector collector = new FeedbackCollector(getForm().getPage()); final List<FeedbackMessage> msgs = collector.collect(); final ErrorMessageResource msgResource = new ErrorMessageResource(); final StringBuilder html = new StringBuilder().append("<table class=\"eFapsValidateFieldValuesTable\">"); for (final FeedbackMessage msg : msgs) { if (!(msg.getReporter() instanceof Form)) { if (msg.getReporter() instanceof AutoCompleteComboBox) { final StringBuilder js = new StringBuilder() .append("require(['dojo/dom','dojo/dom-class'], function (dom, domClass) {") .append("domClass.add(dom.byId('").append(msg.getReporter().getMarkupId()) .append("').parentNode, 'invalid');").append("});"); _target.prependJavaScript(js); } else { msg.getReporter().add(AttributeModifier.append("class", "invalid")); _target.add(msg.getReporter()); } } Serializable warn = null; if (msg.getMessage() instanceof ValidationErrorFeedback) { // look if a message was set warn = ((ValidationErrorFeedback) msg.getMessage()).getMessage(); // still no message, create one if (warn == null) { warn = ((ValidationErrorFeedback) msg.getMessage()).getError().getErrorMessage(msgResource); } } else { warn = String.valueOf(msg.getMessage()); } html.append("<tr>"); if (msg.getReporter() instanceof IFieldConfig) { html.append("<td>").append(((IFieldConfig) msg.getReporter()).getFieldConfig().getLabel()) .append(":</td><td>").append(warn).append("</td>"); } else { html.append("<td colspan=\"2\">").append(warn).append("</td></tr>"); } msg.getReporter().getFeedbackMessages().clear(); } html.append("</table>"); showDialog(_target, html.toString(), true, false); // after every commit the fieldset must be resteted getForm().getPage().visitChildren(SetDataGrid.class, new IVisitor<SetDataGrid, Void>() { @Override public void component(final SetDataGrid _setDataGrid, final IVisit<Void> _visit) { final UIFieldSet fieldSet = (UIFieldSet) _setDataGrid.getDefaultModelObject(); fieldSet.resetIndex(); } }); getForm().getPage().visitChildren(DropDownField.class, new IVisitor<DropDownField, Void>() { @Override public void component(final DropDownField _dropDown, final IVisit<Void> _visit) { _dropDown.setConverted(false); } }); }
From source file:org.efaps.ui.wicket.components.form.command.AjaxCmdBehavior.java
License:Apache License
@Override public void onSubmit(final AjaxRequestTarget _target) { try {//from w ww . j a v a 2 s . com final UICmdField uiObject = (UICmdField) getComponent().getDefaultModelObject(); final StringBuilder snip = new StringBuilder(); try { final AbstractUIPageObject pageObject = (AbstractUIPageObject) getComponent().getPage() .getDefaultModelObject(); final Map<String, String> uiID2Oid = pageObject == null ? null : pageObject.getUiID2Oid(); final List<Return> returns = uiObject.executeEvents(this.others, uiID2Oid); for (final Return oneReturn : returns) { if (oneReturn.contains(ReturnValues.SNIPLETT)) { snip.append(oneReturn.get(ReturnValues.SNIPLETT)); } } } catch (final EFapsException e) { AjaxCmdBehavior.LOG.error("onSubmit", e); } final List<Map<String, String>> values = new ArrayList<Map<String, String>>(); final AbstractUIPageObject pageObject = (AbstractUIPageObject) getComponent().getPage() .getDefaultModelObject(); final Map<String, String> uiID2Oid = pageObject == null ? null : pageObject.getUiID2Oid(); final List<Return> returns = uiObject.executeEvents(EventType.UI_FIELD_UPDATE, getComponent().getMarkupId(), uiID2Oid); for (final Return aReturn : returns) { final Object ob = aReturn.get(ReturnValues.VALUES); if (ob instanceof List) { @SuppressWarnings("unchecked") final List<Map<String, String>> list = (List<Map<String, String>>) ob; values.addAll(list); } } final StringBuilder js = new StringBuilder(); int i = 0; for (final Map<String, String> map : values) { if (map.size() > 0) { for (final String keyString : map.keySet()) { // if the map contains a key that is not defined in this class // it is assumed to be the name of a field if (!EFapsKey.FIELDUPDATE_JAVASCRIPT.getKey().equals(keyString) && !EFapsKey.FIELDUPDATE_USEID.getKey().equals(keyString) && !EFapsKey.FIELDUPDATE_USEIDX.getKey().equals(keyString)) { js.append("eFapsSetFieldValue(").append(i).append(",'").append(keyString).append("',") .append(map.get(keyString).contains("Array(") ? "" : "'") .append(map.get(keyString)) .append(map.get(keyString).contains("Array(") ? "" : "'").append(");"); } } } if (map.containsKey(EFapsKey.FIELDUPDATE_JAVASCRIPT.getKey())) { js.append(map.get(EFapsKey.FIELDUPDATE_JAVASCRIPT.getKey())); } i++; } _target.appendJavaScript(js.toString()); if (uiObject.isTargetField()) { final FormPanel formPanel = getComponent().findParent(FormPanel.class); this.targetComponent = getModelFromChild(formPanel, uiObject.getTargetField()); } if (!uiObject.isAppend() || !this.targetComponent.isVisible()) { final MarkupContainer parent = this.targetComponent.getParent(); final LabelComponent newComp = new LabelComponent(this.targetComponent.getId(), snip.toString()); parent.addOrReplace(newComp); this.targetComponent = newComp; _target.add(parent); } else { final StringBuilder jScript = new StringBuilder(); jScript.append("var ele = document.getElementById('").append(this.targetComponent.getMarkupId()) .append("');").append("var nS = document.createElement('span');") .append("ele.appendChild(nS);").append("nS.innerHTML='").append(snip).append("'"); _target.prependJavaScript(jScript.toString()); } } catch (final EFapsException e) { LOG.error("Catched", e); } }
From source file:org.efaps.ui.wicket.components.picker.PickerCallBack.java
License:Apache License
/** * The actual Javascript that will be executed on close of the modal window. * @param _target Target/*from w w w .j av a 2 s .c o m*/ */ @Override public void onClose(final AjaxRequestTarget _target) { final AbstractUIPageObject pageObject = (AbstractUIPageObject) this.pageReference.getPage() .getDefaultModelObject(); if (pageObject.isOpenedByPicker()) { final UIPicker picker = pageObject.getPicker(); pageObject.setPicker(null); if (picker.isExecuted()) { final Map<String, Object> map = picker.getReturnMap(); final boolean escape = escape(map); final StringBuilder js = new StringBuilder(); final String value = (String) map.get(EFapsKey.PICKER_VALUE.getKey()); if (value != null) { js.append("require(['dojo/dom'], function(dom){\n").append("dom.byId('") .append(this.targetMarkupId).append("').value ='") .append(escape ? StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(value)) : value) .append("';").append("});"); } for (final String keyString : map.keySet()) { // if the map contains a key that is not defined in this // class it is assumed to be the name of a field if (!(EFapsKey.PICKER_JAVASCRIPT.getKey().equals(keyString) || EFapsKey.PICKER_DEACTIVATEESCAPE.getKey().equals(keyString) || EFapsKey.PICKER_VALUE.getKey().equals(keyString))) { final Object valueObj = map.get(keyString); final String strValue; final String strLabel; if (valueObj instanceof String[] && ((String[]) valueObj).length == 2) { strValue = escape && !((String[]) valueObj)[0].contains("Array(") ? StringEscapeUtils.escapeEcmaScript(((String[]) valueObj)[0]) : ((String[]) valueObj)[0]; strLabel = escape && !((String[]) valueObj)[0].contains("Array(") ? StringEscapeUtils.escapeEcmaScript(((String[]) valueObj)[1]) : ((String[]) valueObj)[1]; } else { strValue = escape && !String.valueOf(valueObj).contains("Array(") ? StringEscapeUtils.escapeEcmaScript(String.valueOf(valueObj)) : String.valueOf(valueObj); strLabel = null; } js.append("eFapsSetFieldValue(") .append(this.targetMarkupId == null ? 0 : "'" + this.targetMarkupId + "'") .append(",'").append(keyString).append("',") .append(strValue.contains("Array(") ? "" : "'").append(strValue) .append(strValue.contains("Array(") ? "" : "'"); if (strLabel != null) { js.append(",'").append(strLabel).append("'"); } js.append(");"); } } if (map.containsKey(EFapsKey.PICKER_JAVASCRIPT.getKey())) { js.append(map.get(EFapsKey.PICKER_JAVASCRIPT.getKey())); } _target.prependJavaScript(js.toString()); picker.setExecuted(false); } } }
From source file:org.hippoecm.frontend.dialog.AbstractDialog.java
License:Apache License
/** * Implement onClose callback, invoked when the dialog is closed. Make sure the keyboard shortcuts are cleaned up * correctly. Subclasses overriding this method should also invoke super#onClose(); *///from w w w . jav a 2s . c o m @Override public void onClose() { AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class); if (target != null) { for (ButtonWrapper bw : buttons) { if (bw.getKeyType() != null) { // the input behavior does not support removal, so we need to do this manually target.prependJavaScript( "if (window['shortcut']) { shortcut.remove('" + bw.getKeyType() + "'); }\n"); } } } }
From source file:org.onexus.website.api.pages.browser.filters.FiltersToolbar.java
License:Apache License
protected void addFilter(AjaxRequestTarget target, FilterConfig filterConfig) { statusModel.getObject().getCurrentFilters().add(filterConfig); target.add(this); target.prependJavaScript("$('#" + widgetModal.getMarkupId() + "').modal('hide')"); send(getPage(), Broadcast.BREADTH, EventAddFilter.EVENT); }
From source file:org.onexus.website.api.pages.browser.layouts.ButtonWidget.java
License:Apache License
@Override public void onEvent(IEvent<?> event) { if (event.getPayload() instanceof EventCloseModal) { AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class); if (target != null) { target.prependJavaScript("$('#" + widgetModal.getMarkupId() + "').modal('hide')"); }// w ww . j av a2 s . c om } super.onEvent(event); }
From source file:org.onexus.website.api.theme.DefaultTheme.java
License:Apache License
@Override public void onEvent(Component component, IEvent<?> event) { if (event.getPayload() instanceof AjaxRequestTarget) { AjaxRequestTarget target = (AjaxRequestTarget) event.getPayload(); target.prependJavaScript(getTooltipHideJavascript()); target.appendJavaScript(getTooltipJavascript()); target.appendJavaScript(getMoveFooter()); target.appendJavaScript(getColorBoxJavascript()); }//from w w w. j ava2s . c om }