Java Code Examples for org.apache.wicket.model.LoadableDetachableModel#of()

The following examples show how to use org.apache.wicket.model.LoadableDetachableModel#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationInfoPanel.java    From webanno with Apache License 2.0 6 votes vote down vote up
private Label createSelectedAnnotationTypeLabel()
{
    Label label = new Label("selectedAnnotationType", LoadableDetachableModel.of(() -> {
        try {
            AnnotationDetailEditorPanel editorPanel = findParent(
                    AnnotationDetailEditorPanel.class);
            return String.valueOf(selectFsByAddr(editorPanel.getEditorCas(),
                    getModelObject().getSelection().getAnnotation().getId())).trim();
        }
        catch (IOException e) {
            return "";
        }
    }));
    label.setOutputMarkupPlaceholderTag(true);
    // We show the extended info on the selected annotation only when run in development mode
    label.add(visibleWhen(() -> getModelObject().getSelection().getAnnotation().isSet()
            && DEVELOPMENT.equals(getApplication().getConfigurationType())));
    return label;
}
 
Example 2
Source File: LearningCurveChartPanel.java    From inception with Apache License 2.0 6 votes vote down vote up
public LearningCurveChartPanel(String aId, IModel<AnnotatorState> aModel)
{
    super(aId, aModel);
    model = aModel;

    setOutputMarkupId(true);
    
    //initially the chart is empty. passing empty model
    chartPanel = new ChartPanel(MID_CHART_CONTAINER,
            LoadableDetachableModel.of(this::renderChart));
    // chartPanel.add(visibleWhen(() -> chartPanel.getModelObject() != null));
    
    chartPanel.setOutputMarkupId(true);
    add(chartPanel);
    
    final Panel dropDownPanel = new MetricSelectDropDownPanel(MID_DROPDOWN_PANEL);
    dropDownPanel.setOutputMarkupId(true);
    add(dropDownPanel);
    
    selectedMetric = RecommenderEvaluationScoreMetricEnum.Accuracy;
}
 
Example 3
Source File: ConceptFeatureEditor.java    From inception with Apache License 2.0 5 votes vote down vote up
public ConceptFeatureEditor(String aId, MarkupContainer aItem, IModel<FeatureState> aModel,
        IModel<AnnotatorState> aStateModel, AnnotationActionHandler aHandler)
{
    super(aId, aItem, new CompoundPropertyModel<>(aModel));
    
    IModel<String> iriModel = LoadableDetachableModel.of(this::iriTooltipValue);
    
    iriBadge = new IriInfoBadge("iriInfoBadge", iriModel);
    iriBadge.add(visibleWhen(() -> isNotBlank(iriBadge.getModelObject())));
    add(iriBadge);
    
    openIriLink = new ExternalLink("openIri", iriModel);
    openIriLink.add(visibleWhen(() -> isNotBlank(iriBadge.getModelObject())));
    add(openIriLink);

    add(new DisabledKBWarning("disabledKBWarning", Model.of(getModelObject().feature)));

    add(focusComponent = new AutoCompleteField(MID_VALUE, _query -> 
            getCandidates(aStateModel, aHandler, _query)));
    
    AnnotationFeature feat = getModelObject().feature;
    ConceptFeatureTraits traits = readFeatureTraits(feat);
    
    add(new KeyBindingsPanel("keyBindings", () -> traits.getKeyBindings(), aModel, aHandler)
            // The key bindings are only visible when the label is also enabled, i.e. when the
            // editor is used in a "normal" context and not e.g. in the keybindings 
            // configuration panel
            .add(visibleWhen(() -> getLabelComponent().isVisible())));
    
    description = new Label("description", LoadableDetachableModel.of(this::descriptionValue));
    description.setOutputMarkupPlaceholderTag(true);
    description.add(visibleWhen(
        () -> getLabelComponent().isVisible() && getModelObject().getValue() != null));
    add(description);
}
 
