Example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setWidthUnit

List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setWidthUnit

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setWidthUnit.

Prototype

public ModalWindow setWidthUnit(final String widthUnit) 

Source Link

Document

Sets the CSS unit used for initial window width.

Usage

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.page.annotation.component.GuidelineModalPanel.java

License:Apache License

public GuidelineModalPanel(String id, final IModel<BratAnnotatorModel> aModel) {
    super(id, aModel);
    final ModalWindow guidelineModal;
    add(guidelineModal = new ModalWindow("guidelineModal"));

    guidelineModal.setInitialWidth(550);
    guidelineModal.setInitialHeight(450);
    guidelineModal.setResizable(true);/*from w ww. j  a va 2s  .  c o m*/
    guidelineModal.setWidthUnit("px");
    guidelineModal.setHeightUnit("px");
    guidelineModal.setTitle("Open Annotation Guideline, in separate window");

    add(new AjaxLink<Void>("showGuidelineModal") {
        private static final long serialVersionUID = 7496156015186497496L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            guidelineModal.setContent(
                    new GuidelineModalWindowPanel(guidelineModal.getContentId(), guidelineModal, aModel));

            guidelineModal.show(target);

        }
    });

}

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);/*from   w ww .jav a  2 s .  c o  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;
            }
        }

        @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);//from w w w.  ja  va2s.  c o  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 v  a 2  s  .c  om
    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:gr.interamerican.wicket.factories.ModalWindowFactory.java

License:Open Source License

/**
 * Create a modalWindow with a specific properties file. 
 * The properties file have to contains the properties of modalWindow.
 * @param path Path to the properties file.
 *         //from ww w .  j a v  a 2s.c  om
 * @return the ModalWindow
 */
public static ModalWindow createModalWindow(String path) {
    initializeProperties(path);
    ModalWindow modalWindow = new ModalWindow(wicketId);
    modalWindow.setTitle(title);
    modalWindow.setInitialWidth(initialWidth);
    modalWindow.setInitialHeight(initialHeight);
    modalWindow.setWidthUnit(widthUnit);
    modalWindow.setHeightUnit(heightUnit);
    modalWindow.setResizable(resizable);
    modalWindow.setUseInitialHeight(useInitialHeight);
    return modalWindow;
}

From source file:org.brixcms.plugin.prototype.ManagePrototypesPanel.java

License:Apache License

