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

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

Introduction

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

Prototype

public ModalWindow setInitialHeight(final int initialHeight) 

Source Link

Document

Sets the initial height of the window.

Usage

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 www  . j av 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;
            }
        }
    };

    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   www .  jav 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.abiss.calipso.wicket.EditFieldGroupPanel.java

License:Open Source License

public EditFieldGroupPanel(String id, final ModalWindow modalWindow, final FieldGroup fieldGroup) {
    super(id);// w w  w  . j  av  a2s .com
    modalWindow.setInitialHeight(470);
    modalWindow.setInitialWidth(600);

    Form<FieldGroup> fieldGroupForm = new Form<FieldGroup>("fieldGroupForm");
    fieldGroupForm.setModel(new CompoundPropertyModel<FieldGroup>(fieldGroup));
    add(fieldGroupForm);
    FeedbackPanel fieldGroupFormFeedback = getFeedbackPanel("fieldGroupFormFeedback");
    fieldGroupForm.add(fieldGroupFormFeedback);

    setUpAndAdd(new RequiredTextField<String>("id"), fieldGroupForm);
    setUpAndAdd(new RequiredTextField<String>("name"), fieldGroupForm);
    setUpAndAdd(new RequiredTextField<String>("priority"), fieldGroupForm);

    fieldGroupForm.add(getSaveButton(modalWindow, fieldGroupForm, fieldGroupFormFeedback));
    fieldGroupForm.add(getCancelButton(modalWindow, fieldGroupForm));

}

From source file:gr.abiss.calipso.wicket.EditItemRenderingTemplatePanel.java

License:Open Source License

public EditItemRenderingTemplatePanel(String id, final ModalWindow modalWindow,
        final ItemRenderingTemplate itemRenderingTemplate) {
    super(id);//w  ww .j ava2 s  . c o  m
    modalWindow.setInitialHeight(470);
    modalWindow.setInitialWidth(600);

    initTinyMce();
    log.info("itemRenderingTemplate: " + itemRenderingTemplate);

    Form<ItemRenderingTemplate> itemRenderingTemplateForm = new Form<ItemRenderingTemplate>(
            "itemRenderingTemplateForm",
            new CompoundPropertyModel<ItemRenderingTemplate>(itemRenderingTemplate));
    add(itemRenderingTemplateForm);
    FeedbackPanel itemRenderingTemplateFormFeedback = getFeedbackPanel("itemRenderingTemplateFormFeedback");
    itemRenderingTemplateForm.add(itemRenderingTemplateFormFeedback);

    // itemRenderingTemplate.getName().getDescription();
    setUpAndAdd(new RequiredTextField<String>("description"), itemRenderingTemplateForm);
    // itemRenderingTemplate.getPriority()
    setUpAndAdd(new RequiredTextField<String>("priority"), itemRenderingTemplateForm);
    // itemRenderingTemplate.getHideOverview()
    setUpAndAdd(new CheckBox("hideOverview"), itemRenderingTemplateForm);
    // itemRenderingTemplate.getHideHistory()
    setUpAndAdd(new CheckBox("hideHistory"), itemRenderingTemplateForm);
    // itemRenderingTemplate.getTemplateText()
    TextArea templateText = new TextArea<String>("templateText");
    // templateText.add(new TinyMceBehavior(settings));
    templateText.setMarkupId("templateText");
    templateText.setOutputMarkupId(true);
    setUpAndAdd(templateText, itemRenderingTemplateForm);

    itemRenderingTemplateForm
            .add(getSaveButton(modalWindow, itemRenderingTemplateForm, itemRenderingTemplateFormFeedback));
    itemRenderingTemplateForm.add(getCancelButton(modalWindow, itemRenderingTemplateForm));

}

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.
 *         /* w  w  w .j  a  v a  2  s .  c o m*/
 * @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:nl.knaw.dans.dccd.common.web.confirm.ConfirmDialogPanel.java

License:Apache License

private void initModalWindow(final ModalWindow modalWindow) {
    modalWindow.setTitle("Please confirm");
    // use label from property files when available
    try {// w w w .j  av  a  2 s .c  o m
        String title = getString("confirmDialog.title");
        //if (title != null && !title.isEmpty())
        modalWindow.setTitle(title);
    } catch (MissingResourceException e) {
        // do Nothing
    }

    modalWindow.setInitialHeight(150);
    modalWindow.setInitialWidth(250);
}

From source file:nl.knaw.dans.dccd.web.search.pages.AdvSearchPage.java

License:Apache License

