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.dbmanager;
029
030import org.opencms.ui.A_CmsUI;
031import org.opencms.ui.CmsVaadinUtils;
032import org.opencms.ui.FontOpenCms;
033import org.opencms.ui.apps.A_CmsWorkplaceApp;
034import org.opencms.ui.apps.Messages;
035import org.opencms.ui.components.CmsBasicDialog;
036import org.opencms.ui.components.CmsToolBar;
037
038import java.util.LinkedHashMap;
039import java.util.List;
040
041import com.vaadin.v7.event.FieldEvents.TextChangeEvent;
042import com.vaadin.v7.event.FieldEvents.TextChangeListener;
043import com.vaadin.ui.Button;
044import com.vaadin.ui.Button.ClickEvent;
045import com.vaadin.ui.Button.ClickListener;
046import com.vaadin.ui.Component;
047import com.vaadin.v7.ui.TextField;
048import com.vaadin.ui.UI;
049import com.vaadin.ui.Window;
050import com.vaadin.ui.themes.ValoTheme;
051
052/**
053 * Class for the property definition app.<p>
054 */
055public class CmsDbPropertiesApp extends A_CmsWorkplaceApp {
056
057    /**Table for properties. */
058    protected CmsPropertyTable m_table;
059
060    /**
061     * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getBreadCrumbForState(java.lang.String)
062     */
063    @Override
064    protected LinkedHashMap<String, String> getBreadCrumbForState(String state) {
065
066        LinkedHashMap<String, String> crumbs = new LinkedHashMap<String, String>();
067
068        crumbs.put("", CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_PROPERTY_TOOL_NAME_0));
069        return crumbs;
070
071    }
072
073    /**
074     * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getComponentForState(java.lang.String)
075     */
076    @Override
077    protected Component getComponentForState(String state) {
078
079        m_rootLayout.setMainHeightFull(true);
080
081        m_table = new CmsPropertyTable();
082
083        TextField filter = new TextField();
084        filter.setIcon(FontOpenCms.FILTER);
085        filter.setInputPrompt(
086            Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_FILTER_0));
087        filter.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
088        filter.setWidth("200px");
089        filter.addTextChangeListener(new TextChangeListener() {
090
091            private static final long serialVersionUID = 1L;
092
093            public void textChange(TextChangeEvent event) {
094
095                m_table.filterTable(event.getText());
096            }
097        });
098        m_infoLayout.addComponent(filter);
099        m_table.setSizeFull();
100        addNewPropertyButton(m_table);
101        return m_table;
102    }
103
104    /**
105     * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getSubNavEntries(java.lang.String)
106     */
107    @Override
108    protected List<NavEntry> getSubNavEntries(String state) {
109
110        return null;
111    }
112
113    /**
114     * Button for adding new property.<p>
115     * @param table table to be updated
116     */
117    private void addNewPropertyButton(final CmsPropertyTable table) {
118
119        Button add = CmsToolBar.createButton(
120            FontOpenCms.WAND,
121            CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_PROPERTY_NEW_CAPTION_0));
122        add.addClickListener(new ClickListener() {
123
124            private static final long serialVersionUID = 1L;
125
126            public void buttonClick(ClickEvent event) {
127
128                final Window window = CmsBasicDialog.prepareWindow();
129                window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_PROPERTY_NEW_CAPTION_0));
130                window.setContent(new CmsAddPropertyDefinitionDialog(window, table));
131                A_CmsUI.get().addWindow(window);
132            }
133        });
134        m_uiContext.addToolbarButton(add);
135
136    }
137}