Example 4
Source File: AdminDashboardPage.java    From inception with Apache License 2.0 5 votes vote down vote up
public AdminDashboardPage()
{
    if (!adminAreaAccessRequired(userRepository, projectService)) {
        setResponsePage(getApplication().getHomePage());
    }
    
    setStatelessHint(true);
    setVersioned(false);
    
    // In case we restore a saved session, make sure the user actually still exists in the DB.
    // redirect to login page (if no user is found, admin/admin will be created)
    User user = userRepository.getCurrentUser();
    if (user == null) {
        setResponsePage(LoginPage.class);
    }
    
    // if not either a curator or annotator, display warning message
    if (
            !annotationEnabeled(projectService, user, WebAnnoConst.PROJECT_TYPE_ANNOTATION) && 
            !annotationEnabeled(projectService, user, WebAnnoConst.PROJECT_TYPE_AUTOMATION) && 
            !annotationEnabeled(projectService, user, WebAnnoConst.PROJECT_TYPE_CORRECTION) && 
            !curationEnabeled(projectService, user)) 
    {
        info("You are not member of any projects to annotate or curate");
    }
    
    menu = new DashboardMenu("menu", LoadableDetachableModel.of(this::getMenuItems));
    // Pages linked from the admin menu are global ones - we do not want to set the current
    // project ID there because the same page may support a global and a project-specific view
    // and we might access the project-specific view through another path. E.g. the project
    // setting page should be global (with project selection list) when access throught the
    // administration dashboard, but when accesses through the project dashboard, it should only
    // show the local project view without the project selection.
    menu.setSendProjectIdToPage(false);
    add(menu);
    
    add(new SystemStatusDashlet("systemStatusDashlet"));
}
 
Example 5
Source File: ActivitiesDashlet.java    From inception with Apache License 2.0 5 votes vote down vote up
public ActivitiesDashlet(String aId, IModel<Project> aCurrentProject)
{
    super(aId);
    
    projectModel = aCurrentProject;
    
    if (aCurrentProject == null || aCurrentProject.getObject() == null) {
        return;
    }
    
    annotationEvents = new HashSet<>();
    Collections.addAll(annotationEvents, SPAN_CREATED_EVENT, FEATURE_UPDATED_EVENT, 
            RELATION_CREATED_EVENT);
    
    WebMarkupContainer activitiesList = new WebMarkupContainer("activities",
            new StringResourceModel("activitiesHeading", this));
    activitiesList.setOutputMarkupPlaceholderTag(true);
    
    ListView<LoggedEvent> listView = new ListView<LoggedEvent>("activity",
            LoadableDetachableModel.of(this::listActivities))
    {
        private static final long serialVersionUID = -8613360620764882858L;

        @Override
        protected void populateItem(ListItem<LoggedEvent> aItem)
        {
            SourceDocument document = getSourceDocument(aItem.getModelObject());
            ExternalLink eventLink = createLastActivityLink("eventLink", aItem.getModelObject(),
                    document);
            aItem.add(eventLink);
        }
    };

    add(visibleWhen(() -> !listView.getList().isEmpty()));
    setOutputMarkupPlaceholderTag(true);
    activitiesList.add(listView);
    add(activitiesList);
}
 
Example 6
Source File: ProjectDashboardPage.java    From inception with Apache License 2.0 5 votes vote down vote up
protected void commonInit()
{
    setStatelessHint(true);
    setVersioned(false);
    
    // In case we restore a saved session, make sure the user actually still exists in the DB.
    // redirect to login page (if no usr is found, admin/admin will be created)
    User user = userRepository.getCurrentUser();
    if (user == null) {
        setResponsePage(LoginPage.class);
    }
    
    // If no project has been selected yet, redirect to the project overview page. This allows
    // us to keep the ProjectDashboardPage as the application home page.
    Project project = Session.get().getMetaData(CURRENT_PROJECT);
    if (project == null) {
        setResponsePage(ProjectsOverviewPage.class);
    }
    
    // if not either a curator or annotator, display warning message
    if (
            !annotationEnabeled(projectService, user, PROJECT_TYPE_ANNOTATION) && 
            !annotationEnabeled(projectService, user, PROJECT_TYPE_AUTOMATION) && 
            !annotationEnabeled(projectService, user, PROJECT_TYPE_CORRECTION) && 
            !curationEnabeled(projectService, user)) 
    {
        info("You are not member of any projects to annotate or curate");
    }
    
    menu = new DashboardMenu("menu", LoadableDetachableModel.of(this::getMenuItems));
    add(menu);
    
    Model<Project> currentProject = Model.of(getProject());
    add(new CurrentProjectDashlet("currentProjectDashlet", currentProject));
    add(new ActivitiesDashlet("activitiesDashlet", currentProject));
}
 
Example 7
Source File: DocumentMetadataSidebar.java    From inception with Apache License 2.0 5 votes vote down vote up
public DocumentMetadataSidebar(String aId, IModel<AnnotatorState> aModel,
        AnnotationActionHandler aActionHandler, CasProvider aCasProvider,
        AnnotationPage aAnnotationPage)
{
    super(aId, aModel, aActionHandler, aCasProvider, aAnnotationPage);

    IModel<Project> project = LoadableDetachableModel.of(() -> aModel.getObject().getProject());
    IModel<SourceDocument> sourceDocument = LoadableDetachableModel
            .of(() -> aModel.getObject().getDocument());
    IModel<String> username = LoadableDetachableModel
            .of(() -> aModel.getObject().getUser().getUsername());
    
    add(new DocumentMetadataAnnotationSelectionPanel("annotations", project, sourceDocument,
            username, aCasProvider, aAnnotationPage, aActionHandler, getModelObject()));
}
 
