Example usage for org.apache.wicket.markup.html.form ChoiceRenderer ChoiceRenderer

List of usage examples for org.apache.wicket.markup.html.form ChoiceRenderer ChoiceRenderer

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form ChoiceRenderer ChoiceRenderer.

Prototype

public ChoiceRenderer(String displayExpression) 

Source Link

Document

Constructor.

Usage

From source file:au.org.theark.report.web.component.viewReport.form.AbstractReportFilterForm.java

License:Open Source License

private void initialiseOutputFormatChoice() {

    T grvVO = cpModel.getObject();/*w ww  .j av a  2 s. c  om*/
    grvVO.setListReportOutputFormats(reportService.getOutputFormats());

    PropertyModel<ReportOutputFormat> outputChoicePM = new PropertyModel<ReportOutputFormat>(cpModel,
            "selectedOutputFormat");
    ChoiceRenderer<ReportOutputFormat> defaultChoiceRenderer = new ChoiceRenderer<ReportOutputFormat>(
            Constants.REPORT_OUTPUT_NAME);
    outputFormatChoices = new DropDownChoice<ReportOutputFormat>(Constants.REPORT_OUTPUT_DROP_DOWN_CHOICE,
            outputChoicePM, grvVO.getListReportOutputFormats(), defaultChoiceRenderer);
    outputFormatChoices.setRequired(true);

}

From source file:com.cubeia.games.poker.admin.wicket.pages.tournaments.configuration.TournamentConfigurationPanel.java

License:Open Source License

private <T> ChoiceRenderer<T> renderer(String name) {
    return new ChoiceRenderer<T>(name);
}

From source file:com.doculibre.constellio.wicket.panels.admin.analyzer.AddEditAnalyzerFieldPanel.java

License:Open Source License

public AddEditAnalyzerFieldPanel(String id, IModel analyzerModel) {
    super(id, new CompoundPropertyModel(analyzerModel));

    Analyzer analyzer = (Analyzer) analyzerModel.getObject();
    filtersModel.getObject().addAll(analyzer.getFilters());

    final ModalWindow analyzerClassModal = new ModalWindow("analyzerClassModal");
    add(analyzerClassModal);//from w w w .  j a  va 2  s .c o  m
    analyzerClassModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY);

    IModel analyzerClassesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            AnalyzerClassServices analyzerClassServices = ConstellioSpringUtils.getAnalyzerClassServices();
            return analyzerClassServices.list();
        }
    };

    IChoiceRenderer analyzerClassRenderer = new ChoiceRenderer("className");

    final DropDownChoice analyzerClassField = new DropDownChoice("analyzerClass", analyzerClassesModel,
            analyzerClassRenderer);
    add(analyzerClassField);
    analyzerClassField.setOutputMarkupId(true);

    AjaxLink addAnalyzerClassLink = new AjaxLink("addAnalyzerClassLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            AddEditAnalyzerClassPanel addEditAnalyzerClassPanel = new AddEditAnalyzerClassPanel(
                    analyzerClassModal.getContentId(), new AnalyzerClass(), analyzerClassField);
            analyzerClassModal.setContent(addEditAnalyzerClassPanel);
            analyzerClassModal.show(target);
        }
    };
    add(addAnalyzerClassLink);

    final ModalWindow tokenizerClassModal = new ModalWindow("tokenizerClassModal");
    add(tokenizerClassModal);
    tokenizerClassModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY);

    IModel tokenizerClassesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            TokenizerClassServices tokenizerClassServices = ConstellioSpringUtils.getTokenizerClassServices();
            return tokenizerClassServices.list();
        }
    };

    IChoiceRenderer tokenizerClassRenderer = new ChoiceRenderer("className");

    final DropDownChoice tokenizerClassField = new DropDownChoice("tokenizerClass", tokenizerClassesModel,
            tokenizerClassRenderer);
    add(tokenizerClassField);
    tokenizerClassField.setOutputMarkupId(true);

    AjaxLink addTokenizerClassLink = new AjaxLink("addTokenizerClassLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            AddEditTokenizerClassPanel addEditTokenizerClassPanel = new AddEditTokenizerClassPanel(
                    tokenizerClassModal.getContentId(), new TokenizerClass(), tokenizerClassField);
            tokenizerClassModal.setContent(addEditTokenizerClassPanel);
            tokenizerClassModal.show(target);
        }
    };
    add(addTokenizerClassLink);

    add(new FilterListPanel("filtersPanel"));
}

From source file:com.doculibre.constellio.wicket.panels.admin.analyzer.filter.AddEditFilterPanel.java

License:Open Source License

