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.searchindex;
029
030import org.opencms.main.OpenCms;
031import org.opencms.report.A_CmsReportThread;
032import org.opencms.search.I_CmsSearchIndex;
033import org.opencms.ui.A_CmsUI;
034import org.opencms.ui.CmsVaadinUtils;
035import org.opencms.ui.apps.A_CmsWorkplaceApp;
036import org.opencms.ui.apps.I_CmsCRUDApp;
037import org.opencms.ui.apps.Messages;
038import org.opencms.ui.report.CmsReportWidget;
039import org.opencms.util.CmsStringUtil;
040
041import java.util.LinkedHashMap;
042import java.util.List;
043
044import com.vaadin.ui.Component;
045
046/**
047 * Class for the search index app.<p>
048 */
049public class CmsSearchindexApp extends A_CmsWorkplaceApp implements I_CmsCRUDApp<I_CmsSearchIndex> {
050
051    /**Path to show sources.*/
052    protected static final String PATH_REBUILD = "rebuild";
053
054    /**Seperator used when several index names are submitted.*/
055    protected static final String SEPERATOR_INDEXNAMES = ";";
056
057    /**Table. */
058    protected CmsSearchIndexTable m_table;
059
060    /**
061     * @see org.opencms.ui.apps.I_CmsCRUDApp#createElement(java.lang.Object)
062     */
063    public void createElement(I_CmsSearchIndex element) {
064
065        return;
066
067    }
068
069    /**
070     * @see org.opencms.ui.apps.I_CmsCRUDApp#defaultAction(java.lang.String)
071     */
072    public void defaultAction(String elementId) {
073
074        return;
075
076    }
077
078    /**
079     * @see org.opencms.ui.apps.I_CmsCRUDApp#deleteElements(java.util.List)
080     */
081    public void deleteElements(List<String> elementId) {
082
083        return;
084
085    }
086
087    /**
088     * @see org.opencms.ui.apps.I_CmsCRUDApp#getAllElements()
089     */
090    public List<I_CmsSearchIndex> getAllElements() {
091
092        return OpenCms.getSearchManager().getSearchIndexesAll();
093    }
094
095    /**
096     * @see org.opencms.ui.apps.I_CmsCRUDApp#getElement(java.lang.String)
097     */
098    public I_CmsSearchIndex getElement(String elementId) {
099
100        //TODO maybe put getIDFromElement to I_CmsCRUDApp..
101        return OpenCms.getSearchManager().getIndex(elementId);
102    }
103
104    /**
105     * @see org.opencms.ui.apps.I_CmsCRUDApp#writeElement(java.lang.Object)
106     */
107    public void writeElement(I_CmsSearchIndex element) {
108
109        return;
110    }
111
112    /**
113     * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getBreadCrumbForState(java.lang.String)
114     */
115    @Override
116    protected LinkedHashMap<String, String> getBreadCrumbForState(String state) {
117
118        LinkedHashMap<String, String> crumbs = new LinkedHashMap<String, String>();
119        if (CmsStringUtil.isEmptyOrWhitespaceOnly(state)) {
120            crumbs.put("", CmsVaadinUtils.getMessageText(Messages.GUI_SEARCHINDEX_ADMIN_TOOL_NAME_SHORT_0));
121        }
122        return crumbs;
123    }
124
125    /**
126     * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getComponentForState(java.lang.String)
127     */
128    @Override
129    protected Component getComponentForState(String state) {
130
131        m_rootLayout.setMainHeightFull(true);
132        m_table = new CmsSearchIndexTable(this);
133        m_table.loadTable();
134        return m_table;
135    }
136
137    /**
138     * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getSubNavEntries(java.lang.String)
139     */
140    @Override
141    protected List<NavEntry> getSubNavEntries(String state) {
142
143        return null;
144    }
145
146    /**
147     * Gets the thread to update given indexes.<p>
148     *
149     * @param elementIds to be updated
150     * @return A_CmsReportThread
151     */
152    protected Component getUpdateThreadComponent(List<String> elementIds) {
153
154        final A_CmsReportThread thread = new CmsIndexingReportThread(A_CmsUI.getCmsObject(), elementIds);
155        thread.start();
156        return new CmsReportWidget(thread);
157    }
158}