Example 8
Source File: SimulationLearningCurvePanel.java    From inception with Apache License 2.0 5 votes vote down vote up
private void startEvaluation(IPartialPageRequestHandler aTarget, MarkupContainer aForm )
{
    // replace the empty panel with chart panel on click event so the chard renders
    // with the loadable detachable model.
    chartPanel = new ChartPanel(MID_CHART_CONTAINER, 
            LoadableDetachableModel.of(this::renderChart));
    chartPanel.setOutputMarkupPlaceholderTag(true);
    chartPanel.setOutputMarkupId(true);
    
    aForm.addOrReplace(chartPanel);
    aTarget.add(chartPanel);
}
 
Example 9
Source File: StringMatchingRecommenderTraitsEditor.java    From inception with Apache License 2.0 5 votes vote down vote up
public StringMatchingRecommenderTraitsEditor(String aId, IModel<Recommender> aRecommender)
{
    super(aId, aRecommender);

    gazeteers = new GazeteerList("gazeteers", LoadableDetachableModel.of(this::listGazeteers));
    gazeteers.add(visibleWhen(() -> aRecommender.getObject() != null
            && aRecommender.getObject().getId() != null));
    add(gazeteers);
    
    FileInputConfig config = new FileInputConfig();
    config.initialCaption("Import gazeteers ...");
    config.allowedFileExtensions(asList("txt"));
    config.showPreview(false);
    config.showUpload(true);
    config.removeIcon("<i class=\"fa fa-remove\"></i>");
    config.uploadIcon("<i class=\"fa fa-upload\"></i>");
    config.browseIcon("<i class=\"fa fa-folder-open\"></i>");
    uploadField = new BootstrapFileInput("upload", new ListModel<>(), config) {
        private static final long serialVersionUID = -7072183979425490246L;

        @Override
        protected void onSubmit(AjaxRequestTarget aTarget)
        {
            actionUploadGazeteer(aTarget);
        }
    };
    uploadField.add(visibleWhen(() -> aRecommender.getObject() != null
            && aRecommender.getObject().getId() != null));
    add(uploadField);
}
 
Example 10
Source File: CurationSidebar.java    From inception with Apache License 2.0 5 votes vote down vote up
private Form<List<User>> createUserSelection()
{
    Form<List<User>> usersForm = new Form<List<User>>("usersForm",
            LoadableDetachableModel.of(this::listSelectedUsers));
    LambdaAjaxButton<Void> clearButton = new LambdaAjaxButton<>("clear", this::clearUsers);
    LambdaAjaxButton<Void> mergeButton = new LambdaAjaxButton<>("merge", this::merge);
    LambdaAjaxButton<Void> showButton = new LambdaAjaxButton<>("show", this::selectAndShow);
    usersForm.add(clearButton);
    usersForm.add(showButton);
    usersForm.add(mergeButton);
    selectedUsers = new CheckGroup<User>("selectedUsers", usersForm.getModelObject());
    users = new ListView<User>("users",
            LoadableDetachableModel.of(this::listUsers))
    {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<User> aItem)
        {
            aItem.add(new Check<User>("user", aItem.getModel()));
            aItem.add(new Label("name", aItem.getModelObject().getUsername()));

        }
    };
    selectedUsers.add(users);
    usersForm.add(selectedUsers);
    return usersForm;
}
 