public AddEditFilterPanel(String id, AnalyzerFilter filter, int index) {
    super(id, true);
    this.entityModel = new ReloadableEntityModel<AnalyzerFilter>(filter);
    // Ne pas utiliser filter.getID() pour dterminer si c'est en cration.
    // Car cela empche de modifier un filtre tout juste cr
    this.index = index;

    Form form = getForm();//from   w w w. j a va 2 s .c  o  m
    form.setModel(new CompoundPropertyModel(entityModel));

    final ModalWindow filterClassModal = new ModalWindow("filterClassModal");
    form.add(filterClassModal);
    filterClassModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY);

    IModel filterClassesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            FilterClassServices filterClassServices = ConstellioSpringUtils.getFilterClassServices();
            return filterClassServices.list();
        }
    };

    IChoiceRenderer filterClassRenderer = new ChoiceRenderer("className");

    final DropDownChoice filterClassField = new DropDownChoice("filterClass", filterClassesModel,
            filterClassRenderer);
    form.add(filterClassField);
    filterClassField.setOutputMarkupId(true);

    AjaxLink addFilterClassLink = new AjaxLink("addFilterClassLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            AddEditFilterClassPanel addEditAnalyzerClassPanel = new AddEditFilterClassPanel(
                    filterClassModal.getContentId(), new FilterClass(), filterClassField);
            filterClassModal.setContent(addEditAnalyzerClassPanel);
            filterClassModal.show(target);
        }
    };
    form.add(addFilterClassLink);

    form.add(new CheckBox("ignoreCase"));
    form.add(new CheckBox("expand"));
    form.add(new CheckBox("enablePositionIncrements"));
    form.add(new CheckBox("inject"));
    form.add(new TextField("language"));
    form.add(new TextArea("wordsText"));
    form.add(new TextArea("synonymsText"));
    form.add(new TextArea("protectedText"));
    form.add(new TextField("generateWordParts", Integer.class));
    form.add(new TextField("generateNumberParts", Integer.class));
    form.add(new TextField("catenateWords", Integer.class));
    form.add(new TextField("catenateNumbers", Integer.class));
    form.add(new TextField("catenateAll", Integer.class));
    form.add(new TextField("splitOnCaseChange", Integer.class));
    form.add(new TextField("delimiter"));
    form.add(new TextField("encoder"));
    form.add(new TextField("pattern"));
    form.add(new TextField("replacement"));
    form.add(new TextField("replace"));
}

From source file:com.doculibre.constellio.wicket.panels.admin.connectorTypeMeta.AddEditConnectorTypeMetaMappingPanel.java

License:Open Source License

public AddEditConnectorTypeMetaMappingPanel(String id, ConnectorTypeMetaMapping metaMapping) {
    super(id, true);
    this.metaMappingModel = new ReloadableEntityModel<ConnectorTypeMetaMapping>(metaMapping);

    Form form = getForm();// w w w  .  ja v a  2  s . c o  m
    form.setModel(new CompoundPropertyModel(metaMappingModel));

    TextField metaNameField = new RequiredTextField("metaName");
    metaNameField.add(new StringValidator.MaximumLengthValidator(255));
    form.add(metaNameField);

    TextField indexFieldNameField = new RequiredTextField("indexFieldName");
    indexFieldNameField.add(new StringValidator.MaximumLengthValidator(255));
    form.add(indexFieldNameField);

    final CheckBox indexedCheckbox = new CheckBox("indexed");
    form.add(indexedCheckbox);

    //        final CheckBox storedCheckbox = new CheckBox("stored");
    //        form.add(storedCheckbox);

    final CheckBox multiValuedCheckbox = new CheckBox("multiValued");
    form.add(multiValuedCheckbox);

    final ModalWindow fieldTypeModal = new ModalWindow("fieldTypeModal");
    form.add(fieldTypeModal);
    fieldTypeModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY);

    IModel fieldTypesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices();
            return fieldTypeServices.list();
        }
    };

    IChoiceRenderer fieldTypeRenderer = new ChoiceRenderer("name");

    final DropDownChoice fieldTypeField = new DropDownChoice("fieldType", fieldTypesModel, fieldTypeRenderer);
    form.add(fieldTypeField);
    fieldTypeField.setOutputMarkupId(true);

    AjaxLink addFieldTypeLink = new AjaxLink("addFieldTypeLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            AddEditFieldTypePanel addEditFieldTypePanel = new AddEditFieldTypePanel(
                    fieldTypeModal.getContentId(), new FieldType(), fieldTypeField);
            fieldTypeModal.setContent(addEditFieldTypePanel);
            fieldTypeModal.show(target);
        }
    };
    form.add(addFieldTypeLink);
}

From source file:com.doculibre.constellio.wicket.panels.admin.fieldType.AddEditFieldTypePanel.java

License:Open Source License

