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.ade.sitemap.client.hoverbar;
029
030import org.opencms.ade.sitemap.client.CmsSitemapView;
031import org.opencms.ade.sitemap.client.control.CmsSitemapController;
032import org.opencms.ade.sitemap.client.edit.CmsEditEntryHandler;
033import org.opencms.ade.sitemap.shared.CmsClientSitemapEntry;
034import org.opencms.gwt.client.CmsCoreProvider;
035import org.opencms.gwt.client.rpc.CmsRpcAction;
036import org.opencms.gwt.client.seo.CmsSeoOptionsDialog;
037import org.opencms.gwt.client.seo.Messages;
038import org.opencms.gwt.shared.CmsListInfoBean;
039import org.opencms.gwt.shared.alias.CmsAliasBean;
040import org.opencms.util.CmsUUID;
041import org.opencms.xml.content.CmsXmlContentProperty;
042
043import java.util.List;
044import java.util.Map;
045
046import com.google.gwt.user.client.rpc.AsyncCallback;
047
048/**
049 * The context menu entry used for opening the "alias editor" dialog.<p>
050 */
051public class CmsSeoMenuEntry extends A_CmsSitemapMenuEntry {
052
053    /**
054     * Constructor.<p>
055     *
056     * @param hoverbar the hoverbar
057     */
058    public CmsSeoMenuEntry(CmsSitemapHoverbar hoverbar) {
059
060        super(hoverbar);
061        setLabel(org.opencms.gwt.client.seo.Messages.get().key(Messages.GUI_SEO_OPTIONS_0));
062        setActive(true);
063        setVisible(true);
064    }
065
066    /**
067     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#execute()
068     */
069    public void execute() {
070
071        CmsSitemapView view = CmsSitemapView.getInstance();
072        final CmsSitemapController controller = view.getController();
073        String sitePath = getHoverbar().getEntry().getSitePath();
074        CmsClientSitemapEntry entry = controller.getEntry(sitePath);
075        CmsUUID structureId = entry.getDefaultFileId();
076        if (structureId == null) {
077            structureId = entry.getId();
078        }
079        // use another final variable so that we can use it in the callback
080        final CmsUUID constStructureId = structureId;
081        CmsRpcAction<CmsListInfoBean> infoAction = new CmsRpcAction<CmsListInfoBean>() {
082
083            @Override
084            public void execute() {
085
086                start(200, true);
087                CmsCoreProvider.getVfsService().getPageInfo(constStructureId, this);
088            }
089
090            @Override
091            protected void onResponse(final CmsListInfoBean listInfoBean) {
092
093                stop(false);
094                CmsSeoOptionsDialog.loadAliases(constStructureId, new AsyncCallback<List<CmsAliasBean>>() {
095
096                    public void onFailure(Throwable caught) {
097
098                        // do nothing
099                    }
100
101                    public void onSuccess(List<CmsAliasBean> result) {
102
103                        CmsEditEntryHandler handler = new CmsEditEntryHandler(
104                            controller,
105                            getHoverbar().getEntry(),
106                            CmsSitemapView.getInstance().isNavigationMode());
107                        handler.setPageInfo(listInfoBean);
108                        Map<String, CmsXmlContentProperty> propConfig = CmsSitemapView.getInstance().getController().getData().getProperties();
109                        CmsSeoOptionsDialog dialog = new CmsSeoOptionsDialog(
110                            constStructureId,
111                            listInfoBean,
112                            result,
113                            propConfig,
114                            handler);
115                        dialog.center();
116                    }
117
118                });
119
120            }
121
122        };
123        infoAction.execute();
124
125    }
126
127    /**
128     * @see org.opencms.ade.sitemap.client.hoverbar.A_CmsSitemapMenuEntry#onShow()
129     */
130    @Override
131    public void onShow() {
132
133        CmsClientSitemapEntry entry = getHoverbar().getEntry();
134        boolean show = getHoverbar().getController().isEditable()
135            && !CmsSitemapView.getInstance().isSpecialMode()
136            && (entry != null)
137            && entry.isEditable();
138        setVisible(show);
139    }
140}