Example 11
Source File: RecommenderInfoPanel.java    From inception with Apache License 2.0 4 votes vote down vote up
public RecommenderInfoPanel(String aId, IModel<AnnotatorState> aModel)
{
    super(aId, aModel);
    
    setOutputMarkupId(true);
    
    WebMarkupContainer recommenderContainer = new WebMarkupContainer("recommenderContainer");
    add(recommenderContainer);
    
    ListView<Recommender> searchResultGroups = new ListView<Recommender>("recommender")
    {
        private static final long serialVersionUID = -631500052426449048L;

        @Override
        protected void populateItem(ListItem<Recommender> item)
        {
            User user = userService.getCurrentUser();
            Recommender recommender = item.getModelObject();
            List<EvaluatedRecommender> activeRecommenders = recommendationService
                    .getActiveRecommenders(user, recommender.getLayer());
            Optional<EvaluationResult> evalResult = activeRecommenders.stream()
                    .filter(r -> r.getRecommender().equals(recommender))
                    .map(EvaluatedRecommender::getEvaluationResult)
                    .findAny();
            item.add(new Label("name", recommender.getName()));
            item.add(new Label("state", evalResult.isPresent() ? "active" : "off"));

            item.add(new LambdaAjaxLink("acceptAll", _target -> 
                    actionAcceptAll(_target, recommender)));
            
            WebMarkupContainer resultsContainer = new WebMarkupContainer("resultsContainer");
            // Show results only if the evaluation was not skipped (and of course only if the
            // result is actually present).
            resultsContainer.setVisible(evalResult.map(r -> !r.isEvaluationSkipped())
                    .orElse(evalResult.isPresent()));
            resultsContainer.add(new Label("f1Score",
                    evalResult.map(EvaluationResult::computeF1Score).orElse(0.0d)));
            resultsContainer.add(new Label("accuracy",
                    evalResult.map(EvaluationResult::computeAccuracyScore).orElse(0.0d)));
            resultsContainer.add(new Label("precision",
                    evalResult.map(EvaluationResult::computePrecisionScore).orElse(0.0d)));
            resultsContainer.add(new Label("recall",
                    evalResult.map(EvaluationResult::computeRecallScore).orElse(0.0d)));
            item.add(resultsContainer);
        }
    };
    IModel<List<Recommender>> recommenders = LoadableDetachableModel.of(() -> 
            recommendationService.listEnabledRecommenders(aModel.getObject().getProject()));
    searchResultGroups.setModel(recommenders);
    
    recommenderContainer.add(visibleWhen(() -> !recommenders.getObject().isEmpty()));
    recommenderContainer.add(searchResultGroups);

    WebMarkupContainer noRecommendersWarning = new WebMarkupContainer("noRecommendersWarning");
    noRecommendersWarning.setOutputMarkupPlaceholderTag(true);
    noRecommendersWarning.add(visibleWhen(() -> recommenders.getObject().isEmpty()));
    add(noRecommendersWarning);
}
 
Example 12
Source File: DocumentMetadataAnnotationSelectionPanel.java    From inception with Apache License 2.0 4 votes vote down vote up
private ListView<AnnotationListItem> createAnnotationList()
{
    DocumentMetadataAnnotationSelectionPanel selectionPanel = this;
    return new ListView<AnnotationListItem>(CID_ANNOTATIONS,
            LoadableDetachableModel.of(this::listAnnotations))
    {
        private static final long serialVersionUID = -6833373063896777785L;

        /**
         * Determines if new annotations should be rendered visible or not.
         * For the initialization of existing annotations this value should be false.
         * Afterwards when manually creating new annotations it should be true to immediately
         * open them afterwards.
         * If there are no annotations at initialization it is initialized with true else false.
         */
        @Override
        protected void populateItem(ListItem<AnnotationListItem> aItem)
        {
            aItem.setModel(CompoundPropertyModel.of(aItem.getModel()));

            VID vid = new VID(aItem.getModelObject().addr);

            WebMarkupContainer container = new WebMarkupContainer("annotation");
            aItem.add(container);
            
            DocumentMetadataAnnotationDetailPanel detailPanel = 
                new DocumentMetadataAnnotationDetailPanel(CID_ANNOTATION_DETAILS,
                    Model.of(vid), sourceDocument, username, jcasProvider, project, 
                    annotationPage, selectionPanel, actionHandler, state);
            aItem.add(detailPanel);

            container.add(new AjaxEventBehavior("click")
            {
                @Override protected void onEvent(AjaxRequestTarget aTarget)
                {
                    actionSelect(aTarget, container, detailPanel);
                }
            });

            detailPanel.add(visibleWhen(() -> selectedAnnotation == container));

            if (createdAnnotationAddress == vid.getId()) {
                createdAnnotationAddress = -1;
                selectedAnnotation = container;
                selectedDetailPanel = detailPanel;
            }
            
            WebMarkupContainer close = new WebMarkupContainer("close");
            close.add(visibleWhen(() -> !detailPanel.isVisible()));
            close.setOutputMarkupId(true);
            container.add(close);
            
            WebMarkupContainer open = new WebMarkupContainer("open");
            open.add(visibleWhen(detailPanel::isVisible));
            open.setOutputMarkupId(true);
            container.add(open);
            
            container.add(new Label(CID_TYPE, aItem.getModelObject().layer.getUiName()));
            container.add(new Label(CID_LABEL));
            container.setOutputMarkupId(true);

            aItem.add(new LambdaAjaxLink(CID_DELETE,
                _target -> actionDelete(_target, detailPanel)));

            aItem.setOutputMarkupId(true);
        }
    };
}
 