public ManagePrototypesPanel(String id, final IModel<Workspace> model) {
    super(id, model);
    setOutputMarkupId(true);//from  w  w w  .j  a v a2  s .c om

    IModel<List<Workspace>> prototypesModel = new LoadableDetachableModel<List<Workspace>>() {
        @Override
        protected List<Workspace> load() {
            List<Workspace> list = PrototypePlugin.get().getPrototypes();
            return getBrix().filterVisibleWorkspaces(list, Context.ADMINISTRATION);
        }
    };

    Form<Void> modalWindowForm = new Form<Void>("modalWindowForm");
    add(modalWindowForm);

    final ModalWindow modalWindow = new ModalWindow("modalWindow");
    modalWindow.setInitialWidth(64);
    modalWindow.setWidthUnit("em");
    modalWindow.setUseInitialHeight(false);
    modalWindow.setResizable(false);
    modalWindow.setTitle(new ResourceModel("selectItems"));
    modalWindowForm.add(modalWindow);

    add(new ListView<Workspace>("prototypes", prototypesModel) {
        @Override
        protected IModel<Workspace> getListItemModel(IModel<? extends List<Workspace>> listViewModel,
                int index) {
            return new WorkspaceModel(listViewModel.getObject().get(index));
        }

        @Override
        protected void populateItem(final ListItem<Workspace> item) {
            PrototypePlugin plugin = PrototypePlugin.get();
            final String name = plugin.getUserVisibleName(item.getModelObject(), false);

            item.add(new Label("label", name));
            item.add(new Link<Void>("browse") {
                @Override
                public void onClick() {
                    model.setObject(item.getModelObject());
                }
            });

            item.add(new AjaxLink<Void>("restoreItems") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    String prototypeId = item.getModelObject().getId();
                    String targetId = ManagePrototypesPanel.this.getModelObject().getId();
                    Panel panel = new RestoreItemsPanel(modalWindow.getContentId(), prototypeId, targetId);
                    modalWindow.setTitle(new ResourceModel("selectItems"));
                    modalWindow.setContent(panel);
                    modalWindow.show(target);
                }

                @Override
                public boolean isVisible() {
                    Workspace target = ManagePrototypesPanel.this.getModelObject();
                    Action action = new RestorePrototypeAction(Context.ADMINISTRATION, item.getModelObject(),
                            target);
                    return getBrix().getAuthorizationStrategy().isActionAuthorized(action);
                }
            });

            item.add(new Link<Void>("delete") {
                @Override
                public void onClick() {
                    Workspace prototype = item.getModelObject();
                    prototype.delete();
                }

                @Override
                public boolean isVisible() {
                    Action action = new DeletePrototypeAction(Context.ADMINISTRATION, item.getModelObject());
                    return getBrix().getAuthorizationStrategy().isActionAuthorized(action);
                }
            });
        }
    });

    Form<Object> form = new Form<Object>("form") {
        @Override
        public boolean isVisible() {
            Workspace current = ManagePrototypesPanel.this.getModelObject();
            Action action = new CreatePrototypeAction(Context.ADMINISTRATION, current);
            return getBrix().getAuthorizationStrategy().isActionAuthorized(action);
        }
    };

    TextField<String> prototypeName = new TextField<String>("prototypeName",
            new PropertyModel<String>(this, "prototypeName"));
    form.add(prototypeName);

    prototypeName.setRequired(true);
    prototypeName.add(new UniquePrototypeNameValidator());

    final FeedbackPanel feedback;

    add(feedback = new FeedbackPanel("feedback"));
    feedback.setOutputMarkupId(true);

    form.add(new AjaxButton("submit") {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            String workspaceId = ManagePrototypesPanel.this.getModelObject().getId();
            CreatePrototypePanel panel = new CreatePrototypePanel(modalWindow.getContentId(), workspaceId,
                    ManagePrototypesPanel.this.prototypeName);
            modalWindow.setContent(panel);
            modalWindow.setTitle(new ResourceModel("selectItemsToCreate"));
            modalWindow.setWindowClosedCallback(new WindowClosedCallback() {
                public void onClose(AjaxRequestTarget target) {
                    target.addComponent(ManagePrototypesPanel.this);
                }
            });
            modalWindow.show(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(feedback);
        }
    });

    add(form);
}

From source file:org.obiba.onyx.webapp.participant.page.InterviewPage.java

License:Open Source License

