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

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

Introduction

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

Prototype

public ModalWindow setInitialWidth(final int initialWidth) 

Source Link

Document

Sets the initial width of the window.

Usage

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  w  w.j  ava2  s.co  m

    LinkedList<CurationUserSegmentForAnnotationDocument> sentences = new LinkedList<CurationUserSegmentForAnnotationDocument>();
    CurationUserSegmentForAnnotationDocument curationUserSegmentForAnnotationDocument = new CurationUserSegmentForAnnotationDocument();
    if (bModel.getDocument() != null) {
        curationUserSegmentForAnnotationDocument
                .setAnnotationSelectionByUsernameAndAddress(annotationSelectionByUsernameAndAddress);
        curationUserSegmentForAnnotationDocument.setBratAnnotatorModel(bModel);
        sentences.add(curationUserSegmentForAnnotationDocument);
    }
    automateView = new SuggestionViewPanel("automateView",
            new Model<LinkedList<CurationUserSegmentForAnnotationDocument>>(sentences)) {
        private static final long serialVersionUID = 2583509126979792202L;

        @Override
        public void onChange(AjaxRequestTarget aTarget) {
            try {
                // update begin/end of the curationsegment based on bratAnnotatorModel changes
                // (like sentence change in auto-scroll mode,....
                aTarget.addChildren(getPage(), FeedbackPanel.class);
                curationContainer.setBratAnnotatorModel(bModel);
                setCurationSegmentBeginEnd();

                CuratorUtil.updatePanel(aTarget, this, curationContainer, annotator, repository,
                        annotationSelectionByUsernameAndAddress, curationSegment, annotationService,
                        userRepository);
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            } catch (BratAnnotationException e) {
                error(e.getMessage());
            }
            annotator.bratRenderLater(aTarget);
            aTarget.add(numberOfPages);
            update(aTarget);
        }
    };

    automateView.setOutputMarkupId(true);
    add(automateView);

    editor = new AnnotationDetailEditorPanel("annotationDetailEditorPanel",
            new Model<BratAnnotatorModel>(bModel)) {
        private static final long serialVersionUID = 2857345299480098279L;

        @Override
        protected void onChange(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel) {
            aTarget.addChildren(getPage(), FeedbackPanel.class);

            try {
                annotator.bratRender(aTarget, getCas(aBModel));
            } catch (UIMAException | ClassNotFoundException | IOException e) {
                LOG.info("Error reading CAS " + e.getMessage());
                error("Error reading CAS " + e.getMessage());
                return;
            }

            annotator.bratRenderHighlight(aTarget, aBModel.getSelection().getAnnotation());

            annotator.onChange(aTarget, aBModel);
        }

        @Override
        protected void onAutoForward(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel) {
            try {
                annotator.autoForward(aTarget, getCas(aBModel));
            } catch (UIMAException | ClassNotFoundException | IOException | BratAnnotationException e) {
                LOG.info("Error reading CAS " + e.getMessage());
                error("Error reading CAS " + e.getMessage());
                return;
            }
        }

        @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 www. ja  va 2s . co  m

    LinkedList<CurationUserSegmentForAnnotationDocument> sentences = new LinkedList<CurationUserSegmentForAnnotationDocument>();
    CurationUserSegmentForAnnotationDocument curationUserSegmentForAnnotationDocument = new CurationUserSegmentForAnnotationDocument();
    if (bModel.getDocument() != null) {
        curationUserSegmentForAnnotationDocument
                .setAnnotationSelectionByUsernameAndAddress(annotationSelectionByUsernameAndAddress);
        curationUserSegmentForAnnotationDocument.setBratAnnotatorModel(bModel);
        sentences.add(curationUserSegmentForAnnotationDocument);
    }
    automateView = new SuggestionViewPanel("automateView",
            new Model<LinkedList<CurationUserSegmentForAnnotationDocument>>(sentences)) {
        private static final long serialVersionUID = 2583509126979792202L;

        @Override
        public void onChange(AjaxRequestTarget aTarget) {
            try {
                // update begin/end of the curationsegment based on bratAnnotatorModel changes
                // (like sentence change in auto-scroll mode,....
                aTarget.addChildren(getPage(), FeedbackPanel.class);
                curationContainer.setBratAnnotatorModel(bModel);
                setCurationSegmentBeginEnd();

                CuratorUtil.updatePanel(aTarget, this, curationContainer, annotator, repository,
                        annotationSelectionByUsernameAndAddress, curationSegment, annotationService,
                        userRepository);
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            } catch (BratAnnotationException e) {
                error(e.getMessage());
            }
            annotator.bratRenderLater(aTarget);
            aTarget.add(numberOfPages);
            update(aTarget);
        }
    };

    automateView.setOutputMarkupId(true);
    add(automateView);

    editor = new AnnotationDetailEditorPanel("annotationDetailEditorPanel",
            new Model<BratAnnotatorModel>(bModel)) {
        private static final long serialVersionUID = 2857345299480098279L;

        @Override
        protected void onChange(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel) {
            aTarget.addChildren(getPage(), FeedbackPanel.class);

            try {
                annotator.bratRender(aTarget, getCas(aBModel));
            } catch (UIMAException | ClassNotFoundException | IOException e) {
                LOG.info("Error reading CAS " + e.getMessage());
                error("Error reading CAS " + e.getMessage());
                return;
            }

            annotator.bratRenderHighlight(aTarget, aBModel.getSelection().getAnnotation());

            annotator.onChange(aTarget, aBModel);

        }

        @Override
        protected void onAutoForward(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel) {
            try {
                annotator.autoForward(aTarget, getCas(aBModel));
            } catch (UIMAException | ClassNotFoundException | IOException | BratAnnotationException e) {
                LOG.info("Error reading CAS " + e.getMessage());
                error("Error reading CAS " + e.getMessage());
                return;
            }
        }
    };

    editor.setOutputMarkupId(true);
    add(editor);

    annotator = new BratAnnotator("mergeView", new Model<BratAnnotatorModel>(bModel), editor) {
        private static final long serialVersionUID = 7279648231521710155L;

        @Override
        public void onChange(AjaxRequestTarget aTarget, BratAnnotatorModel aBratAnnotatorModel) {
            try {
                aTarget.addChildren(getPage(), FeedbackPanel.class);
                // info(bratAnnotatorModel.getMessage());
                bModel = aBratAnnotatorModel;
                SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService,
                        userRepository);
                curationContainer = builder.buildCurationContainer(bModel);
                setCurationSegmentBeginEnd();
                curationContainer.setBratAnnotatorModel(bModel);

                CuratorUtil.updatePanel(aTarget, automateView, curationContainer, this, repository,
                        annotationSelectionByUsernameAndAddress, curationSegment, annotationService,
                        userRepository);
                aTarget.add(automateView);
                aTarget.add(numberOfPages);
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            } catch (BratAnnotationException e) {
                error(e.getMessage());
            }
            update(aTarget);
        }
    };
    // reset sentenceAddress and lastSentenceAddress to the orginal once

    annotator.setOutputMarkupId(true);
    add(annotator);

    curationContainer = new CurationContainer();
    curationContainer.setBratAnnotatorModel(bModel);

    add(documentNamePanel = new DocumentNamePanel("documentNamePanel", new Model<BratAnnotatorModel>(bModel)));

    add(numberOfPages = (Label) new Label("numberOfPages", new LoadableDetachableModel<String>() {
        private static final long serialVersionUID = 891566759811286173L;

        @Override
        protected String load() {
            if (bModel.getDocument() != null) {

                JCas mergeJCas = null;
                try {

                    mergeJCas = repository.readCorrectionCas(bModel.getDocument());

                    totalNumberOfSentence = getNumberOfPages(mergeJCas);

                    // If only one page, start displaying from sentence 1
                    /*
                     * if (totalNumberOfSentence == 1) {
                     * bratAnnotatorModel.setSentenceAddress(bratAnnotatorModel
                     * .getFirstSentenceAddress()); }
                     */
                    int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(),
                            bModel.getSentenceEndOffset()));
                    sentenceNumber = getFirstSentenceNumber(mergeJCas, address);
                    int firstSentenceNumber = sentenceNumber + 1;
                    int lastSentenceNumber;
                    if (firstSentenceNumber + bModel.getPreferences().getWindowSize()
                            - 1 < totalNumberOfSentence) {
                        lastSentenceNumber = firstSentenceNumber + bModel.getPreferences().getWindowSize() - 1;
                    } else {
                        lastSentenceNumber = totalNumberOfSentence;
                    }

                    return "showing " + firstSentenceNumber + "-" + lastSentenceNumber + " of "
                            + totalNumberOfSentence + " sentences";
                } catch (UIMAException e) {
                    return "";
                } catch (DataRetrievalFailureException e) {
                    return "";
                } catch (ClassNotFoundException e) {
                    return "";
                } catch (FileNotFoundException e) {
                    return "";
                } catch (IOException e) {
                    return "";
                }

            } else {
                return "";// no document yet selected
            }

        }
    }).setOutputMarkupId(true));

    final ModalWindow openDocumentsModal;
    add(openDocumentsModal = new ModalWindow("openDocumentsModal"));
    openDocumentsModal.setOutputMarkupId(true);

    openDocumentsModal.setInitialWidth(500);
    openDocumentsModal.setInitialHeight(300);
    openDocumentsModal.setResizable(true);
    openDocumentsModal.setWidthUnit("px");
    openDocumentsModal.setHeightUnit("px");
    openDocumentsModal.setTitle("Open document");

    // Add project and document information at the top
    add(new AjaxLink<Void>("showOpenDocumentModal") {
        private static final long serialVersionUID = 7496156015186497496L;

        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            editor.reset(aTarget);
            openDocumentsModal.setContent(new OpenModalWindowPanel(openDocumentsModal.getContentId(), bModel,
                    openDocumentsModal, Mode.CORRECTION));
            openDocumentsModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
                private static final long serialVersionUID = -1746088901018629567L;

                @Override
                public void onClose(AjaxRequestTarget target) {
                    if (bModel.getDocument() == null) {
                        setResponsePage(WelcomePage.class);
                        return;
                    }

                    try {
                        target.addChildren(getPage(), FeedbackPanel.class);
                        bModel.setDocument(bModel.getDocument());
                        bModel.setProject(bModel.getProject());

                        loadDocumentAction();
                        setCurationSegmentBeginEnd();
                        update(target);

                        String username = SecurityContextHolder.getContext().getAuthentication().getName();
                        User user = userRepository.get(username);
                        editor.setEnabled(!FinishImage.isFinished(new Model<BratAnnotatorModel>(bModel), user,
                                repository));

                    } catch (UIMAException e) {
                        target.appendJavaScript("alert('" + e.getMessage() + "')");
                        setResponsePage(WelcomePage.class);
                    } catch (ClassNotFoundException e) {
                        target.appendJavaScript("alert('" + e.getMessage() + "')");
                        setResponsePage(WelcomePage.class);
                    } catch (IOException e) {
                        target.appendJavaScript("alert('" + e.getMessage() + "')");
                        setResponsePage(WelcomePage.class);
                    } catch (BratAnnotationException e) {
                        target.appendJavaScript("alert('" + e.getMessage() + "')");
                        setResponsePage(WelcomePage.class);
                    }
                    finish.setModelObject(bModel);
                    target.add(finish.setOutputMarkupId(true));
                    target.appendJavaScript("Wicket.Window.unloadConfirmation=false;window.location.reload()");
                    target.add(documentNamePanel.setOutputMarkupId(true));
                    target.add(numberOfPages);
                }
            });
            openDocumentsModal.show(aTarget);
        }
    });

    add(new AnnotationLayersModalPanel("annotationLayersModalPanel", new Model<BratAnnotatorModel>(bModel),
            editor) {
        private static final long serialVersionUID = -4657965743173979437L;

        @Override
        protected void onChange(AjaxRequestTarget aTarget) {
            curationContainer.setBratAnnotatorModel(bModel);
            try {
                aTarget.addChildren(getPage(), FeedbackPanel.class);
                setCurationSegmentBeginEnd();
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCauseMessage(e));
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            }
            update(aTarget);
            // mergeVisualizer.reloadContent(aTarget);
            aTarget.appendJavaScript("Wicket.Window.unloadConfirmation = false;window.location.reload()");

        }
    });

    add(new ExportModalPanel("exportModalPanel", new Model<BratAnnotatorModel>(bModel)));

    gotoPageTextField = (NumberTextField<Integer>) new NumberTextField<Integer>("gotoPageText",
            new Model<Integer>(0));
    Form<Void> gotoPageTextFieldForm = new Form<Void>("gotoPageTextFieldForm");
    gotoPageTextFieldForm.add(new AjaxFormSubmitBehavior(gotoPageTextFieldForm, "onsubmit") {
        private static final long serialVersionUID = -4549805321484461545L;

        @Override
        protected void onSubmit(AjaxRequestTarget aTarget) {
            if (gotoPageAddress == 0) {
                aTarget.appendJavaScript("alert('The sentence number entered is not valid')");
                return;
            }
            JCas mergeJCas = null;
            try {
                aTarget.addChildren(getPage(), FeedbackPanel.class);
                mergeJCas = repository.readCorrectionCas(bModel.getDocument());
                if (bModel.getSentenceAddress() != gotoPageAddress) {
                    bModel.setSentenceAddress(gotoPageAddress);

                    Sentence sentence = selectByAddr(mergeJCas, Sentence.class, gotoPageAddress);
                    bModel.setSentenceBeginOffset(sentence.getBegin());
                    bModel.setSentenceEndOffset(sentence.getEnd());

                    SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService,
                            userRepository);
                    curationContainer = builder.buildCurationContainer(bModel);
                    setCurationSegmentBeginEnd();
                    curationContainer.setBratAnnotatorModel(bModel);
                    update(aTarget);
                    annotator.bratRenderLater(aTarget);
                }
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            } catch (BratAnnotationException e) {
                error(e.getMessage());
            }
        }
    });

    gotoPageTextField.setType(Integer.class);
    gotoPageTextField.setMinimum(1);
    gotoPageTextField.setDefaultModelObject(1);
    add(gotoPageTextFieldForm.add(gotoPageTextField));
    gotoPageTextField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = -3853194405966729661L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            JCas mergeJCas = null;
            try {
                mergeJCas = repository.readCorrectionCas(bModel.getDocument());
                gotoPageAddress = getSentenceAddress(mergeJCas, gotoPageTextField.getModelObject());
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (ClassNotFoundException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (IOException e) {
                error(e.getMessage());
            }

        }
    });

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

        @Override
        public void onClick(AjaxRequestTarget aTarget) {

            if (gotoPageAddress == 0) {
                aTarget.appendJavaScript("alert('The sentence number entered is not valid')");
                return;
            }
            if (bModel.getDocument() == null) {
                aTarget.appendJavaScript("alert('Please open a document first!')");
                return;
            }
            JCas mergeJCas = null;
            try {
                aTarget.addChildren(getPage(), FeedbackPanel.class);
                mergeJCas = repository.readCorrectionCas(bModel.getDocument());
                if (bModel.getSentenceAddress() != gotoPageAddress) {
                    bModel.setSentenceAddress(gotoPageAddress);

                    Sentence sentence = selectByAddr(mergeJCas, Sentence.class, gotoPageAddress);
                    bModel.setSentenceBeginOffset(sentence.getBegin());
                    bModel.setSentenceEndOffset(sentence.getEnd());

                    SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService,
                            userRepository);
                    curationContainer = builder.buildCurationContainer(bModel);
                    setCurationSegmentBeginEnd();
                    curationContainer.setBratAnnotatorModel(bModel);
                    update(aTarget);
                    annotator.bratRenderLater(aTarget);
                }
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            } catch (BratAnnotationException e) {
                error(e.getMessage());
            }
        }
    });

    finish = new FinishImage("finishImage", new LoadableDetachableModel<BratAnnotatorModel>() {
        private static final long serialVersionUID = -2737326878793568454L;

        @Override
        protected BratAnnotatorModel load() {
            return bModel;
        }
    });

    add(new FinishLink("showYesNoModalPanel", new Model<BratAnnotatorModel>(bModel), finish) {
        private static final long serialVersionUID = -4657965743173979437L;
    });

    // Show the previous document, if exist
    add(new AjaxLink<Void>("showPreviousDocument") {
        private static final long serialVersionUID = 7496156015186497496L;

        /**
         * Get the current beginning sentence address and add on it the size of the display
         * window
         */
        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            editor.reset(aTarget);
            aTarget.addChildren(getPage(), FeedbackPanel.class);
            // List of all Source Documents in the project
            List<SourceDocument> listOfSourceDocuements = repository.listSourceDocuments(bModel.getProject());

            User user = userRepository.get(SecurityContextHolder.getContext().getAuthentication().getName());

            List<SourceDocument> sourceDocumentsinIgnorState = new ArrayList<SourceDocument>();
            for (SourceDocument sourceDocument : listOfSourceDocuements) {
                if (repository.existsAnnotationDocument(sourceDocument, user)
                        && repository.getAnnotationDocument(sourceDocument, user).getState()
                                .equals(AnnotationDocumentState.IGNORE)) {
                    sourceDocumentsinIgnorState.add(sourceDocument);
                }
            }

            listOfSourceDocuements.removeAll(sourceDocumentsinIgnorState);

            // Index of the current source document in the list
            int currentDocumentIndex = listOfSourceDocuements.indexOf(bModel.getDocument());

            // If the first the document
            if (currentDocumentIndex == 0) {
                aTarget.appendJavaScript("alert('This is the first document!')");
            } else {
                bModel.setDocumentName(listOfSourceDocuements.get(currentDocumentIndex - 1).getName());
                bModel.setDocument(listOfSourceDocuements.get(currentDocumentIndex - 1));

                try {
                    loadDocumentAction();
                    setCurationSegmentBeginEnd();
                    update(aTarget);

                } catch (UIMAException e) {
                    error(ExceptionUtils.getRootCause(e));
                } catch (ClassNotFoundException e) {
                    error(ExceptionUtils.getRootCause(e));
                } catch (IOException e) {
                    error(ExceptionUtils.getRootCause(e));
                } catch (BratAnnotationException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                }

                finish.setModelObject(bModel);
                aTarget.add(finish.setOutputMarkupId(true));
                aTarget.add(documentNamePanel);
                annotator.bratRenderLater(aTarget);
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_up }, EventType.click)));

    // Show the next document if exist
    add(new AjaxLink<Void>("showNextDocument") {
        private static final long serialVersionUID = 7496156015186497496L;

        /**
         * Get the current beginning sentence address and add on it the size of the display
         * window
         */
        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            editor.reset(aTarget);
            aTarget.addChildren(getPage(), FeedbackPanel.class);
            // List of all Source Documents in the project
            List<SourceDocument> listOfSourceDocuements = repository.listSourceDocuments(bModel.getProject());

            String username = SecurityContextHolder.getContext().getAuthentication().getName();
            User user = userRepository.get(username);

            List<SourceDocument> sourceDocumentsinIgnorState = new ArrayList<SourceDocument>();
            for (SourceDocument sourceDocument : listOfSourceDocuements) {
                if (repository.existsAnnotationDocument(sourceDocument, user)
                        && repository.getAnnotationDocument(sourceDocument, user).getState()
                                .equals(AnnotationDocumentState.IGNORE)) {
                    sourceDocumentsinIgnorState.add(sourceDocument);
                }
            }

            listOfSourceDocuements.removeAll(sourceDocumentsinIgnorState);

            // Index of the current source document in the list
            int currentDocumentIndex = listOfSourceDocuements.indexOf(bModel.getDocument());

            // If the first document
            if (currentDocumentIndex == listOfSourceDocuements.size() - 1) {
                aTarget.appendJavaScript("alert('This is the last document!')");
                return;
            }
            bModel.setDocumentName(listOfSourceDocuements.get(currentDocumentIndex + 1).getName());
            bModel.setDocument(listOfSourceDocuements.get(currentDocumentIndex + 1));

            try {
                loadDocumentAction();
                setCurationSegmentBeginEnd();
                update(aTarget);

            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (ClassNotFoundException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (IOException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (BratAnnotationException e) {
                aTarget.addChildren(getPage(), FeedbackPanel.class);
                error(e.getMessage());
            } catch (Exception e) {
                aTarget.addChildren(getPage(), FeedbackPanel.class);
                error(e.getMessage());
            }

            finish.setModelObject(bModel);
            aTarget.add(finish.setOutputMarkupId(true));
            aTarget.add(documentNamePanel);
            annotator.bratRenderLater(aTarget);
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_down }, EventType.click)));

    // Show the next page of this document
    add(new AjaxLink<Void>("showNext") {
        private static final long serialVersionUID = 7496156015186497496L;

        /**
         * Get the current beginning sentence address and add on it the size of the display
         * window
         */
        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            if (bModel.getDocument() != null) {
                JCas mergeJCas = null;
                try {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    mergeJCas = repository.readCorrectionCas(bModel.getDocument());
                    int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(),
                            bModel.getSentenceEndOffset()));
                    int nextSentenceAddress = getNextPageFirstSentenceAddress(mergeJCas, address,
                            bModel.getPreferences().getWindowSize());
                    if (address != nextSentenceAddress) {
                        bModel.setSentenceAddress(nextSentenceAddress);

                        Sentence sentence = selectByAddr(mergeJCas, Sentence.class, nextSentenceAddress);
                        bModel.setSentenceBeginOffset(sentence.getBegin());
                        bModel.setSentenceEndOffset(sentence.getEnd());

                        SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService,
                                userRepository);
                        curationContainer = builder.buildCurationContainer(bModel);
                        setCurationSegmentBeginEnd();
                        curationContainer.setBratAnnotatorModel(bModel);
                        update(aTarget);
                        annotator.bratRenderLater(aTarget);
                    }

                    else {
                        aTarget.appendJavaScript("alert('This is last page!')");
                    }
                } catch (UIMAException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(ExceptionUtils.getRootCause(e));
                } catch (ClassNotFoundException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (IOException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (BratAnnotationException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (Exception e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                }
            } else {
                aTarget.appendJavaScript("alert('Please open a document first!')");
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.Page_down }, EventType.click)));

    // SHow the previous page of this document
    add(new AjaxLink<Void>("showPrevious") {
        private static final long serialVersionUID = 7496156015186497496L;

        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            if (bModel.getDocument() != null) {

                JCas mergeJCas = null;
                try {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    mergeJCas = repository.readCorrectionCas(bModel.getDocument());
                    int previousSentenceAddress = BratAjaxCasUtil.getPreviousDisplayWindowSentenceBeginAddress(
                            mergeJCas, bModel.getSentenceAddress(), bModel.getPreferences().getWindowSize());
                    if (bModel.getSentenceAddress() != previousSentenceAddress) {
                        bModel.setSentenceAddress(previousSentenceAddress);

                        Sentence sentence = selectByAddr(mergeJCas, Sentence.class, previousSentenceAddress);
                        bModel.setSentenceBeginOffset(sentence.getBegin());
                        bModel.setSentenceEndOffset(sentence.getEnd());

                        SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService,
                                userRepository);

                        curationContainer = builder.buildCurationContainer(bModel);
                        setCurationSegmentBeginEnd();
                        curationContainer.setBratAnnotatorModel(bModel);
                        update(aTarget);
                        annotator.bratRenderLater(aTarget);
                    } else {
                        aTarget.appendJavaScript("alert('This is First Page!')");
                    }
                } catch (UIMAException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(ExceptionUtils.getRootCause(e));
                } catch (ClassNotFoundException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (IOException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (BratAnnotationException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (Exception e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                }
            } else {
                aTarget.appendJavaScript("alert('Please open a document first!')");
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.Page_up }, EventType.click)));

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

        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            if (bModel.getDocument() != null) {
                JCas mergeJCas = null;
                try {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    mergeJCas = repository.readCorrectionCas(bModel.getDocument());

                    int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(),
                            bModel.getSentenceEndOffset()));
                    int firstAddress = getFirstSentenceAddress(mergeJCas);

                    if (firstAddress != address) {
                        bModel.setSentenceAddress(firstAddress);

                        Sentence sentence = selectByAddr(mergeJCas, Sentence.class, firstAddress);
                        bModel.setSentenceBeginOffset(sentence.getBegin());
                        bModel.setSentenceEndOffset(sentence.getEnd());

                        SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService,
                                userRepository);
                        curationContainer = builder.buildCurationContainer(bModel);
                        setCurationSegmentBeginEnd();
                        curationContainer.setBratAnnotatorModel(bModel);
                        update(aTarget);
                        annotator.bratRenderLater(aTarget);
                    } else {
                        aTarget.appendJavaScript("alert('This is first page!')");
                    }
                } catch (UIMAException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(ExceptionUtils.getRootCause(e));
                } catch (ClassNotFoundException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (IOException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (BratAnnotationException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (Exception e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                }
            } else {
                aTarget.appendJavaScript("alert('Please open a document first!')");
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.Home }, EventType.click)));

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

        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            if (bModel.getDocument() != null) {
                JCas mergeJCas = null;
                try {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    mergeJCas = repository.readCorrectionCas(bModel.getDocument());
                    int lastDisplayWindowBeginingSentenceAddress = BratAjaxCasUtil
                            .getLastDisplayWindowFirstSentenceAddress(mergeJCas,
                                    bModel.getPreferences().getWindowSize());
                    if (lastDisplayWindowBeginingSentenceAddress != bModel.getSentenceAddress()) {
                        bModel.setSentenceAddress(lastDisplayWindowBeginingSentenceAddress);

                        Sentence sentence = selectByAddr(mergeJCas, Sentence.class,
                                lastDisplayWindowBeginingSentenceAddress);
                        bModel.setSentenceBeginOffset(sentence.getBegin());
                        bModel.setSentenceEndOffset(sentence.getEnd());

                        SuggestionBuilder builder = new SuggestionBuilder(repository, annotationService,
                                userRepository);
                        curationContainer = builder.buildCurationContainer(bModel);
                        setCurationSegmentBeginEnd();
                        curationContainer.setBratAnnotatorModel(bModel);
                        update(aTarget);
                        annotator.bratRenderLater(aTarget);

                    } else {
                        aTarget.appendJavaScript("alert('This is last Page!')");
                    }
                } catch (UIMAException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(ExceptionUtils.getRootCause(e));
                } catch (ClassNotFoundException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (IOException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (BratAnnotationException e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                } catch (Exception e) {
                    aTarget.addChildren(getPage(), FeedbackPanel.class);
                    error(e.getMessage());
                }
            } else {
                aTarget.appendJavaScript("alert('Please open a document first!')");
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.End }, EventType.click)));

    add(new GuidelineModalPanel("guidelineModalPanel", new Model<BratAnnotatorModel>(bModel)));
}

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.page.curation.CurationPage.java

