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.client;
029
030import org.opencms.gwt.client.ui.contextmenu.CmsContextMenuButton;
031import org.opencms.gwt.client.ui.contextmenu.CmsContextMenuHandler;
032import org.opencms.gwt.shared.CmsCoreData.AdeContext;
033import org.opencms.ui.components.CmsGwtContextMenuButton;
034import org.opencms.ui.shared.components.CmsGwtContextMenuButtonState;
035import org.opencms.ui.shared.rpc.I_CmsGwtContextMenuServerRpc;
036import org.opencms.util.CmsUUID;
037
038import com.vaadin.client.communication.StateChangeEvent;
039import com.vaadin.client.ui.AbstractComponentConnector;
040import com.vaadin.shared.ui.Connect;
041
042/**
043 * Connector for using the GWT based context menu buttons as Vaadin widgets.
044 */
045@Connect(CmsGwtContextMenuButton.class)
046public class CmsGwtContextMenuButtonConnector extends AbstractComponentConnector {
047
048    /** Serial version id. */
049    private static final long serialVersionUID = 1L;
050
051    /**
052     * @see com.vaadin.client.ui.AbstractComponentConnector#getState()
053     */
054    @Override
055    public CmsGwtContextMenuButtonState getState() {
056
057        return (CmsGwtContextMenuButtonState)super.getState();
058    }
059
060    /**
061     * @see com.vaadin.client.ui.AbstractComponentConnector#getWidget()
062     */
063    @Override
064    public CmsContextMenuButton getWidget() {
065
066        return (CmsContextMenuButton)super.getWidget();
067    }
068
069    /**
070     * @see com.vaadin.client.ui.AbstractComponentConnector#onStateChanged(com.vaadin.client.communication.StateChangeEvent)
071     */
072    @Override
073    public void onStateChanged(StateChangeEvent stateChangeEvent) {
074
075        super.onStateChanged(stateChangeEvent);
076    }
077
078    /**
079     * @see com.vaadin.client.ui.AbstractComponentConnector#createWidget()
080     */
081    @Override
082    protected CmsContextMenuButton createWidget() {
083
084        CmsGwtContextMenuButtonState state = getState();
085        final I_CmsGwtContextMenuServerRpc rpc = getRpcProxy(I_CmsGwtContextMenuServerRpc.class);
086        CmsContextMenuButton result = new CmsContextMenuButton(
087            new CmsUUID(state.getStructureId()),
088            new CmsContextMenuHandler() {
089
090                @Override
091                public void refreshResource(CmsUUID structureId) {
092
093                    rpc.refresh("" + structureId);
094                }
095            },
096            AdeContext.resourceinfo);
097        if (state.styles != null) {
098            for (String s : state.styles) {
099                // onStateChanged apparently isn't called for the initial state, so set the styles manually here.
100                // There may be a better way to handle this, but I haven't found one.
101                result.addStyleName(s);
102            }
103        }
104        return result;
105    }
106
107}