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

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

Introduction

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

Prototype

public ModalWindow(final String id) 

Source Link

Document

Creates a new modal window component.

Usage

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

License:Apache License

@SuppressWarnings("deprecation")
public CurationPage() {
    bModel = new BratAnnotatorModel();
    bModel.setMode(Mode.CURATION);/*from  www .j  av 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:de.tudarmstadt.ukp.csniper.webapp.evaluation.page.EvaluationPage.java

License:Apache License

/**
 * Constructor that is invoked when page is invoked without a session.
 *//*from w  w w  .  j ava2s  .  co m*/
@SuppressWarnings({ "serial" })
public EvaluationPage() {
    contextViewsContainer = new WebMarkupContainer("contextViewsContainer") {
        {
            contextViews = new ListView<ContextView>("contextViews") {
                @Override
                protected void populateItem(ListItem aItem) {
                    aItem.add((Component) aItem.getModelObject());
                }
            };
            add(contextViews);
        }
    };
    contextViewsContainer.setOutputMarkupId(true);
    add(contextViewsContainer);

    columns = new ArrayList<IColumn<EvaluationResult, String>>();
    columns.add(new AbstractColumn<EvaluationResult, String>(new Model<String>("")) {
        @Override
        public void populateItem(final Item<ICellPopulator<EvaluationResult>> aCellItem, String aComponentId,
                final IModel<EvaluationResult> model) {
            EmbeddableImage iconContext = new EmbeddableImage(aComponentId,
                    new ContextRelativeResource("images/context.png"));
            iconContext.add(new AjaxEventBehavior("onclick") {
                @Override
                protected void onEvent(AjaxRequestTarget aTarget) {
                    try {
                        contextViews
                                .setList(asList(new ContextView(contextProvider, model.getObject().getItem())));
                        aTarget.add(contextViewsContainer);
                    } catch (IOException e) {
                        aTarget.add(getFeedbackPanel());
                        error("Unable to load context: " + e.getMessage());
                    }
                }
            });
            iconContext.add(new AttributeModifier("class", new Model<String>("clickableElement")));
            aCellItem.add(iconContext);
        }
    });
    columns.add(new AbstractColumn<EvaluationResult, String>(new Model<String>("")) {
        @Override
        public void populateItem(final Item<ICellPopulator<EvaluationResult>> aCellItem,
                final String aComponentId, final IModel<EvaluationResult> model) {
            // PopupLink pl = new PopupLink(aComponentId, new AnalysisPage(model.getObject()
            // .getItem()), "analysis", "Analyse", 800, 600);
            // pl.add(new AttributeModifier("class", new Model<String>("clickableElement")));
            // aCellItem.add(pl);

            EmbeddableImage iconAnalysis = new EmbeddableImage(aComponentId,
                    new ContextRelativeResource("images/analysis.png"));
            iconAnalysis.add(new AjaxEventBehavior("onclick") {
                @Override
                protected void onEvent(AjaxRequestTarget aTarget) {
                    EvaluationItem item = model.getObject().getItem();
                    CachedParse cachedTree = repository.getCachedParse(item);
                    ParseTreeResource ptr;

                    if (cachedTree != null) {
                        ptr = new ParseTreeResource(cachedTree.getPennTree());
                    } else {
                        if (pp == null) {
                            pp = new ParsingPipeline();
                        }
                        CasHolder ch = new CasHolder(pp.parseInput("stanfordParser",
                                corpusService.getCorpus(item.getCollectionId()).getLanguage(),
                                item.getCoveredText()));
                        ptr = new ParseTreeResource(ch);
                    }
                    analysisModal.setContent(new AnalysisPanel(analysisModal.getContentId(), ptr));
                    analysisModal.show(aTarget);
                }
            });
            iconAnalysis.add(new AttributeModifier("class", new Model<String>("clickableElement")));
            aCellItem.add(iconAnalysis);
        }
    });
    // columns.add(new PropertyColumn(new Model<String>("ID"), "id", "id"));
    // columns.add(new PropertyColumn(new Model<String>("Collection"), "item.collectionId",
    // "item.collectionId"));
    columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Doc"), "item.documentId",
            "item.documentId"));
    // columns.add(new PropertyColumn(new Model<String>("Begin"), "item.beginOffset",
    // "item.beginOffset"));
    // columns.add(new PropertyColumn(new Model<String>("End"), "item.endOffset",
    // "item.endOffset"));
    columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Left"), "item.leftContext",
            "item.leftContext") {
        @Override
        public String getCssClass() {
            return contextAvailable ? "leftContext" : " hideCol";
        }
    });
    columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Match"), "item.match",
            "item.match") {
        @Override
        public String getCssClass() {
            return contextAvailable ? "match nowrap" : null;
        }
    });
    columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Right"), "item.rightContext",
            "item.rightContext") {
        @Override
        public String getCssClass() {
            return contextAvailable ? "rightContext" : " hideCol";
        }
    });
    columns.add(new AbstractColumn<EvaluationResult, String>(new Model<String>("Label"), "result") {
        @Override
        public void populateItem(final Item<ICellPopulator<EvaluationResult>> aCellItem, String aComponentId,
                final IModel<EvaluationResult> model) {
            final Label resultLabel = new Label(aComponentId, new PropertyModel(model, "result"));
            resultLabel.setOutputMarkupId(true);
            aCellItem.add(resultLabel);
            if (showResultColumns) {
                aCellItem.add(AttributeModifier.replace("class",
                        new Model<String>("editable " + model.getObject().getResult().toLowerCase())));
            }

            aCellItem.add(new AjaxEventBehavior("onclick") {
                @Override
                protected void onEvent(AjaxRequestTarget aTarget) {
                    EvaluationResult result = model.getObject();

                    // cycle to next result
                    Mark newResult = Mark.fromString(result.getResult()).next();

                    // update database
                    result.setResult(newResult.getTitle());
                    repository.updateEvaluationResult(result);

                    // update DataTable
                    aCellItem.add(AttributeModifier.replace("class",
                            new Model<String>("editable " + newResult.getTitle().toLowerCase())));
                    aTarget.add(resultLabel, aCellItem);
                }
            });
        }

        @Override
        public String getCssClass() {
            return (showResultColumns ? "" : " hideCol");
        }
    });
    columns.add(new AbstractColumn<EvaluationResult, String>(new Model<String>("Comment"), "comment") {
        @Override
        public void populateItem(Item<ICellPopulator<EvaluationResult>> cellItem, String componentId,
                final IModel<EvaluationResult> model) {
            cellItem.add(
                    new AjaxEditableLabel<String>(componentId, new PropertyModel<String>(model, "comment")) {
                        @Override
                        public void onSubmit(final AjaxRequestTarget aTarget) {
                            super.onSubmit(aTarget);

                            EvaluationResult result = model.getObject();

                            // get new comment
                            String newComment = getEditor().getInput();

                            // update database
                            result.setComment(newComment);
                            repository.updateEvaluationResult(result);
                        }

                        @Override
                        public void onError(AjaxRequestTarget aTarget) {
                            super.onError(aTarget);
                            aTarget.add(getFeedbackPanel());
                        }
                    }.add(new DbFieldMaxLengthValidator(projectRepository, "EvaluationResult", "comment")));
        }

        @Override
        public String getCssClass() {
            return "editable" + (showResultColumns ? "" : " hideCol");
        }
    });

    // collection and type
    add(parentOptionsForm = new ParentOptionsForm("parentOptions"));

    tabs = new Tabs("tabs");
    tabs.setVisible(false);
    // query tab
    tabs.add(queryForm = new QueryForm("queryForm"));
    // revision tab
    tabs.add(reviewForm = new ReviewForm("reviewForm"));
    // completion tab
    tabs.add(new Form("completeForm") {
        {
            add(new ExtendedIndicatingAjaxButton("completeButton", new Model<String>("Complete"),
                    new Model<String>("Running query ...")) {
                {
                    setDefaultFormProcessing(false);
                }

                @Override
                public void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm) {
                    AnnotationType type = parentOptionsForm.typeInput.getModelObject();
                    if (type == null) {
                        error(LocalizerUtil.getString(parentOptionsForm.typeInput, "Required"));
                        aTarget.add(getFeedbackPanel());
                        return;
                    }

                    ParentOptionsFormModel pModel = parentOptionsForm.getModelObject();
                    String user = SecurityContextHolder.getContext().getAuthentication().getName();
                    List<String> otherUsers = new ArrayList<String>(repository.listUsers());
                    otherUsers.remove(user);

                    // get items, create/persist results
                    List<EvaluationItem> items = repository.listEvaluationResultsMissing(pModel.collectionId,
                            pModel.type.getName(), user, otherUsers);
                    List<EvaluationResult> results = createEvaluationResults(items);
                    repository.writeEvaluationResults(results);

                    // persis. results: hide saveButton, show result columns and filter options
                    limitForm.setVisible(false);
                    filterForm.setChoices(ResultFilter.values());
                    showColumnsForm.setVisible(true && !pModel.type.getAdditionalColumns().isEmpty());
                    showResultColumns(true);
                    saveButton.setVisible(false);
                    predictButton.setVisible(true);
                    samplesetButton.setVisible(true);

                    // update dataprovider
                    dataProvider = new SortableEvaluationResultDataProvider(results);
                    dataProvider.setSort("item.documentId", SortOrder.ASCENDING);
                    dataProvider.setFilter(ResultFilter.ALL);
                    // then update the table
                    resultTable = resultTable.replaceWith(new CustomDataTable<EvaluationResult>("resultTable",
                            getAllColumns(pModel.type), dataProvider, ROWS_PER_PAGE));
                    contextAvailable = false;

                    updateComponents(aTarget);
                }

                @Override
                public void onError(AjaxRequestTarget aTarget, Form<?> aForm) {
                    super.onError(aTarget, aForm);
                    // Make sure the feedback messages are rendered
                    aTarget.add(getFeedbackPanel());
                }
            });
        }
    });
    // sampleset tab
    tabs.add(samplesetForm = new SamplesetForm("samplesetForm"));
    // sampleset tab
    tabs.add(findForm = new FindForm("findForm"));
    add(tabs);

    add(new Label("description", new LoadableDetachableModel<String>() {
        @Override
        protected String load() {
            Object value = PropertyResolver.getValue("type.description", parentOptionsForm.getModelObject());
            if (value != null) {
                RenderContext context = new BaseRenderContext();
                RenderEngine engine = new BaseRenderEngine();
                return engine.render(String.valueOf(value), context);
            } else {
                return getString("page.selectTypeHint");
            }
        }
    }).setEscapeModelStrings(false));
    add(filterForm = (FilterForm) new FilterForm("filterForm").setOutputMarkupPlaceholderTag(true));
    add(showColumnsForm = (ShowColumnsForm) new ShowColumnsForm("showColumnsForm")
            .setOutputMarkupPlaceholderTag(true));
    add(resultTable = new Label("resultTable").setOutputMarkupId(true));

    add(predictionModal = new ModalWindow("predictionModal"));
    final PredictionPanel predictionPanel = new PredictionPanel(predictionModal.getContentId());
    predictionModal.setContent(predictionPanel);
    predictionModal.setTitle("Predict results");
    predictionModal.setAutoSize(false);
    predictionModal.setInitialWidth(550);
    predictionModal.setInitialHeight(350);
    predictionModal.setCloseButtonCallback(new CloseButtonCallback() {
        @Override
        public boolean onCloseButtonClicked(AjaxRequestTarget aTarget) {
            predictionPanel.cancel(aTarget);
            return true;
        }
    });

    add(samplesetModal = new ModalWindow("samplesetModal"));
    samplesetModal.setContent(new SamplesetPanel(samplesetModal.getContentId()));
    samplesetModal.setTitle("Create / Extend sampleset");
    samplesetModal.setAutoSize(true);

    add(analysisModal = new ModalWindow("analysisModal"));
    analysisModal.setTitle("Parse tree");
    analysisModal.setInitialWidth(65 * 16);
    analysisModal.setInitialHeight(65 * 9);
    // autosize does not work...
    // analysisModal.setAutoSize(true);

    add(new Form("saveForm") {
        {
            add(saveButton = (ExtendedIndicatingAjaxButton) new ExtendedIndicatingAjaxButton("saveButton",
                    new Model<String>("Start annotating"), new Model<String>("Preparing ...")) {
                @Override
                protected void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm) {
                    // persist items and results
                    List<EvaluationItem> items = dataProvider.getItems();
                    items = repository.writeEvaluationItems(items);
                    List<EvaluationResult> results = createEvaluationResults(items);
                    dataProvider.setResults(results);
                    repository.writeEvaluationResults(results);

                    // save results, query
                    ParentOptionsFormModel pModel = parentOptionsForm.getModelObject();
                    String user = SecurityContextHolder.getContext().getAuthentication().getName();
                    QueryFormModel model = queryForm.getModelObject();
                    if (model.engine != null && !StringUtils.isBlank(model.query)) {
                        repository.recordQuery(model.engine.getName(), model.query, pModel.collectionId,
                                pModel.type.getName(), model.comment, user);
                    }

                    // hide saveButton, show result columns and filter options
                    limitForm.setVisible(false);
                    filterForm.setChoices(ResultFilter.values());
                    showColumnsForm.setVisible(true && !pModel.type.getAdditionalColumns().isEmpty());
                    showResultColumns(true);
                    saveButton.setVisible(false);
                    predictButton.setVisible(true);
                    samplesetButton.setVisible(true);

                    updateComponents(aTarget);
                }
            }.setOutputMarkupPlaceholderTag(true));

            add(predictButton = (ExtendedIndicatingAjaxButton) new ExtendedIndicatingAjaxButton("predictButton",
                    new Model<String>("Predict results"), new Model<String>("Predicting ...")) {
                @Override
                protected void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm) {
                    aTarget.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
                    predictionModal.show(aTarget);
                }
            }.setOutputMarkupPlaceholderTag(true));

            add(samplesetButton = (ExtendedIndicatingAjaxButton) new ExtendedIndicatingAjaxButton(
                    "samplesetButton", new Model<String>("Save results as sampleset"),
                    new Model<String>("Saving...")) {
                @Override
                public void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm) {
                    samplesetModal.show(aTarget);
                }
            }.setOutputMarkupPlaceholderTag(true));
        }
    });
    add(limitForm = (LimitForm) new LimitForm("limit").setOutputMarkupPlaceholderTag(true));

    // at start, don't show: save button, results columns, filter
    limitForm.setVisible(false);
    filterForm.setChoices();
    showColumnsForm.setVisible(false);
    showResultColumns(false);
    saveButton.setVisible(false);
    predictButton.setVisible(false);
    samplesetButton.setVisible(false);
}

