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.gwt.client.ui.contextmenu;
029
030import org.opencms.gwt.client.CmsCoreProvider;
031import org.opencms.gwt.client.rpc.CmsRpcAction;
032import org.opencms.gwt.client.util.CmsJsUtil;
033import org.opencms.gwt.shared.CmsContextMenuEntryBean;
034import org.opencms.util.CmsUUID;
035
036/**
037 * Provides a method to open the workplace.<p>
038 *
039 * @since 8.0.0
040 */
041public final class CmsShowWorkplace implements I_CmsHasContextMenuCommand {
042
043    /**
044     * Hidden utility class constructor.<p>
045     */
046    private CmsShowWorkplace() {
047
048        // nothing to do
049    }
050
051    /**
052     * Returns the context menu command according to
053     * {@link org.opencms.gwt.client.ui.contextmenu.I_CmsHasContextMenuCommand}.<p>
054     *
055     * @return the context menu command
056     */
057    public static I_CmsContextMenuCommand getContextMenuCommand() {
058
059        return new I_CmsContextMenuCommand() {
060
061            public void execute(CmsUUID structureId, I_CmsContextMenuHandler handler, CmsContextMenuEntryBean bean) {
062
063                openWorkplace(structureId, false);
064            }
065
066            public A_CmsContextMenuItem getItemWidget(
067                CmsUUID structureId,
068                I_CmsContextMenuHandler handler,
069                CmsContextMenuEntryBean bean) {
070
071                return null;
072            }
073
074            public boolean hasItemWidget() {
075
076                return false;
077            }
078        };
079    }
080
081    /**
082     * Opens the workplace.<p>
083     *
084     * @param structureId the structure id of the resource for which the workplace should be opened
085     * @param classic if true, opens the old workplace, else the new workplace
086     */
087    public static void openWorkplace(final CmsUUID structureId, final boolean classic) {
088
089        CmsRpcAction<String> callback = new CmsRpcAction<String>() {
090
091            /**
092             * @see org.opencms.gwt.client.rpc.CmsRpcAction#execute()
093             */
094            @Override
095            public void execute() {
096
097                start(0, true);
098                CmsCoreProvider.getService().getWorkplaceLink(structureId, this);
099            }
100
101            /**
102             * @see org.opencms.gwt.client.rpc.CmsRpcAction#onResponse(java.lang.Object)
103             */
104            @Override
105            protected void onResponse(String result) {
106
107                stop(false);
108                CmsJsUtil.forceLoadUri(result);
109            }
110        };
111        callback.execute();
112    }
113}