List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setCloseButtonCallback
public ModalWindow setCloseButtonCallback(final CloseButtonCallback callback)
CloseButtonCallback
instance. From source file:com.doculibre.constellio.wicket.panels.results.tagging.SearchResultTaggingPanel.java
License:Open Source License
public SearchResultTaggingPanel(String id, final SolrDocument doc, final IDataProvider dataProviderParam) { super(id);/*from ww w . jav a 2 s .c o m*/ RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices(); final SimpleSearch simpleSearch; if (dataProviderParam instanceof FacetsDataProvider) { FacetsDataProvider dataProvider = (FacetsDataProvider) dataProviderParam; simpleSearch = dataProvider.getSimpleSearch(); } else { SearchResultsDataProvider dataProvider = (SearchResultsDataProvider) dataProviderParam; simpleSearch = dataProvider.getSimpleSearch(); } String collectionName = simpleSearch.getCollectionName(); RecordCollection collection = collectionServices.get(collectionName); if (!collection.isOpenSearch()) { RecordServices recordServices = ConstellioSpringUtils.getRecordServices(); Record record = recordServices.get(doc); recordModel = new RecordModel(record); final ModalWindow taggingModal = new ModalWindow("taggingModal"); taggingModal.setTitle(new StringResourceModel("tags", this, null)); taggingModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY); taggingModal.setInitialWidth(800); taggingModal.setInitialHeight(450); taggingModal.setCloseButtonCallback(new CloseButtonCallback() { @Override public boolean onCloseButtonClicked(AjaxRequestTarget target) { target.addComponent(SearchResultTaggingPanel.this); return true; } }); add(taggingModal); IModel thesaurusListModel = new LoadableDetachableModel() { @Override protected Object load() { List<Thesaurus> thesaurusList = new ArrayList<Thesaurus>(); RecordCollectionServices collectionServices = ConstellioSpringUtils .getRecordCollectionServices(); String collectionName = simpleSearch.getCollectionName(); RecordCollection collection = collectionServices.get(collectionName); thesaurusList.add(null);// free text tags if (collection.getThesaurus() != null) { thesaurusList.add(collection.getThesaurus()); } return thesaurusList; } }; add(new ListView("taggingLinks", thesaurusListModel) { @Override protected void populateItem(ListItem item) { Thesaurus thesaurus = (Thesaurus) item.getModelObject(); final ReloadableEntityModel<Thesaurus> thesaurusModel = new ReloadableEntityModel<Thesaurus>( thesaurus); final String thesaurusName; if (thesaurus == null) { thesaurusName = getLocalizer().getString("tags", this); } else { thesaurusName = getLocalizer().getString("thesaurus", this); } AjaxLink link = new AjaxLink("taggingLink") { @Override public void onClick(AjaxRequestTarget target) { Thesaurus thesaurus = thesaurusModel.getObject(); SearchResultEditTaggingPanel editTaggingPanel = new SearchResultEditTaggingPanel( taggingModal.getContentId(), doc, dataProviderParam, thesaurus); taggingModal.setContent(editTaggingPanel); taggingModal.show(target); } @Override public boolean isEnabled() { boolean enabled = super.isEnabled(); if (enabled) { Record record = recordModel.getObject(); if (record != null) { ConstellioUser user = ConstellioSession.get().getUser(); if (user != null) { RecordCollection collection = record.getConnectorInstance() .getRecordCollection(); enabled = user.hasCollaborationPermission(collection); } else { enabled = false; } } else { enabled = false; } } return enabled; } @Override public void detachModels() { thesaurusModel.detach(); super.detachModels(); } }; item.add(link); link.add(new Label("thesaurusName", thesaurusName)); final IModel tagsModel = new LoadableDetachableModel() { @Override protected Object load() { Record record = recordModel.getObject(); Thesaurus thesaurus = thesaurusModel.getObject(); return new ArrayList<RecordTag>(record.getIncludedRecordTags(thesaurus)); } }; item.add(new ListView("tags", tagsModel) { @SuppressWarnings("unchecked") @Override protected void populateItem(ListItem item) { RecordTag recordTag = (RecordTag) item.getModelObject(); final RecordTagModel recordTagModel = new RecordTagModel(recordTag); Link addTagLink = new Link("addTagLink") { @Override public void onClick() { RecordTag recordTag = recordTagModel.getObject(); SimpleSearch clone = simpleSearch.clone(); clone.getTags().add(recordTag.getName(getLocale())); PageFactoryPlugin pageFactoryPlugin = PluginFactory .getPlugin(PageFactoryPlugin.class); if (StringUtils.isNotBlank(clone.getLuceneQuery())) { // ConstellioSession.get().addSearchHistory(clone); setResponsePage(pageFactoryPlugin.getSearchResultsPage(), SearchResultsPage.getParameters(clone)); } else { SimpleSearch newSearch = new SimpleSearch(); newSearch.setCollectionName(simpleSearch.getCollectionName()); newSearch.setSingleSearchLocale(simpleSearch.getSingleSearchLocale()); setResponsePage(pageFactoryPlugin.getSearchFormPage(), SearchFormPage.getParameters(newSearch)); } } @Override public void detachModels() { recordTagModel.detach(); super.detachModels(); } }; item.add(addTagLink); List<RecordTag> recordTags = (List<RecordTag>) tagsModel.getObject(); String tag = recordTag.getName(getLocale()); if (item.getIndex() < recordTags.size() - 1) { tag += ";"; } addTagLink.add(new Label("tag", tag)); addTagLink.setEnabled(false); } }); item.add(new WebMarkupContainer("noTags") { @SuppressWarnings("unchecked") @Override public boolean isVisible() { List<RecordTag> recordTags = (List<RecordTag>) tagsModel.getObject(); return super.isVisible() && recordTags.isEmpty(); } }); } }); } else { setVisible(false); } }
From source file:com.evolveum.midpoint.gui.api.page.PageBase.java
License:Apache License
protected ModalWindow createModalWindow(final String id, IModel<String> title, int width, int height) { final ModalWindow modal = new ModalWindow(id); add(modal);//from w w w. jav a 2 s. c om modal.setResizable(false); modal.setTitle(title); modal.setCookieName(PageBase.class.getSimpleName() + ((int) (Math.random() * 100))); modal.setInitialWidth(width); modal.setWidthUnit("px"); modal.setInitialHeight(height); modal.setHeightUnit("px"); modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { @Override public boolean onCloseButtonClicked(AjaxRequestTarget target) { return true; } }); modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget target) { modal.close(target); } }); modal.add(new AbstractDefaultAjaxBehavior() { @Override public void renderHead(Component component, IHeaderResponse response) { response.render(OnDomReadyHeaderItem.forScript("Wicket.Window.unloadConfirmation = false;")); response.render(JavaScriptHeaderItem.forScript( "$(document).ready(function() {\n" + " $(document).bind('keyup', function(evt) {\n" + " if (evt.keyCode == 27) {\n" + getCallbackScript() + "\n" + " evt.preventDefault();\n" + " }\n" + " });\n" + "});", id)); } @Override protected void respond(AjaxRequestTarget target) { modal.close(target); } }); return modal; }
From source file:com.evolveum.midpoint.web.component.util.SimplePanel.java
License:Apache License
protected ModalWindow createModalWindow(final String id, IModel<String> title, int width, int height) { final ModalWindow modal = new ModalWindow(id); add(modal);/*from ww w. j av a2 s .c om*/ modal.setResizable(false); modal.setTitle(title); modal.setCookieName(PageBase.class.getSimpleName() + ((int) (Math.random() * 100))); modal.setInitialWidth(width); modal.setWidthUnit("px"); modal.setInitialHeight(height); modal.setHeightUnit("px"); modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { @Override public boolean onCloseButtonClicked(AjaxRequestTarget target) { return true; } }); modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget target) { modal.close(target); } }); modal.add(new AbstractDefaultAjaxBehavior() { @Override public void renderHead(Component component, IHeaderResponse response) { response.render(OnDomReadyHeaderItem.forScript("Wicket.Window.unloadConfirmation = false;")); response.render(JavaScriptHeaderItem.forScript( "$(document).ready(function() {\n" + " $(document).bind('keyup', function(evt) {\n" + " if (evt.keyCode == 27) {\n" + getCallbackScript() + "\n" + " evt.preventDefault();\n" + " }\n" + " });\n" + "});", id)); } @Override protected void respond(AjaxRequestTarget target) { modal.close(target); } }); return modal; }
From source file:com.evolveum.midpoint.web.page.PageTemplate.java
License:Apache License
protected ModalWindow createModalWindow(final String id, IModel<String> title, int width, int height) { final ModalWindow modal = new ModalWindow(id); add(modal);// w ww .j a v a2 s .c o m modal.setResizable(false); modal.setTitle(title); modal.setCookieName(PageTemplate.class.getSimpleName() + ((int) (Math.random() * 100))); modal.setInitialWidth(width); modal.setWidthUnit("px"); modal.setInitialHeight(height); modal.setHeightUnit("px"); modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { @Override public boolean onCloseButtonClicked(AjaxRequestTarget target) { return true; } }); modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget target) { modal.close(target); } }); modal.add(new AbstractDefaultAjaxBehavior() { @Override public void renderHead(Component component, IHeaderResponse response) { response.render(OnDomReadyHeaderItem.forScript("Wicket.Window.unloadConfirmation = false;")); response.render(JavaScriptHeaderItem.forScript( "$(document).ready(function() {\n" + " $(document).bind('keyup', function(evt) {\n" + " if (evt.keyCode == 27) {\n" + getCallbackScript() + "\n" + " evt.preventDefault();\n" + " }\n" + " });\n" + "});", id)); } @Override protected void respond(AjaxRequestTarget target) { modal.close(target); } }); return modal; }
From source file:com.socialsite.course.NewCoursePanel.java
License:Open Source License
public NewCoursePanel(String id) { super(id);/* ww w .ja v a2 s. c om*/ final ModalWindow courseModal; add(courseModal = new ModalWindow("coursemodal")); courseModal.setContent(new NewCourseModal(courseModal.getContentId())); courseModal.setTitle("Create new Course"); courseModal.setCookieName("coursemodal"); courseModal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { /** * */ private static final long serialVersionUID = 1L; public boolean onCloseButtonClicked(AjaxRequestTarget target) { return true; } }); courseModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { /** * */ private static final long serialVersionUID = 1L; public void onClose(AjaxRequestTarget target) { } }); add(new AjaxLink<Void>("newcourse") { /** * */ private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { courseModal.show(target); } }); }
From source file:com.socialsite.image.ImagePanel.java
License:Open Source License
/** * //from www. j a va 2 s.co m * @param component * component id * @param id * id used to fetch the image * @param imageType * type of the image (userimage , courseimage etc) * @param thumb * will show thumb image if true * @param lastModified * lastmodified date of the image */ public ImagePanel(final String component, final long id, final ImageType imageType, final Date lastModified, final boolean thumb, final boolean changeLink) { super(component); this.changeLink = changeLink; // allow the modal window to update the panel setOutputMarkupId(true); final ResourceReference imageResource = new ResourceReference(imageType.name()); final Image userImage; final ValueMap valueMap = new ValueMap(); valueMap.add("id", id + ""); // the version is used to change the url dynamically if the image is // changed. This will allow the browser to cache images // reference http://code.google.com/speed/page-speed/docs/caching.html // #Use fingerprinting to dynamically enable caching. valueMap.add("version", lastModified.getTime() + ""); if (thumb) { valueMap.add("thumb", "true"); } add(userImage = new Image("userimage", imageResource, valueMap)); userImage.setOutputMarkupId(true); final ModalWindow modal; add(modal = new ModalWindow("modal")); modal.setContent(new UploadPanel(modal.getContentId()) { /** * */ private static final long serialVersionUID = 1L; @Override public String onFileUploaded(final FileUpload upload) { if (upload == null || upload.getSize() == 0) { // No image was provided error("Please upload an image."); } else if (!checkContentType(upload.getContentType())) { error("Only images of types png, jpg, and gif are allowed."); } else { saveImage(upload.getBytes()); } return null; } @Override public void onUploadFinished(final AjaxRequestTarget target, final String filename, final String newFileUrl) { final ResourceReference imageResource = new ResourceReference(imageType.name()); final ValueMap valueMap = new ValueMap(); valueMap.add("id", id + ""); // change the image lively valueMap.add("version", new Date().getTime() + ""); if (thumb) { valueMap.add("thumb", "true"); } userImage.setImageResourceReference(imageResource, valueMap); // update the image after the user changes it target.addComponent(userImage); } }); modal.setTitle(" Select the image "); modal.setCookieName("modal"); modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { /** * */ private static final long serialVersionUID = 1L; public boolean onCloseButtonClicked(final AjaxRequestTarget target) { return true; } }); modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { /** * */ private static final long serialVersionUID = 1L; public void onClose(final AjaxRequestTarget target) { } }); add(new AjaxLink<Void>("changeimage") { /** * */ private static final long serialVersionUID = 1L; @Override public boolean isVisible() { if (changeLink) { // TODO allow admins to change the university image and // allow // staffs to change the course image // it. don't show it for thumb images return hasRole(SocialSiteRoles.OWNER) || hasRole(SocialSiteRoles.STAFF); } return false; } @Override public void onClick(final AjaxRequestTarget target) { modal.show(target); } }); }
From source file:de.jetwick.ui.UserPanel.java
License:Apache License
public UserPanel(String id, final TweetSearchPage tweetSearchRef) { super(id);/*from ww w .j a v a2 s. c om*/ ExternalLink profileImageLink = new ExternalLink("profileImageLink", new PropertyModel(this, "profileLink")); profileImageLink.add(new ContextImage("profileImage", new PropertyModel(this, "imageUrl"))); profileImageLink.add(new AttributeAppender("title", new PropertyModel(this, "title"), " ")); add(profileImageLink); add(new WebMarkupContainer("gojetslideLink") { @Override public boolean isVisible() { return !tweetSearchRef.getMySession().hasLoggedIn(); } }); Link loginLink = new Link("loginLink") { @Override public void onClick() { setResponsePage(Login.class); } }; add(loginLink); if (!tweetSearchRef.getMySession().hasLoggedIn()) { add(new WebMarkupContainer("loginContainer").setVisible(false)); add(new AttributeModifier("class", "logged-in", new Model("logged-out"))); return; } title = tweetSearchRef.getMySession().getUser().getScreenName(); imageUrl = tweetSearchRef.getMySession().getUser().getProfileImageUrl(); profileLink = Helper.TURL + "/" + title; loginLink.setVisible(false); WebMarkupContainer container = new WebMarkupContainer("loginContainer") { { final JUser user = tweetSearchRef.getMySession().getUser(); String name = user.getRealName(); if (name == null) name = user.getScreenName(); add(new Label("loginText", "Hi " + name + "!")); add(new Link("logout") { @Override public void onClick() { onLogout(); } }); add(new AjaxFallbackLink("showHomeline") { @Override public void onClick(AjaxRequestTarget target) { onHomeline(target, user.getScreenName()); } }); add(new AjaxFallbackLink("showTweets") { @Override public void onClick(AjaxRequestTarget target) { onShowTweets(target, user.getScreenName()); } }); final ModalWindow modalW = new ModalWindow("userModal"); add(modalW); add(new AjaxLink("grabTweets") { @Override public void onClick(AjaxRequestTarget target) { modalW.show(target); } }); modalW.setTitle("Specify the user and the number of tweets you want to grab"); final GrabTweetsDialog dialog = new GrabTweetsDialog(modalW.getContentId(), user.getScreenName()) { @Override public TwitterSearch getTwitterSearch() { return tweetSearchRef.getTwitterSearch(); } @Override public void updateAfterAjax(AjaxRequestTarget target) { UserPanel.this.updateAfterAjax(target); } @Override public void onClose(AjaxRequestTarget target) { modalW.close(target); } @Override protected Collection<String> getUserChoices(String input) { return UserPanel.this.getUserChoices(input); } }; modalW.setContent(dialog); modalW.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { @Override public boolean onCloseButtonClicked(AjaxRequestTarget target) { logger.info("cancel grabber archiving thread!"); dialog.interruptGrabber(); modalW.close(target); return true; } }); modalW.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget target) { logger.info("closed dialog"); } }); modalW.setCookieName("user-modal"); } }; add(container); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.page.annotation.AnnotationPage.java
License:Apache License
public AnnotationPage() { editor = new AnnotationDetailEditorPanel("annotationDetailEditorPanel", new Model<BratAnnotatorModel>(bModel)) { private static final long serialVersionUID = 2857345299480098279L; @Override/*w w w . ja va 2 s . c om*/ protected void onChange(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel) { aTarget.addChildren(getPage(), FeedbackPanel.class); try { annotator.bratRender(aTarget, getCas(aBModel)); } catch (UIMAException | ClassNotFoundException | IOException e) { LOG.info("Error reading CAS " + e.getMessage()); error("Error reading CAS " + e.getMessage()); return; } annotator.bratRenderHighlight(aTarget, aBModel.getSelection().getAnnotation()); annotator.onChange(aTarget, aBModel); } @Override protected void onAutoForward(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel) { try { annotator.autoForward(aTarget, getCas(aBModel)); } catch (UIMAException | ClassNotFoundException | IOException | BratAnnotationException e) { LOG.info("Error reading CAS " + e.getMessage()); error("Error reading CAS " + e.getMessage()); return; } } }; editor.setOutputMarkupId(true); add(editor); annotator = new BratAnnotator("embedder1", new Model<BratAnnotatorModel>(bModel), editor) { private static final long serialVersionUID = 7279648231521710155L; @Override public void onChange(AjaxRequestTarget aTarget, BratAnnotatorModel aBratAnnotatorModel) { bModel = aBratAnnotatorModel; aTarget.add(numberOfPages); } @Override public void renderHead(IHeaderResponse aResponse) { super.renderHead(aResponse); // If the page is reloaded in the browser and a document was already open, we need // to render it. We use the "later" commands here to avoid polluting the Javascript // header items with document data and because loading times are not that critical // on a reload. if (getModelObject().getProject() != null) { // We want to trigger a late rendering only on a page reload, but not on a // Ajax request. if (!aResponse.getResponse().getClass().getName().endsWith("AjaxResponse")) { aResponse.render(OnLoadHeaderItem.forScript(bratInitLaterCommand())); aResponse.render(OnLoadHeaderItem.forScript(bratRenderLaterCommand())); } } } }; // This is an Annotation Operation, set model to ANNOTATION mode bModel.setMode(Mode.ANNOTATION); add(annotator); add(documentNamePanel = (DocumentNamePanel) new DocumentNamePanel("documentNamePanel", new Model<BratAnnotatorModel>(bModel)).setOutputMarkupId(true)); numberOfPages = new Label("numberOfPages", new Model<String>()); numberOfPages.setOutputMarkupId(true); add(numberOfPages); final ModalWindow openDocumentsModal; add(openDocumentsModal = new ModalWindow("openDocumentsModal")); openDocumentsModal.setOutputMarkupId(true); openDocumentsModal.setInitialWidth(500); openDocumentsModal.setInitialHeight(300); openDocumentsModal.setResizable(true); openDocumentsModal.setWidthUnit("px"); openDocumentsModal.setHeightUnit("px"); openDocumentsModal.setTitle("Open document"); openDocumentsModal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { private static final long serialVersionUID = -5423095433535634321L; @Override public boolean onCloseButtonClicked(AjaxRequestTarget aTarget) { closeButtonClicked = true; return true; } }); add(new AjaxLink<Void>("showOpenDocumentModal") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { editor.reset(aTarget); closeButtonClicked = false; openDocumentsModal.setContent(new OpenModalWindowPanel(openDocumentsModal.getContentId(), bModel, openDocumentsModal, Mode.ANNOTATION) { private static final long serialVersionUID = -3434069761864809703L; @Override protected void onCancel(AjaxRequestTarget aTarget) { closeButtonClicked = true; }; }); openDocumentsModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = -1746088901018629567L; @Override public void onClose(AjaxRequestTarget target) { // A hack, the dialog opens for the first time, and if no document is // selected window will be "blind down". Something in the brat js causes // this! if (bModel.getProject() == null || bModel.getDocument() == null) { setResponsePage(WelcomePage.class); } // Dialog was cancelled rather that a document was selected. if (closeButtonClicked) { return; } loadDocumentAction(target); String username = SecurityContextHolder.getContext().getAuthentication().getName(); User user = userRepository.get(username); editor.setEnabled( !FinishImage.isFinished(new Model<BratAnnotatorModel>(bModel), user, repository)); } }); // target.appendJavaScript("Wicket.Window.unloadConfirmation = false;"); openDocumentsModal.show(aTarget); } }); add(new AnnotationLayersModalPanel("annotationLayersModalPanel", new Model<BratAnnotatorModel>(bModel), editor) { private static final long serialVersionUID = -4657965743173979437L; @Override protected void onChange(AjaxRequestTarget aTarget) { try { JCas jCas = getJCas(); annotator.bratRender(aTarget, jCas); updateSentenceAddress(jCas, aTarget); } catch (UIMAException | ClassNotFoundException | IOException e) { LOG.info("Error reading CAS " + e.getMessage()); error("Error reading CAS " + e.getMessage()); return; } } }); add(new ExportModalPanel("exportModalPanel", new Model<BratAnnotatorModel>(bModel))); // Show the previous document, if exist add(new AjaxLink<Void>("showPreviousDocument") { private static final long serialVersionUID = 7496156015186497496L; /** * Get the current beginning sentence address and add on it the size of the display * window */ @Override public void onClick(AjaxRequestTarget aTarget) { editor.reset(aTarget); // List of all Source Documents in the project List<SourceDocument> listOfSourceDocuements = repository.listSourceDocuments(bModel.getProject()); String username = SecurityContextHolder.getContext().getAuthentication().getName(); User user = userRepository.get(username); List<SourceDocument> sourceDocumentsinIgnorState = new ArrayList<SourceDocument>(); for (SourceDocument sourceDocument : listOfSourceDocuements) { if (repository.existsAnnotationDocument(sourceDocument, user) && repository.getAnnotationDocument(sourceDocument, user).getState() .equals(AnnotationDocumentState.IGNORE)) { sourceDocumentsinIgnorState.add(sourceDocument); } } listOfSourceDocuements.removeAll(sourceDocumentsinIgnorState); // Index of the current source document in the list int currentDocumentIndex = listOfSourceDocuements.indexOf(bModel.getDocument()); // If the first the document if (currentDocumentIndex == 0) { aTarget.appendJavaScript("alert('This is the first document!')"); return; } bModel.setDocumentName(listOfSourceDocuements.get(currentDocumentIndex - 1).getName()); bModel.setDocument(listOfSourceDocuements.get(currentDocumentIndex - 1)); loadDocumentAction(aTarget); } }.add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_up }, EventType.click))); // Show the next document if exist add(new AjaxLink<Void>("showNextDocument") { private static final long serialVersionUID = 7496156015186497496L; /** * Get the current beginning sentence address and add on it the size of the display * window */ @Override public void onClick(AjaxRequestTarget aTarget) { editor.reset(aTarget); // List of all Source Documents in the project List<SourceDocument> listOfSourceDocuements = repository.listSourceDocuments(bModel.getProject()); String username = SecurityContextHolder.getContext().getAuthentication().getName(); User user = userRepository.get(username); List<SourceDocument> sourceDocumentsinIgnorState = new ArrayList<SourceDocument>(); for (SourceDocument sourceDocument : listOfSourceDocuements) { if (repository.existsAnnotationDocument(sourceDocument, user) && repository.getAnnotationDocument(sourceDocument, user).getState() .equals(AnnotationDocumentState.IGNORE)) { sourceDocumentsinIgnorState.add(sourceDocument); } } listOfSourceDocuements.removeAll(sourceDocumentsinIgnorState); // Index of the current source document in the list int currentDocumentIndex = listOfSourceDocuements.indexOf(bModel.getDocument()); // If the first document if (currentDocumentIndex == listOfSourceDocuements.size() - 1) { aTarget.appendJavaScript("alert('This is the last document!')"); return; } bModel.setDocumentName(listOfSourceDocuements.get(currentDocumentIndex + 1).getName()); bModel.setDocument(listOfSourceDocuements.get(currentDocumentIndex + 1)); loadDocumentAction(aTarget); } }.add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_down }, EventType.click))); // Show the next page of this document add(new AjaxLink<Void>("showNext") { private static final long serialVersionUID = 7496156015186497496L; /** * Get the current beginning sentence address and add on it the size of the display * window */ @Override public void onClick(AjaxRequestTarget aTarget) { try { if (bModel.getDocument() != null) { JCas jCas = getJCas(); int nextSentenceAddress = BratAjaxCasUtil.getNextPageFirstSentenceAddress(jCas, bModel.getSentenceAddress(), bModel.getPreferences().getWindowSize()); if (bModel.getSentenceAddress() != nextSentenceAddress) { updateSentenceNumber(jCas, nextSentenceAddress); aTarget.addChildren(getPage(), FeedbackPanel.class); annotator.bratRenderLater(aTarget); gotoPageTextField.setModelObject( BratAjaxCasUtil.getFirstSentenceNumber(jCas, bModel.getSentenceAddress()) + 1); updateSentenceAddress(jCas, aTarget); } else { aTarget.appendJavaScript("alert('This is last page!')"); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } catch (Exception e) { error(e.getMessage()); aTarget.addChildren(getPage(), FeedbackPanel.class); } } }.add(new InputBehavior(new KeyType[] { KeyType.Page_down }, EventType.click))); // Show the previous page of this document add(new AjaxLink<Void>("showPrevious") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { try { if (bModel.getDocument() != null) { JCas jCas = getJCas(); int previousSentenceAddress = BratAjaxCasUtil.getPreviousDisplayWindowSentenceBeginAddress( jCas, bModel.getSentenceAddress(), bModel.getPreferences().getWindowSize()); if (bModel.getSentenceAddress() != previousSentenceAddress) { updateSentenceNumber(jCas, previousSentenceAddress); aTarget.addChildren(getPage(), FeedbackPanel.class); annotator.bratRenderLater(aTarget); gotoPageTextField.setModelObject( BratAjaxCasUtil.getFirstSentenceNumber(jCas, bModel.getSentenceAddress()) + 1); updateSentenceAddress(jCas, aTarget); } else { aTarget.appendJavaScript("alert('This is First Page!')"); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } catch (Exception e) { error(e.getMessage()); aTarget.addChildren(getPage(), FeedbackPanel.class); } } }.add(new InputBehavior(new KeyType[] { KeyType.Page_up }, EventType.click))); add(new AjaxLink<Void>("showFirst") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { try { if (bModel.getDocument() != null) { JCas jCas = getJCas(); if (bModel.getFirstSentenceAddress() != bModel.getSentenceAddress()) { updateSentenceNumber(jCas, bModel.getFirstSentenceAddress()); aTarget.addChildren(getPage(), FeedbackPanel.class); annotator.bratRenderLater(aTarget); gotoPageTextField.setModelObject( BratAjaxCasUtil.getFirstSentenceNumber(jCas, bModel.getSentenceAddress()) + 1); updateSentenceAddress(jCas, aTarget); } else { aTarget.appendJavaScript("alert('This is first page!')"); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } catch (Exception e) { error(e.getMessage()); aTarget.addChildren(getPage(), FeedbackPanel.class); } } }.add(new InputBehavior(new KeyType[] { KeyType.Home }, EventType.click))); add(new AjaxLink<Void>("showLast") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { try { if (bModel.getDocument() != null) { JCas jCas = getJCas(); int lastDisplayWindowBeginingSentenceAddress = BratAjaxCasUtil .getLastDisplayWindowFirstSentenceAddress(jCas, bModel.getPreferences().getWindowSize()); if (lastDisplayWindowBeginingSentenceAddress != bModel.getSentenceAddress()) { updateSentenceNumber(jCas, lastDisplayWindowBeginingSentenceAddress); aTarget.addChildren(getPage(), FeedbackPanel.class); annotator.bratRenderLater(aTarget); gotoPageTextField.setModelObject( BratAjaxCasUtil.getFirstSentenceNumber(jCas, bModel.getSentenceAddress()) + 1); updateSentenceAddress(jCas, aTarget); } else { aTarget.appendJavaScript("alert('This is last Page!')"); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } catch (Exception e) { error(e.getMessage()); aTarget.addChildren(getPage(), FeedbackPanel.class); } } }.add(new InputBehavior(new KeyType[] { KeyType.End }, EventType.click))); add(new AjaxLink<Void>("toggleScriptDirection") { private static final long serialVersionUID = -4332566542278611728L; @Override public void onClick(AjaxRequestTarget aTarget) { if (ScriptDirection.LTR.equals(bModel.getScriptDirection())) { bModel.setScriptDirection(ScriptDirection.RTL); } else { bModel.setScriptDirection(ScriptDirection.LTR); } annotator.bratRenderLater(aTarget); } }); add(new GuidelineModalPanel("guidelineModalPanel", new Model<BratAnnotatorModel>(bModel))); gotoPageTextField = (NumberTextField<Integer>) new NumberTextField<Integer>("gotoPageText", new Model<Integer>(0)); Form<Void> gotoPageTextFieldForm = new Form<Void>("gotoPageTextFieldForm"); gotoPageTextFieldForm.add(new AjaxFormSubmitBehavior(gotoPageTextFieldForm, "onsubmit") { private static final long serialVersionUID = -4549805321484461545L; @Override protected void onSubmit(AjaxRequestTarget aTarget) { try { if (gotoPageAddress == 0) { aTarget.appendJavaScript("alert('The sentence number entered is not valid')"); return; } if (bModel.getSentenceAddress() != gotoPageAddress) { JCas jCas = getJCas(); updateSentenceNumber(jCas, gotoPageAddress); aTarget.addChildren(getPage(), FeedbackPanel.class); annotator.bratRenderLater(aTarget); aTarget.add(numberOfPages); gotoPageTextField.setModelObject( BratAjaxCasUtil.getFirstSentenceNumber(jCas, bModel.getSentenceAddress()) + 1); aTarget.add(gotoPageTextField); } } catch (Exception e) { error(e.getMessage()); aTarget.addChildren(getPage(), FeedbackPanel.class); } } }); gotoPageTextField.setType(Integer.class); gotoPageTextField.setMinimum(1); gotoPageTextField.setDefaultModelObject(1); add(gotoPageTextFieldForm.add(gotoPageTextField)); gotoPageTextField.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 56637289242712170L; @Override protected void onUpdate(AjaxRequestTarget aTarget) { try { if (gotoPageTextField.getModelObject() < 1) { aTarget.appendJavaScript("alert('Page number shouldn't be less than 1')"); } else { updateSentenceAddress(getJCas(), aTarget); } } catch (Exception e) { error(e.getMessage()); aTarget.addChildren(getPage(), FeedbackPanel.class); } } }); add(new AjaxLink<Void>("gotoPageLink") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { try { if (gotoPageAddress == 0) { aTarget.appendJavaScript("alert('The sentence number entered is not valid')"); return; } if (bModel.getDocument() == null) { aTarget.appendJavaScript("alert('Please open a document first!')"); return; } if (bModel.getSentenceAddress() != gotoPageAddress) { JCas jCas = getJCas(); updateSentenceNumber(jCas, gotoPageAddress); updateSentenceAddress(jCas, aTarget); annotator.bratRenderLater(aTarget); } } catch (Exception e) { error(e.getMessage()); aTarget.addChildren(getPage(), FeedbackPanel.class); } } }); finish = new FinishImage("finishImage", new Model<BratAnnotatorModel>(bModel)); finish.setOutputMarkupId(true); add(new FinishLink("showYesNoModalPanel", new Model<BratAnnotatorModel>(bModel), finish) { private static final long serialVersionUID = -4657965743173979437L; }); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.page.annotation.component.AnnotationLayersModalPanel.java
License:Apache License
public AnnotationLayersModalPanel(String id, final IModel<BratAnnotatorModel> aBModel, AnnotationDetailEditorPanel aEditor) { super(id, aBModel); // dialog window to select annotation layer preferences final ModalWindow annotationLayerSelectionModal; add(annotationLayerSelectionModal = new ModalWindow("annotationLayerModal")); annotationLayerSelectionModal.setOutputMarkupId(true); annotationLayerSelectionModal.setInitialWidth(450); annotationLayerSelectionModal.setInitialHeight(350); annotationLayerSelectionModal.setResizable(true); annotationLayerSelectionModal.setWidthUnit("px"); annotationLayerSelectionModal.setHeightUnit("px"); annotationLayerSelectionModal.setTitle("Annotation Layer and window size configuration Window"); annotationLayerSelectionModal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { private static final long serialVersionUID = -5423095433535634321L; @Override/*from w w w .j a v a2s . co m*/ public boolean onCloseButtonClicked(AjaxRequestTarget aTarget) { closeButtonClicked = true; return true; } }); add(new AjaxLink<Void>("showannotationLayerModal") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget target) { if (aBModel.getObject().getProject() == null) { target.appendJavaScript("alert('Please open a project first!')"); } else { closeButtonClicked = false; annotationLayerSelectionModal.setContent( new AnnotationPreferenceModalPanel(annotationLayerSelectionModal.getContentId(), annotationLayerSelectionModal, aBModel.getObject(), aEditor) { private static final long serialVersionUID = -3434069761864809703L; @Override protected void onCancel(AjaxRequestTarget aTarget) { closeButtonClicked = true; }; }); annotationLayerSelectionModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = 1643342179335627082L; @Override public void onClose(AjaxRequestTarget target) { if (!closeButtonClicked) { onChange(target); } } }); annotationLayerSelectionModal.show(target); } } }); }
From source file:nl.knaw.dans.dccd.web.search.pages.AdvSearchPage.java
License:Apache License
private void initTaxonSelection(final AdvancedSearchForm form, final AdvSearchData data) { // With plain text input: //add(new TextField("elementTaxon", new SearchFieldModel(data, "elementTaxon"))); // With autocomplete: //add(new TridasVocabularyAutoCompleteSelector("elementTaxon", // new SearchFieldModel(data, "elementTaxon"), // "element.taxon")); // With ComboBox: final DropDown elemTaxonComboBox = new DropDown("elementTaxon", new SearchFieldModel(data, "elementTaxon"), new DropDownDataSource<String>() { private static final long serialVersionUID = 1L; public String getName() { return "element.taxon"; }/*ww w .j a va 2 s . c o m*/ public List<String> getValues() { // Use current language to get terms for that language String langCode = getSession().getLocale().getLanguage(); return DccdVocabularyService.getService().getTerms("element.taxon", langCode); } public String getDescriptionForValue(String t) { return t; } }, false); elemTaxonComboBox.setCharacterWidth(25); elemTaxonComboBox.setOutputMarkupId(true); //form.add(elemTaxonComboBox); // FIX Container is needed to workaround visural-wicket ISSUE 67 final WebMarkupContainer taxonContainer = new WebMarkupContainer("elementTaxonContainer"); taxonContainer.setOutputMarkupId(true); form.add(taxonContainer); taxonContainer.add(elemTaxonComboBox); //TEST adding the window with the table //Problem, the TaxonSelectPanel wants a real TridasTaxon final ModalWindow modalSelectDialog; form.add(modalSelectDialog = new ModalWindow("taxonSelectPanel")); final TaxonSelectPanel taxonSelectPanel = new TaxonSelectPanel(modalSelectDialog.getContentId(), new Model(null)) { private static final long serialVersionUID = 1L; @Override protected void onSelectionChanged(AjaxRequestTarget target) { String taxonString = getSelectionAsString(); LOGGER.debug("Selected taxon: " + taxonString); data.elementTaxon.setValue(taxonString); //target.addComponent(elemTaxonComboBox); // FIX workaround visural-wicket ISSUE 67 by updating the container target.addComponent(taxonContainer); } }; modalSelectDialog.setContent(taxonSelectPanel); //modalSelectDialog.setTitle(ProjectPermissionSettingsPage.this.getString("userAddDialogTitle")); modalSelectDialog.setCookieName("taxonSelectPanelWindow"); modalSelectDialog.setInitialWidth(400); modalSelectDialog.setInitialHeight(160); modalSelectDialog.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { private static final long serialVersionUID = 1L; public boolean onCloseButtonClicked(AjaxRequestTarget target) { return true; } }); //button to show the dialog AjaxLink taxonSelectButton = new IndicatingAjaxLink("taxonSelectButton") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { //LOGGER.debug("term=" + data.elementTaxon.getValue()); //taxonSelectPanel.selectTerm(elemTaxonComboBox.getValue()); modalSelectDialog.show(target); } }; form.add(taxonSelectButton); }