001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (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.gwt.client.ui.contextmenu;
029
030import org.opencms.gwt.client.CmsCoreProvider;
031import org.opencms.gwt.client.property.CmsSimplePropertyEditorHandler;
032import org.opencms.gwt.client.rpc.CmsRpcAction;
033import org.opencms.gwt.client.seo.CmsSeoOptionsDialog;
034import org.opencms.gwt.client.util.I_CmsSimpleCallback;
035import org.opencms.gwt.shared.CmsContextMenuEntryBean;
036import org.opencms.gwt.shared.CmsListInfoBean;
037import org.opencms.gwt.shared.alias.CmsAliasBean;
038import org.opencms.gwt.shared.property.CmsPropertiesBean;
039import org.opencms.util.CmsUUID;
040
041import java.util.List;
042
043import com.google.gwt.user.client.rpc.AsyncCallback;
044
045/**
046 * The context menu command to open the SEO dialog from the container page editor.<p>
047 */
048public class CmsOpenSeoDialog implements I_CmsHasContextMenuCommand, I_CmsContextMenuCommand {
049
050    /**
051     * Returns the context menu command according to
052     * {@link org.opencms.gwt.client.ui.contextmenu.I_CmsHasContextMenuCommand}.<p>
053     *
054     * @return the context menu command
055     */
056    public static I_CmsContextMenuCommand getContextMenuCommand() {
057
058        return new CmsOpenSeoDialog();
059    }
060
061    /**
062     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuCommand#execute(org.opencms.util.CmsUUID, org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler, org.opencms.gwt.shared.CmsContextMenuEntryBean)
063     */
064    public void execute(
065        final CmsUUID structureId,
066        final I_CmsContextMenuHandler contextMenuHandler,
067        final CmsContextMenuEntryBean bean) {
068
069        contextMenuHandler.ensureLockOnResource(structureId, new I_CmsSimpleCallback<Boolean>() {
070
071            public void execute(Boolean arg) {
072
073                if (arg.booleanValue()) {
074                    CmsRpcAction<CmsPropertiesBean> action = new CmsRpcAction<CmsPropertiesBean>() {
075
076                        @Override
077                        public void execute() {
078
079                            start(0, true);
080                            CmsCoreProvider.getVfsService().loadPropertyData(structureId, this);
081                        }
082
083                        @Override
084                        protected void onResponse(final CmsPropertiesBean propertyData) {
085
086                            stop(false);
087                            CmsRpcAction<CmsListInfoBean> infoAction = new CmsRpcAction<CmsListInfoBean>() {
088
089                                @Override
090                                public void execute() {
091
092                                    start(200, true);
093                                    CmsCoreProvider.getVfsService().getPageInfo(structureId, this);
094                                }
095
096                                @Override
097                                protected void onResponse(final CmsListInfoBean listInfoBean) {
098
099                                    stop(false);
100                                    CmsSeoOptionsDialog.loadAliases(
101                                        structureId,
102                                        new AsyncCallback<List<CmsAliasBean>>() {
103
104                                            public void onFailure(Throwable caught) {
105
106                                                // do nothing
107                                            }
108
109                                            public void onSuccess(final List<CmsAliasBean> aliases) {
110
111                                                CmsSimplePropertyEditorHandler handler = new CmsSimplePropertyEditorHandler(
112                                                    contextMenuHandler);
113                                                handler.setPropertiesBean(propertyData);
114                                                CmsSeoOptionsDialog dialog = new CmsSeoOptionsDialog(
115                                                    structureId,
116                                                    listInfoBean,
117                                                    aliases,
118                                                    propertyData.getPropertyDefinitions(),
119                                                    handler);
120                                                dialog.centerHorizontally(50);
121                                                dialog.catchNotifications();
122                                                dialog.center();
123                                            }
124                                        });
125                                }
126                            };
127                            infoAction.execute();
128
129                        }
130                    };
131                    action.execute();
132                }
133            }
134        });
135    }
136
137    /**
138     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuCommand#getItemWidget(org.opencms.util.CmsUUID, org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler, org.opencms.gwt.shared.CmsContextMenuEntryBean)
139     */
140    public A_CmsContextMenuItem getItemWidget(
141        CmsUUID structureId,
142        I_CmsContextMenuHandler handler,
143        CmsContextMenuEntryBean bean) {
144
145        return null;
146    }
147
148    /**
149     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuCommand#hasItemWidget()
150     */
151    public boolean hasItemWidget() {
152
153        return false;
154    }
155
156}