public AddEditFieldTypePanel(String id, FieldType fieldType, Component refreshComponentP) {
    super(id, true);
    this.fieldTypeModel = new ReloadableEntityModel<FieldType>(fieldType);
    this.refreshComponent = refreshComponentP;

    Form form = getForm();/*w  w w.  j  a v  a2 s. c  o m*/
    form.setModel(new CompoundPropertyModel(fieldTypeModel));

    TextField nameField = new RequiredTextField("name");
    nameField.add(new StringValidator.MaximumLengthValidator(255));
    form.add(nameField);

    final ModalWindow fieldTypeClassModal = new ModalWindow("fieldTypeClassModal");
    form.add(fieldTypeClassModal);
    fieldTypeClassModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY);

    IModel fieldTypeClassesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            FieldTypeClassServices fieldTypeClassServices = ConstellioSpringUtils.getFieldTypeClassServices();
            return fieldTypeClassServices.list();
        }
    };

    IChoiceRenderer fieldTypeClassRenderer = new ChoiceRenderer("className");

    final DropDownChoice fieldTypeClassField = new DropDownChoice("fieldTypeClass", fieldTypeClassesModel,
            fieldTypeClassRenderer);
    form.add(fieldTypeClassField);
    fieldTypeClassField.setOutputMarkupId(true);

    AjaxLink addFieldTypeClassLink = new AjaxLink("addFieldTypeClassLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            AddEditFieldTypeClassPanel addEditFieldTypeClassPanel = new AddEditFieldTypeClassPanel(
                    fieldTypeClassModal.getContentId(), new FieldTypeClass(), fieldTypeClassField);
            fieldTypeClassModal.setContent(addEditFieldTypeClassPanel);
            fieldTypeClassModal.show(target);
        }
    };
    form.add(addFieldTypeClassLink);

    analyzerPanel = new AddEditAnalyzerFieldPanel("analyzerPanel", new LoadableDetachableModel() {
        @Override
        protected Object load() {
            FieldType fieldType = fieldTypeModel.getObject();
            return fieldType.getAnalyzer() != null ? fieldType.getAnalyzer() : new Analyzer();
        }
    });
    form.add(analyzerPanel);

    queryAnalyzerPanel = new AddEditAnalyzerFieldPanel("queryAnalyzerPanel", new LoadableDetachableModel() {
        @Override
        protected Object load() {
            FieldType fieldType = fieldTypeModel.getObject();
            return fieldType.getQueryAnalyzer() != null ? fieldType.getQueryAnalyzer() : new Analyzer();
        }
    });
    form.add(queryAnalyzerPanel);

    TextField precisionStepField = new TextField("precisionStep", Integer.class);
    form.add(precisionStepField);

    TextField positionIncrementGapField = new TextField("positionIncrementGap", Integer.class);
    form.add(positionIncrementGapField);

    final CheckBox sortMissingLastCheckbox = new CheckBox("sortMissingLast");
    form.add(sortMissingLastCheckbox);

    final CheckBox omitNormsCheckbox = new CheckBox("omitNorms");
    form.add(omitNormsCheckbox);

    final CheckBox multiValuedCheckbox = new CheckBox("multiValued");
    form.add(multiValuedCheckbox);

}

From source file:com.doculibre.constellio.wicket.panels.admin.indexField.AddEditIndexFieldPanel.java

License:Open Source License