From source file:de.tudarmstadt.ukp.csniper.webapp.search.page.SearchPage.java

License:Apache License

/**
 * Constructor that is invoked when page is invoked without a session.
 *///  ww  w. j a v  a2 s.  co m
@SuppressWarnings({ "serial" })
public SearchPage() {
    contextViewsContainer = new WebMarkupContainer("contextViewsContainer") {
        {
            contextViews = new ListView<ContextView>("contextViews") {
                @Override
                protected void populateItem(ListItem aItem) {
                    aItem.add((Component) aItem.getModelObject());
                }
            };
            add(contextViews);
        }
    };
    contextViewsContainer.setOutputMarkupId(true);
    add(contextViewsContainer);

    columns = new ArrayList<IColumn<EvaluationResult, String>>();
    columns.add(new AbstractColumn<EvaluationResult, String>(new Model<String>("")) {
        @Override
        public void populateItem(final Item<ICellPopulator<EvaluationResult>> aCellItem, String aComponentId,
                final IModel<EvaluationResult> model) {
            EmbeddableImage iconContext = new EmbeddableImage(aComponentId,
                    new ContextRelativeResource("images/context.png"));
            iconContext.add(new AjaxEventBehavior("onclick") {
                @Override
                protected void onEvent(AjaxRequestTarget aTarget) {
                    try {
                        contextViews
                                .setList(asList(new ContextView(contextProvider, model.getObject().getItem())));
                        aTarget.add(contextViewsContainer);
                    } catch (IOException e) {
                        error("Unable to load context: " + e.getMessage());
                        aTarget.add(getFeedbackPanel());
                    }
                }
            });
            iconContext.add(new AttributeModifier("class", new Model<String>("clickableElement")));
            aCellItem.add(iconContext);
        }
    });
    columns.add(new AbstractColumn<EvaluationResult, String>(new Model<String>("")) {
        @Override
        public void populateItem(final Item<ICellPopulator<EvaluationResult>> aCellItem, String aComponentId,
                final IModel<EvaluationResult> model) {
            EmbeddableImage iconAnalysis = new EmbeddableImage(aComponentId,
                    new ContextRelativeResource("images/analysis.png"));
            iconAnalysis.add(new AjaxEventBehavior("onclick") {
                @Override
                protected void onEvent(AjaxRequestTarget aTarget) {
                    EvaluationItem item = model.getObject().getItem();
                    CachedParse cachedTree = repository.getCachedParse(item);
                    ParseTreeResource ptr;

                    if (cachedTree != null) {
                        ptr = new ParseTreeResource(cachedTree.getPennTree());
                    } else {
                        if (pp == null) {
                            pp = new ParsingPipeline();
                        }
                        CasHolder ch = new CasHolder(pp.parseInput("stanfordParser",
                                corpusService.getCorpus(item.getCollectionId()).getLanguage(),
                                item.getCoveredText()));
                        ptr = new ParseTreeResource(ch);
                    }
                    analysisModal.setContent(new AnalysisPanel(analysisModal.getContentId(), ptr));
                    analysisModal.show(aTarget);
                }
            });
            iconAnalysis.add(new AttributeModifier("class", new Model<String>("clickableElement")));
            aCellItem.add(iconAnalysis);
        }
    });
    columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Doc"), "item.documentId",
            "item.documentId"));
    columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Left"), "item.leftContext",
            "item.leftContext") {
        @Override
        public String getCssClass() {
            return contextAvailable ? "leftContext" : " hideCol";
        }
    });
    columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Match"), "item.match",
            "item.match") {
        @Override
        public String getCssClass() {
            return contextAvailable ? "match nowrap" : null;
        }
    });
    columns.add(new PropertyColumn<EvaluationResult, String>(new Model<String>("Right"), "item.rightContext",
            "item.rightContext") {
        @Override
        public String getCssClass() {
            return contextAvailable ? "rightContext" : " hideCol";
        }
    });

    add(queryForm = new QueryForm("queryForm"));

    add(limitForm = (LimitForm) new LimitForm("limit").setOutputMarkupPlaceholderTag(true));

    add(resultTable = new Label("resultTable").setOutputMarkupId(true));

    add(analysisModal = new ModalWindow("analysisModal"));
    analysisModal.setTitle("Parse tree");
    analysisModal.setInitialWidth(65 * 16);
    analysisModal.setInitialHeight(65 * 9);
    // autosize does not work...
    // analysisModal.setAutoSize(true);

    // at start, don't show: save button, results columns, filter
    limitForm.setVisible(false);
}