Example 13
Source File: KnowledgeBasePanel.java    From inception with Apache License 2.0 4 votes vote down vote up
public KnowledgeBasePanel(String id, IModel<Project> aProjectModel,
        IModel<KnowledgeBase> aKbModel)
{
    super(id, aKbModel);

    setOutputMarkupId(true);

    kbModel = aKbModel;
    
    // add the selector for the knowledge bases
    DropDownChoice<KnowledgeBase> ddc = new BootstrapSelect<KnowledgeBase>("knowledgebases",
            LoadableDetachableModel
                    .of(() -> kbService.getEnabledKnowledgeBases(aProjectModel.getObject())));
    
    ddc.add(new LambdaAjaxFormComponentUpdatingBehavior("change", t -> {
        long projectId = aProjectModel.getObject().getId();
        String kbName = aKbModel.getObject().getName();

        PageParameters params = new PageParameters()
            .set(PAGE_PARAM_PROJECT_ID, projectId)
            .set(PAGE_PARAM_KB_NAME, kbName);

        setResponsePage(KnowledgeBasePage.class, params);
    }));

    ddc.setModel(aKbModel);
    ddc.setChoiceRenderer(new ChoiceRenderer<>("name"));
    add(ddc);

    add(createSearchField("searchBar", searchHandleModel, aProjectModel));

    add(conceptTreePanel = new ConceptTreePanel("concepts", kbModel, selectedConceptHandle));
    add(propertyListPanel = new PropertyListPanel("properties", kbModel,
            selectedPropertyHandle));
    
    detailContainer = new WebMarkupContainer(DETAIL_CONTAINER_MARKUP_ID);
    detailContainer.setOutputMarkupId(true);
    add(detailContainer);
    
    details = new EmptyPanel(DETAILS_MARKUP_ID);
    detailContainer.add(details);
}
 
Example 14
Source File: AnnotatedListIdentifiers.java    From inception with Apache License 2.0 4 votes vote down vote up
public AnnotatedListIdentifiers(String aId, IModel<KnowledgeBase> aKbModel,
        IModel<KBObject> aConcept, IModel<KBObject> aInstance, boolean flagInstanceSelect)
{
    super(aId, aConcept);
    setOutputMarkupId(true);
    kbModel = aKbModel;
    conceptModel = aConcept;
    currentUser = userRepository.getCurrentUser();
    
    String queryIri = flagInstanceSelect ? aInstance.getObject().getIdentifier()
            : aConcept.getObject().getIdentifier();
    // MTAS internally escapes certain characters, so we need to escape them here as well.
    // Cf. MtasToken.createAutomatonMap()
    queryIri = queryIri.replaceAll("([\\\"\\)\\(\\<\\>\\.\\@\\#\\]\\[\\{\\}])", "\\\\$1");
    targetQuery = Model.of(
            String.format("<%s=\"%s\"/>", ConceptFeatureIndexingSupport.KB_ENTITY, queryIri));
    
    LoadableDetachableModel<List<SearchResult>> searchResults = LoadableDetachableModel
            .of(this::getSearchResults);
    LOG.trace("SearchResult count : {}" , searchResults.getObject().size());
    ListView<String> overviewList = new ListView<String>("searchResultGroups")
    {
        private static final long serialVersionUID = -122960232588575731L;

        @Override protected void onConfigure()
        {
            super.onConfigure();
            
            setVisible(!searchResults.getObject().isEmpty());
        }

        @Override
        protected void populateItem(ListItem<String> aItem)
        {
            aItem.add(new Label("documentTitle", aItem.getModel()));
            aItem.add(new SearchResultGroup("group", "resultGroup",
                    AnnotatedListIdentifiers.this, getSearchResultsFormattedForDocument(
                            searchResults, aItem.getModelObject())));
        }
    };
    overviewList.setList(
        searchResults.getObject().stream().map(res -> res.getDocumentTitle()).distinct()
            .collect(Collectors.toList()));
    
    add(overviewList);
    add(new Label("count", LambdaModel.of(() -> searchResults.getObject().size())));
}
 