private void initTaxonSelection(final AdvancedSearchForm form, final AdvSearchData data) {
    // With plain text input:
    //add(new TextField("elementTaxon", new SearchFieldModel(data, "elementTaxon")));
    // With autocomplete:
    //add(new TridasVocabularyAutoCompleteSelector("elementTaxon", 
    //      new SearchFieldModel(data, "elementTaxon"),
    //      "element.taxon"));         
    // With ComboBox:
    final DropDown elemTaxonComboBox = new DropDown("elementTaxon", new SearchFieldModel(data, "elementTaxon"),
            new DropDownDataSource<String>() {
                private static final long serialVersionUID = 1L;

                public String getName() {
                    return "element.taxon";
                }//w  ww .ja  va 2s.  com

                public List<String> getValues() {
                    // Use current language to get terms for that language
                    String langCode = getSession().getLocale().getLanguage();
                    return DccdVocabularyService.getService().getTerms("element.taxon", langCode);
                }

                public String getDescriptionForValue(String t) {
                    return t;
                }
            }, false);
    elemTaxonComboBox.setCharacterWidth(25);
    elemTaxonComboBox.setOutputMarkupId(true);
    //form.add(elemTaxonComboBox);
    // FIX Container is needed to workaround visural-wicket ISSUE 67
    final WebMarkupContainer taxonContainer = new WebMarkupContainer("elementTaxonContainer");
    taxonContainer.setOutputMarkupId(true);
    form.add(taxonContainer);
    taxonContainer.add(elemTaxonComboBox);

    //TEST adding the window with the table
    //Problem, the TaxonSelectPanel wants a real TridasTaxon
    final ModalWindow modalSelectDialog;
    form.add(modalSelectDialog = new ModalWindow("taxonSelectPanel"));
    final TaxonSelectPanel taxonSelectPanel = new TaxonSelectPanel(modalSelectDialog.getContentId(),
            new Model(null)) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSelectionChanged(AjaxRequestTarget target) {
            String taxonString = getSelectionAsString();
            LOGGER.debug("Selected taxon: " + taxonString);
            data.elementTaxon.setValue(taxonString);
            //target.addComponent(elemTaxonComboBox);
            // FIX   workaround visural-wicket ISSUE 67 by updating the container         
            target.addComponent(taxonContainer);
        }
    };
    modalSelectDialog.setContent(taxonSelectPanel);
    //modalSelectDialog.setTitle(ProjectPermissionSettingsPage.this.getString("userAddDialogTitle"));
    modalSelectDialog.setCookieName("taxonSelectPanelWindow");
    modalSelectDialog.setInitialWidth(400);
    modalSelectDialog.setInitialHeight(160);
    modalSelectDialog.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
        private static final long serialVersionUID = 1L;

        public boolean onCloseButtonClicked(AjaxRequestTarget target) {
            return true;
        }
    });

    //button to show the dialog
    AjaxLink taxonSelectButton = new IndicatingAjaxLink("taxonSelectButton") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            //LOGGER.debug("term=" + data.elementTaxon.getValue());
            //taxonSelectPanel.selectTerm(elemTaxonComboBox.getValue());
            modalSelectDialog.show(target);
        }
    };
    form.add(taxonSelectButton);
}

From source file:nl.mpi.lamus.web.components.ConfirmPanel.java

License:Open Source License

public ConfirmPanel(String id, final ModalWindow modalWindow, final ConfirmationOptions options) {
    super(id);//  w w  w  .java2s.  c om

    Form confirmSubmitForm = new Form("confirmSubmitForm");

    MultiLineLabel infoText = new MultiLineLabel("confirmation_info_text", options.getConfirmationInfoText());

    confirmSubmitForm.add(infoText);

    confirmSubmitForm.add(new Label("confirmation_text", options.getConfirmationText()));

    CheckBox keepUnlinkedFilesCheckbox = new CheckBox("checkbox", Model.of(options.isKeepUnlinkedFiles())) {

        @Override
        protected void onSelectionChanged(Boolean newSelection) {
            options.setKeepUnlinkedFiles(newSelection);
        }

        @Override
        protected void onModelChanged() {
            options.setKeepUnlinkedFiles(getModelObject());
        }
    };

    keepUnlinkedFilesCheckbox.setLabel(Model.of("keep unlinked files"));
    confirmSubmitForm.add(keepUnlinkedFilesCheckbox);

    modalWindow.setTitle("Please confirm");

    if (options.getConfirmationInfoText() != null && !options.getConfirmationInfoText().isEmpty()) {
        modalWindow.setInitialHeight(300);
        modalWindow.setInitialWidth(580);
    } else {
        infoText.setVisible(Boolean.FALSE);
        modalWindow.setInitialHeight(200);
        modalWindow.setInitialWidth(350);
    }

    AjaxButton yesButton = new AjaxButton("yesButton", confirmSubmitForm) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            if (target != null) {
                options.setConfirmed(true);
                modalWindow.close(target);
            }
        }
    };

    AjaxButton noButton = new AjaxButton("noButton", confirmSubmitForm) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            if (target != null) {
                options.setConfirmed(false);
                modalWindow.close(target);
            }
        }
    };

    confirmSubmitForm.add(yesButton);
    confirmSubmitForm.add(noButton);

    add(confirmSubmitForm);
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

private ModalWindow generateAboutLink(final String id, final ModalWindow window) {
    window.setInitialWidth(450);// w w w  .  ja v  a 2 s  .c o m
    window.setInitialHeight(700);
    window.setTitle("About HatchetHarry");
    window.setContent(new AboutModalWindow(window.getContentId(), window));
    window.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    window.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT);
    this.add(window);

    final AjaxLink<Void> aboutLink = new AjaxLink<Void>(id) {
        private static final long serialVersionUID = 8140325977385015896L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            target.prependJavaScript(BattlefieldService.HIDE_MENUS);
            target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
            window.show(target);
        }
    };

    aboutLink.setOutputMarkupId(true);
    window.setOutputMarkupId(true);
    this.add(aboutLink);
    return window;
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

private ModalWindow generateMulliganLink(final String id, final ModalWindow window) {
    window.setInitialWidth(500);/*from  w w  w.j  a  va2s. co  m*/
    window.setInitialHeight(150);
    window.setTitle("HatchetHarry - Mulligan");
    window.setContent(new MulliganModalWindow(window, window.getContentId()));
    window.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    window.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT);
    this.add(window);

    final AjaxLink<Void> mulliganLink = new AjaxLink<Void>(id) {
        private static final long serialVersionUID = 8140325977385015896L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            target.prependJavaScript(BattlefieldService.HIDE_MENUS);
            target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
            window.show(target);
        }
    };

    mulliganLink.setOutputMarkupId(true);
    window.setOutputMarkupId(true);
    this.add(mulliganLink);
    return window;
}