License:Apache License

@SuppressWarnings("deprecation")
public CurationPage() {
    bModel = new BratAnnotatorModel();
    bModel.setMode(Mode.CURATION);/*w w w. j a v  a 2 s.co m*/
    reMerge = new ReMergeCasModel();

    curationContainer = new CurationContainer();
    curationContainer.setBratAnnotatorModel(bModel);

    curationPanel = new CurationPanel("curationPanel", new Model<CurationContainer>(curationContainer)) {
        private static final long serialVersionUID = 2175915644696513166L;

        @Override
        protected void onChange(AjaxRequestTarget aTarget) {
            JCas mergeJCas = null;
            try {
                mergeJCas = repository.readCurationCas(bModel.getDocument());
            } catch (UIMAException e) {
                error(e.getMessage());
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            }
            aTarget.add(numberOfPages);
            gotoPageTextField
                    .setModelObject(getFirstSentenceNumber(mergeJCas, bModel.getSentenceAddress()) + 1);
            gotoPageAddress = getSentenceAddress(mergeJCas, gotoPageTextField.getModelObject());
            aTarget.add(gotoPageTextField);
            aTarget.add(curationPanel);
        }
    };

    curationPanel.setOutputMarkupId(true);
    add(curationPanel);

    add(documentNamePanel = new DocumentNamePanel("documentNamePanel", new Model<BratAnnotatorModel>(bModel)));
    documentNamePanel.setOutputMarkupId(true);

    add(numberOfPages = (Label) new Label("numberOfPages", new LoadableDetachableModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        protected String load() {
            if (bModel.getDocument() != null) {

                JCas mergeJCas = null;
                try {
                    mergeJCas = repository.readCurationCas(bModel.getDocument());

                    totalNumberOfSentence = getNumberOfPages(mergeJCas);

                    // If only one page, start displaying from
                    // sentence 1
                    if (totalNumberOfSentence == 1) {
                        bModel.setSentenceAddress(bModel.getFirstSentenceAddress());
                    }
                    sentenceNumber = getFirstSentenceNumber(mergeJCas, bModel.getSentenceAddress());
                    int firstSentenceNumber = sentenceNumber + 1;
                    int lastSentenceNumber;
                    if (firstSentenceNumber + bModel.getPreferences().getWindowSize()
                            - 1 < totalNumberOfSentence) {
                        lastSentenceNumber = firstSentenceNumber + bModel.getPreferences().getWindowSize() - 1;
                    } else {
                        lastSentenceNumber = totalNumberOfSentence;
                    }

                    return "showing " + firstSentenceNumber + "-" + lastSentenceNumber + " of "
                            + totalNumberOfSentence + " sentences";
                } catch (UIMAException e) {
                    return "";
                } catch (ClassNotFoundException e) {
                    return "";
                } catch (IOException e) {
                    return "";
                }

            } else {
                return "";// no document yet selected
            }

        }
    }).setOutputMarkupId(true));

    final ModalWindow openDocumentsModal;
    add(openDocumentsModal = new ModalWindow("openDocumentsModal"));
    openDocumentsModal.setOutputMarkupId(true);

    openDocumentsModal.setInitialWidth(500);
    openDocumentsModal.setInitialHeight(300);
    openDocumentsModal.setResizable(true);
    openDocumentsModal.setWidthUnit("px");
    openDocumentsModal.setHeightUnit("px");
    openDocumentsModal.setTitle("Open document");

    // Add project and document information at the top
    add(new AjaxLink<Void>("showOpenDocumentModal") {
        private static final long serialVersionUID = 7496156015186497496L;

        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            curationPanel.resetEditor(aTarget);
            openDocumentsModal.setContent(new OpenModalWindowPanel(openDocumentsModal.getContentId(), bModel,
                    openDocumentsModal, Mode.CURATION));
            openDocumentsModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
                private static final long serialVersionUID = -1746088901018629567L;

                @Override
                public void onClose(AjaxRequestTarget target) {
                    String username = SecurityContextHolder.getContext().getAuthentication().getName();
                    /*
                     * Changed for #152, getDocument was returning null even after opening a document
                     * Also, surrounded following code into if block to avoid error.
                     */
                    if (bModel.getProject() == null) {
                        setResponsePage(WelcomePage.class);
                        return;
                    }
                    if (bModel.getDocument() != null) {
                        User user = userRepository.get(username);
                        // Update source document state to
                        // CURRATION_INPROGRESS, if it was not
                        // ANNOTATION_FINISHED
                        if (!bModel.getDocument().getState().equals(SourceDocumentState.CURATION_FINISHED)) {

                            bModel.getDocument().setState(SourceDocumentState.CURATION_IN_PROGRESS);
                        }

                        try {
                            repository.createSourceDocument(bModel.getDocument(), user);
                            repository.upgradeCasAndSave(bModel.getDocument(), Mode.CURATION, username);

                            loadDocumentAction(target);

                        } catch (IOException | UIMAException | ClassNotFoundException
                                | BratAnnotationException e) {
                            target.add(getFeedbackPanel());
                            error(e.getCause().getMessage());
                        }
                    }
                }
            });
            openDocumentsModal.show(aTarget);
        }
    });

    add(new AnnotationLayersModalPanel("annotationLayersModalPanel", new Model<BratAnnotatorModel>(bModel),
            curationPanel.editor) {
        private static final long serialVersionUID = -4657965743173979437L;

        @Override
        protected void onChange(AjaxRequestTarget aTarget) {
            aTarget.add(getFeedbackPanel());
            aTarget.add(numberOfPages);
            JCas mergeJCas = null;
            try {
                aTarget.add(getFeedbackPanel());
                mergeJCas = repository.readCurationCas(bModel.getDocument());
                curationPanel.updatePanel(aTarget, curationContainer);
                updatePanel(curationContainer, aTarget);
                updateSentenceNumber(mergeJCas, bModel.getSentenceAddress());
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCauseMessage(e));
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            } catch (BratAnnotationException e) {
                error(e.getMessage());
            }

        }
    });

    // Show the previous document, if exist
    add(new AjaxLink<Void>("showPreviousDocument") {
        private static final long serialVersionUID = 7496156015186497496L;

        /**
         * Get the current beginning sentence address and add on it the size of the display
         * window
         */
        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            curationPanel.resetEditor(aTarget);
            // List of all Source Documents in the project
            List<SourceDocument> listOfSourceDocuements = repository.listSourceDocuments(bModel.getProject());

            String username = SecurityContextHolder.getContext().getAuthentication().getName();
            User user = userRepository.get(username);

            List<SourceDocument> sourceDocumentsinIgnorState = new ArrayList<SourceDocument>();
            for (SourceDocument sourceDocument : listOfSourceDocuements) {
                if (!repository.existFinishedDocument(sourceDocument, bModel.getProject())) {
                    sourceDocumentsinIgnorState.add(sourceDocument);
                }
            }

            listOfSourceDocuements.removeAll(sourceDocumentsinIgnorState);

            // Index of the current source document in the list
            int currentDocumentIndex = listOfSourceDocuements.indexOf(bModel.getDocument());

            // If the first the document
            if (currentDocumentIndex == 0) {
                aTarget.appendJavaScript("alert('This is the first document!')");
            } else {
                bModel.setDocumentName(listOfSourceDocuements.get(currentDocumentIndex - 1).getName());
                bModel.setDocument(listOfSourceDocuements.get(currentDocumentIndex - 1));
                try {
                    repository.upgradeCasAndSave(bModel.getDocument(), Mode.CURATION,
                            bModel.getUser().getUsername());

                    loadDocumentAction(aTarget);
                } catch (IOException | UIMAException | ClassNotFoundException | BratAnnotationException e) {
                    aTarget.add(getFeedbackPanel());
                    error(e.getCause().getMessage());
                }
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_up }, EventType.click)));

    // Show the next document if exist
    add(new AjaxLink<Void>("showNextDocument") {
        private static final long serialVersionUID = 7496156015186497496L;

        /**
         * Get the current beginning sentence address and add on it the size of the display
         * window
         */
        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            curationPanel.resetEditor(aTarget);
            // List of all Source Documents in the project
            List<SourceDocument> listOfSourceDocuements = repository.listSourceDocuments(bModel.getProject());

            String username = SecurityContextHolder.getContext().getAuthentication().getName();
            User user = userRepository.get(username);

            List<SourceDocument> sourceDocumentsinIgnorState = new ArrayList<SourceDocument>();
            for (SourceDocument sourceDocument : listOfSourceDocuements) {
                if (!repository.existFinishedDocument(sourceDocument, bModel.getProject())) {
                    sourceDocumentsinIgnorState.add(sourceDocument);
                }
            }

            listOfSourceDocuements.removeAll(sourceDocumentsinIgnorState);

            // Index of the current source document in the list
            int currentDocumentIndex = listOfSourceDocuements.indexOf(bModel.getDocument());

            // If the first document
            if (currentDocumentIndex == listOfSourceDocuements.size() - 1) {
                aTarget.appendJavaScript("alert('This is the last document!')");
            } else {
                bModel.setDocumentName(listOfSourceDocuements.get(currentDocumentIndex + 1).getName());
                bModel.setDocument(listOfSourceDocuements.get(currentDocumentIndex + 1));

                try {
                    aTarget.add(getFeedbackPanel());
                    repository.upgradeCasAndSave(bModel.getDocument(), Mode.CURATION,
                            bModel.getUser().getUsername());

                    loadDocumentAction(aTarget);
                } catch (IOException | UIMAException | ClassNotFoundException | BratAnnotationException e) {
                    aTarget.add(getFeedbackPanel());
                    error(e.getCause().getMessage());
                }
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_down }, EventType.click)));

    add(new ExportModalPanel("exportModalPanel", new Model<BratAnnotatorModel>(bModel)));

    gotoPageTextField = (NumberTextField<Integer>) new NumberTextField<Integer>("gotoPageText",
            new Model<Integer>(0));
    Form<Void> gotoPageTextFieldForm = new Form<Void>("gotoPageTextFieldForm");
    gotoPageTextFieldForm.add(new AjaxFormSubmitBehavior(gotoPageTextFieldForm, "onsubmit") {
        private static final long serialVersionUID = -4549805321484461545L;

        @Override
        protected void onSubmit(AjaxRequestTarget aTarget) {
            if (gotoPageAddress == 0) {
                aTarget.appendJavaScript("alert('The sentence number entered is not valid')");
                return;
            }
            JCas mergeJCas = null;
            try {
                aTarget.add(getFeedbackPanel());
                mergeJCas = repository.readCurationCas(bModel.getDocument());
                if (bModel.getSentenceAddress() != gotoPageAddress) {

                    updateSentenceNumber(mergeJCas, gotoPageAddress);

                    aTarget.add(numberOfPages);
                    updatePanel(curationContainer, aTarget);
                }
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCauseMessage(e));
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            }
        }
    });

    gotoPageTextField.setType(Integer.class);
    gotoPageTextField.setMinimum(1);
    gotoPageTextField.setDefaultModelObject(1);
    add(gotoPageTextFieldForm.add(gotoPageTextField));
    gotoPageTextField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1244526899787707931L;

        @Override
        protected void onUpdate(AjaxRequestTarget aTarget) {
            JCas mergeJCas = null;
            try {
                aTarget.add(getFeedbackPanel());
                mergeJCas = repository.readCurationCas(bModel.getDocument());
                gotoPageAddress = getSentenceAddress(mergeJCas, gotoPageTextField.getModelObject());

            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            }

        }
    });

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

        @Override
        public void onClick(AjaxRequestTarget aTarget) {

            if (gotoPageAddress == 0) {
                aTarget.appendJavaScript("alert('The sentence number entered is not valid')");
                return;
            }
            if (bModel.getDocument() == null) {
                aTarget.appendJavaScript("alert('Please open a document first!')");
                return;
            }

            JCas mergeJCas = null;
            try {
                aTarget.add(getFeedbackPanel());
                mergeJCas = repository.readCurationCas(bModel.getDocument());
                if (bModel.getSentenceAddress() != gotoPageAddress) {

                    updateSentenceNumber(mergeJCas, gotoPageAddress);

                    aTarget.add(numberOfPages);
                    curationPanel.updatePanel(aTarget, curationContainer);
                }
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCauseMessage(e));
            } catch (ClassNotFoundException e) {
                error(e.getMessage());
            } catch (IOException e) {
                error(e.getMessage());
            } catch (BratAnnotationException e) {
                error(e.getMessage());
            }
        }
    });

    finish = new WebMarkupContainer("finishImage");
    finish.setOutputMarkupId(true);
    finish.add(new AttributeModifier("src", new LoadableDetachableModel<String>() {
        private static final long serialVersionUID = 1562727305401900776L;

        @Override
        protected String load() {

            if (bModel.getProject() != null && bModel.getDocument() != null) {
                if (repository
                        .getSourceDocument(bModel.getDocument().getProject(), bModel.getDocument().getName())
                        .getState().equals(SourceDocumentState.CURATION_FINISHED)) {
                    return "images/accept.png";
                } else {
                    return "images/inprogress.png";
                }
            } else {
                return "images/inprogress.png";
            }

        }
    }));

    final ModalWindow finishCurationModal;
    add(finishCurationModal = new ModalWindow("finishCurationModal"));
    finishCurationModal.setOutputMarkupId(true);

    finishCurationModal.setInitialWidth(700);
    finishCurationModal.setInitialHeight(50);
    finishCurationModal.setResizable(true);
    finishCurationModal.setWidthUnit("px");
    finishCurationModal.setHeightUnit("px");

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

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (bModel.getDocument() != null
                    && bModel.getDocument().getState().equals(SourceDocumentState.CURATION_FINISHED)) {
                finishCurationModal.setTitle(
                        "Curation was finished. Are you sure you want to re-open document for curation?");
            } else {
                finishCurationModal.setTitle("Are you sure you want to finish curating?");
            }
            finishCurationModal.setContent(new YesNoFinishModalPanel(finishCurationModal.getContentId(), bModel,
                    finishCurationModal, Mode.CURATION));
            finishCurationModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
                private static final long serialVersionUID = -1746088901018629567L;

                @Override
                public void onClose(AjaxRequestTarget target) {
                    target.add(finish);
                    target.appendJavaScript("Wicket.Window.unloadConfirmation=false;window.location.reload()");
                }
            });
            finishCurationModal.show(target);
        }
    });

    showFinishCurationModal.add(finish);

    add(new GuidelineModalPanel("guidelineModalPanel", new Model<BratAnnotatorModel>(bModel)));

    final ModalWindow reCreateMergeCas;
    add(reCreateMergeCas = new ModalWindow("reCreateMergeCasModal"));
    reCreateMergeCas.setOutputMarkupId(true);

    reCreateMergeCas.setInitialWidth(400);
    reCreateMergeCas.setInitialHeight(50);
    reCreateMergeCas.setResizable(true);
    reCreateMergeCas.setWidthUnit("px");
    reCreateMergeCas.setHeightUnit("px");
    reCreateMergeCas.setTitle("are you sure? all curation annotations for this document will be lost");

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

        @Override
        protected void onConfigure() {
            setEnabled(bModel.getDocument() != null
                    && !bModel.getDocument().getState().equals(SourceDocumentState.CURATION_FINISHED));
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            reCreateMergeCas.setContent(
                    new ReCreateMergeCASModalPanel(reCreateMergeCas.getContentId(), reCreateMergeCas, reMerge));
            reCreateMergeCas.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

                private static final long serialVersionUID = 4816615910398625993L;

                @Override
                public void onClose(AjaxRequestTarget aTarget) {
                    if (reMerge.isReMerege()) {
                        try {
                            aTarget.add(getFeedbackPanel());
                            repository.removeCurationDocumentContent(bModel.getDocument(),
                                    bModel.getUser().getUsername());
                            loadDocumentAction(aTarget);

                            aTarget.appendJavaScript("alert('remerege finished!')");
                        } catch (IOException | UIMAException | ClassNotFoundException
                                | BratAnnotationException e) {
                            aTarget.add(getFeedbackPanel());
                            error(e.getCause().getMessage());
                        }
                    }
                }
            });
            reCreateMergeCas.show(target);
        }
    });
    // Show the next page of this document
    add(new AjaxLink<Void>("showNext") {
        private static final long serialVersionUID = 7496156015186497496L;

        /**
         * Get the current beginning sentence address and add on it the size of the display
         * window
         */
        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            if (bModel.getDocument() != null) {
                JCas mergeJCas = null;
                try {
                    mergeJCas = repository.readCurationCas(bModel.getDocument());
                    int nextSentenceAddress = getNextPageFirstSentenceAddress(mergeJCas,
                            bModel.getSentenceAddress(), bModel.getPreferences().getWindowSize());
                    if (bModel.getSentenceAddress() != nextSentenceAddress) {
                        aTarget.add(getFeedbackPanel());

                        updateSentenceNumber(mergeJCas, nextSentenceAddress);

                        aTarget.add(numberOfPages);
                        curationPanel.updatePanel(aTarget, curationContainer);
                        updatePanel(curationContainer, aTarget);
                    }

                    else {
                        aTarget.appendJavaScript("alert('This is last page!')");
                    }
                } catch (UIMAException e) {
                    error(ExceptionUtils.getRootCauseMessage(e));
                } catch (ClassNotFoundException e) {
                    error(e.getMessage());
                } catch (IOException e) {
                    error(e.getMessage());
                } catch (BratAnnotationException e) {
                    error(e.getMessage());
                }
            } else {
                aTarget.appendJavaScript("alert('Please open a document first!')");
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.Page_down }, EventType.click)));

    // SHow the previous page of this document
    add(new AjaxLink<Void>("showPrevious") {
        private static final long serialVersionUID = 7496156015186497496L;

        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            if (bModel.getDocument() != null) {

                JCas mergeJCas = null;
                try {
                    aTarget.add(getFeedbackPanel());
                    mergeJCas = repository.readCurationCas(bModel.getDocument());
                    int previousSentenceAddress = BratAjaxCasUtil.getPreviousDisplayWindowSentenceBeginAddress(
                            mergeJCas, bModel.getSentenceAddress(), bModel.getPreferences().getWindowSize());
                    if (bModel.getSentenceAddress() != previousSentenceAddress) {

                        updateSentenceNumber(mergeJCas, previousSentenceAddress);

                        aTarget.add(numberOfPages);
                        curationPanel.updatePanel(aTarget, curationContainer);
                        updatePanel(curationContainer, aTarget);
                    } else {
                        aTarget.appendJavaScript("alert('This is First Page!')");
                    }
                } catch (UIMAException e) {
                    error(ExceptionUtils.getRootCauseMessage(e));
                } catch (ClassNotFoundException e) {
                    error(e.getMessage());
                } catch (IOException e) {
                    error(e.getMessage());
                } catch (BratAnnotationException e) {
                    error(e.getMessage());
                }
            } else {
                aTarget.appendJavaScript("alert('Please open a document first!')");
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.Page_up }, EventType.click)));

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

        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            if (bModel.getDocument() != null) {
                JCas mergeJCas = null;
                try {
                    aTarget.add(getFeedbackPanel());
                    mergeJCas = repository.readCurationCas(bModel.getDocument());

                    int address = getAddr(selectSentenceAt(mergeJCas, bModel.getSentenceBeginOffset(),
                            bModel.getSentenceEndOffset()));
                    int firstAddress = getFirstSentenceAddress(mergeJCas);

                    if (firstAddress != address) {

                        updateSentenceNumber(mergeJCas, firstAddress);

                        aTarget.add(numberOfPages);
                        curationPanel.updatePanel(aTarget, curationContainer);
                        updatePanel(curationContainer, aTarget);
                    } else {
                        aTarget.appendJavaScript("alert('This is first page!')");
                    }
                } catch (UIMAException e) {
                    error(ExceptionUtils.getRootCauseMessage(e));
                } catch (ClassNotFoundException e) {
                    error(e.getMessage());
                } catch (IOException e) {
                    error(e.getMessage());
                } catch (BratAnnotationException e) {
                    error(e.getMessage());
                }
            } else {
                aTarget.appendJavaScript("alert('Please open a document first!')");
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.Home }, EventType.click)));

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

        @Override
        public void onClick(AjaxRequestTarget aTarget) {
            if (bModel.getDocument() != null) {
                JCas mergeJCas = null;
                try {
                    aTarget.add(getFeedbackPanel());
                    mergeJCas = repository.readCurationCas(bModel.getDocument());
                    int lastDisplayWindowBeginingSentenceAddress = BratAjaxCasUtil
                            .getLastDisplayWindowFirstSentenceAddress(mergeJCas,
                                    bModel.getPreferences().getWindowSize());
                    if (lastDisplayWindowBeginingSentenceAddress != bModel.getSentenceAddress()) {

                        updateSentenceNumber(mergeJCas, lastDisplayWindowBeginingSentenceAddress);

                        aTarget.add(numberOfPages);
                        curationPanel.updatePanel(aTarget, curationContainer);
                        updatePanel(curationContainer, aTarget);
                    } else {
                        aTarget.appendJavaScript("alert('This is last Page!')");
                    }
                } catch (UIMAException e) {
                    error(ExceptionUtils.getRootCauseMessage(e));
                } catch (ClassNotFoundException e) {
                    error(e.getMessage());
                } catch (IOException e) {
                    error(e.getMessage());
                } catch (BratAnnotationException e) {
                    error(e.getMessage());
                }
            } else {
                aTarget.appendJavaScript("alert('Please open a document first!')");
            }
        }
    }.add(new InputBehavior(new KeyType[] { KeyType.End }, EventType.click)));
}

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