Example 15
Source File: StatementGroupPanel.java    From inception with Apache License 2.0 4 votes vote down vote up
public ExistingStatementGroupFragment(String aId)
{
    super(aId, "existingStatementGroup", StatementGroupPanel.this, groupModel);

    StatementGroupBean statementGroupBean = groupModel.getObject();
    Form<StatementGroupBean> form = new Form<StatementGroupBean>("form");
    LambdaAjaxLink propertyLink = new LambdaAjaxLink("propertyLink",
            this::actionPropertyLinkClicked);
    propertyLink.add(new Label("property", groupModel.bind("property.uiLabel")));
    form.add(propertyLink);

    // TODO what about handling type intersection when multiple range statements are
    // present?
    // obtain IRI of property range, if existent
    IModel<KBProperty> propertyModel = Model.of(statementGroupBean.getProperty());

    form.add(new IriInfoBadge("statementIdtext", groupModel.bind("property.identifier")));
                
    RefreshingView<KBStatement> statementList = new RefreshingView<KBStatement>(
            "statementList") {
        private static final long serialVersionUID = 5811425707843441458L;

        @Override
        protected Iterator<IModel<KBStatement>> getItemModels() {
            return new ModelIteratorAdapter<KBStatement>(
                statementGroupBean.getStatements()) {
                @Override
                protected IModel<KBStatement> model(KBStatement object) {
                    return LambdaModel.of(() -> object);
                }
            };
        }

        @Override
        protected void populateItem(Item<KBStatement> aItem) {
            StatementEditor editor = new StatementEditor("statement",
                    groupModel.bind("kb"), aItem.getModel(), propertyModel);
            aItem.add(editor);
            aItem.setOutputMarkupId(true);
        }

    };
    statementList.setItemReuseStrategy(new ReuseIfModelsEqualStrategy());

    // wrap the RefreshingView in a WMC, otherwise we can't redraw it with AJAX (see
    // https://cwiki.apache.org/confluence/display/WICKET/How+to+repaint+a+ListView+via+Ajax)
    statementListWrapper = new WebMarkupContainer("statementListWrapper");
    statementListWrapper.setOutputMarkupId(true);
    statementListWrapper.add(statementList);
    form.add(statementListWrapper);

    WebMarkupContainer statementGroupFooter = new WebMarkupContainer("statementGroupFooter");
    LambdaAjaxLink addLink = new LambdaAjaxLink("add", this::actionAddValue);
    addLink.add(new Label("label", new ResourceModel("statement.value.add")));
    addLink.add(new WriteProtectionBehavior(groupModel.bind("kb")));
    statementGroupFooter.add(addLink);

    AttributeAppender framehighlightAppender = new AttributeAppender("style",
            LoadableDetachableModel.of(() -> 
                "background-color:#" + getColoringStrategy().getFrameColor()
            ));
    statementGroupFooter.add(framehighlightAppender);
    form.add(framehighlightAppender);

    AttributeAppender highlightAppender = new AttributeAppender("style",
            LoadableDetachableModel.of(() -> {
                StatementColoringStrategy coloringStrategy = getColoringStrategy();
                return "background-color:#" + coloringStrategy.getBackgroundColor()
                        + ";color:#" + coloringStrategy.getTextColor();
            }));
    statementListWrapper.add(highlightAppender);

    form.add(statementGroupFooter);
    add(form);

}
 
Example 16
Source File: ProjectsOverviewPage.java    From inception with Apache License 2.0 4 votes vote down vote up
private WebMarkupContainer createProjectList()
{
    ListView<Project> listview = new ListView<Project>(MID_PROJECT,
            LoadableDetachableModel.of(this::listProjects))
    {
        private static final long serialVersionUID = -755155675319764642L;

        @Override
        protected void populateItem(ListItem<Project> aItem)
        {
            PageParameters pageParameters = new PageParameters().add(
                    ProjectDashboardPage.PAGE_PARAM_PROJECT_ID, aItem.getModelObject().getId());
            BookmarkablePageLink<Void> projectLink = new BookmarkablePageLink<>(
                    MID_PROJECT_LINK, ProjectDashboardPage.class, pageParameters);
            projectLink.add(new Label(MID_NAME, aItem.getModelObject().getName()));
            DateLabel createdLabel = DateLabel.forDatePattern(MID_CREATED,
                () -> aItem.getModelObject().getCreated(), "yyyy-MM-dd");
            addActionsDropdown(aItem);
            aItem.add(projectLink);
            createdLabel.add(visibleWhen(() -> createdLabel.getModelObject() != null));
            aItem.add(createdLabel);
            aItem.add(createRoleBadges(aItem.getModelObject()));
        }

        @Override
        protected void onConfigure()
        {
            super.onConfigure();

            if (getModelObject().isEmpty()) {
                warn("There are no projects accessible to you matching the filter criteria.");
                emptyListLabel.setVisible(true);
            }
            else {
                emptyListLabel.setVisible(false);
            }
        }
    };
    
    WebMarkupContainer projectList = new WebMarkupContainer(MID_PROJECTS);
    projectList.setOutputMarkupPlaceholderTag(true);
    projectList.add(listview);
    
    return projectList;
}
 