From source file:de.tudarmstadt.ukp.csniper.webapp.statistics.page.StatisticsPage.java

License:Apache License

/**
 * Constructor that is invoked when page is invoked without a session.
 *//* w  ww .  j a  v a2s. c  o  m*/
public StatisticsPage() {
    super();
    contextViewsContainer = new WebMarkupContainer("contextViewsContainer") {
        {
            contextViews = new ListView<ContextView>("contextViews") {
                @Override
                protected void populateItem(ListItem aItem) {
                    aItem.add((Component) aItem.getModelObject());
                }
            };
            add(contextViews);
        }
    };
    contextViewsContainer.setOutputMarkupId(true);
    add(contextViewsContainer);

    columns.add(new AbstractColumn<AggregatedEvaluationResult, String>(new Model<String>("")) {
        @Override
        public void populateItem(final Item<ICellPopulator<AggregatedEvaluationResult>> aCellItem,
                String aComponentId, final IModel<AggregatedEvaluationResult> model) {
            EmbeddableImage iconContext = new EmbeddableImage(aComponentId,
                    new ContextRelativeResource("images/context.png"));
            iconContext.add(new AjaxEventBehavior("onclick") {
                @Override
                protected void onEvent(AjaxRequestTarget aTarget) {
                    try {
                        contextViews
                                .setList(asList(new ContextView(contextProvider, model.getObject().getItem())));
                        aTarget.add(contextViewsContainer);
                    } catch (IOException e) {
                        error("Unable to load context: " + e.getMessage());
                    }
                }
            });
            iconContext.add(new AttributeModifier("class", new Model<String>("clickableElement")));
            aCellItem.add(iconContext);
        }
    });
    columns.add(new PropertyColumn<AggregatedEvaluationResult, String>(new Model<String>("Type"), "item.type",
            "item.type") {
        private static final long serialVersionUID = 1L;

        @Override
        public String getCssClass() {
            return super.getCssClass() + " nowrap";
        }
    });
    columns.add(new PropertyColumn<AggregatedEvaluationResult, String>(new Model<String>("Collection"),
            "item.collectionId", "item.collectionId") {
        private static final long serialVersionUID = 1L;

        @Override
        public String getCssClass() {
            return super.getCssClass() + " nowrap";
        }

    });
    columns.add(new PropertyColumn<AggregatedEvaluationResult, String>(new Model<String>("Document"),
            "item.documentId", "item.documentId") {
        private static final long serialVersionUID = 1L;

        @Override
        public String getCssClass() {
            return super.getCssClass() + " nowrap";
        }
    });
    columns.add(new PropertyColumn<AggregatedEvaluationResult, String>(new Model<String>("Item"),
            "item.coveredText", "item.coveredText"));
    columns.add(new PropertyColumn<AggregatedEvaluationResult, String>(new Model<String>("#Correct"), "correct",
            "correct"));
    columns.add(new PropertyColumn<AggregatedEvaluationResult, String>(new Model<String>("#Wrong"), "wrong",
            "wrong"));
    columns.add(new PropertyColumn<AggregatedEvaluationResult, String>(new Model<String>("#Incomplete"),
            "incomplete", "incomplete"));
    columns.add(new PropertyColumn<AggregatedEvaluationResult, String>(new Model<String>("Aggregated"),
            "classification", "classification"));
    // {
    // private static final long serialVersionUID = 1L;
    //
    // @Override
    // public void populateItem(Item<ICellPopulator<AggregatedEvaluationResult>> aCellItem,
    // String aComponentId, IModel<AggregatedEvaluationResult> aRowModel)
    // {
    // StatisticsFormModel sModel = statisticsForm.getModelObject();
    // ResultFilter aggregated = aRowModel.getObject().getClassification(sModel.users,
    // sModel.userThreshold, sModel.confidenceThreshold);
    // aCellItem.add(new Label(aComponentId, aggregated.getLabel()));
    // }
    // });
    columns.add(new PropertyColumn<AggregatedEvaluationResult, String>(new Model<String>("Confidence"),
            "confidence", "confidence"));
    // {
    // private static final long serialVersionUID = 1L;
    //
    // @Override
    // public void populateItem(Item<ICellPopulator<AggregatedEvaluationResult>> aCellItem,
    // String aComponentId, IModel<AggregatedEvaluationResult> aRowModel)
    // {
    // StatisticsFormModel sModel = statisticsForm.getModelObject();
    // double confidence = aRowModel.getObject().getConfidence(sModel.users,
    // sModel.userThreshold);
    // aCellItem.add(new Label(aComponentId, Double.toString(confidence)));
    // }
    // });

    add(exportModal = new ModalWindow("exportModal"));
    final ExportPanel exportPanel = new ExportPanel(exportModal.getContentId());
    exportModal.setContent(exportPanel);
    exportModal.setTitle("Export");
    exportModal.setInitialWidth(550);
    exportModal.setInitialHeight(350);
    exportModal.setCloseButtonCallback(new CloseButtonCallback() {
        @Override
        public boolean onCloseButtonClicked(AjaxRequestTarget aTarget) {
            exportPanel.cancel(aTarget);
            return true;
        }
    });

    add(exportDownload = new AjaxFileDownload());

    add(statisticsForm = new StatisticsForm("statisticsForm"));
    add(displayOptions = (WebMarkupContainer) new WebMarkupContainer("displayOptions") {
        private static final long serialVersionUID = 1L;
        {
            add(new Label("filterLabel",
                    new PropertyModel<List<ResultFilter>>(statisticsForm, "modelObject.filters")));
            add(new Label("collectionIdLabel",
                    new PropertyModel<Set<String>>(statisticsForm, "modelObject.collections")));
            add(new Label("typeLabel",
                    new PropertyModel<Set<AnnotationType>>(statisticsForm, "modelObject.types")) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
                    Set<AnnotationType> types = (Set<AnnotationType>) getDefaultModelObject();
                    List<String> typeNames = new ArrayList<String>();
                    for (AnnotationType t : types) {
                        typeNames.add(t.getName());
                    }
                    Collections.sort(typeNames);
                    replaceComponentTagBody(markupStream, openTag, typeNames.toString());
                };
            });
        }
    }.setOutputMarkupPlaceholderTag(true).setVisible(false));
    add(resultTable = new Label("resultTable").setOutputMarkupId(true));
}