public AddEditIndexFieldPanel(String id, IndexField indexField) {
    super(id);/*from   w  ww  .  j a  va2s  . c o  m*/
    this.indexFieldModel = new ReloadableEntityModel<IndexField>(indexField);
    for (CopyField copyFieldDest : indexField.getCopyFieldsDest()) {
        copyFieldsDest.add(new CopyFieldDTO(copyFieldDest));
    }
    for (CopyField copyFieldSource : indexField.getCopyFieldsDest()) {
        copyFieldsSource.add(new CopyFieldDTO(copyFieldSource));
    }
    for (ConnectorInstanceMeta meta : indexField.getConnectorInstanceMetas()) {
        metas.add(new ConnectorInstanceMetaDTO(meta));
    }

    add(new FeedbackPanel("feedback"));

    Form form = new Form("form", new CompoundPropertyModel(indexFieldModel));
    add(form);
    form.add(new SetFocusBehavior(form));

    String titleKey = indexField.getId() == null ? "add" : "edit";
    IModel titleModel = new StringResourceModel(titleKey, this, null);
    form.add(new Label("title", titleModel));

    TextField nameField = new RequiredTextField("name");
    nameField.add(new StringValidator.MaximumLengthValidator(255));
    nameField.setEnabled(!indexField.isInternalField());
    form.add(nameField);

    final CheckBox indexedCheckbox = new CheckBox("indexed");
    indexedCheckbox.setEnabled(!indexField.isInternalField());
    form.add(indexedCheckbox);

    //      final CheckBox storedCheckbox = new CheckBox("stored");
    //      storedCheckbox.setEnabled(!indexField.isInternalField());
    //      form.add(storedCheckbox);

    final CheckBox dynamicFieldCheckbox = new CheckBox("dynamicField");
    dynamicFieldCheckbox.setEnabled(!indexField.isInternalField());
    form.add(dynamicFieldCheckbox);

    final CheckBox multiValuedCheckbox = new CheckBox("multiValued");
    multiValuedCheckbox.setEnabled(!indexField.isInternalField());
    form.add(multiValuedCheckbox);

    final CheckBox sortableCheckbox = new CheckBox("sortable");
    form.add(sortableCheckbox);

    final CheckBox highlightedCheckbox = new CheckBox("highlighted");
    form.add(highlightedCheckbox);

    final ModalWindow fieldTypeModal = new ModalWindow("fieldTypeModal");
    form.add(fieldTypeModal);
    fieldTypeModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY);

    IModel fieldTypesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices();
            return fieldTypeServices.list();
        }
    };

    IChoiceRenderer fieldTypeRenderer = new ChoiceRenderer("name");

    final DropDownChoice fieldTypeField = new DropDownChoice("fieldType", fieldTypesModel, fieldTypeRenderer);
    form.add(fieldTypeField);
    fieldTypeField.setOutputMarkupId(true);
    fieldTypeField.setEnabled(indexField.isAnalyzingCustomizable());

    AjaxLink addFieldTypeLink = new AjaxLink("addFieldTypeLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            AddEditFieldTypePanel addEditFieldTypePanel = new AddEditFieldTypePanel(
                    fieldTypeModal.getContentId(), new FieldType(), fieldTypeField);
            fieldTypeModal.setContent(addEditFieldTypePanel);
            fieldTypeModal.show(target);
        }
    };
    form.add(addFieldTypeLink);
    addFieldTypeLink.setVisible(indexField.isAnalyzingCustomizable());

    form.add(new MetaListPanel("metas").setVisible(indexField.isAnalyzingCustomizable()));
    form.add(new CopyFieldListPanel("copyFieldsDest", true).setVisible(indexField.isAnalyzingCustomizable()));

    IModel localesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            return collection.getLocales();
        }
    };
    MultiLocaleComponentHolder nameHolder = new MultiLocaleComponentHolder("label", indexFieldModel,
            localesModel) {
        @Override
        protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) {
            TextField nameField = new TextField("nameLocale", componentModel);
            item.add(nameField);
            item.add(new LocaleNameLabel("localeName", locale, true) {
                @Override
                public boolean isVisible() {
                    AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                            AdminCollectionPanel.class);
                    RecordCollection collection = collectionAdminPanel.getCollection();
                    return collection.getLocales().size() > 1;
                }
            });
        }
    };
    form.add(nameHolder);

    Button submitButton = new AjaxButton("submitButton") {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            IndexField indexField = indexFieldModel.getObject();

            EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
            if (!entityManager.getTransaction().isActive()) {
                entityManager.getTransaction().begin();
            }

            List<ConnectorInstanceMeta> existingMetas = new ArrayList<ConnectorInstanceMeta>(
                    indexField.getConnectorInstanceMetas());
            // Remove deleted metas
            List<ConnectorInstanceMeta> formMetas = new ArrayList<ConnectorInstanceMeta>();
            for (ConnectorInstanceMetaDTO metaDTO : getMetas()) {
                formMetas.add(metaDTO.toConnectorInstanceMeta());
            }
            for (Iterator<ConnectorInstanceMeta> it = existingMetas.iterator(); it.hasNext();) {
                ConnectorInstanceMeta meta = it.next();
                meta = entityManager.merge(meta);
                if (!hasMeta(meta, formMetas)) {
                    indexField.removeConnectorInstanceMeta(meta);
                }
            }
            // Add new
            for (ConnectorInstanceMetaDTO metaDTO : getMetas()) {
                ConnectorInstanceMeta meta = metaDTO.toConnectorInstanceMeta();
                if (!hasMeta(meta, existingMetas)) {
                    meta = entityManager.merge(meta);
                    indexField.addConnectorInstanceMeta(meta);
                }
            }

            Set<CopyField> existingCopyFieldsSource = indexField.getCopyFieldsSource();
            // Remove deleted copy fields
            for (Iterator<CopyField> it = existingCopyFieldsSource.iterator(); it.hasNext();) {
                CopyField copyField = it.next();
                if (!getCopyFieldsSource().contains(new CopyFieldDTO(copyField))) {
                    it.remove();
                }
            }
            // Add new or update set
            for (CopyFieldDTO copyFieldDTO : getCopyFieldsSource()) {
                CopyField copyField = copyFieldDTO.toCopyField();
                copyField.setIndexFieldSource(indexField);
                if (copyField.getId() != null) {
                    entityManager.merge(copyField);
                } else {
                    existingCopyFieldsSource.add(copyField);
                }
            }

            Set<CopyField> existingCopyFieldsDest = indexField.getCopyFieldsDest();
            // Remove deleted copy fields
            for (Iterator<CopyField> it = existingCopyFieldsDest.iterator(); it.hasNext();) {
                CopyField copyField = it.next();
                if (!getCopyFieldsDest().contains(new CopyFieldDTO(copyField))) {
                    it.remove();
                }
            }
            // Add new or update set
            for (CopyFieldDTO copyFieldDTO : getCopyFieldsDest()) {
                CopyField copyField = copyFieldDTO.toCopyField();
                copyField.setIndexFieldDest(indexField);
                if (copyField.getId() != null) {
                    entityManager.merge(copyField);
                } else {
                    existingCopyFieldsDest.add(copyField);
                }
            }

            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            indexField.setRecordCollection(collection);

            IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices();
            FederationServices federationServices = ConstellioSpringUtils.getFederationServices();

            if (indexField.isSortable()) {
                if (indexFieldServices.getSortFieldOf(indexField) == null) {
                    indexFieldServices.newSortFieldFor(indexField);
                }
            }

            AutocompleteServices autocompleteServices = ConstellioSpringUtils.getAutocompleteServices();
            if (indexField.isAutocompleted()) {
                autocompleteServices.setAutoCompleteToField(indexField);
            } else {
                autocompleteServices.removeAutoCompleteFromField(indexField);
            }

            if (collection.isIncludedInFederation()) {
                List<String> conflicts = new ArrayList<String>();
                List<IndexField> newFederationFields = new ArrayList<IndexField>();
                List<RecordCollection> ownerCollections = federationServices.listOwnerCollections(collection);
                for (RecordCollection ownerCollection : ownerCollections) {
                    String indexFieldName = indexField.getName();
                    IndexField ownerIndexField = ownerCollection.getIndexField(indexFieldName);
                    if (ownerIndexField == null) {
                        IndexField copy = federationServices.copy(indexField, ownerCollection);
                        newFederationFields.add(copy);
                    }
                    if (federationServices.isConflict(indexFieldName, ownerCollection, collection)) {
                        Locale displayLocale = ownerCollection.getDisplayLocale(getLocale());
                        conflicts.add(ownerCollection.getTitle(displayLocale));
                    }
                }
                if (conflicts.isEmpty()) {
                    indexFieldServices.makePersistent(indexField);
                    for (IndexField newFederationField : newFederationFields) {
                        indexFieldServices.makePersistent(newFederationField);
                    }
                } else {
                    for (String collectionTitle : conflicts) {
                        error(getLocalizer().getString("conflict", this) + " : " + collectionTitle);
                    }
                }
            } else {
                indexFieldServices.makePersistent(indexField);
            }

            entityManager.getTransaction().commit();

            ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class);
            modalWindow.close(target);

            target.addComponent(modalWindow.findParent(AdminIndexFieldsPanel.class));
        }
    };
    form.add(submitButton);

    Button cancelButton = new AjaxButton("cancelButton") {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class);
            modalWindow.close(target);
        }
    }.setDefaultFormProcessing(false);
    form.add(cancelButton);
}