Example 17
Source File: ExternalSearchAnnotationSidebar.java    From inception with Apache License 2.0 4 votes vote down vote up
public ExternalSearchAnnotationSidebar(String aId, IModel<AnnotatorState> aModel,
    AnnotationActionHandler aActionHandler, CasProvider aCasProvider,
    AnnotationPage aAnnotationPage)
{
    super(aId, aModel, aActionHandler, aCasProvider, aAnnotationPage);

    // Attach search state to annotation page
    // This state is to maintain persistence of this sidebar so that when user moves to another
    // sidebar and comes back here, the state of this sidebar (search results) are preserved.
    searchStateModel = new CompoundPropertyModel<>(LambdaModelAdapter.of(
        () -> aAnnotationPage.getMetaData(CURRENT_ES_USER_STATE),
        searchState -> aAnnotationPage.setMetaData(CURRENT_ES_USER_STATE, searchState)));

    // Set up the search state in the page if it is not already there
    if (aAnnotationPage.getMetaData(CURRENT_ES_USER_STATE) == null) {
        searchStateModel.setObject(new ExternalSearchUserState());
    }

    project = getModel().getObject().getProject();
    List<DocumentRepository> repositories = externalSearchService
        .listDocumentRepositories(project);

    ExternalSearchUserState searchState = searchStateModel.getObject();
    currentRepository = searchState.getCurrentRepository();
    if (currentRepository == null && repositories.size() > 0) {
        currentRepository = repositories.get(0);
    }

    repositoriesModel = LoadableDetachableModel
        .of(() -> externalSearchService.listDocumentRepositories(project));

    mainContainer = new WebMarkupContainer("mainContainer");
    mainContainer.setOutputMarkupId(true);
    add(mainContainer);

    DocumentRepositorySelectionForm projectSelectionForm = new DocumentRepositorySelectionForm(
        "repositorySelectionForm");
    mainContainer.add(projectSelectionForm);

    SearchForm searchForm = new SearchForm("searchForm");
    add(searchForm);
    mainContainer.add(searchForm);

    List<IColumn<ExternalSearchResult, String>> columns = new ArrayList<>();

    columns.add(new AbstractColumn<ExternalSearchResult, String>(new Model<>("Results"))
    {
        private static final long serialVersionUID = -5658664083675871242L;

        @Override public void populateItem(Item<ICellPopulator<ExternalSearchResult>> cellItem,
            String componentId, IModel<ExternalSearchResult> model)
        {
            @SuppressWarnings("rawtypes") Item rowItem = cellItem.findParent(Item.class);
            int rowIndex = rowItem.getIndex();
            ResultRowView rowView = new ResultRowView(componentId, rowIndex + 1, model);
            cellItem.add(rowView);
        }
    });

    if (searchState.getDataProvider() == null) {
        searchState.setDataProvider(new ExternalResultDataProvider(externalSearchService,
                userRepository.getCurrentUser()));
    }

    dataTableContainer = new WebMarkupContainer("dataTableContainer");
    dataTableContainer.setOutputMarkupId(true);
    mainContainer.add(dataTableContainer);

    DataTable<ExternalSearchResult, String> resultTable = new DefaultDataTable<>("resultsTable",
        columns, searchState.getDataProvider(), 8);
    resultTable.setCurrentPage(searchState.getCurrentPage());
    dataTableContainer.add(resultTable);
}
 
Example 18
Source File: TagSetEditorPanel.java    From webanno with Apache License 2.0 4 votes vote down vote up
public TagSetEditorPanel(String aId, IModel<Project> aProject, IModel<TagSet> aTagSet,
        IModel<Tag> aSelectedTag)
{
    super(aId, aTagSet);
    
    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);
    
    selectedProject = aProject;
    selectedTagSet = aTagSet;
    selectedTag = aSelectedTag;
    exportFormat = Model.of(supportedFormats().get(0));
    
    Form<TagSet> form = new Form<>("form", CompoundPropertyModel.of(aTagSet));
    add(form);

    form.add(new TextField<String>("name")
            .add(new TagSetExistsValidator())
            .setRequired(true));
    form.add(new TextField<String>("language"));
    form.add(new TextArea<String>("description"));
    form.add(new CheckBox("createTag"));
    
    form.add(new LambdaAjaxButton<>("save", this::actionSave));
    form.add(new LambdaAjaxLink("delete", this::actionDelete)
            .onConfigure(_this -> _this.setVisible(form.getModelObject().getId() != null)));
    form.add(new LambdaAjaxLink("cancel", this::actionCancel));
    
    BootstrapRadioChoice<String> format = new BootstrapRadioChoice<>("format", exportFormat,
            LoadableDetachableModel.of(this::supportedFormats));
    // The AjaxDownloadLink does not submit the form, so the format radio-buttons need to 
    // submit themselves so their value is available when the export button is pressed
    format.add(onUpdateChoice(_target -> { /*NO-OP*/ }));
    form.add(format);
    
    form.add(new AjaxDownloadLink("export", LoadableDetachableModel.of(this::export)));
    
    confirmationDialog = new ConfirmationDialog("confirmationDialog");
    confirmationDialog.setTitleModel(new StringResourceModel("DeleteDialog.title", this));
    add(confirmationDialog);
}
 