License:Open Source License

public EditFieldGroupPanel(String id, final ModalWindow modalWindow, final FieldGroup fieldGroup) {
    super(id);// w  ww.  j  av a  2 s.  co  m
    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  w  w . j a v a2 s .  c om*/
    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.
 *         //from  w w w .j  a v  a2s. 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:hsa.awp.usergui.CampaignPreviewPanel.java

License:Open Source License

public CampaignPreviewPanel(String id, final Campaign campaign) {
    super(id);/*ww w  .  jav  a2s  .  c o  m*/
    Link<String> campaignDetail = createCampaignDetail(campaign);
    campaignDetail.setEnabled(isCampaignActive(campaign.findCurrentProcedure()));
    add(campaignDetail);
    final ModalWindow detailWindow = new ModalWindow("campaignListPanel.detailWindow");
    detailWindow.setContent(new AjaxLazyLoadPanel(detailWindow.getContentId()) {
        /**
         *
         */
        private static final long serialVersionUID = -822132746613326567L;

        @Override
        public Component getLazyLoadComponent(String markupId) {

            return new CampaignDetailPanel(markupId, campaign.getDetailText());
        }
    });
    detailWindow.setTitle(new Model<String>("Kampagnendetails"));
    detailWindow.setInitialWidth(450);

    add(detailWindow);

    add(new AjaxFallbackLink<Object>("campaignListPanel.infoLink") {
        /**
         * unique serialization id.
         */
        private static final long serialVersionUID = 543607735730300949L;

        @Override
        public void onClick(AjaxRequestTarget target) {

            detailWindow.show(target);
        }
    });

}

From source file:hsa.awp.usergui.FlatListPanel.java

License:Open Source License

/**
 * Constructor for the FlatList panel, which defines all needed components.
 *
 * @param id ID which declares the location in the markup.
 *//*  w  w w.jav  a 2s.  c om*/
public FlatListPanel(String id, final Campaign campaign) {

    super(id);

    this.campaign = campaign;

    singleUser = controller.getUserById(SecurityContextHolder.getContext().getAuthentication().getName());

    // find events where user is allowed
    events = controller.getEventsWhereRegistrationIsAllowed(campaign, singleUser);

    // find categories with events where user is allowed
    categories = getCategoriesOfEvents(events);

    // find events of category where user is allowed

    final LoadableDetachedModel<List<Category>> categoriesModel = new LoadableDetachedModel<List<Category>>() {
        /**
         * unique serialization id.
         */
        private static final long serialVersionUID = 1594571791900639307L;

        @Override
        protected List<Category> load() {
            List<Category> categoryList = new ArrayList<Category>(categories);
            Collections.sort(categoryList, EventSorter.alphabeticalCategoryName());
            return categoryList;
        }
    };

    final WebMarkupContainer flatListContainer = new WebMarkupContainer("flatlist.container");
    flatListContainer.setOutputMarkupId(true);

    flatListContainer.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(30f)));

    add(flatListContainer);

    add(new Label("flatlist.capacityDE", new Model<Integer>((int) (capacityPercent * 100))));
    add(new Label("flatlist.capacityEN", new Model<Integer>((int) (capacityPercent * 100))));

    flatListContainer.add(new ListView<Category>("categorylist", categoriesModel) {
        /**
         * Generated serialization id.
         */
        private static final long serialVersionUID = 490760462608363776L;

        @Override
        protected void populateItem(ListItem<Category> item) {

            List<Event> eventsOfCategory = getEventsOfCategory(item.getModelObject(), events);

            item.add(new Label("categoryname", item.getModelObject().getName()));
            item.add(new ListView<Event>("eventlist", eventsOfCategory) {
                /**
                 * Generated serialization id.
                 */
                private static final long serialVersionUID = 497760462608363776L;

                @SuppressWarnings("serial")
                @Override
                protected void populateItem(final ListItem<Event> item) {

                    final Event event = item.getModelObject();

                    int maxParticipants = event.getMaxParticipants();

                    long participantCount = controller.countConfirmedRegistrationsByEventId(event.getId());

                    if (participantCount > maxParticipants) {
                        participantCount = maxParticipants;
                    }

                    item.add(new Label("eventNumber", formatEventId(event)));
                    item.add(new Label("subjectname", event.getSubject().getName()));
                    item.add(new Label("eventdescription", formatDetailInformation(event)));
                    item.add(new Label("eventplaces", "(" + participantCount + "/" + maxParticipants + ")"));

                    Link<Object> link = new Link<Object>("submited") {
                        public void onClick() {

                            Procedure procedure = campaign.findCurrentProcedure();

                            FifoProcedure fifo;

                            if (procedure instanceof FifoProcedure) {
                                fifo = (FifoProcedure) procedure;
                            } else {
                                throw new IllegalStateException("Flatlist works only with Fifoprocedure.");
                            }

                            String initiator = SecurityContextHolder.getContext().getAuthentication().getName();
                            controller.registerWithFifoProcedure(fifo, event, initiator, initiator, true);
                        }
                    };

                    Image icon = new Image("icon");
                    icon.add(new AttributeModifier("src", true, new Model<String>()));

                    if (controller.hasParticipantConfirmedRegistrationInEvent(singleUser, event)) {
                        link.setVisible(false);
                        item.add(new AttributeAppender("class", new Model<String>("disabled"), " "));
                    }

                    if ((maxParticipants - participantCount) <= 0) {
                        link.setEnabled(false);
                        item.add(new AttributeAppender("class", new Model<String>("disabled"), " "));
                        icon.add(new AttributeModifier("src", true, new Model<String>("images/red.png")));
                    } else if ((Float.valueOf(maxParticipants - participantCount)
                            / maxParticipants) <= capacityPercent) {
                        icon.add(new AttributeModifier("src", true, new Model<String>("images/yellow.png")));
                    } else {
                        icon.add(new AttributeModifier("src", true, new Model<String>("images/green.png")));
                    }

                    link.add(icon);
                    link.add(new JavascriptEventConfirmation("onclick", "Sind Sie sicher?"));
                    item.add(link);

                    final ModalWindow detailWindow = new ModalWindow("detailWindow");
                    detailWindow.setTitle(new Model<String>("Veranstaltungsdetails"));
                    detailWindow.setInitialWidth(450);

                    item.add(detailWindow);

                    item.add(new AjaxFallbackLink<Object>("infoLink") {
                        /**
                         * unique serialization id.
                         */
                        private static final long serialVersionUID = 543607735730300949L;

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            detailWindow.setContent(new EventDetailPanel(detailWindow.getContentId(), event));
                            detailWindow.show(target);
                        }
                    });
                }
            });
        }
    });

    LoadableDetachedModel<String> dateModel = new LoadableDetachedModel<String>() {
        /**
         * unique serialization id.
         */
        private static final long serialVersionUID = -3714278116173742179L;

        @Override
        protected String load() {

            DateFormat singleFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            return singleFormat.format(Calendar.getInstance().getTime());
        }
    };
    flatListContainer.add(new Label("flatlist.date", dateModel));

    flatListContainer.add(new AjaxFallbackLink<Object>("flatlist.refresh") {
        /**
         * unique serialization id.
         */
        private static final long serialVersionUID = 8370439147861506762L;

        @Override
        public void onClick(AjaxRequestTarget target) {

            categoriesModel.detach();
            target.addComponent(flatListContainer);
        }
    });

    flatListContainer.add(new Label("flatlist.userInfo", new LoadableDetachedModel<String>() {
        @Override
        protected String load() { //Kampangenname: Phase: Phasenname vom xx.xx.xx. hh:mm bis xx.xx.xx hh:mm
            StringBuilder sb = new StringBuilder();
            sb.append(campaign.getName());
            sb.append(": Phase: ");
            Procedure currentProcedure = campaign.findCurrentProcedure();
            sb.append(currentProcedure.getName());
            sb.append(" vom ");
            DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");
            sb.append(df.format(currentProcedure.getStartDate().getTime()));
            sb.append(" bis ");
            sb.append(df.format(currentProcedure.getEndDate().getTime()));
            return sb.toString();
        }
    }));
}