From source file:de.widone.web.page.base.BasePage.java

License:Apache License

public BasePage() {
    super();/*  w  w  w .  ja  va  2  s .  c o  m*/
    final ModalWindow modalWindow = new ModalWindow("modalWindow");
    modalWindow.setContent(new UserDetailsPanel(modalWindow.getContentId(), new CurrentUserModel()));
    modalWindow.add(new Behavior() {
        @Override
        public void onEvent(Component component, IEvent<?> event) {
            if (event.getPayload() instanceof CancelEvent) {
                modalWindow.close(((CancelEvent) event.getPayload()).getTarget());
            }
        }
    });
    add(new Label("loginName", new StringResourceModel("loginName", this,
            new CompoundPropertyModel<User>(((WiDoneSession) WebSession.get()).getUser()))));
    add(modalWindow);
    add(new AjaxFallbackLink<Void>("userDetails") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
            modalWindow.show(target);
        }
    });
    add(new AjaxFallbackLink<Void>("logout") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            WebSession.get().invalidate();
            setResponsePage(SignInPage.class);
        }
    });
}

From source file:edu.wfu.inotado.tool.pages.SchoolChaptersPage.java

License:Apache License

public SchoolChaptersPage() {
    disableLink(schoolChaptersLink);/*w  w w  .java 2 s.  c o  m*/

    // gets the authStore object
    AuthStore authStore = inotadoService.getAuthStoreForCurrentUser(Constants.SCHOOL_CHAPTERS);
    if (authStore == null) {
        authStore = new AuthStore();
    }

    final Notification notification = new Notification("scNotification");
    this.add(notification);

    // Form
    Form<?> authForm = new Form("authenticationForm");
    this.add(authForm);

    final SchoolChaptersAuthWindow settingWindow = new SchoolChaptersAuthWindow("settingWindow", "Settings",
            authStore);
    this.add(settingWindow);

    final AjaxButton editAuthButton = new AjaxButton("editAuthButton") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            settingWindow.setAuthStore(inotadoService.getAuthStoreForCurrentUser(Constants.SCHOOL_CHAPTERS));
            settingWindow.open(target);
        }
    };
    authForm.add(editAuthButton);

    final ModalWindow authWindow = new ModalWindow("authWindow");
    this.add(authWindow);

    final AjaxButton authButton = new AjaxButton("authButton") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            // retrieve the url for OAuth authentication
            AuthStore authStore = inotadoService.getAuthStoreForCurrentUser(Constants.SCHOOL_CHAPTERS);
            final String authUrl = inotadoService.getSchoolChaptersAuthUrl(authStore);

            if (!StringUtils.isBlank(authUrl)) {
                notification.success(target, "Key and secret have been accepted");
                authWindow.setPageCreator(new ModalWindow.PageCreator() {
                    @Override
                    public Page createPage() {
                        return new RedirectPage(authUrl);
                    }
                });
                authWindow.show(target);
            } else {
                notification.error(target, "Invalid key or secret!");
            }
        }
    };

    authForm.add(authButton);

    final AjaxButton sendRequestButton = new AjaxButton("sendRequestButton") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            try {
                syncResourcesService.syncAssignments();
                notification.success(target, "Data retrived successfully");
            } catch (Exception e) {
                notification.error(target, "Unable to process request. " + e.getMessage());
            }
        }
    };

    authForm.add(sendRequestButton);

}

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