public InterviewPage() {
    super();/*  w  ww. ja v a 2  s . co  m*/

    if (activeInterviewService.getParticipant() == null || activeInterviewService.getInterview() == null) {
        setResponsePage(WebApplication.get().getHomePage());
    } else {

        addOrReplace(new EmptyPanel("header"));
        //
        // Modify menu bar.
        //
        remove("menuBar");
        add(new InterviewMenuBar("menuBar"));

        final InterviewLogPanel interviewLogPanel;
        final Dialog interviewLogsDialog;
        interviewLogPanel = new InterviewLogPanel("content", 338, new LoadableInterviewLogModel());
        interviewLogsDialog = DialogBuilder
                .buildDialog("interviewLogsDialog", new StringResourceModel("Log", this, null),
                        interviewLogPanel)
                .setOptions(Option.CLOSE_OPTION).setFormCssClass("interview-log-dialog-form").getDialog();
        interviewLogsDialog.setHeightUnit("em");
        interviewLogsDialog.setWidthUnit("em");
        interviewLogsDialog.setInitialHeight(34);
        interviewLogsDialog.setInitialWidth(59);
        interviewLogsDialog.setCloseButtonCallback(new CloseButtonCallback() {
            private static final long serialVersionUID = 1L;

            public boolean onCloseButtonClicked(AjaxRequestTarget target, Status status) {
                // Update comment count on interview page once the modal window closes. User may have added comments.
                updateCommentCount(target);
                return true;
            }
        });
        interviewLogPanel.setup(interviewLogsDialog);
        interviewLogPanel.add(new AttributeModifier("class", true, new Model("interview-log-panel-content")));
        interviewLogPanel.setMarkupId("interviewLogPanel");
        interviewLogPanel.setOutputMarkupId(true);

        add(interviewLogsDialog);

        Participant participant = activeInterviewService.getParticipant();

        add(new ParticipantPanel("participant", new DetachableEntityModel(queryService, participant), true));

        // Create modal comments window
        final ModalWindow commentsWindow;
        add(commentsWindow = new ModalWindow("addCommentsModal"));
        commentsWindow.setCssClassName("onyx");
        commentsWindow.setTitle(new StringResourceModel("CommentsWindow", this, null));
        commentsWindow.setHeightUnit("em");
        commentsWindow.setWidthUnit("em");
        commentsWindow.setInitialHeight(34);
        commentsWindow.setInitialWidth(50);

        commentsWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

            private static final long serialVersionUID = 1L;

            public void onClose(AjaxRequestTarget target) {

            }
        });

        ViewInterviewLogsLink viewCommentsIconLink = createIconLink("viewCommentsIconLink", interviewLogsDialog,
                interviewLogPanel, true);
        add(viewCommentsIconLink);
        ContextImage commentIcon = createContextImage("commentIcon", "icons/note.png");
        viewCommentsIconLink.add(commentIcon);

        ViewInterviewLogsLink viewLogIconLink = createIconLink("viewLogIconLink", interviewLogsDialog,
                interviewLogPanel, false);
        add(viewLogIconLink);
        ContextImage logIcon = createContextImage("logIcon", "icons/loupe_button.png");
        viewLogIconLink.add(logIcon);

        // Add view interview comments action
        add(viewComments = new ViewInterviewLogsLink("viewComments", interviewLogsDialog, interviewLogPanel,
                true) {

            private static final long serialVersionUID = -5561038138085317724L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                interviewLogPanel.setCommentsOnly(true);

                // Disable Show All Button
                target.appendJavascript(
                        "$('[name=showAll]').attr('disabled','true');$('[name=showAll]').css('color','rgba(0, 0, 0, 0.2)');$('[name=showAll]').css('border-color','rgba(0, 0, 0, 0.2)');");
                super.onClick(target);
            }

        });
        add(new ViewInterviewLogsLink("viewLog", interviewLogsDialog, interviewLogPanel, false) {

            private static final long serialVersionUID = -5561038138085317724L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                interviewLogPanel.setCommentsOnly(false);

                // Disable Show All Button
                target.appendJavascript(
                        "$('[name=showAll]').attr('disabled','true');$('[name=showAll]').css('color','rgba(0, 0, 0, 0.2)');$('[name=showAll]').css('border-color','rgba(0, 0, 0, 0.2)');");
                super.onClick(target);
            }

        });

        // Add create interview comments action
        add(addCommentDialog = createAddCommentDialog());
        add(new AjaxLink("addComment") {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                addCommentDialog.show(target);
            }
        });

        // Initialize comments counter
        updateCommentsCount();

        ActiveInterviewModel interviewModel = new ActiveInterviewModel();

        kvPanel = new KeyValueDataPanel("interview");
        kvPanel.addRow(new StringResourceModel("StartDate", this, null),
                new PropertyModel(interviewModel, "startDate"));
        kvPanel.addRow(new StringResourceModel("EndDate", this, null),
                new PropertyModel(interviewModel, "endDate"));
        kvPanel.addRow(new StringResourceModel("Status", this, null),
                new PropertyModel(interviewModel, "status"));
        add(kvPanel);

        // Interview cancellation
        final ActionDefinition cancelInterviewDef = actionDefinitionConfiguration
                .getActionDefinition(ActionType.STOP, "Interview", null, null);
        final ActionWindow interviewActionWindow = new ActionWindow("modal") {

            private static final long serialVersionUID = 1L;

            @Override
            public void onActionPerformed(AjaxRequestTarget target, Stage stage, Action action) {
                activeInterviewService.setStatus(InterviewStatus.CANCELLED);
                setResponsePage(InterviewPage.class);
            }

        };
        add(interviewActionWindow);

        AjaxLink link = new AjaxLink("cancelInterview") {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                Label label = new Label("content",
                        new StringResourceModel("ConfirmCancellationOfInterview", InterviewPage.this, null));
                label.add(new AttributeModifier("class", true, new Model("confirmation-dialog-content")));
                ConfirmationDialog confirmationDialog = getConfirmationDialog();

                confirmationDialog.setContent(label);
                confirmationDialog
                        .setTitle(new StringResourceModel("ConfirmCancellationOfInterviewTitle", this, null));
                confirmationDialog.setYesButtonCallback(new OnYesCallback() {

                    private static final long serialVersionUID = -6691702933562884991L;

                    public void onYesButtonClicked(AjaxRequestTarget target) {
                        interviewActionWindow.show(target, null, cancelInterviewDef);
                    }

                });
                confirmationDialog.show(target);
            }

            @Override
            public boolean isVisible() {
                InterviewStatus status = activeInterviewService.getInterview().getStatus();
                return (status == InterviewStatus.IN_PROGRESS || status == InterviewStatus.COMPLETED);
            }
        };
        MetaDataRoleAuthorizationStrategy.authorize(link, RENDER, "PARTICIPANT_MANAGER");
        add(link);

        // Interview closing
        final ActionDefinition closeInterviewDef = actionDefinitionConfiguration
                .getActionDefinition(ActionType.STOP, "Closed.Interview", null, null);
        final ActionWindow closeInterviewActionWindow = new ActionWindow("closeModal") {

            private static final long serialVersionUID = 1L;

            @Override
            public void onActionPerformed(AjaxRequestTarget target, Stage stage, Action action) {
                activeInterviewService.setStatus(InterviewStatus.CLOSED);
                setResponsePage(InterviewPage.class);
            }

        };
        add(closeInterviewActionWindow);

        AjaxLink closeLink = new AjaxLink("closeInterview") {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                Label label = new Label("content",
                        new StringResourceModel("ConfirmClosingOfInterview", InterviewPage.this, null));
                label.add(new AttributeModifier("class", true, new Model("confirmation-dialog-content")));
                ConfirmationDialog confirmationDialog = getConfirmationDialog();

                confirmationDialog.setContent(label);
                confirmationDialog
                        .setTitle(new StringResourceModel("ConfirmClosingOfInterviewTitle", this, null));
                confirmationDialog.setYesButtonCallback(new OnYesCallback() {

                    private static final long serialVersionUID = -6691702933562884991L;

                    public void onYesButtonClicked(AjaxRequestTarget target) {
                        closeInterviewActionWindow.show(target, null, closeInterviewDef);
                    }

                });
                confirmationDialog.show(target);
            }

            @Override
            public boolean isVisible() {
                InterviewStatus status = activeInterviewService.getInterview().getStatus();
                return (status == InterviewStatus.IN_PROGRESS);
            }
        };
        MetaDataRoleAuthorizationStrategy.authorize(link, RENDER, "PARTICIPANT_MANAGER");
        add(closeLink);

        // Reinstate interview link
        add(createReinstateInterviewLink());

        // Print report link
        class ReportLink extends AjaxLink {

            private static final long serialVersionUID = 1L;

            public ReportLink(String id) {
                super(id);
            }

            @Override
            public void onClick(AjaxRequestTarget target) {
                getPrintableReportsDialog().show(target);
            }
        }

        ReportLink printReportLink = new ReportLink("printReport");
        printReportLink.add(new Label("reportLabel", new ResourceModel("PrintReport")));
        add(printReportLink);

        add(new StageSelectionPanel("stage-list", getFeedbackWindow()) {

            private static final long serialVersionUID = 1L;

            @Override
            public void onViewComments(AjaxRequestTarget target, String stage) {

                commentsWindow.setContent(new CommentsModalPanel("content", commentsWindow, stage) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onAddComments(AjaxRequestTarget target) {
                        InterviewPage.this.updateCommentsCount();
                        target.addComponent(InterviewPage.this.commentsCount);
                    }

                });
                commentsWindow.show(target);
            }

            @Override
            public void onViewLogs(AjaxRequestTarget target, String stage, boolean commentsOnly) {
                interviewLogPanel.setStageName(stage);
                interviewLogPanel.setCommentsOnly(commentsOnly);
                interviewLogPanel.setReadOnly(true);
                interviewLogPanel.addInterviewLogComponent();

                interviewLogsDialog.show(target);
            }

            @Override
            public void onActionPerformed(AjaxRequestTarget target, Stage stage, Action action) {
                if (activeInterviewService.getStageExecution(action.getStage()).isFinal()) {
                    setResponsePage(InterviewPage.class);
                } else {
                    InterviewPage.this.updateCommentsCount();
                    target.addComponent(InterviewPage.this.commentsCount);
                }

            }

        });

        AjaxLink exitLink = new AjaxLink("exitInterview") {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                interviewManager.releaseInterview();
                setResponsePage(HomePage.class);
            }
        };
        add(exitLink);

    }
}