List of usage examples for org.apache.wicket.ajax AjaxRequestTarget appendJavaScript
void appendJavaScript(CharSequence javascript);
If the javascript needs to do something asynchronously (i.e.
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 . j a v a2s . 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/* w w w. ja v a2 s .c o 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:de.tudarmstadt.ukp.clarin.webanno.webapp.page.annotation.component.ExportModalPanel.java
License:Apache License
public ExportModalPanel(String id, final IModel<BratAnnotatorModel> aModel) { super(id, aModel); final ModalWindow exportModal; add(exportModal = new ModalWindow("exportModal")); exportModal.setCookieName("modal-1"); exportModal.setInitialWidth(550);// w w w .j ava2 s .c o m exportModal.setInitialHeight(450); exportModal.setResizable(true); exportModal.setWidthUnit("px"); exportModal.setHeightUnit("px"); exportModal.setTitle("Export Annotated data to a given Format"); exportModal.setContent( new ExportModalWindowPanel(exportModal.getContentId(), exportModal, aModel.getObject())); add(new AjaxLink<Void>("showExportModal") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget target) { if (aModel.getObject().getDocument() == null) { target.appendJavaScript("alert('Please open a document first!')"); } else { exportModal.show(target); } } }); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.page.annotation.component.FinishLink.java
License:Apache License
public FinishLink(String id, final IModel<BratAnnotatorModel> aModel, final FinishImage finishImag) { super(id, aModel); final ModalWindow FinishModal; add(FinishModal = new ModalWindow("yesNoModal")); FinishModal.setOutputMarkupId(true); FinishModal.setInitialWidth(400);/* w w w. ja v a 2s .c om*/ FinishModal.setInitialHeight(50); FinishModal.setResizable(true); FinishModal.setWidthUnit("px"); FinishModal.setHeightUnit("px"); FinishModal.setTitle("Are you sure you want to finish annotating?"); AjaxLink<Void> showYesNoModal; add(showYesNoModal = new AjaxLink<Void>("showYesNoModal") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget target) { String username = SecurityContextHolder.getContext().getAuthentication().getName(); User user = userRepository.get(username); if (FinishImage.isFinished(aModel, user, repository)) { target.appendJavaScript("alert('Document already closed!')"); } else { FinishModal.setContent(new YesNoFinishModalPanel(FinishModal.getContentId(), aModel.getObject(), FinishModal, Mode.ANNOTATION)); FinishModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = -1746088901018629567L; @Override public void onClose(AjaxRequestTarget target) { target.add(finishImag.setOutputMarkupId(true)); } }); FinishModal.show(target); } } }); showYesNoModal.add(finishImag); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.page.automation.AutomationPage.java
License:Apache License
public AutomationPage() { bModel = new BratAnnotatorModel(); bModel.setMode(Mode.AUTOMATION);/* ww w .j a va 2 s. com*/ LinkedList<CurationUserSegmentForAnnotationDocument> sentences = new LinkedList<CurationUserSegmentForAnnotationDocument>(); CurationUserSegmentForAnnotationDocument curationUserSegmentForAnnotationDocument = new CurationUserSegmentForAnnotationDocument(); if (bModel.getDocument() != null) { curationUserSegmentForAnnotationDocument .setAnnotationSelectionByUsernameAndAddress(annotationSelectionByUsernameAndAddress); curationUserSegmentForAnnotationDocument.setBratAnnotatorModel(bModel); sentences.add(curationUserSegmentForAnnotationDocument); } automateView = new SuggestionViewPanel("automateView", new Model<LinkedList<CurationUserSegmentForAnnotationDocument>>(sentences)) { private static final long serialVersionUID = 2583509126979792202L; @Override public void onChange(AjaxRequestTarget aTarget) { try { // update begin/end of the curationsegment based on bratAnnotatorModel changes // (like sentence change in auto-scroll mode,.... aTarget.addChildren(getPage(), FeedbackPanel.class); curationContainer.setBratAnnotatorModel(bModel); setCurationSegmentBeginEnd(); CuratorUtil.updatePanel(aTarget, this, curationContainer, annotator, repository, annotationSelectionByUsernameAndAddress, curationSegment, annotationService, userRepository); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } annotator.bratRenderLater(aTarget); aTarget.add(numberOfPages); update(aTarget); } }; automateView.setOutputMarkupId(true); add(automateView); editor = new AnnotationDetailEditorPanel("annotationDetailEditorPanel", new Model<BratAnnotatorModel>(bModel)) { private static final long serialVersionUID = 2857345299480098279L; @Override 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; } } @Override public void onAnnotate(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel, int aStart, int aEnd) { AnnotationLayer layer = aBModel.getSelectedAnnotationLayer(); int address = aBModel.getSelection().getAnnotation().getId(); try { AnnotationDocument annodoc = repository.createOrGetAnnotationDocument(aBModel.getDocument(), aBModel.getUser()); JCas jCas = repository.readAnnotationCas(annodoc); AnnotationFS fs = selectByAddr(jCas, address); for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) { Type type = CasUtil.getType(fs.getCAS(), layer.getName()); Feature feat = type.getFeatureByBaseName(f.getName()); if (!automationService.existsMiraTemplate(f)) { continue; } if (!automationService.getMiraTemplate(f).isAnnotateAndRepeat()) { continue; } TagSet tagSet = f.getTagset(); boolean isRepeatabl = false; // repeat only if the value is in the tagset for (Tag tag : annotationService.listTags(tagSet)) { if (fs.getFeatureValueAsString(feat) == null) { break; // this is new annotation without values } if (fs.getFeatureValueAsString(feat).equals(tag.getName())) { isRepeatabl = true; break; } } if (automationService.getMiraTemplate(f) != null && isRepeatabl) { if (layer.getType().endsWith(WebAnnoConst.RELATION_TYPE)) { AutomationUtil.repeateRelationAnnotation(aBModel, repository, annotationService, fs, f, fs.getFeatureValueAsString(feat)); update(aTarget); break; } else if (layer.getType().endsWith(WebAnnoConst.SPAN_TYPE)) { AutomationUtil.repeateSpanAnnotation(aBModel, repository, annotationService, aStart, aEnd, f, fs.getFeatureValueAsString(feat)); update(aTarget); break; } } } } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } @Override public void onDelete(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel, AnnotationFS aFs) { AnnotationLayer layer = aBModel.getSelectedAnnotationLayer(); for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) { if (!automationService.existsMiraTemplate(f)) { continue; } if (!automationService.getMiraTemplate(f).isAnnotateAndRepeat()) { continue; } try { Type type = CasUtil.getType(aFs.getCAS(), layer.getName()); Feature feat = type.getFeatureByBaseName(f.getName()); if (layer.getType().endsWith(WebAnnoConst.RELATION_TYPE)) { AutomationUtil.deleteRelationAnnotation(aBModel, repository, annotationService, aFs, f, aFs.getFeatureValueAsString(feat)); } else { AutomationUtil.deleteSpanAnnotation(aBModel, repository, annotationService, aFs.getBegin(), aFs.getEnd(), f, aFs.getFeatureValueAsString(feat)); } update(aTarget); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } } }; editor.setOutputMarkupId(true); add(editor); annotator = new BratAnnotator("mergeView", new Model<BratAnnotatorModel>(bModel), editor) { private static final long serialVersionUID = 7279648231521710155L; @Override public void onChange(AjaxRequestTarget aTarget, BratAnnotatorModel aBratAnnotatorModel) { try { aTarget.addChildren(getPage(), FeedbackPanel.class); // info(bratAnnotatorModel.getMessage()); aTarget.addChildren(getPage(), FeedbackPanel.class); bModel = aBratAnnotatorModel; SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); CuratorUtil.updatePanel(aTarget, automateView, curationContainer, this, repository, annotationSelectionByUsernameAndAddress, curationSegment, annotationService, userRepository); aTarget.add(automateView); aTarget.add(numberOfPages); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } update(aTarget); } }; // reset sentenceAddress and lastSentenceAddress to the orginal once annotator.setOutputMarkupId(true); add(annotator); curationContainer = new CurationContainer(); curationContainer.setBratAnnotatorModel(bModel); add(documentNamePanel = new DocumentNamePanel("documentNamePanel", new Model<BratAnnotatorModel>(bModel))); add(numberOfPages = (Label) new Label("numberOfPages", new LoadableDetachableModel<String>() { private static final long serialVersionUID = 891566759811286173L; @Override protected String load() { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { mergeJCas = repository.readCorrectionCas(bModel.getDocument()); totalNumberOfSentence = getNumberOfPages(mergeJCas); // If only one page, start displaying from sentence 1 /* * if (totalNumberOfSentence == 1) { * bratAnnotatorModel.setSentenceAddress(bratAnnotatorModel * .getFirstSentenceAddress()); } */ int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(), bModel.getSentenceEndOffset())); sentenceNumber = getFirstSentenceNumber(mergeJCas, address); int firstSentenceNumber = sentenceNumber + 1; int lastSentenceNumber; if (firstSentenceNumber + bModel.getPreferences().getWindowSize() - 1 < totalNumberOfSentence) { lastSentenceNumber = firstSentenceNumber + bModel.getPreferences().getWindowSize() - 1; } else { lastSentenceNumber = totalNumberOfSentence; } return "showing " + firstSentenceNumber + "-" + lastSentenceNumber + " of " + totalNumberOfSentence + " sentences"; } catch (UIMAException e) { return ""; } catch (DataRetrievalFailureException e) { return ""; } catch (ClassNotFoundException e) { return ""; } catch (FileNotFoundException e) { return ""; } catch (IOException e) { return ""; } } else { return "";// no document yet selected } } }).setOutputMarkupId(true)); 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"); add(new AjaxLink<Void>("showOpenDocumentModal") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { editor.reset(aTarget); openDocumentsModal.setContent(new OpenModalWindowPanel(openDocumentsModal.getContentId(), bModel, openDocumentsModal, Mode.AUTOMATION)); openDocumentsModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = -1746088901018629567L; @Override public void onClose(AjaxRequestTarget target) { if (bModel.getDocument() == null) { setResponsePage(WelcomePage.class); return; } try { target.addChildren(getPage(), FeedbackPanel.class); bModel.setDocument(bModel.getDocument()); bModel.setProject(bModel.getProject()); String username = SecurityContextHolder.getContext().getAuthentication().getName(); loadDocumentAction(); setCurationSegmentBeginEnd(); update(target); User user = userRepository.get(username); editor.setEnabled(!FinishImage.isFinished(new Model<BratAnnotatorModel>(bModel), user, repository)); } catch (UIMAException e) { target.addChildren(getPage(), FeedbackPanel.class); error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { target.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (IOException e) { target.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } finish.setModelObject(bModel); target.add(finish.setOutputMarkupId(true)); target.appendJavaScript("Wicket.Window.unloadConfirmation=false;window.location.reload()"); target.add(documentNamePanel.setOutputMarkupId(true)); target.add(numberOfPages); } }); openDocumentsModal.show(aTarget); } }); add(new AnnotationLayersModalPanel("annotationLayersModalPanel", new Model<BratAnnotatorModel>(bModel), editor) { private static final long serialVersionUID = -4657965743173979437L; @Override protected void onChange(AjaxRequestTarget aTarget) { curationContainer.setBratAnnotatorModel(bModel); try { aTarget.addChildren(getPage(), FeedbackPanel.class); setCurationSegmentBeginEnd(); } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } update(aTarget); // mergeVisualizer.reloadContent(aTarget); aTarget.appendJavaScript("Wicket.Window.unloadConfirmation = false;window.location.reload()"); } }); add(new ExportModalPanel("exportModalPanel", 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) { if (gotoPageAddress == 0) { aTarget.appendJavaScript("alert('The sentence number entered is not valid')"); return; } JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); if (bModel.getSentenceAddress() != gotoPageAddress) { updateSentenceNumber(mergeJCas, gotoPageAddress); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } }); gotoPageTextField.setType(Integer.class); gotoPageTextField.setMinimum(1); gotoPageTextField.setDefaultModelObject(1); add(gotoPageTextFieldForm.add(gotoPageTextField)); gotoPageTextField.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -3853194405966729661L; @Override protected void onUpdate(AjaxRequestTarget target) { JCas mergeJCas = null; try { mergeJCas = repository.readCorrectionCas(bModel.getDocument()); gotoPageAddress = getSentenceAddress(mergeJCas, gotoPageTextField.getModelObject()); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(ExceptionUtils.getRootCause(e)); } catch (IOException e) { error(e.getMessage()); } } }); add(new AjaxLink<Void>("gotoPageLink") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { 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; } JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); if (bModel.getSentenceAddress() != gotoPageAddress) { updateSentenceNumber(mergeJCas, gotoPageAddress); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } }); finish = new FinishImage("finishImage", new LoadableDetachableModel<BratAnnotatorModel>() { private static final long serialVersionUID = -2737326878793568454L; @Override protected BratAnnotatorModel load() { return bModel; } }); add(new FinishLink("showYesNoModalPanel", new Model<BratAnnotatorModel>(bModel), finish) { private static final long serialVersionUID = -4657965743173979437L; }); // 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); aTarget.addChildren(getPage(), FeedbackPanel.class); // 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); } else if (sourceDocument.isTrainingDocument()) { 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!')"); } else { bModel.setDocumentName(listOfSourceDocuements.get(currentDocumentIndex - 1).getName()); bModel.setDocument(listOfSourceDocuements.get(currentDocumentIndex - 1)); try { repository.upgradeCasAndSave(bModel.getDocument(), Mode.AUTOMATION, bModel.getUser().getUsername()); loadDocumentAction(); setCurationSegmentBeginEnd(); update(aTarget); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(ExceptionUtils.getRootCause(e)); } catch (IOException e) { error(ExceptionUtils.getRootCause(e)); } catch (BratAnnotationException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } finish.setModelObject(bModel); aTarget.add(finish.setOutputMarkupId(true)); aTarget.add(numberOfPages); aTarget.add(documentNamePanel); annotator.bratRenderLater(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); aTarget.addChildren(getPage(), FeedbackPanel.class); // 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); } else if (sourceDocument.isTrainingDocument()) { 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)); try { repository.upgradeCasAndSave(bModel.getDocument(), Mode.AUTOMATION, bModel.getUser().getUsername()); loadDocumentAction(); setCurationSegmentBeginEnd(); update(aTarget); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(ExceptionUtils.getRootCause(e)); } catch (IOException e) { error(ExceptionUtils.getRootCause(e)); } catch (BratAnnotationException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } finish.setModelObject(bModel); aTarget.add(finish.setOutputMarkupId(true)); aTarget.add(numberOfPages); aTarget.add(documentNamePanel); annotator.bratRenderLater(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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(), bModel.getSentenceEndOffset())); int nextSentenceAddress = getNextPageFirstSentenceAddress(mergeJCas, address, bModel.getPreferences().getWindowSize()); if (address != nextSentenceAddress) { updateSentenceNumber(mergeJCas, nextSentenceAddress); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } else { aTarget.appendJavaScript("alert('This is last page!')"); } } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); int previousSentenceAddress = BratAjaxCasUtil.getPreviousDisplayWindowSentenceBeginAddress( mergeJCas, bModel.getSentenceAddress(), bModel.getPreferences().getWindowSize()); if (bModel.getSentenceAddress() != previousSentenceAddress) { updateSentenceNumber(mergeJCas, previousSentenceAddress); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } else { aTarget.appendJavaScript("alert('This is First Page!')"); } } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { ; error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(), bModel.getSentenceEndOffset())); int firstAddress = getFirstSentenceAddress(mergeJCas); if (firstAddress != address) { updateSentenceNumber(mergeJCas, firstAddress); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } else { aTarget.appendJavaScript("alert('This is first page!')"); } } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); int lastDisplayWindowBeginingSentenceAddress = BratAjaxCasUtil .getLastDisplayWindowFirstSentenceAddress(mergeJCas, bModel.getPreferences().getWindowSize()); if (lastDisplayWindowBeginingSentenceAddress != bModel.getSentenceAddress()) { updateSentenceNumber(mergeJCas, lastDisplayWindowBeginingSentenceAddress); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } else { aTarget.appendJavaScript("alert('This is last Page!')"); } } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.add(new InputBehavior(new KeyType[] { KeyType.End }, EventType.click))); add(new GuidelineModalPanel("guidelineModalPanel", new Model<BratAnnotatorModel>(bModel))); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.page.correction.CorrectionPage.java
License:Apache License
public CorrectionPage() { bModel = new BratAnnotatorModel(); bModel.setMode(Mode.CORRECTION);// w ww . j a v a 2 s . co m LinkedList<CurationUserSegmentForAnnotationDocument> sentences = new LinkedList<CurationUserSegmentForAnnotationDocument>(); CurationUserSegmentForAnnotationDocument curationUserSegmentForAnnotationDocument = new CurationUserSegmentForAnnotationDocument(); if (bModel.getDocument() != null) { curationUserSegmentForAnnotationDocument .setAnnotationSelectionByUsernameAndAddress(annotationSelectionByUsernameAndAddress); curationUserSegmentForAnnotationDocument.setBratAnnotatorModel(bModel); sentences.add(curationUserSegmentForAnnotationDocument); } automateView = new SuggestionViewPanel("automateView", new Model<LinkedList<CurationUserSegmentForAnnotationDocument>>(sentences)) { private static final long serialVersionUID = 2583509126979792202L; @Override public void onChange(AjaxRequestTarget aTarget) { try { // update begin/end of the curationsegment based on bratAnnotatorModel changes // (like sentence change in auto-scroll mode,.... aTarget.addChildren(getPage(), FeedbackPanel.class); curationContainer.setBratAnnotatorModel(bModel); setCurationSegmentBeginEnd(); CuratorUtil.updatePanel(aTarget, this, curationContainer, annotator, repository, annotationSelectionByUsernameAndAddress, curationSegment, annotationService, userRepository); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } annotator.bratRenderLater(aTarget); aTarget.add(numberOfPages); update(aTarget); } }; automateView.setOutputMarkupId(true); add(automateView); editor = new AnnotationDetailEditorPanel("annotationDetailEditorPanel", new Model<BratAnnotatorModel>(bModel)) { private static final long serialVersionUID = 2857345299480098279L; @Override 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("mergeView", new Model<BratAnnotatorModel>(bModel), editor) { private static final long serialVersionUID = 7279648231521710155L; @Override public void onChange(AjaxRequestTarget aTarget, BratAnnotatorModel aBratAnnotatorModel) { try { aTarget.addChildren(getPage(), FeedbackPanel.class); // info(bratAnnotatorModel.getMessage()); bModel = aBratAnnotatorModel; SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); CuratorUtil.updatePanel(aTarget, automateView, curationContainer, this, repository, annotationSelectionByUsernameAndAddress, curationSegment, annotationService, userRepository); aTarget.add(automateView); aTarget.add(numberOfPages); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } update(aTarget); } }; // reset sentenceAddress and lastSentenceAddress to the orginal once annotator.setOutputMarkupId(true); add(annotator); curationContainer = new CurationContainer(); curationContainer.setBratAnnotatorModel(bModel); add(documentNamePanel = new DocumentNamePanel("documentNamePanel", new Model<BratAnnotatorModel>(bModel))); add(numberOfPages = (Label) new Label("numberOfPages", new LoadableDetachableModel<String>() { private static final long serialVersionUID = 891566759811286173L; @Override protected String load() { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { mergeJCas = repository.readCorrectionCas(bModel.getDocument()); totalNumberOfSentence = getNumberOfPages(mergeJCas); // If only one page, start displaying from sentence 1 /* * if (totalNumberOfSentence == 1) { * bratAnnotatorModel.setSentenceAddress(bratAnnotatorModel * .getFirstSentenceAddress()); } */ int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(), bModel.getSentenceEndOffset())); sentenceNumber = getFirstSentenceNumber(mergeJCas, address); int firstSentenceNumber = sentenceNumber + 1; int lastSentenceNumber; if (firstSentenceNumber + bModel.getPreferences().getWindowSize() - 1 < totalNumberOfSentence) { lastSentenceNumber = firstSentenceNumber + bModel.getPreferences().getWindowSize() - 1; } else { lastSentenceNumber = totalNumberOfSentence; } return "showing " + firstSentenceNumber + "-" + lastSentenceNumber + " of " + totalNumberOfSentence + " sentences"; } catch (UIMAException e) { return ""; } catch (DataRetrievalFailureException e) { return ""; } catch (ClassNotFoundException e) { return ""; } catch (FileNotFoundException e) { return ""; } catch (IOException e) { return ""; } } else { return "";// no document yet selected } } }).setOutputMarkupId(true)); 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"); // Add project and document information at the top add(new AjaxLink<Void>("showOpenDocumentModal") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { editor.reset(aTarget); openDocumentsModal.setContent(new OpenModalWindowPanel(openDocumentsModal.getContentId(), bModel, openDocumentsModal, Mode.CORRECTION)); openDocumentsModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = -1746088901018629567L; @Override public void onClose(AjaxRequestTarget target) { if (bModel.getDocument() == null) { setResponsePage(WelcomePage.class); return; } try { target.addChildren(getPage(), FeedbackPanel.class); bModel.setDocument(bModel.getDocument()); bModel.setProject(bModel.getProject()); loadDocumentAction(); setCurationSegmentBeginEnd(); update(target); String username = SecurityContextHolder.getContext().getAuthentication().getName(); User user = userRepository.get(username); editor.setEnabled(!FinishImage.isFinished(new Model<BratAnnotatorModel>(bModel), user, repository)); } catch (UIMAException e) { target.appendJavaScript("alert('" + e.getMessage() + "')"); setResponsePage(WelcomePage.class); } catch (ClassNotFoundException e) { target.appendJavaScript("alert('" + e.getMessage() + "')"); setResponsePage(WelcomePage.class); } catch (IOException e) { target.appendJavaScript("alert('" + e.getMessage() + "')"); setResponsePage(WelcomePage.class); } catch (BratAnnotationException e) { target.appendJavaScript("alert('" + e.getMessage() + "')"); setResponsePage(WelcomePage.class); } finish.setModelObject(bModel); target.add(finish.setOutputMarkupId(true)); target.appendJavaScript("Wicket.Window.unloadConfirmation=false;window.location.reload()"); target.add(documentNamePanel.setOutputMarkupId(true)); target.add(numberOfPages); } }); openDocumentsModal.show(aTarget); } }); add(new AnnotationLayersModalPanel("annotationLayersModalPanel", new Model<BratAnnotatorModel>(bModel), editor) { private static final long serialVersionUID = -4657965743173979437L; @Override protected void onChange(AjaxRequestTarget aTarget) { curationContainer.setBratAnnotatorModel(bModel); try { aTarget.addChildren(getPage(), FeedbackPanel.class); setCurationSegmentBeginEnd(); } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } update(aTarget); // mergeVisualizer.reloadContent(aTarget); aTarget.appendJavaScript("Wicket.Window.unloadConfirmation = false;window.location.reload()"); } }); add(new ExportModalPanel("exportModalPanel", 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) { if (gotoPageAddress == 0) { aTarget.appendJavaScript("alert('The sentence number entered is not valid')"); return; } JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); if (bModel.getSentenceAddress() != gotoPageAddress) { bModel.setSentenceAddress(gotoPageAddress); Sentence sentence = selectByAddr(mergeJCas, Sentence.class, gotoPageAddress); bModel.setSentenceBeginOffset(sentence.getBegin()); bModel.setSentenceEndOffset(sentence.getEnd()); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } }); gotoPageTextField.setType(Integer.class); gotoPageTextField.setMinimum(1); gotoPageTextField.setDefaultModelObject(1); add(gotoPageTextFieldForm.add(gotoPageTextField)); gotoPageTextField.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -3853194405966729661L; @Override protected void onUpdate(AjaxRequestTarget target) { JCas mergeJCas = null; try { mergeJCas = repository.readCorrectionCas(bModel.getDocument()); gotoPageAddress = getSentenceAddress(mergeJCas, gotoPageTextField.getModelObject()); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(ExceptionUtils.getRootCause(e)); } catch (IOException e) { error(e.getMessage()); } } }); add(new AjaxLink<Void>("gotoPageLink") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { 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; } JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); if (bModel.getSentenceAddress() != gotoPageAddress) { bModel.setSentenceAddress(gotoPageAddress); Sentence sentence = selectByAddr(mergeJCas, Sentence.class, gotoPageAddress); bModel.setSentenceBeginOffset(sentence.getBegin()); bModel.setSentenceEndOffset(sentence.getEnd()); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } }); finish = new FinishImage("finishImage", new LoadableDetachableModel<BratAnnotatorModel>() { private static final long serialVersionUID = -2737326878793568454L; @Override protected BratAnnotatorModel load() { return bModel; } }); add(new FinishLink("showYesNoModalPanel", new Model<BratAnnotatorModel>(bModel), finish) { private static final long serialVersionUID = -4657965743173979437L; }); // 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); aTarget.addChildren(getPage(), FeedbackPanel.class); // List of all Source Documents in the project List<SourceDocument> listOfSourceDocuements = repository.listSourceDocuments(bModel.getProject()); User user = userRepository.get(SecurityContextHolder.getContext().getAuthentication().getName()); 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!')"); } else { bModel.setDocumentName(listOfSourceDocuements.get(currentDocumentIndex - 1).getName()); bModel.setDocument(listOfSourceDocuements.get(currentDocumentIndex - 1)); try { loadDocumentAction(); setCurationSegmentBeginEnd(); update(aTarget); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(ExceptionUtils.getRootCause(e)); } catch (IOException e) { error(ExceptionUtils.getRootCause(e)); } catch (BratAnnotationException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } finish.setModelObject(bModel); aTarget.add(finish.setOutputMarkupId(true)); aTarget.add(documentNamePanel); annotator.bratRenderLater(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); aTarget.addChildren(getPage(), FeedbackPanel.class); // 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)); try { loadDocumentAction(); setCurationSegmentBeginEnd(); update(aTarget); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(ExceptionUtils.getRootCause(e)); } catch (IOException e) { error(ExceptionUtils.getRootCause(e)); } catch (BratAnnotationException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (Exception e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } finish.setModelObject(bModel); aTarget.add(finish.setOutputMarkupId(true)); aTarget.add(documentNamePanel); annotator.bratRenderLater(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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(), bModel.getSentenceEndOffset())); int nextSentenceAddress = getNextPageFirstSentenceAddress(mergeJCas, address, bModel.getPreferences().getWindowSize()); if (address != nextSentenceAddress) { bModel.setSentenceAddress(nextSentenceAddress); Sentence sentence = selectByAddr(mergeJCas, Sentence.class, nextSentenceAddress); bModel.setSentenceBeginOffset(sentence.getBegin()); bModel.setSentenceEndOffset(sentence.getEnd()); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } else { aTarget.appendJavaScript("alert('This is last page!')"); } } catch (UIMAException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (IOException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (BratAnnotationException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (Exception e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); int previousSentenceAddress = BratAjaxCasUtil.getPreviousDisplayWindowSentenceBeginAddress( mergeJCas, bModel.getSentenceAddress(), bModel.getPreferences().getWindowSize()); if (bModel.getSentenceAddress() != previousSentenceAddress) { bModel.setSentenceAddress(previousSentenceAddress); Sentence sentence = selectByAddr(mergeJCas, Sentence.class, previousSentenceAddress); bModel.setSentenceBeginOffset(sentence.getBegin()); bModel.setSentenceEndOffset(sentence.getEnd()); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } else { aTarget.appendJavaScript("alert('This is First Page!')"); } } catch (UIMAException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (IOException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (BratAnnotationException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (Exception e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(), bModel.getSentenceEndOffset())); int firstAddress = getFirstSentenceAddress(mergeJCas); if (firstAddress != address) { bModel.setSentenceAddress(firstAddress); Sentence sentence = selectByAddr(mergeJCas, Sentence.class, firstAddress); bModel.setSentenceBeginOffset(sentence.getBegin()); bModel.setSentenceEndOffset(sentence.getEnd()); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } else { aTarget.appendJavaScript("alert('This is first page!')"); } } catch (UIMAException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (IOException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (BratAnnotationException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (Exception e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.addChildren(getPage(), FeedbackPanel.class); mergeJCas = repository.readCorrectionCas(bModel.getDocument()); int lastDisplayWindowBeginingSentenceAddress = BratAjaxCasUtil .getLastDisplayWindowFirstSentenceAddress(mergeJCas, bModel.getPreferences().getWindowSize()); if (lastDisplayWindowBeginingSentenceAddress != bModel.getSentenceAddress()) { bModel.setSentenceAddress(lastDisplayWindowBeginingSentenceAddress); Sentence sentence = selectByAddr(mergeJCas, Sentence.class, lastDisplayWindowBeginingSentenceAddress); bModel.setSentenceBeginOffset(sentence.getBegin()); bModel.setSentenceEndOffset(sentence.getEnd()); SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService, userRepository); curationContainer = builder.buildCurationContainer(bModel); setCurationSegmentBeginEnd(); curationContainer.setBratAnnotatorModel(bModel); update(aTarget); annotator.bratRenderLater(aTarget); } else { aTarget.appendJavaScript("alert('This is last Page!')"); } } catch (UIMAException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (IOException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (BratAnnotationException e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } catch (Exception e) { aTarget.addChildren(getPage(), FeedbackPanel.class); error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.add(new InputBehavior(new KeyType[] { KeyType.End }, EventType.click))); add(new GuidelineModalPanel("guidelineModalPanel", new Model<BratAnnotatorModel>(bModel))); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.page.curation.CurationPage.java
License:Apache License
@SuppressWarnings("deprecation") public CurationPage() { bModel = new BratAnnotatorModel(); bModel.setMode(Mode.CURATION);//from w ww . ja va 2s . c o m reMerge = new ReMergeCasModel(); curationContainer = new CurationContainer(); curationContainer.setBratAnnotatorModel(bModel); curationPanel = new CurationPanel("curationPanel", new Model<CurationContainer>(curationContainer)) { private static final long serialVersionUID = 2175915644696513166L; @Override protected void onChange(AjaxRequestTarget aTarget) { JCas mergeJCas = null; try { mergeJCas = repository.readCurationCas(bModel.getDocument()); } catch (UIMAException e) { error(e.getMessage()); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } aTarget.add(numberOfPages); gotoPageTextField .setModelObject(getFirstSentenceNumber(mergeJCas, bModel.getSentenceAddress()) + 1); gotoPageAddress = getSentenceAddress(mergeJCas, gotoPageTextField.getModelObject()); aTarget.add(gotoPageTextField); aTarget.add(curationPanel); } }; curationPanel.setOutputMarkupId(true); add(curationPanel); add(documentNamePanel = new DocumentNamePanel("documentNamePanel", new Model<BratAnnotatorModel>(bModel))); documentNamePanel.setOutputMarkupId(true); add(numberOfPages = (Label) new Label("numberOfPages", new LoadableDetachableModel<String>() { private static final long serialVersionUID = 1L; @Override protected String load() { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { mergeJCas = repository.readCurationCas(bModel.getDocument()); totalNumberOfSentence = getNumberOfPages(mergeJCas); // If only one page, start displaying from // sentence 1 if (totalNumberOfSentence == 1) { bModel.setSentenceAddress(bModel.getFirstSentenceAddress()); } sentenceNumber = getFirstSentenceNumber(mergeJCas, bModel.getSentenceAddress()); int firstSentenceNumber = sentenceNumber + 1; int lastSentenceNumber; if (firstSentenceNumber + bModel.getPreferences().getWindowSize() - 1 < totalNumberOfSentence) { lastSentenceNumber = firstSentenceNumber + bModel.getPreferences().getWindowSize() - 1; } else { lastSentenceNumber = totalNumberOfSentence; } return "showing " + firstSentenceNumber + "-" + lastSentenceNumber + " of " + totalNumberOfSentence + " sentences"; } catch (UIMAException e) { return ""; } catch (ClassNotFoundException e) { return ""; } catch (IOException e) { return ""; } } else { return "";// no document yet selected } } }).setOutputMarkupId(true)); 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"); // Add project and document information at the top add(new AjaxLink<Void>("showOpenDocumentModal") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { curationPanel.resetEditor(aTarget); openDocumentsModal.setContent(new OpenModalWindowPanel(openDocumentsModal.getContentId(), bModel, openDocumentsModal, Mode.CURATION)); openDocumentsModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = -1746088901018629567L; @Override public void onClose(AjaxRequestTarget target) { String username = SecurityContextHolder.getContext().getAuthentication().getName(); /* * Changed for #152, getDocument was returning null even after opening a document * Also, surrounded following code into if block to avoid error. */ if (bModel.getProject() == null) { setResponsePage(WelcomePage.class); return; } if (bModel.getDocument() != null) { User user = userRepository.get(username); // Update source document state to // CURRATION_INPROGRESS, if it was not // ANNOTATION_FINISHED if (!bModel.getDocument().getState().equals(SourceDocumentState.CURATION_FINISHED)) { bModel.getDocument().setState(SourceDocumentState.CURATION_IN_PROGRESS); } try { repository.createSourceDocument(bModel.getDocument(), user); repository.upgradeCasAndSave(bModel.getDocument(), Mode.CURATION, username); loadDocumentAction(target); } catch (IOException | UIMAException | ClassNotFoundException | BratAnnotationException e) { target.add(getFeedbackPanel()); error(e.getCause().getMessage()); } } } }); openDocumentsModal.show(aTarget); } }); add(new AnnotationLayersModalPanel("annotationLayersModalPanel", new Model<BratAnnotatorModel>(bModel), curationPanel.editor) { private static final long serialVersionUID = -4657965743173979437L; @Override protected void onChange(AjaxRequestTarget aTarget) { aTarget.add(getFeedbackPanel()); aTarget.add(numberOfPages); JCas mergeJCas = null; try { aTarget.add(getFeedbackPanel()); mergeJCas = repository.readCurationCas(bModel.getDocument()); curationPanel.updatePanel(aTarget, curationContainer); updatePanel(curationContainer, aTarget); updateSentenceNumber(mergeJCas, bModel.getSentenceAddress()); } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } }); // 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) { curationPanel.resetEditor(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.existFinishedDocument(sourceDocument, bModel.getProject())) { 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!')"); } else { bModel.setDocumentName(listOfSourceDocuements.get(currentDocumentIndex - 1).getName()); bModel.setDocument(listOfSourceDocuements.get(currentDocumentIndex - 1)); try { repository.upgradeCasAndSave(bModel.getDocument(), Mode.CURATION, bModel.getUser().getUsername()); loadDocumentAction(aTarget); } catch (IOException | UIMAException | ClassNotFoundException | BratAnnotationException e) { aTarget.add(getFeedbackPanel()); error(e.getCause().getMessage()); } } } }.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) { curationPanel.resetEditor(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.existFinishedDocument(sourceDocument, bModel.getProject())) { 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!')"); } else { bModel.setDocumentName(listOfSourceDocuements.get(currentDocumentIndex + 1).getName()); bModel.setDocument(listOfSourceDocuements.get(currentDocumentIndex + 1)); try { aTarget.add(getFeedbackPanel()); repository.upgradeCasAndSave(bModel.getDocument(), Mode.CURATION, bModel.getUser().getUsername()); loadDocumentAction(aTarget); } catch (IOException | UIMAException | ClassNotFoundException | BratAnnotationException e) { aTarget.add(getFeedbackPanel()); error(e.getCause().getMessage()); } } } }.add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_down }, EventType.click))); add(new ExportModalPanel("exportModalPanel", 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) { if (gotoPageAddress == 0) { aTarget.appendJavaScript("alert('The sentence number entered is not valid')"); return; } JCas mergeJCas = null; try { aTarget.add(getFeedbackPanel()); mergeJCas = repository.readCurationCas(bModel.getDocument()); if (bModel.getSentenceAddress() != gotoPageAddress) { updateSentenceNumber(mergeJCas, gotoPageAddress); aTarget.add(numberOfPages); updatePanel(curationContainer, aTarget); } } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } } }); gotoPageTextField.setType(Integer.class); gotoPageTextField.setMinimum(1); gotoPageTextField.setDefaultModelObject(1); add(gotoPageTextFieldForm.add(gotoPageTextField)); gotoPageTextField.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1244526899787707931L; @Override protected void onUpdate(AjaxRequestTarget aTarget) { JCas mergeJCas = null; try { aTarget.add(getFeedbackPanel()); mergeJCas = repository.readCurationCas(bModel.getDocument()); gotoPageAddress = getSentenceAddress(mergeJCas, gotoPageTextField.getModelObject()); } catch (UIMAException e) { error(ExceptionUtils.getRootCause(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } } }); add(new AjaxLink<Void>("gotoPageLink") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget aTarget) { 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; } JCas mergeJCas = null; try { aTarget.add(getFeedbackPanel()); mergeJCas = repository.readCurationCas(bModel.getDocument()); if (bModel.getSentenceAddress() != gotoPageAddress) { updateSentenceNumber(mergeJCas, gotoPageAddress); aTarget.add(numberOfPages); curationPanel.updatePanel(aTarget, curationContainer); } } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } }); finish = new WebMarkupContainer("finishImage"); finish.setOutputMarkupId(true); finish.add(new AttributeModifier("src", new LoadableDetachableModel<String>() { private static final long serialVersionUID = 1562727305401900776L; @Override protected String load() { if (bModel.getProject() != null && bModel.getDocument() != null) { if (repository .getSourceDocument(bModel.getDocument().getProject(), bModel.getDocument().getName()) .getState().equals(SourceDocumentState.CURATION_FINISHED)) { return "images/accept.png"; } else { return "images/inprogress.png"; } } else { return "images/inprogress.png"; } } })); final ModalWindow finishCurationModal; add(finishCurationModal = new ModalWindow("finishCurationModal")); finishCurationModal.setOutputMarkupId(true); finishCurationModal.setInitialWidth(700); finishCurationModal.setInitialHeight(50); finishCurationModal.setResizable(true); finishCurationModal.setWidthUnit("px"); finishCurationModal.setHeightUnit("px"); AjaxLink<Void> showFinishCurationModal; add(showFinishCurationModal = new AjaxLink<Void>("showFinishCurationModal") { private static final long serialVersionUID = 7496156015186497496L; @Override public void onClick(AjaxRequestTarget target) { if (bModel.getDocument() != null && bModel.getDocument().getState().equals(SourceDocumentState.CURATION_FINISHED)) { finishCurationModal.setTitle( "Curation was finished. Are you sure you want to re-open document for curation?"); } else { finishCurationModal.setTitle("Are you sure you want to finish curating?"); } finishCurationModal.setContent(new YesNoFinishModalPanel(finishCurationModal.getContentId(), bModel, finishCurationModal, Mode.CURATION)); finishCurationModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = -1746088901018629567L; @Override public void onClose(AjaxRequestTarget target) { target.add(finish); target.appendJavaScript("Wicket.Window.unloadConfirmation=false;window.location.reload()"); } }); finishCurationModal.show(target); } }); showFinishCurationModal.add(finish); add(new GuidelineModalPanel("guidelineModalPanel", new Model<BratAnnotatorModel>(bModel))); final ModalWindow reCreateMergeCas; add(reCreateMergeCas = new ModalWindow("reCreateMergeCasModal")); reCreateMergeCas.setOutputMarkupId(true); reCreateMergeCas.setInitialWidth(400); reCreateMergeCas.setInitialHeight(50); reCreateMergeCas.setResizable(true); reCreateMergeCas.setWidthUnit("px"); reCreateMergeCas.setHeightUnit("px"); reCreateMergeCas.setTitle("are you sure? all curation annotations for this document will be lost"); add(showreCreateMergeCasModal = new AjaxLink<Void>("showreCreateMergeCasModal") { private static final long serialVersionUID = 7496156015186497496L; @Override protected void onConfigure() { setEnabled(bModel.getDocument() != null && !bModel.getDocument().getState().equals(SourceDocumentState.CURATION_FINISHED)); } @Override public void onClick(AjaxRequestTarget target) { reCreateMergeCas.setContent( new ReCreateMergeCASModalPanel(reCreateMergeCas.getContentId(), reCreateMergeCas, reMerge)); reCreateMergeCas.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = 4816615910398625993L; @Override public void onClose(AjaxRequestTarget aTarget) { if (reMerge.isReMerege()) { try { aTarget.add(getFeedbackPanel()); repository.removeCurationDocumentContent(bModel.getDocument(), bModel.getUser().getUsername()); loadDocumentAction(aTarget); aTarget.appendJavaScript("alert('remerege finished!')"); } catch (IOException | UIMAException | ClassNotFoundException | BratAnnotationException e) { aTarget.add(getFeedbackPanel()); error(e.getCause().getMessage()); } } } }); reCreateMergeCas.show(target); } }); // 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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { mergeJCas = repository.readCurationCas(bModel.getDocument()); int nextSentenceAddress = getNextPageFirstSentenceAddress(mergeJCas, bModel.getSentenceAddress(), bModel.getPreferences().getWindowSize()); if (bModel.getSentenceAddress() != nextSentenceAddress) { aTarget.add(getFeedbackPanel()); updateSentenceNumber(mergeJCas, nextSentenceAddress); aTarget.add(numberOfPages); curationPanel.updatePanel(aTarget, curationContainer); updatePanel(curationContainer, aTarget); } else { aTarget.appendJavaScript("alert('This is last page!')"); } } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.add(getFeedbackPanel()); mergeJCas = repository.readCurationCas(bModel.getDocument()); int previousSentenceAddress = BratAjaxCasUtil.getPreviousDisplayWindowSentenceBeginAddress( mergeJCas, bModel.getSentenceAddress(), bModel.getPreferences().getWindowSize()); if (bModel.getSentenceAddress() != previousSentenceAddress) { updateSentenceNumber(mergeJCas, previousSentenceAddress); aTarget.add(numberOfPages); curationPanel.updatePanel(aTarget, curationContainer); updatePanel(curationContainer, aTarget); } else { aTarget.appendJavaScript("alert('This is First Page!')"); } } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.add(getFeedbackPanel()); mergeJCas = repository.readCurationCas(bModel.getDocument()); int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(), bModel.getSentenceEndOffset())); int firstAddress = getFirstSentenceAddress(mergeJCas); if (firstAddress != address) { updateSentenceNumber(mergeJCas, firstAddress); aTarget.add(numberOfPages); curationPanel.updatePanel(aTarget, curationContainer); updatePanel(curationContainer, aTarget); } else { aTarget.appendJavaScript("alert('This is first page!')"); } } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.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) { if (bModel.getDocument() != null) { JCas mergeJCas = null; try { aTarget.add(getFeedbackPanel()); mergeJCas = repository.readCurationCas(bModel.getDocument()); int lastDisplayWindowBeginingSentenceAddress = BratAjaxCasUtil .getLastDisplayWindowFirstSentenceAddress(mergeJCas, bModel.getPreferences().getWindowSize()); if (lastDisplayWindowBeginingSentenceAddress != bModel.getSentenceAddress()) { updateSentenceNumber(mergeJCas, lastDisplayWindowBeginingSentenceAddress); aTarget.add(numberOfPages); curationPanel.updatePanel(aTarget, curationContainer); updatePanel(curationContainer, aTarget); } else { aTarget.appendJavaScript("alert('This is last Page!')"); } } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } } else { aTarget.appendJavaScript("alert('Please open a document first!')"); } } }.add(new InputBehavior(new KeyType[] { KeyType.End }, EventType.click))); }
From source file:de.tudarmstadt.ukp.csniper.webapp.evaluation.page.EvaluationPage.java
License:Apache License
/** * Constructor that is invoked when page is invoked without a session. *///from w w w .jav a 2 s.c o m @SuppressWarnings({ "serial" }) public EvaluationPage() { contextViewsContainer = new WebMarkupContainer("contextViewsContainer") { { contextViews = new ListView<ContextView>("contextViews") { @Override protected void populateItem(ListItem aItem) { aItem.add((Component) aItem.getModelObject()); } }; add(contextViews); } }; contextViewsContainer.setOutputMarkupId(true); add(contextViewsContainer); columns = new ArrayList<IColumn<EvaluationResult, String>>(); columns.add(new AbstractColumn<EvaluationResult, String>(new Model<String>("")) { @Override public void populateItem(final Item<ICellPopulator<EvaluationResult>> aCellItem, String aComponentId, final IModel<EvaluationResult> model) { EmbeddableImage iconContext = new EmbeddableImage(aComponentId, new ContextRelativeResource("images/context.png")); iconContext.add(new AjaxEventBehavior("onclick") { @Override protected void onEvent(AjaxRequestTarget aTarget) { try { contextViews .setList(asList(new ContextView(contextProvider, model.getObject().getItem()))); aTarget.add(contextViewsContainer); } catch (IOException e) { aTarget.add(getFeedbackPanel()); error("Unable to load context: " + e.getMessage()); } } }); iconContext.add(new AttributeModifier("class", new Model<String>("clickableElement"))); aCellItem.add(iconContext); } }); columns.add(new AbstractColumn<EvaluationResult, String>(new Model<String>("")) { @Override public void populateItem(final Item<ICellPopulator<EvaluationResult>> aCellItem, final String aComponentId, final IModel<EvaluationResult> model) { // PopupLink pl = new PopupLink(aComponentId, new AnalysisPage(model.getObject() // .getItem()), "analysis", "Analyse", 800, 600); // pl.add(new AttributeModifier("class", new Model<String>("clickableElement"))); // aCellItem.add(pl); EmbeddableImage iconAnalysis = new EmbeddableImage(aComponentId, new ContextRelativeResource("images/analysis.png")); iconAnalysis.add(new AjaxEventBehavior("onclick") { @Override protected void onEvent(AjaxRequestTarget aTarget) { EvaluationItem item = model.getObject().getItem(); CachedParse cachedTree = repository.getCachedParse(item); ParseTreeResource ptr; if (cachedTree != null) { ptr = new ParseTreeResource(cachedTree.getPennTree()); } else { if (pp == null) { pp = new ParsingPipeline(); } CasHolder ch = new CasHolder(pp.parseInput("stanfordParser", corpusService.getCorpus(item.getCollectionId()).getLanguage(), item.getCoveredText())); ptr = new ParseTreeResource(ch); } analysisModal.setContent(new AnalysisPanel(analysisModal.getContentId(), ptr)); analysisModal.show(aTarget); } }); iconAnalysis.add(new AttributeModifier("class", new Model<String>("clickableElement"))); aCellItem.add(iconAnalysis); } }); // columns.add(new PropertyColumn(new Model<String>("ID"), "id", "id")); // columns.add(new PropertyColumn(new Model<String>("Collection"), "item.collectionId", // "item.collectionId")); columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Doc"), "item.documentId", "item.documentId")); // columns.add(new PropertyColumn(new Model<String>("Begin"), "item.beginOffset", // "item.beginOffset")); // columns.add(new PropertyColumn(new Model<String>("End"), "item.endOffset", // "item.endOffset")); columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Left"), "item.leftContext", "item.leftContext") { @Override public String getCssClass() { return contextAvailable ? "leftContext" : " hideCol"; } }); columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Match"), "item.match", "item.match") { @Override public String getCssClass() { return contextAvailable ? "match nowrap" : null; } }); columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Right"), "item.rightContext", "item.rightContext") { @Override public String getCssClass() { return contextAvailable ? "rightContext" : " hideCol"; } }); columns.add(new AbstractColumn<EvaluationResult, String>(new Model<String>("Label"), "result") { @Override public void populateItem(final Item<ICellPopulator<EvaluationResult>> aCellItem, String aComponentId, final IModel<EvaluationResult> model) { final Label resultLabel = new Label(aComponentId, new PropertyModel(model, "result")); resultLabel.setOutputMarkupId(true); aCellItem.add(resultLabel); if (showResultColumns) { aCellItem.add(AttributeModifier.replace("class", new Model<String>("editable " + model.getObject().getResult().toLowerCase()))); } aCellItem.add(new AjaxEventBehavior("onclick") { @Override protected void onEvent(AjaxRequestTarget aTarget) { EvaluationResult result = model.getObject(); // cycle to next result Mark newResult = Mark.fromString(result.getResult()).next(); // update database result.setResult(newResult.getTitle()); repository.updateEvaluationResult(result); // update DataTable aCellItem.add(AttributeModifier.replace("class", new Model<String>("editable " + newResult.getTitle().toLowerCase()))); aTarget.add(resultLabel, aCellItem); } }); } @Override public String getCssClass() { return (showResultColumns ? "" : " hideCol"); } }); columns.add(new AbstractColumn<EvaluationResult, String>(new Model<String>("Comment"), "comment") { @Override public void populateItem(Item<ICellPopulator<EvaluationResult>> cellItem, String componentId, final IModel<EvaluationResult> model) { cellItem.add( new AjaxEditableLabel<String>(componentId, new PropertyModel<String>(model, "comment")) { @Override public void onSubmit(final AjaxRequestTarget aTarget) { super.onSubmit(aTarget); EvaluationResult result = model.getObject(); // get new comment String newComment = getEditor().getInput(); // update database result.setComment(newComment); repository.updateEvaluationResult(result); } @Override public void onError(AjaxRequestTarget aTarget) { super.onError(aTarget); aTarget.add(getFeedbackPanel()); } }.add(new DbFieldMaxLengthValidator(projectRepository, "EvaluationResult", "comment"))); } @Override public String getCssClass() { return "editable" + (showResultColumns ? "" : " hideCol"); } }); // collection and type add(parentOptionsForm = new ParentOptionsForm("parentOptions")); tabs = new Tabs("tabs"); tabs.setVisible(false); // query tab tabs.add(queryForm = new QueryForm("queryForm")); // revision tab tabs.add(reviewForm = new ReviewForm("reviewForm")); // completion tab tabs.add(new Form("completeForm") { { add(new ExtendedIndicatingAjaxButton("completeButton", new Model<String>("Complete"), new Model<String>("Running query ...")) { { setDefaultFormProcessing(false); } @Override public void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm) { AnnotationType type = parentOptionsForm.typeInput.getModelObject(); if (type == null) { error(LocalizerUtil.getString(parentOptionsForm.typeInput, "Required")); aTarget.add(getFeedbackPanel()); return; } ParentOptionsFormModel pModel = parentOptionsForm.getModelObject(); String user = SecurityContextHolder.getContext().getAuthentication().getName(); List<String> otherUsers = new ArrayList<String>(repository.listUsers()); otherUsers.remove(user); // get items, create/persist results List<EvaluationItem> items = repository.listEvaluationResultsMissing(pModel.collectionId, pModel.type.getName(), user, otherUsers); List<EvaluationResult> results = createEvaluationResults(items); repository.writeEvaluationResults(results); // persis. results: hide saveButton, show result columns and filter options limitForm.setVisible(false); filterForm.setChoices(ResultFilter.values()); showColumnsForm.setVisible(true && !pModel.type.getAdditionalColumns().isEmpty()); showResultColumns(true); saveButton.setVisible(false); predictButton.setVisible(true); samplesetButton.setVisible(true); // update dataprovider dataProvider = new SortableEvaluationResultDataProvider(results); dataProvider.setSort("item.documentId", SortOrder.ASCENDING); dataProvider.setFilter(ResultFilter.ALL); // then update the table resultTable = resultTable.replaceWith(new CustomDataTable<EvaluationResult>("resultTable", getAllColumns(pModel.type), dataProvider, ROWS_PER_PAGE)); contextAvailable = false; updateComponents(aTarget); } @Override public void onError(AjaxRequestTarget aTarget, Form<?> aForm) { super.onError(aTarget, aForm); // Make sure the feedback messages are rendered aTarget.add(getFeedbackPanel()); } }); } }); // sampleset tab tabs.add(samplesetForm = new SamplesetForm("samplesetForm")); // sampleset tab tabs.add(findForm = new FindForm("findForm")); add(tabs); add(new Label("description", new LoadableDetachableModel<String>() { @Override protected String load() { Object value = PropertyResolver.getValue("type.description", parentOptionsForm.getModelObject()); if (value != null) { RenderContext context = new BaseRenderContext(); RenderEngine engine = new BaseRenderEngine(); return engine.render(String.valueOf(value), context); } else { return getString("page.selectTypeHint"); } } }).setEscapeModelStrings(false)); add(filterForm = (FilterForm) new FilterForm("filterForm").setOutputMarkupPlaceholderTag(true)); add(showColumnsForm = (ShowColumnsForm) new ShowColumnsForm("showColumnsForm") .setOutputMarkupPlaceholderTag(true)); add(resultTable = new Label("resultTable").setOutputMarkupId(true)); add(predictionModal = new ModalWindow("predictionModal")); final PredictionPanel predictionPanel = new PredictionPanel(predictionModal.getContentId()); predictionModal.setContent(predictionPanel); predictionModal.setTitle("Predict results"); predictionModal.setAutoSize(false); predictionModal.setInitialWidth(550); predictionModal.setInitialHeight(350); predictionModal.setCloseButtonCallback(new CloseButtonCallback() { @Override public boolean onCloseButtonClicked(AjaxRequestTarget aTarget) { predictionPanel.cancel(aTarget); return true; } }); add(samplesetModal = new ModalWindow("samplesetModal")); samplesetModal.setContent(new SamplesetPanel(samplesetModal.getContentId())); samplesetModal.setTitle("Create / Extend sampleset"); samplesetModal.setAutoSize(true); add(analysisModal = new ModalWindow("analysisModal")); analysisModal.setTitle("Parse tree"); analysisModal.setInitialWidth(65 * 16); analysisModal.setInitialHeight(65 * 9); // autosize does not work... // analysisModal.setAutoSize(true); add(new Form("saveForm") { { add(saveButton = (ExtendedIndicatingAjaxButton) new ExtendedIndicatingAjaxButton("saveButton", new Model<String>("Start annotating"), new Model<String>("Preparing ...")) { @Override protected void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm) { // persist items and results List<EvaluationItem> items = dataProvider.getItems(); items = repository.writeEvaluationItems(items); List<EvaluationResult> results = createEvaluationResults(items); dataProvider.setResults(results); repository.writeEvaluationResults(results); // save results, query ParentOptionsFormModel pModel = parentOptionsForm.getModelObject(); String user = SecurityContextHolder.getContext().getAuthentication().getName(); QueryFormModel model = queryForm.getModelObject(); if (model.engine != null && !StringUtils.isBlank(model.query)) { repository.recordQuery(model.engine.getName(), model.query, pModel.collectionId, pModel.type.getName(), model.comment, user); } // hide saveButton, show result columns and filter options limitForm.setVisible(false); filterForm.setChoices(ResultFilter.values()); showColumnsForm.setVisible(true && !pModel.type.getAdditionalColumns().isEmpty()); showResultColumns(true); saveButton.setVisible(false); predictButton.setVisible(true); samplesetButton.setVisible(true); updateComponents(aTarget); } }.setOutputMarkupPlaceholderTag(true)); add(predictButton = (ExtendedIndicatingAjaxButton) new ExtendedIndicatingAjaxButton("predictButton", new Model<String>("Predict results"), new Model<String>("Predicting ...")) { @Override protected void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm) { aTarget.appendJavaScript("Wicket.Window.unloadConfirmation = false;"); predictionModal.show(aTarget); } }.setOutputMarkupPlaceholderTag(true)); add(samplesetButton = (ExtendedIndicatingAjaxButton) new ExtendedIndicatingAjaxButton( "samplesetButton", new Model<String>("Save results as sampleset"), new Model<String>("Saving...")) { @Override public void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm) { samplesetModal.show(aTarget); } }.setOutputMarkupPlaceholderTag(true)); } }); add(limitForm = (LimitForm) new LimitForm("limit").setOutputMarkupPlaceholderTag(true)); // at start, don't show: save button, results columns, filter limitForm.setVisible(false); filterForm.setChoices(); showColumnsForm.setVisible(false); showResultColumns(false); saveButton.setVisible(false); predictButton.setVisible(false); samplesetButton.setVisible(false); }
From source file:de.tudarmstadt.ukp.csniper.webapp.support.wicket.AjaxFileDownload.java
License:Apache License
/** * Call this method to initiate the download. *///from w w w. ja v a2 s.com public void initiate(AjaxRequestTarget target, File aFile, String aFilename, String aContentType) { file = aFile; filename = aFilename; contentType = aContentType; String url = getCallbackUrl().toString(); url = url + (url.contains("?") ? "&" : "?"); url = url + "antiCache=" + System.currentTimeMillis(); // the timeout is needed to let Wicket release the channel target.appendJavaScript("setTimeout(\"window.location.href='" + url + "'\", 100);"); }
From source file:de.widone.web.page.base.BasePage.java
License:Apache License
public BasePage() { super();/*from ww w .ja v a 2 s . c o m*/ final ModalWindow modalWindow = new ModalWindow("modalWindow"); modalWindow.setContent(new UserDetailsPanel(modalWindow.getContentId(), new CurrentUserModel())); modalWindow.add(new Behavior() { @Override public void onEvent(Component component, IEvent<?> event) { if (event.getPayload() instanceof CancelEvent) { modalWindow.close(((CancelEvent) event.getPayload()).getTarget()); } } }); add(new Label("loginName", new StringResourceModel("loginName", this, new CompoundPropertyModel<User>(((WiDoneSession) WebSession.get()).getUser())))); add(modalWindow); add(new AjaxFallbackLink<Void>("userDetails") { @Override public void onClick(AjaxRequestTarget target) { target.appendJavaScript("Wicket.Window.unloadConfirmation = false;"); modalWindow.show(target); } }); add(new AjaxFallbackLink<Void>("logout") { @Override public void onClick(AjaxRequestTarget target) { WebSession.get().invalidate(); setResponsePage(SignInPage.class); } }); }