License:Open Source License

private void addAggregates(final ItemSearch itemSearch) {
    boolean showAgregates = !getPrincipal().isAnonymous() && itemSearch.getSpace() != null;
    //if(!getPrincipal().isAnonymous() && itemSearch.getSpace() != null){
    final ModalWindow agregatesReportModal = new ModalWindow("agregatesReportModal");
    add(agregatesReportModal);//  w ww. j  av a  2  s . c o m
    //modal2.setCookieName("modal-2");
    WebMarkupContainer agregatesContainer = new WebMarkupContainer("agregatesContainer");
    AjaxLink agregatesReportLink = new AjaxLink("agregatesReportLink") {
        public void onClick(AjaxRequestTarget target) {

            agregatesReportModal
                    .setContent(new AggregatesReportPanel("content", agregatesReportModal, itemSearch));
            agregatesReportModal.setTitle("");
            agregatesReportModal.show(target);
        }
    };
    agregatesContainer.add(agregatesReportLink);
    add(agregatesContainer.setVisible(showAgregates));
    //       }
    //       else{
    //          add(new EmptyPanel("agregatesReportLink"));
    //       }

}

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

License:Open Source License

public SpaceFieldListPanel(String id, IBreadCrumbModel breadCrumbModel, final Space space,
        String selectedFieldName) {
    super(id, breadCrumbModel);

    setupVisuals(space);/*from  www .  ja  va2s  . c om*/

    // FIELD GROUPS
    List<IGridColumn> cols = (List) Arrays.asList(new CheckBoxColumn("selected"),
            new PropertyColumn(new Model("Id"), "id"), new PropertyColumn(new Model("Name"), "name"),
            new PropertyColumn(new Model("Priority"), "priority"));
    final ListDataProvider listDataProvider = new ListDataProvider(space.getMetadata().getFieldGroups());
    final WebMarkupContainer gridContainer = new WebMarkupContainer("gridContainer");
    gridContainer.setOutputMarkupId(true);
    final DataGrid grid = new DefaultDataGrid("fieldGroupGrid", new DataProviderAdapter(listDataProvider),
            cols);
    grid.setSelectToEdit(false);
    grid.setClickRowToSelect(true);
    grid.setAllowSelectMultiple(false);
    gridContainer.add(grid);
    add(gridContainer);
    // add "new" link
    final ModalWindow fieldGroupModal = new ModalWindow("fieldGroupModal");
    gridContainer.add(fieldGroupModal);
    gridContainer.add(grid);
    add(gridContainer);
    add(new AjaxLink("newFieldGroupLink") {
        public void onClick(AjaxRequestTarget target) {
            // TODO: add row to grid?
            final FieldGroup tpl;
            if (CollectionUtils.isNotEmpty(grid.getSelectedItems())) {
                tpl = (FieldGroup) ((IModel) grid.getSelectedItems().iterator().next()).getObject();
            } else {
                tpl = new FieldGroup("", "");
            }

            fieldGroupModal.setContent(new EditFieldGroupPanel("content", fieldGroupModal, tpl) {
                @Override
                protected void persist(AjaxRequestTarget target, Form form) {
                    if (!space.getMetadata().getFieldGroups().contains(tpl)) {
                        space.getMetadata().getFieldGroups().add(tpl);
                        //logger.info("added new fieldgroup to space");
                    }
                    SortedSet<FieldGroup> fieldGroups = new TreeSet<FieldGroup>();
                    fieldGroups.addAll(space.getMetadata().getFieldGroups());
                    space.getMetadata().getFieldGroups().clear();
                    space.getMetadata().getFieldGroups().addAll(fieldGroups);
                    //update grid
                    if (target != null) {
                        target.addComponent(gridContainer);
                    }

                }
            });
            fieldGroupModal.setTitle(this.getLocalizer().getString("fieldGroups", this));
            fieldGroupModal.show(target);
        }
    });

    // FIELDS
    SpaceFieldsForm form = new SpaceFieldsForm("form", space, selectedFieldName);
    add(form);
}