From source file:com.doculibre.constellio.wicket.panels.admin.indexField.meta.AddMetaPanel.java

License:Open Source License

public AddMetaPanel(String id) {
    super(id);//from ww w.  j  a  va  2s.c o  m

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

    Form form = new Form("form");
    add(form);
    form.add(new SetFocusBehavior(form));

    String titleKey = "add";
    IModel titleModel = new StringResourceModel(titleKey, this, null);
    form.add(new Label("title", titleModel));

    IModel connectorInstancesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            return new ArrayList<ConnectorInstance>(collection.getConnectorInstances());
        }
    };

    IModel connectorInstanceMetasModel = new LoadableDetachableModel() {
        @SuppressWarnings("unchecked")
        @Override
        protected Object load() {
            ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
            List<ConnectorInstanceMeta> connectorInstanceMetas = new ArrayList<ConnectorInstanceMeta>();
            if (connectorInstance != null) {
                MetaListPanel metaListPanel = (MetaListPanel) findParent(MetaListPanel.class);
                List<ConnectorInstanceMetaDTO> metas = (List<ConnectorInstanceMetaDTO>) metaListPanel
                        .getModelObject();
                for (ConnectorInstanceMeta meta : connectorInstance.getConnectorInstanceMetas()) {
                    if (!hasMeta(meta, metas)) {
                        connectorInstanceMetas.add(meta);
                    }
                }
            }
            return connectorInstanceMetas;
        }
    };

    IChoiceRenderer connectorInstanceRenderer = new ChoiceRenderer("displayName");
    IChoiceRenderer metaRenderer = new ChoiceRenderer("name");

    final DropDownChoice connectorInstanceMeta = new DropDownChoice("connectorInstanceMeta", metaModel,
            connectorInstanceMetasModel, metaRenderer);
    connectorInstanceMeta.setRequired(true);
    connectorInstanceMeta.setOutputMarkupId(true);
    form.add(connectorInstanceMeta);

    DropDownChoice connectorInstance = new DropDownChoice("connectorInstance", connectorInstanceModel,
            connectorInstancesModel, connectorInstanceRenderer);
    connectorInstance.setRequired(true);
    connectorInstance.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(connectorInstanceMeta);
        }
    });
    form.add(connectorInstance);

    AjaxButton submitButton = new AjaxButton("submitButton") {
        @SuppressWarnings("unchecked")
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            ConnectorInstanceMeta meta = metaModel.getObject();

            MetaListPanel metaListPanel = (MetaListPanel) findParent(MetaListPanel.class);

            List<ConnectorInstanceMetaDTO> metas = (List<ConnectorInstanceMetaDTO>) metaListPanel
                    .getModelObject();
            metas.add(new ConnectorInstanceMetaDTO(meta));

            ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class);
            modalWindow.close(target);

            target.addComponent(metaListPanel);
        }

        @Override
        protected void onError(final AjaxRequestTarget target, Form form) {
            target.addComponent(feedback);
        }
    };
    form.add(submitButton);

    Button cancelButton = new AjaxButton("cancelButton") {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class);
            modalWindow.close(target);
        }
    }.setDefaultFormProcessing(false);
    form.add(cancelButton);
}