Example 19
Source File: MainMenuPage.java    From webanno with Apache License 2.0 4 votes vote down vote up
public MainMenuPage()
{
    setStatelessHint(true);
    setVersioned(false);
    
    // In case we restore a saved session, make sure the user actually still exists in the DB.
    // redirect to login page (if no usr is found, admin/admin will be created)
    User user = userRepository.getCurrentUser();
    if (user == null) {
        setResponsePage(LoginPage.class);
    }
    
    // if not either a curator or annotator, display warning message
    if (
            !annotationEnabeled(projectService, user, PROJECT_TYPE_ANNOTATION)
            && !annotationEnabeled(projectService, user, PROJECT_TYPE_AUTOMATION)
            && !annotationEnabeled(projectService, user, PROJECT_TYPE_CORRECTION)
            && !curationEnabeled(projectService, user)) 
    {
        warn("You are not member of any projects to annotate or curate.");
    }
    
    menu = new ListView<MenuItem>("menu",
            LoadableDetachableModel.of(menuItemService::getMenuItems))
    {
        private static final long serialVersionUID = -5492972164756003552L;

        @Override
        protected void populateItem(ListItem<MenuItem> aItem)
        {
            MenuItem item = aItem.getModelObject();
            final Class<? extends Page> pageClass = item.getPageClass();
            BookmarkablePageLink<Void> menulink = new BookmarkablePageLink<>("menulink",
                    pageClass);
            menulink.add(
                    new Image("icon", new UrlResourceReference(Url.parse(item.getIcon()))));
            menulink.add(new Label("label", item.getLabel()));
            menulink.setVisible(item.applies());
            aItem.add(menulink);
        }
    };
    add(menu);
}
 
Example 20
Source File: InstanceListPanel.java    From inception with Apache License 2.0 4 votes vote down vote up
public InstanceListPanel(String aId, IModel<KnowledgeBase> aKbModel, IModel<KBObject> aConcept,
        IModel<KBObject> aInstance) {
    super(aId, aInstance);

    setOutputMarkupId(true);

    kbModel = aKbModel;
    conceptModel = aConcept;
    showAll = Model.of(Boolean.FALSE);
    
    IModel<List<KBHandle>> instancesModel = LoadableDetachableModel.of(this::getInstances);

    OverviewListChoice<KBObject> overviewList = new OverviewListChoice<KBObject>("instances") {
        private static final long serialVersionUID = -122960232588575731L;

        @Override
        protected void onConfigure()
        {
            super.onConfigure();
            
            setVisible(!instancesModel.getObject().isEmpty());
        }
    };
    overviewList.setChoiceRenderer(new ChoiceRenderer<>("uiLabel"));
    overviewList.setModel(aInstance);
    overviewList.setChoices(instancesModel);
    overviewList
            .add(new LambdaAjaxFormComponentUpdatingBehavior("change",
                target -> send(getPage(), Broadcast.BREADTH,
                            new AjaxInstanceSelectionEvent(target, aInstance.getObject()))));
    add(overviewList);

    add(new Label("count", LambdaModel.of(() -> overviewList.getChoices().size())));

    LambdaAjaxLink addLink = new LambdaAjaxLink("add",
        target -> send(getPage(), Broadcast.BREADTH, new AjaxNewInstanceEvent(target)));
    addLink.add(new Label("label", new ResourceModel("instance.add")));
    addLink.add(new WriteProtectionBehavior(kbModel));
    add(addLink);

    add(new Label("noInstancesNotice", new ResourceModel("instance.nonedefined")) {
        private static final long serialVersionUID = 2252854898212441711L;

        @Override
        protected void onConfigure()
        {
            super.onConfigure();

            setVisible(instancesModel.getObject().isEmpty());
        }
    });

    CheckBox showAllCheckBox = new CheckBox("showAllInstances", showAll);
    showAllCheckBox
            .add(new LambdaAjaxFormComponentUpdatingBehavior("change", t -> t.add(this)));
    add(showAllCheckBox);
}