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