From source file:com.doculibre.constellio.wicket.panels.results.tagging.SearchResultEditTaggingPanel.java

License:Open Source License

public SearchResultEditTaggingPanel(String id, final SolrDocument doc, final IDataProvider dataProvider,
        Thesaurus source) {//from   w  ww  .j  a v a  2s  .co  m
    super(id);
    if (source == null) {
        freeTextTags = true;
        source = new Thesaurus(getLocalizer().getString("freeTextTags", SearchResultEditTaggingPanel.this));
    }
    RecordServices recordServices = ConstellioSpringUtils.getRecordServices();
    Record record = recordServices.get(doc);
    recordModel = new RecordModel(record);
    taggingSourceModel = new EntityModel<Thesaurus>(source);

    filterAddForm = new Form("filterAddForm");
    filterAddForm.setOutputMarkupId(true);

    IModel taggingSourceChoicesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            List<Object> taggingSources = new ArrayList<Object>();

            taggingSources.add(
                    new Thesaurus(getLocalizer().getString("freeTextTags", SearchResultEditTaggingPanel.this)));

            SkosServices skosServices = ConstellioSpringUtils.getSkosServices();
            Record record = recordModel.getObject();
            ConnectorInstance connectorInstance = record.getConnectorInstance();
            RecordCollection collection = connectorInstance.getRecordCollection();
            Map<String, Object> criteria = new HashMap<String, Object>();
            criteria.put("recordCollection", collection);
            taggingSources.addAll(skosServices.list(criteria));

            return taggingSources;
        }
    };
    IChoiceRenderer taggingSourceRenderer = new ChoiceRenderer("dcTitle");
    taggingSourceField = new DropDownChoice("taggingSource", taggingSourceModel, taggingSourceChoicesModel,
            taggingSourceRenderer);
    taggingSourceField.setVisible(isSourceSelectionVisible());
    taggingSourceField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(availableTagsContainer);
            target.addComponent(appliedTagsContainer);
            target.addComponent(filterAddField);
            target.addComponent(filterAddButton);
        }
    });

    filterAddField = new TextField("filterAddField", new Model());
    filterAddField.setOutputMarkupId(true);
    filterAddField.add(new AjaxFormComponentUpdatingBehavior("onkeyup") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String input = filterAddField.getModelObjectAsString();
            availableTagsModel.setFilter(input);
            appliedTagsModel.setFilter(input);
            if (isFreeTextTagSource()) {
                target.addComponent(availableTagsContainer);
                target.addComponent(appliedTagsContainer);
            }
        }
    });

    filterAddButton = new AjaxButton("filterAddButton") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            String tagName = (String) filterAddField.getModelObject();
            if (StringUtils.isNotBlank(tagName)) {
                if (isFreeTextTagSource()) {
                    FreeTextTagServices freeTextTagServices = ConstellioSpringUtils.getFreeTextTagServices();
                    FreeTextTag existingTag = freeTextTagServices.get(tagName);
                    if (existingTag == null) {
                        FreeTextTag newTag = new FreeTextTag();
                        newTag.setFreeText(tagName);

                        EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
                        if (!entityManager.getTransaction().isActive()) {
                            entityManager.getTransaction().begin();
                        }
                        freeTextTagServices.makePersistent(newTag);
                        entityManager.getTransaction().commit();

                        availableTagsModel.setFilter(null);
                        appliedTagsModel.setFilter(null);
                        filterAddField.clearInput();
                        filterAddField.setModelObject(null);
                        target.addComponent(filterAddField);
                        target.addComponent(availableTagsContainer);
                        target.addComponent(appliedTagsContainer);
                    }
                } else {
                    target.addComponent(availableTagsContainer);
                }
            }
        }
    };
    filterAddButton.add(new AttributeModifier("value", true, new LoadableDetachableModel() {
        @Override
        protected Object load() {
            String key = isFreeTextTagSource() ? "add" : "filter";
            return getLocalizer().getString(key, SearchResultEditTaggingPanel.this);
        }
    }));

    availableTagsContainer = new WebMarkupContainer("availableTagsContainer");
    availableTagsContainer.setOutputMarkupId(true);
    availableTagsModel = new FilteredObjectsModel() {
        @Override
        protected List<Object> filter(String filter) {
            List<Object> matches = new ArrayList<Object>();
            Thesaurus taggingSource = taggingSourceModel.getObject();

            if (taggingSource == null || taggingSource.getId() == null) {
                if (StringUtils.isNotBlank(filter)) {
                    filter = filter + "*";
                }
                FreeTextTagServices taggingServices = ConstellioSpringUtils.getFreeTextTagServices();
                if (StringUtils.isBlank(filter)) {
                    List<FreeTextTag> first100 = taggingServices.list(100);
                    matches.addAll(first100);
                } else {
                    Set<FreeTextTag> searchResults = taggingServices.search(filter);
                    matches.addAll(searchResults);
                }
            } else {
                SkosServices skosServices = ConstellioSpringUtils.getSkosServices();
                Set<SkosConcept> searchResults = skosServices.searchAllLabels(filter, taggingSource, null);
                matches.addAll(searchResults);
            }
            return matches;
        }
    };
    availableTagsListView = new ListView("availableTags", availableTagsModel) {
        @Override
        protected void populateItem(ListItem item) {
            ConstellioEntity tagSource = (ConstellioEntity) item.getModelObject();
            final ReloadableEntityModel<ConstellioEntity> tagSourceModel = new ReloadableEntityModel<ConstellioEntity>(
                    tagSource);
            final ModalWindow detailsModal = new ModalWindow("detailsModal");
            item.add(detailsModal);

            final AjaxLink detailsLink = new AjaxLink("detailsLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    ConstellioEntity tagSource = (ConstellioEntity) tagSourceModel.getObject();
                    if (tagSource instanceof SkosConcept) {
                        SkosConcept skosConcept = (SkosConcept) tagSource;
                        detailsModal.setContent(
                                new SkosConceptModalPanel(detailsModal.getContentId(), skosConcept));
                        detailsModal.show(target);
                    }
                }
            };
            item.add(detailsLink);
            detailsLink.setEnabled(tagSource instanceof SkosConcept);

            detailsLink.add(new Label("name", new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    String name;
                    ConstellioEntity tagSource = (ConstellioEntity) tagSourceModel.getObject();
                    if (tagSource != null) {
                        if (tagSource instanceof FreeTextTag) {
                            FreeTextTag freeTextTag = (FreeTextTag) tagSource;
                            name = freeTextTag.getFreeText();
                        } else {
                            SkosConcept skosConcept = (SkosConcept) tagSource;
                            name = skosConcept.getPrefLabel(getLocale());
                        }
                    } else {
                        name = "null";
                    }
                    return name;
                }
            }));

            item.add(new AjaxLink("addLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    Record record = recordModel.getObject();
                    ConstellioEntity tagSource = (ConstellioEntity) tagSourceModel.getObject();
                    if (tagSource instanceof FreeTextTag) {
                        FreeTextTag freeTextTag = (FreeTextTag) tagSource;
                        record.addFreeTextTag(freeTextTag, true);
                    } else {
                        SkosConcept skosConcept = (SkosConcept) tagSource;
                        record.addSkosConcept(skosConcept, true);
                    }
                    record.setUpdateIndex(true);

                    RecordServices recordServices = ConstellioSpringUtils.getRecordServices();

                    SolrServer solrServer = SolrCoreContext
                            .getSolrServer(record.getConnectorInstance().getRecordCollection());
                    try {
                        ConstellioPersistenceUtils.beginTransaction();
                        recordServices.makePersistent(record);
                        try {
                            solrServer.commit();
                        } catch (Throwable t) {
                            try {
                                solrServer.rollback();
                            } catch (Exception e) {
                                throw new RuntimeException(t);
                            }
                        }
                    } finally {
                        ConstellioPersistenceUtils.finishTransaction(false);
                    }

                    target.addComponent(availableTagsContainer);
                    target.addComponent(appliedTagsContainer);
                }

                @Override
                public boolean isVisible() {
                    boolean visible = super.isVisible();
                    if (visible) {
                        Record record = recordModel.getObject();
                        if (tagSourceModel.getObject() instanceof FreeTextTag) {
                            FreeTextTag freeTextTag = (FreeTextTag) tagSourceModel.getObject();
                            visible = !record.hasFreeTextTag(freeTextTag);
                        } else {
                            SkosConcept skosConcept = (SkosConcept) tagSourceModel.getObject();
                            visible = !record.hasSkosConcept(skosConcept);
                        }
                    }
                    return visible;
                }

                @Override
                public void detachModels() {
                    tagSourceModel.detach();
                    super.detachModels();
                }
            });
        }
    };

    appliedTagsContainer = new WebMarkupContainer("appliedTagsContainer");
    appliedTagsContainer.setOutputMarkupId(true);
    appliedTagsModel = new FilteredObjectsModel() {
        @Override
        protected List<RecordTag> filter(String filter) {
            List<RecordTag> matches = new ArrayList<RecordTag>();
            Record record = recordModel.getObject();
            Thesaurus source = taggingSourceModel.getObject();
            for (RecordTag recordTag : record.getIncludedRecordTags(freeTextTags ? null : source, true)) {
                //                    if (StringUtils.isEmpty(filter)
                //                        || recordTag.getName(getLocale()).toLowerCase().indexOf(filter.toLowerCase()) != -1) {
                matches.add(recordTag);
                //                    }
            }
            return matches;
        }
    };
    appliedTagsListView = new ListView("appliedTags", appliedTagsModel) {
        @Override
        protected void populateItem(ListItem item) {
            RecordTag recordTag = (RecordTag) item.getModelObject();
            final RecordTagModel recordTagModel = new RecordTagModel(recordTag);

            ConstellioEntity tagSource;
            if (recordTag.getFreeTextTag() != null) {
                tagSource = recordTag.getFreeTextTag();
            } else {
                tagSource = recordTag.getSkosConcept();
            }
            final ReloadableEntityModel<ConstellioEntity> tagSourceModel = new ReloadableEntityModel<ConstellioEntity>(
                    tagSource);
            final ModalWindow detailsModal = new ModalWindow("detailsModal");
            item.add(detailsModal);

            final AjaxLink detailsLink = new AjaxLink("detailsLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    ConstellioEntity tagSource = (ConstellioEntity) tagSourceModel.getObject();
                    if (tagSource instanceof SkosConcept) {
                        SkosConcept skosConcept = (SkosConcept) tagSource;
                        detailsModal.setContent(
                                new SkosConceptModalPanel(detailsModal.getContentId(), skosConcept));
                        detailsModal.show(target);
                    }
                }
            };
            item.add(detailsLink);
            detailsLink.setEnabled(tagSource instanceof SkosConcept);

            detailsLink.add(new Label("name", new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    String name;
                    ConstellioEntity tagSource = (ConstellioEntity) tagSourceModel.getObject();
                    if (tagSource != null) {
                        if (tagSource instanceof FreeTextTag) {
                            FreeTextTag freeTextTag = (FreeTextTag) tagSource;
                            name = freeTextTag.getFreeText();
                        } else {
                            SkosConcept skosConcept = (SkosConcept) tagSource;
                            name = skosConcept.getPrefLabel(getLocale());
                        }
                    } else {
                        name = "null";
                    }
                    return name;
                }
            }));
            detailsLink.add(new AttributeModifier("style", true, new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    RecordTag recordTag = recordTagModel.getObject();
                    return recordTag.isExcluded() ? "text-decoration: line-through;" : "text-decoration:none";
                }
            }));
            item.add(new AjaxLink("removeLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    Record record = recordModel.getObject();
                    RecordTag recordTag = recordTagModel.getObject();
                    boolean excluded = recordTag.isExcluded();
                    if (excluded) {
                        record.getRecordTags().remove(recordTag);
                    } else {
                        recordTag.setManual(true);
                        recordTag.setExcluded(true);
                    }
                    record.setUpdateIndex(true);

                    RecordServices recordServices = ConstellioSpringUtils.getRecordServices();

                    SolrServer solrServer = SolrCoreContext
                            .getSolrServer(record.getConnectorInstance().getRecordCollection());
                    try {
                        ConstellioPersistenceUtils.beginTransaction();
                        recordServices.makePersistent(record);
                        try {
                            solrServer.commit();
                        } catch (Throwable t) {
                            try {
                                solrServer.rollback();
                            } catch (Exception e) {
                                throw new RuntimeException(t);
                            }
                        }
                    } finally {
                        ConstellioPersistenceUtils.finishTransaction(false);
                    }

                    target.addComponent(availableTagsContainer);
                    target.addComponent(appliedTagsContainer);
                }

                @Override
                public void detachModels() {
                    recordTagModel.detach();
                    tagSourceModel.detach();
                    super.detachModels();
                }
            });
        }
    };

    closeLink = new AjaxLink("closeLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            SearchResultTaggingPanel parent = (SearchResultTaggingPanel) findParent(
                    SearchResultTaggingPanel.class);
            target.addComponent(parent);
            ModalWindow.closeCurrent(target);
        }
    };

    add(taggingSourceField);
    add(new Label("sourceName", source.getDcTitle()).setVisible(!isSourceSelectionVisible()));
    add(filterAddForm);
    filterAddForm.add(filterAddField);
    filterAddForm.add(filterAddButton);

    add(availableTagsContainer);
    availableTagsContainer.add(availableTagsListView);

    add(appliedTagsContainer);
    appliedTagsContainer.add(appliedTagsListView);

    add(closeLink);
}

