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.dialogs.embedded;
029
030import org.opencms.ui.A_CmsUI;
031import org.opencms.ui.CmsVaadinUtils;
032import org.opencms.ui.I_CmsDialogContext;
033import org.opencms.ui.components.CmsBasicDialog;
034import org.opencms.ui.dataview.CmsDataViewPanel;
035import org.opencms.widgets.dataview.I_CmsDataView;
036import org.opencms.widgets.dataview.I_CmsDataViewItem;
037
038import java.util.List;
039
040import com.vaadin.ui.Button;
041import com.vaadin.ui.Button.ClickEvent;
042import com.vaadin.ui.Button.ClickListener;
043import com.vaadin.ui.JavaScript;
044import com.vaadin.v7.ui.VerticalLayout;
045
046/**
047 * Dialog used to select data items from an external data source.<p>
048 */
049public class CmsDataViewDialog extends CmsBasicDialog {
050
051    /** The serial version id. */
052    private static final long serialVersionUID = 1L;
053
054    /** The container for the other widgets. */
055    private VerticalLayout m_container;
056
057    /** The OK button. */
058    private Button m_okButton;
059
060    /** The cancel button. */
061    private Button m_cancelButton;
062
063    /** The dialog context. */
064    private I_CmsDialogContext m_context;
065
066    /**
067     * Creates a new instance.<p>
068     *
069     * @param context the dialog context
070     */
071    public CmsDataViewDialog(I_CmsDialogContext context) {
072
073        m_context = context;
074        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
075        final CmsDataViewParams params = new CmsDataViewParams(context);
076
077        I_CmsDataView example = params.createViewInstance(context.getCms(), A_CmsUI.get().getLocale());
078        final CmsDataViewPanel panel = new CmsDataViewPanel(example, params.isMultiSelect());
079
080        panel.setSizeFull();
081        m_container.addComponent(panel);
082        m_okButton.addClickListener(new ClickListener() {
083
084            private static final long serialVersionUID = 1L;
085
086            @SuppressWarnings("synthetic-access")
087            public void buttonClick(ClickEvent event) {
088
089                List<I_CmsDataViewItem> result = panel.getSelection();
090                String script = params.prepareCallbackScript(result);
091                JavaScript.eval(script);
092                m_context.finish(null);
093
094            }
095        });
096        m_cancelButton.addClickListener(new ClickListener() {
097
098            private static final long serialVersionUID = 1L;
099
100            @SuppressWarnings("synthetic-access")
101            public void buttonClick(ClickEvent event) {
102
103                m_context.finish(null);
104            }
105        });
106    }
107}