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;
023import org.nuxeo.ecm.platform.annotations.gwt.client.view.i18n.TranslationConstants;
024
025import com.google.gwt.core.client.GWT;
026import com.google.gwt.event.dom.client.ClickEvent;
027import com.google.gwt.event.dom.client.ClickHandler;
028import com.google.gwt.user.client.ui.Composite;
029import com.google.gwt.user.client.ui.ToggleButton;
030
031/**
032 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
033 */
034public class HideShowAnnotationsButton extends Composite {
035
036    public HideShowAnnotationsButton(final AnnotationController annotationController) {
037        final TranslationConstants translationConstants = GWT.create(TranslationConstants.class);
038        final ToggleButton button = new ToggleButton(translationConstants.showAnnotations(),
039                translationConstants.hideAnnotations());
040        button.setStyleName("annotation-hide-show-button");
041        button.setDown(annotationController.isAnnotationsVisible());
042        button.addClickHandler(new ClickHandler() {
043            @Override
044            public void onClick(ClickEvent event) {
045                if (button.isDown()) {
046                    showAnnotations();
047                } else {
048                    hideAnnotations();
049                }
050            }
051        });
052        initWidget(button);
053    }
054
055    private native void showAnnotations() /*-{
056                                          if (typeof top['showAnnotations'] != "undefined") {
057                                          top['showAnnotations']();
058                                          }
059                                          }-*/;
060
061    private native void hideAnnotations() /*-{
062                                          if (typeof top['hideAnnotations'] != "undefined") {
063                                          top['hideAnnotations']();
064                                          }
065                                          }-*/;
066
067}