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.ade.containerpage.client.ui;
029
030import org.opencms.ade.containerpage.client.Messages;
031import org.opencms.ade.contenteditor.shared.CmsEditorConstants;
032import org.opencms.gwt.client.CmsCoreProvider;
033import org.opencms.gwt.client.rpc.CmsRpcAction;
034import org.opencms.gwt.client.ui.CmsCreateModeSelectionDialog;
035import org.opencms.gwt.client.ui.I_CmsButton.ButtonColor;
036import org.opencms.gwt.shared.CmsListInfoBean;
037import org.opencms.util.CmsUUID;
038
039import com.google.gwt.user.client.rpc.AsyncCallback;
040
041/**
042 * Dialog for selecting between copying and reusing an element dropped from the clipboard into the page.<p>
043 */
044public class CmsDroppedElementModeSelectionDialog extends CmsCreateModeSelectionDialog {
045
046    /**
047     * Creates a new instance.<p>
048     *
049     * @param info the file information
050     *
051     * @param createModeCallback the callback to call with the result
052     */
053    public CmsDroppedElementModeSelectionDialog(CmsListInfoBean info, AsyncCallback<String> createModeCallback) {
054
055        super(info, createModeCallback);
056    }
057
058    /**
059     * Shows the dialog.<p>
060     *
061     * @param referenceId the  structure id of the resource for which to load the dialog
062     * @param createModeCallback the callback to call with the result
063     */
064    public static void showDialog(final CmsUUID referenceId, final AsyncCallback<String> createModeCallback) {
065
066        CmsRpcAction<CmsListInfoBean> action = new CmsRpcAction<CmsListInfoBean>() {
067
068            @Override
069            public void execute() {
070
071                start(0, true);
072                CmsCoreProvider.getVfsService().getPageInfo(referenceId, this);
073
074            }
075
076            @Override
077            protected void onResponse(CmsListInfoBean result) {
078
079                stop(false);
080                (new CmsDroppedElementModeSelectionDialog(result, createModeCallback)).center();
081            }
082        };
083        action.execute();
084
085    }
086
087    /**
088     * @see org.opencms.gwt.client.ui.CmsCreateModeSelectionDialog#messageAskMode()
089     */
090    @Override
091    public String messageAskMode() {
092
093        return Messages.get().key(Messages.GUI_SELECT_COPY_OR_REUSE_TEXT_0);
094    }
095
096    /**
097     * @see org.opencms.gwt.client.ui.CmsCreateModeSelectionDialog#messageCaption()
098     */
099    @Override
100    public String messageCaption() {
101
102        return Messages.get().key(Messages.GUI_SELECT_COPY_OR_REUSE_CAPTION_0);
103    }
104
105    /**
106     * @see org.opencms.gwt.client.ui.CmsCreateModeSelectionDialog#messageCopy()
107     */
108    @Override
109    public String messageCopy() {
110
111        return Messages.get().key(Messages.GUI_COPY_ELEMENT_0);
112    }
113
114    /**
115     * @see org.opencms.gwt.client.ui.CmsCreateModeSelectionDialog#messageNew()
116     */
117    @Override
118    public String messageNew() {
119
120        return Messages.get().key(Messages.GUI_REUSE_ELEMENT_0);
121
122    }
123
124    /**
125     * @see org.opencms.gwt.client.ui.CmsCreateModeSelectionDialog#addButtons()
126     */
127    @Override
128    protected void addButtons() {
129
130        addButton(createButton(messageNew(), ButtonColor.BLUE, CmsEditorConstants.MODE_REUSE));
131        addButton(createButton(messageCopy(), ButtonColor.GREEN, CmsEditorConstants.MODE_COPY));
132
133    }
134
135}