From source file:hsa.awp.usergui.util.DragableElement.java

License:Open Source License

/**
 * Constructor for the DragableElement./* w  ww  .  ja va 2s. co  m*/
 *
 * @param id       Wicket id
 * @param event    event to display
 * @param isActive true if draggabiliy is given
 */
public DragableElement(String id, final Event event, boolean isActive) {

    super(id);
    this.event = event;
    this.setOutputMarkupId(true);
    WebMarkupContainer box = new WebMarkupContainer("prioListDragableElement.element");

    String eventString = formatEventId(event) + " " + event.getSubject().getName();
    box.add(new Label("prioListDragableElement.title", eventString));
    box.add(new Label("prioListDragableElement.info", formatDetailInformation(event)));

    final ModalWindow detailWindow = new ModalWindow("prioListDragableElement.detailWindow");
    detailWindow.setContent(new AjaxLazyLoadPanel(detailWindow.getContentId()) {
        /**
         *
         */
        private static final long serialVersionUID = -822132746613326567L;

        @Override
        public Component getLazyLoadComponent(String markupId) {

            return new EventDetailPanel(markupId, event);
        }
    });
    detailWindow.setTitle(new Model<String>("Veranstaltungsdetails"));
    detailWindow.setInitialWidth(450);

    box.add(detailWindow);

    box.add(new AjaxFallbackLink<Object>("prioListDragableElement.infoLink") {
        /**
         * unique serialization id.
         */
        private static final long serialVersionUID = 543607735730300949L;

        @Override
        public void onClick(AjaxRequestTarget target) {

            detailWindow.show(target);
        }
    });

    if (isActive) {
        dragBehavior = new DraggableBehavior();
        dragBehavior.setRevert(true);
        box.add(dragBehavior);
        box.add(new AttributeAppender("class", new Model<String>("draggable"), " "));
    }
    add(box);
}