From source file:com.issuetracker.pages.component.workflow.WorkflowForm.java

public WorkflowForm(String id) {
    super(id);/*from  w w  w  . ja  v  a2  s  .c  om*/

    Form<Workflow> workflowForm = new Form<Workflow>("workflowForm") {
        @Override
        protected void onSubmit() {
            if (workflowService.getWorkflowByName(workflow.getName()) != null) {
                error("Specified workflow is already added.");
            } else {
                workflowService.insert(workflow);
                for (Project project : selectedProjects) {
                    project.setWorkflow(workflow);
                    projectService.update(project);
                }
            }
            workflow = new Workflow();
            //this will clear the form
            selectedProjects = null;
        }
    };

    workflowForm.add(new RequiredTextField<>("name", new PropertyModel<String>(this, "workflow.name")));

    IModel<List<Project>> projectsModel = new AbstractReadOnlyModel<List<Project>>() {
        @Override
        public List<Project> getObject() {
            return projectService.getDisplayableProjects();
        }
    };

    final ListMultipleChoice<Project> projectMultipleChoise = new ListMultipleChoice<>("projectMultipleChoise",
            new PropertyModel<List<Project>>(this, "selectedProjects"), projectsModel,
            new ChoiceRenderer<Project>("name"));
    workflowForm.add(projectMultipleChoise);
    add(workflowForm);
}