001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ui.apps.search;
029
030import org.opencms.file.CmsObject;
031import org.opencms.file.CmsProject;
032import org.opencms.file.CmsPropertyDefinition;
033import org.opencms.file.CmsResource;
034import org.opencms.file.CmsResourceFilter;
035import org.opencms.file.types.CmsResourceTypeXmlContainerPage;
036import org.opencms.file.types.I_CmsResourceType;
037import org.opencms.i18n.CmsLocaleManager;
038import org.opencms.loader.CmsLoaderException;
039import org.opencms.main.CmsException;
040import org.opencms.main.CmsLog;
041import org.opencms.main.OpenCms;
042import org.opencms.search.CmsSearchIndex;
043import org.opencms.search.I_CmsSearchIndex;
044import org.opencms.ui.A_CmsUI;
045import org.opencms.ui.CmsVaadinUtils;
046import org.opencms.ui.CmsVaadinUtils.PropertyId;
047import org.opencms.ui.apps.Messages;
048import org.opencms.ui.components.fileselect.CmsPathSelectField;
049import org.opencms.util.CmsStringUtil;
050import org.opencms.util.CmsUUID;
051
052import java.io.ByteArrayInputStream;
053import java.util.Collections;
054import java.util.Locale;
055
056import org.apache.commons.logging.Log;
057
058import com.vaadin.server.FileDownloader;
059import com.vaadin.server.StreamResource;
060import com.vaadin.ui.Button;
061import com.vaadin.ui.Button.ClickEvent;
062import com.vaadin.ui.Button.ClickListener;
063import com.vaadin.v7.data.Item;
064import com.vaadin.v7.data.Property.ValueChangeEvent;
065import com.vaadin.v7.data.Property.ValueChangeListener;
066import com.vaadin.v7.data.util.IndexedContainer;
067import com.vaadin.v7.shared.ui.combobox.FilteringMode;
068import com.vaadin.v7.ui.CheckBox;
069import com.vaadin.v7.ui.ComboBox;
070import com.vaadin.v7.ui.TextField;
071import com.vaadin.v7.ui.VerticalLayout;
072
073/**
074 * The source search form.<p>
075 */
076public class CmsSourceSearchForm extends VerticalLayout {
077
078    /** The available search types. */
079    public static enum SearchType {
080
081        /** XML content values only. */
082        contentValues(false, true, false),
083        /** Full text search. */
084        fullText(false, false, false),
085        /** Property search. */
086        properties(false, false, true),
087        /** */
088        renameContainer(false, false, false),
089
090        /** */
091        resourcetype(false, false, false),
092        /** Filter using a solr index, before searching for matches. */
093        solr(true, false, false),
094        /** Filter using a solr index, before searching for matches, XML content values only. */
095        solrContentValues(true, true, false);
096
097        /** The content values only flag. */
098        private boolean m_contentValuesOnly;
099
100        /** The property flag.*/
101        private boolean m_property;
102
103        /** The is solr search flag. */
104        private boolean m_solrSearch;
105
106        /**
107         * Constructor.<p>
108         *
109         * @param solrSearch the is solr search flag
110         * @param contentValuesOnly the content values only flag
111         * @param property the property flag
112         */
113        private SearchType(boolean solrSearch, boolean contentValuesOnly, boolean property) {
114
115            m_solrSearch = solrSearch;
116            m_contentValuesOnly = contentValuesOnly;
117            m_property = property;
118        }
119
120        /**
121         * Returns whether this is a content values only search type.<p>
122         *
123         * @return <code>true</code> if this is a content values only search type
124         */
125        public boolean isContentValuesOnly() {
126
127            return m_contentValuesOnly;
128        }
129
130        /**
131         * Returns whether this is a property search type.<p>
132         *
133         * @return true if this is property search
134         *  */
135        public boolean isPropertySearch() {
136
137            return m_property;
138        }
139
140        /**
141         * Returns whether this is a SOLR search type.<p>
142         *
143         * @return <code>true</code> if this is a SOLR search type
144         */
145        public boolean isSolrSearch() {
146
147            return m_solrSearch;
148        }
149    }
150
151    /**Regex expression for finding all. */
152    public static final String REGEX_ALL = ".*";
153
154    /** Special select option for resource types that only excludes types binary and image. */
155    public static final String RESOURCE_TYPES_ALL_NON_BINARY = "_NonBinary_";
156
157    /** The log object for this class. */
158    static final Log LOG = CmsLog.getLog(CmsSourceSearchForm.class);
159
160    /** The serial version id. */
161    private static final long serialVersionUID = 1023130318064811880L;
162
163    /** The source search app instance. */
164    private CmsSourceSearchApp m_app;
165
166    /** The download button. */
167    private Button m_download;
168
169    /** The downloader for the CSV export. */
170    private FileDownloader m_downloader;
171
172    /** Check box to ignore subsites. */
173    private CheckBox m_ignoreSubSites;
174
175    /** The search locale select. */
176    private ComboBox m_locale;
177
178    /** Vaadin component.*/
179    private TextField m_newName;
180
181    /** Vaadin component.*/
182    private TextField m_oldName;
183
184    /** The property select.*/
185    private ComboBox m_property;
186
187    /** The replace check box. */
188    private CheckBox m_replace;
189
190    /** The replace pattern field. */
191    private TextField m_replacePattern;
192
193    /** The search root path select. */
194    private CmsPathSelectField m_replaceResource;
195
196    /** The search root path select. */
197    private CmsPathSelectField m_resourceSearch;
198
199    /** The resource type select. */
200    private ComboBox m_resourceType;
201
202    /** The search button. */
203    private Button m_search;
204
205    /** The search index select. */
206    private ComboBox m_searchIndex;
207
208    /** The search pattern field. */
209    private TextField m_searchPattern;
210
211    /** The search root path select. */
212    private CmsPathSelectField m_searchRoot;
213
214    /** The search type select. */
215    private ComboBox m_searchType;
216
217    /** The site select. */
218    private ComboBox m_siteSelect;
219
220    /** The SOLR query field. */
221    private TextField m_solrQuery;
222
223    /** The replace project. */
224    private ComboBox m_workProject;
225
226    /** The XPath field. */
227    private TextField m_xPath;
228
229    /**
230     * Constructor.<p>
231     *
232     * @param app the source search app instance
233     */
234    public CmsSourceSearchForm(CmsSourceSearchApp app) {
235
236        m_app = app;
237        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
238        initFields();
239        m_replace.addValueChangeListener(new ValueChangeListener() {
240
241            private static final long serialVersionUID = 1L;
242
243            public void valueChange(ValueChangeEvent event) {
244
245                updateReplace();
246            }
247        });
248        m_searchType.addValueChangeListener(new ValueChangeListener() {
249
250            private static final long serialVersionUID = 1L;
251
252            public void valueChange(ValueChangeEvent event) {
253
254                changedSearchType();
255            }
256        });
257        m_search.addClickListener(new ClickListener() {
258
259            private static final long serialVersionUID = 1L;
260
261            public void buttonClick(ClickEvent event) {
262
263                search();
264            }
265        });
266        m_download.setVisible(false);
267        m_downloader = new FileDownloader(
268            new StreamResource(() -> new ByteArrayInputStream(new byte[] {}), "empty.csv"));
269        m_downloader.extend(m_download);
270        updateReplace();
271        changedSearchType();
272    }
273
274    /**
275     * Initializes the form with the given settings.<p>
276     *
277     * @param settings the settings
278     */
279    public void initFormValues(CmsSearchReplaceSettings settings) {
280
281        m_siteSelect.setValue(settings.getSiteRoot());
282        m_ignoreSubSites.setValue(Boolean.valueOf(settings.ignoreSubSites()));
283        m_searchType.setValue(settings.getType());
284        if (!settings.getPaths().isEmpty()) {
285            m_searchRoot.setValue(settings.getPaths().get(0));
286        }
287        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(settings.getTypes())) {
288            if (RESOURCE_TYPES_ALL_NON_BINARY.equals(settings.getTypes())) {
289                m_resourceType.setValue(RESOURCE_TYPES_ALL_NON_BINARY);
290            } else {
291                try {
292                    I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(settings.getTypes());
293                    m_resourceType.setValue(type);
294                } catch (CmsLoaderException e) {
295                    // nothing to do, skip setting the type
296                }
297            }
298        }
299        m_searchPattern.setValue(settings.getSearchpattern());
300        m_ignoreSubSites.setValue(Boolean.valueOf(settings.ignoreSubSites()));
301        if (settings.getType().isContentValuesOnly()) {
302            if (settings.getLocale() != null) {
303                OpenCms.getLocaleManager();
304                Locale l = CmsLocaleManager.getLocale(settings.getLocale());
305                // if the locale is invalid, the default locale will be returned
306                // we want to prevent setting the default locale in such a case.
307                if (!l.equals(CmsLocaleManager.getDefaultLocale()) || l.toString().equals(settings.getLocale())) {
308                    m_locale.setValue(l);
309                }
310            }
311            m_xPath.setValue(settings.getXpath());
312        }
313        if (settings.getType().isSolrSearch()) {
314            m_solrQuery.setValue(settings.getQuery());
315            m_searchIndex.setValue(settings.getSource());
316        }
317
318        if (settings.getType().isPropertySearch()) {
319            m_property.select(settings.getProperty());
320        }
321        if (settings.getType().equals(SearchType.resourcetype)) {
322            try {
323                CmsObject cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
324                cms.getRequestContext().setSiteRoot("");
325                m_resourceSearch.setValue(
326                    cms.readResource(
327                        new CmsUUID(
328                            settings.getSearchpattern().substring(
329                                settings.getSearchpattern().indexOf("<uuid>") + 6,
330                                settings.getSearchpattern().indexOf("</uuid>")))).getRootPath());
331            } catch (CmsException e) {
332                LOG.error("Unable to read resource", e);
333            }
334
335        }
336    }
337
338    /**
339     * Sets the download provider (which may be null), and shows or hides the download button based on whether it is null.
340     *
341     * @param resource the download resource
342     */
343    public void setDownload(StreamResource resource) {
344
345        m_downloader.setFileDownloadResource(resource);
346        m_download.setVisible(resource != null);
347    }
348
349    /**
350     * Updates the search root.<p>
351     *
352     * @throws CmsException if CmsObject init fails
353     */
354    protected void updateSearchRoot() throws CmsException {
355
356        CmsObject newCms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
357        newCms.getRequestContext().setSiteRoot((String)m_siteSelect.getValue());
358        m_searchRoot.setCmsObject(newCms);
359        m_searchRoot.setValue("/");
360
361    }
362
363    /**
364     * Handles search type changes.<p>
365     */
366    void changedSearchType() {
367
368        SearchType type = (SearchType)m_searchType.getValue();
369
370        m_property.setVisible(type.isPropertySearch());
371        m_searchPattern.setVisible(
372            (!type.equals(SearchType.resourcetype)) & (!type.equals(SearchType.renameContainer)));
373        m_resourceSearch.setVisible(type.equals(SearchType.resourcetype) | type.equals(SearchType.renameContainer));
374        if ((!type.equals(SearchType.resourcetype)) & (!type.equals(SearchType.renameContainer))) {
375            m_ignoreSubSites.setValue(Boolean.FALSE);
376            m_ignoreSubSites.setVisible(false);
377        } else {
378            m_ignoreSubSites.setVisible(true);
379        }
380
381        m_searchIndex.setVisible(type.isSolrSearch());
382        m_solrQuery.setVisible(type.isSolrSearch());
383        updateReplace();
384        m_xPath.setVisible(type.isContentValuesOnly());
385        m_locale.setVisible(type.isContentValuesOnly());
386
387        m_resourceType.setVisible(
388            !type.isPropertySearch()
389                & !type.equals(SearchType.resourcetype)
390                & !type.equals(SearchType.renameContainer));
391
392        IndexedContainer types = (IndexedContainer)m_resourceType.getContainerDataSource();
393        types.removeAllContainerFilters();
394        types.addContainerFilter(
395            type.isContentValuesOnly() ? CmsVaadinUtils.FILTER_XML_CONTENTS : CmsVaadinUtils.FILTER_NO_FOLDERS);
396    }
397
398    /**
399     * Calls the search for the given parameters.<p>
400     */
401    void search() {
402
403        CmsSearchReplaceSettings settings = new CmsSearchReplaceSettings();
404        settings.setSiteRoot((String)m_siteSelect.getValue());
405        settings.setType((SearchType)m_searchType.getValue());
406        settings.setPaths(Collections.singletonList(m_searchRoot.getValue()));
407        settings.setIgnoreSubSites(m_ignoreSubSites.getValue().booleanValue());
408        Object resTypeSelection = m_resourceType.getValue();
409        if (resTypeSelection != null) {
410            if (resTypeSelection instanceof String) {
411                settings.setTypes((String)resTypeSelection);
412            } else {
413                I_CmsResourceType type = (I_CmsResourceType)m_resourceType.getValue();
414                settings.setTypes(type.getTypeName());
415            }
416        }
417        if (SearchType.resourcetype.equals(m_searchType.getValue())
418            | SearchType.renameContainer.equals(m_searchType.getValue())) {
419            settings.setTypes(
420                CmsResourceTypeXmlContainerPage.getStaticTypeName()
421                    + ","
422                    + CmsResourceTypeXmlContainerPage.MODEL_GROUP_TYPE_NAME);
423        }
424
425        if (SearchType.renameContainer.equals(m_searchType.getValue())) {
426            try {
427                CmsObject cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
428                cms.getRequestContext().setSiteRoot("");
429                CmsResource element = cms.readResource(m_resourceSearch.getValue());
430                settings.setElementResource(element);
431            } catch (CmsException e) {
432                LOG.error("Can not read resource", e);
433            }
434        }
435
436        if (m_replace.getValue().booleanValue()) {
437            try {
438                CmsProject workProject = A_CmsUI.getCmsObject().readProject((CmsUUID)m_workProject.getValue());
439                settings.setProject(workProject.getName());
440            } catch (CmsException e) {
441                // ignore
442            }
443            if (SearchType.resourcetype.equals(m_searchType.getValue())) {
444                try {
445                    CmsObject cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
446                    cms.getRequestContext().setSiteRoot("");
447                    CmsResource resource = cms.readResource(m_replaceResource.getValue());
448                    settings.setReplacepattern(CmsSearchReplaceSettings.replaceElementInPagePattern(resource));
449                } catch (CmsException e) {
450                    LOG.error("Unable to read resource.", e);
451                }
452            } else if (SearchType.renameContainer.equals(m_searchType.getValue())) {
453                settings.setReplacepattern(m_oldName.getValue() + ";" + m_newName.getValue());
454            } else {
455                settings.setReplacepattern(m_replacePattern.getValue());
456            }
457        }
458        settings.setForceReplace(m_replace.getValue().booleanValue());
459
460        if (SearchType.resourcetype.equals(m_searchType.getValue())
461            | SearchType.renameContainer.equals(m_searchType.getValue())) {
462            try {
463                CmsObject cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
464                cms.getRequestContext().setSiteRoot("");
465                CmsResource resource = cms.readResource(m_resourceSearch.getValue());
466                settings.setSearchpattern(CmsSearchReplaceSettings.searchElementInPagePattern(resource));
467            } catch (CmsException e) {
468                LOG.error("Unable to read resource.", e);
469            }
470        } else {
471
472            settings.setSearchpattern(m_searchPattern.getValue());
473        }
474        if (settings.getType().isContentValuesOnly()) {
475            if (m_locale.getValue() != null) {
476                settings.setLocale(m_locale.getValue().toString());
477            }
478            settings.setXpath(m_xPath.getValue());
479        }
480        if (settings.getType().isSolrSearch()) {
481            settings.setQuery(m_solrQuery.getValue());
482            settings.setSource((String)m_searchIndex.getValue());
483        }
484
485        if (settings.getType().isPropertySearch()) {
486            settings.setProperty((CmsPropertyDefinition)m_property.getValue());
487            settings.setForceReplace(m_replace.getValue().booleanValue());
488        }
489
490        m_app.search(settings, true);
491    }
492
493    /**
494     * Toggles the replace option.<p>
495     */
496    void updateReplace() {
497
498        boolean replace = m_replace.getValue().booleanValue();
499
500        m_replaceResource.setVisible(replace ? SearchType.resourcetype.equals(m_searchType.getValue()) : replace);
501        m_replacePattern.setVisible(
502            replace
503            ? !SearchType.resourcetype.equals(m_searchType.getValue())
504                & !SearchType.renameContainer.equals(m_searchType.getValue())
505            : replace);
506
507        m_newName.setVisible(replace ? SearchType.renameContainer.equals(m_searchType.getValue()) : replace);
508        m_oldName.setVisible(replace ? SearchType.renameContainer.equals(m_searchType.getValue()) : replace);
509
510        m_workProject.setVisible(replace);
511
512        m_search.setCaption(
513            replace
514            ? CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_REPLACE_0)
515            : CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_SEARCH_0));
516
517    }
518
519    /**
520     * Initializes the form fields.<p>
521     */
522    private void initFields() {
523
524        CmsObject cms = A_CmsUI.getCmsObject();
525        boolean online = cms.getRequestContext().getCurrentProject().isOnlineProject();
526
527        if (m_searchPattern.getValue().isEmpty()) {
528            m_searchPattern.setValue(REGEX_ALL);
529        }
530        m_resourceSearch.setUseRootPaths(true);
531        m_replaceResource.setUseRootPaths(true);
532        m_resourceSearch.requireFile();
533        m_replaceResource.requireFile();
534        CmsObject rootCms;
535        try {
536            rootCms = OpenCms.initCmsObject(cms);
537
538            rootCms.getRequestContext().setSiteRoot("");
539            m_resourceSearch.setCmsObject(rootCms);
540            m_resourceSearch.setDefaultPath(cms.getRequestContext().getSiteRoot());
541            m_replaceResource.setCmsObject(rootCms);
542            m_replaceResource.setDefaultPath(cms.getRequestContext().getSiteRoot());
543
544        } catch (CmsException e1) {
545            //
546        }
547        m_siteSelect.setContainerDataSource(
548            CmsVaadinUtils.getAvailableSitesContainer(cms, CmsVaadinUtils.PROPERTY_LABEL));
549        m_siteSelect.setItemCaptionPropertyId(CmsVaadinUtils.PROPERTY_LABEL);
550        m_siteSelect.setTextInputAllowed(true);
551        m_siteSelect.setNullSelectionAllowed(false);
552        m_siteSelect.setFilteringMode(FilteringMode.CONTAINS);
553        m_siteSelect.setValue(cms.getRequestContext().getSiteRoot());
554        try {
555            for (CmsPropertyDefinition prop : A_CmsUI.getCmsObject().readAllPropertyDefinitions()) {
556                m_property.addItem(prop);
557                m_property.setItemCaption(prop, prop.getName());
558            }
559        } catch (CmsException e) {
560            //
561        }
562        m_siteSelect.addValueChangeListener(new ValueChangeListener() {
563
564            private static final long serialVersionUID = -1079794209679015125L;
565
566            public void valueChange(ValueChangeEvent event) {
567
568                try {
569                    updateSearchRoot();
570                } catch (CmsException e) {
571                    LOG.error("Unable to initialize CmsObject", e);
572                }
573            }
574
575        });
576        m_property.setNullSelectionAllowed(false);
577        m_property.select(m_property.getItemIds().iterator().next());
578        m_property.setFilteringMode(FilteringMode.CONTAINS);
579        m_searchType.setFilteringMode(FilteringMode.OFF);
580        m_searchType.setNullSelectionAllowed(false);
581        m_searchType.addItem(SearchType.fullText);
582        m_searchType.setItemCaption(
583            SearchType.fullText,
584            CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_SERACH_TYPE_FULLTEXT_0));
585        m_searchType.addItem(SearchType.contentValues);
586        m_searchType.setItemCaption(
587            SearchType.contentValues,
588            CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_SERACH_TYPE_XMLCONTENT_0));
589        m_searchType.addItem(SearchType.properties);
590        m_searchType.setItemCaption(
591            SearchType.properties,
592            CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_PROPERTY_SEARCH_0));
593        m_searchType.addItem(SearchType.resourcetype);
594        m_searchType.setItemCaption(
595            SearchType.resourcetype,
596            CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_RESOURCE_SEARCH_0));
597        m_searchType.addItem(SearchType.renameContainer);
598        m_searchType.setItemCaption(
599            SearchType.renameContainer,
600            CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_RENAME_CONTAINER_SEARCH_0));
601        if (OpenCms.getSearchManager().getSolrServerConfiguration().isEnabled()) {
602
603            m_searchIndex.setFilteringMode(FilteringMode.OFF);
604            m_searchIndex.setNullSelectionAllowed(false);
605            String selectIndex = null;
606            for (CmsSearchIndex index : OpenCms.getSearchManager().getAllSolrIndexes()) {
607                boolean offlineMode = I_CmsSearchIndex.REBUILD_MODE_OFFLINE.equals(index.getRebuildMode());
608                // in case the current project is offline, show offline indexes, otherwise show online indexes
609                if ((!online && offlineMode) || (online && !offlineMode)) {
610                    m_searchIndex.addItem(index.getName());
611                    if (selectIndex == null) {
612                        selectIndex = index.getName();
613                    }
614                }
615            }
616            if (selectIndex != null) {
617                m_searchIndex.setValue(selectIndex);
618
619                // only add the solr search types if there is an index available
620                m_searchType.addItem(SearchType.solr);
621                m_searchType.setItemCaption(
622                    SearchType.solr,
623                    CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_SERACH_TYPE_SOLR_0));
624                m_searchType.addItem(SearchType.solrContentValues);
625                m_searchType.setItemCaption(
626                    SearchType.solrContentValues,
627                    CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_SERACH_TYPE_SOLR_CONTENT_VALUES_0));
628
629            }
630        }
631        m_searchType.setValue(SearchType.fullText);
632
633        m_searchRoot.setValue("/");
634        m_searchRoot.disableSiteSwitch();
635        m_searchRoot.setResourceFilter(CmsResourceFilter.DEFAULT_FOLDERS);
636        m_searchRoot.requireFolder();
637        m_locale.setFilteringMode(FilteringMode.OFF);
638        for (Locale locale : OpenCms.getLocaleManager().getAvailableLocales()) {
639            m_locale.addItem(locale);
640        }
641
642        m_resourceType.setNullSelectionAllowed(true);
643        IndexedContainer resTypes = CmsVaadinUtils.getResourceTypesContainer();
644        Item typeItem = resTypes.addItemAt(0, RESOURCE_TYPES_ALL_NON_BINARY);
645        String caption = CmsVaadinUtils.getMessageText(Messages.GUI_SOURCESEARCH_RESOURCE_TYPE_NON_BINARY_0);
646        typeItem.getItemProperty(PropertyId.caption).setValue(caption);
647        typeItem.getItemProperty(PropertyId.icon).setValue(null);
648        typeItem.getItemProperty(PropertyId.isXmlContent).setValue(Boolean.TRUE);
649        typeItem.getItemProperty(PropertyId.isFolder).setValue(Boolean.FALSE);
650        resTypes.addContainerFilter(CmsVaadinUtils.FILTER_NO_FOLDERS);
651
652        m_resourceType.setContainerDataSource(resTypes);
653        m_resourceType.setItemCaptionPropertyId(PropertyId.caption);
654        m_resourceType.setItemIconPropertyId(PropertyId.icon);
655        m_resourceType.setFilteringMode(FilteringMode.CONTAINS);
656
657        m_workProject.setNullSelectionAllowed(false);
658        IndexedContainer projects = CmsVaadinUtils.getProjectsContainer(A_CmsUI.getCmsObject(), "caption");
659        projects.removeItem(CmsProject.ONLINE_PROJECT_ID);
660        m_workProject.setContainerDataSource(projects);
661        m_workProject.setItemCaptionPropertyId("caption");
662
663        if (online) {
664            m_replace.setEnabled(false);
665        } else {
666            m_workProject.setValue(cms.getRequestContext().getCurrentProject().getUuid());
667        }
668    }
669}