From source file:mil.nga.giat.elasticsearch.ElasticConfigurationPanel.java

License:Open Source License

/**
 * Adds Elasticsearch configuration panel link, configure modal dialog and 
 * implements modal callback.//from   w  w w  .j ava 2  s . c o m
 * 
 * @see {@link ElasticConfigurationPage#done}
 */

public ElasticConfigurationPanel(final String panelId, final IModel model) {
    super(panelId, model);
    final FeatureTypeInfo fti = (FeatureTypeInfo) model.getObject();

    final ModalWindow modal = new ModalWindow("modal");
    modal.setInitialWidth(800);
    modal.setTitle(new ParamResourceModel("modalTitle", ElasticConfigurationPanel.this));
    modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
        @Override
        public void onClose(AjaxRequestTarget target) {
            if (_layerInfo != null) {
                GeoServerApplication app = (GeoServerApplication) getApplication();
                final FeatureTypeInfo ft = (FeatureTypeInfo) getResourceInfo();

                app.getCatalog().getResourcePool().clear(ft);
                app.getCatalog().getResourcePool().clear(ft.getStore());
                setResponsePage(new ElasticResourceConfigurationPage(ft));
            }
        }
    });

    if (fti.getMetadata().get(ElasticLayerConfiguration.KEY) == null) {
        modal.add(new OpenWindowOnLoadBehavior());
    }

    modal.setContent(new ElasticConfigurationPage(panelId, model) {
        @Override
        void done(AjaxRequestTarget target, LayerInfo layerInfo, ElasticLayerConfiguration layerConfig) {
            _layerInfo = layerInfo;
            _layerConfig = layerConfig;
            modal.close(target);
        }
    });
    add(modal);

    AjaxLink findLink = new AjaxLink("edit") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            modal.show(target);
        }
    };
    final Fragment attributePanel = new Fragment("esPanel", "esPanelFragment", this);
    attributePanel.setOutputMarkupId(true);
    add(attributePanel);
    attributePanel.add(findLink);
}