001/*
002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     troger
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.annotations.gwt.client.view;
021
022import org.nuxeo.ecm.platform.annotations.gwt.client.controler.AnnotationController;
023
024import com.google.gwt.dom.client.IFrameElement;
025import com.google.gwt.user.client.ui.Frame;
026import com.google.gwt.user.client.ui.ToggleButton;
027
028/**
029 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
030 */
031public class HideManagerButton extends ToggleButton {
032
033    private static final String CLASS_NAME = "hideManagerButton";
034
035    private boolean show = true;
036
037    private AnnotationManagerPanel panel;
038
039    private AnnotationController controller;
040
041    private IFrameElement previewFrame;
042
043    public HideManagerButton(AnnotationController controller, AnnotationManagerPanel panel, Frame previewFrame) {
044        super();
045        this.controller = controller;
046        this.panel = panel;
047        this.previewFrame = IFrameElement.as(previewFrame.getElement());
048        setStyleName(CLASS_NAME);
049        setDown(!show);
050    }
051
052    @Override
053    protected void onClick() {
054        super.onClick();
055        show = !isDown();
056        panel.setVisible(show);
057        reloadPreviewFrame();
058        NewAnnotationPopup popup = controller.getNewAnnotationPopup();
059        if (popup != null) {
060            popup.cancel();
061        }
062    }
063
064    private void reloadPreviewFrame() {
065        String src = previewFrame.getSrc();
066        previewFrame.setSrc(src);
067    }
068
069}