From source file:gr.interamerican.wicket.factories.ModalWindowFactory.java

License:Open Source License

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

From source file:hsa.awp.admingui.usermanagement.TemplateTab.java

License:Open Source License

public TemplateTab(String panelId, final Mandator mandator) {
    super(panelId);

    final DropDownChoice<TemplateType> templateTypeDropDownChoice = new DropDownChoice<TemplateType>(
            "templateTypes", new Model<TemplateType>(TemplateType.DRAWN), Arrays.asList(TemplateType.values()),
            new ChoiceRenderer<TemplateType>("desc"));

    final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
    feedbackPanel.setOutputMarkupId(true);

    final IModel<String> templateModel = new Model<String>(
            findTemplateAsString(mandator, templateTypeDropDownChoice.getModelObject()));

    final TextArea<String> textArea = new TextArea<String>("template.area", templateModel);
    textArea.setOutputMarkupId(true);/*  w w w . ja  v a  2 s .  c o  m*/

    templateTypeDropDownChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String s = findTemplateAsString(mandator, templateTypeDropDownChoice.getModelObject());
            templateModel.setObject(s);
            Session.get().getFeedbackMessages().clear();
            target.addComponent(textArea);
            target.addComponent(feedbackPanel);
        }
    });

    Button button = new Button("submitButton", new Model<String>("Speichern")) {
        @Override
        public void onSubmit() {
            controller.saveTemplate(mandator.getId(), textArea.getModelObject(),
                    templateTypeDropDownChoice.getModelObject());
            feedbackPanel.info("Erfolgreich gespreichert");
        }
    };

    AjaxButton resetButton = new AjaxButton("resetButton",
            new Model<String>("Standardvariante Wiederherstellen")) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            String s = controller.loadDefaultTemplate(templateTypeDropDownChoice.getModelObject());
            templateModel.setObject(s);
            feedbackPanel.info("Standard wiederhergestellt. Es wurde noch nicht gespeichert!");
            target.addComponent(textArea);
            target.addComponent(feedbackPanel);
        }
    };

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

        @Override
        public Component getLazyLoadComponent(String markupId) {

            return new TemplateTestPanel(markupId, textArea.getModelObject());
        }
    });
    detailWindow.setTitle(new Model<String>("Template Test"));

    AjaxButton testButton = new AjaxButton("testButton", new Model<String>("Template Testen")) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            detailWindow.show(target);
        }
    };

    Form<String> modalForm = new Form<String>("modalForm");
    modalForm.add(detailWindow);

    Form<String> form = new Form<String>("template.form");
    form.add(textArea);
    form.add(templateTypeDropDownChoice);
    form.add(button);
    form.add(resetButton);
    form.add(testButton);
    add(form);
    add(modalForm);
    add(feedbackPanel);
}