/*
 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     troger
 *
 * $Id$
 */

package org.nuxeo.ecm.platform.annotations.gwt.client.view;

import org.nuxeo.ecm.platform.annotations.gwt.client.controler.AnnotationController;
import org.nuxeo.ecm.platform.annotations.gwt.client.view.i18n.TranslationConstants;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
 *
 */
public class HideShowAnnotationsButton extends Composite {

    public HideShowAnnotationsButton(
            final AnnotationController annotationController) {
        final TranslationConstants translationConstants = GWT.create(TranslationConstants.class);
        final ToggleButton button = new ToggleButton(
                annotationController.isAnnotationsVisible() ? translationConstants.hideAnnotations()
                        : translationConstants.showAnnotations());
        button.setStyleName("annotation-hide-show-button");
        button.setDown(!annotationController.isAnnotationsVisible());

        button.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                if (!button.isDown()) {
                    button.setTitle(translationConstants.hideAnnotations());
                    button.setText(translationConstants.hideAnnotations());
                    showAnnotations();
                } else {
                    button.setTitle(translationConstants.showAnnotations());
                    button.setText(translationConstants.showAnnotations());
                    hideAnnotations();
                }
            }
        });

        initWidget(button);
    }

    private native void showAnnotations() /*-{
        if (typeof top['showAnnotations'] != "undefined") {
            top['showAnnotations']();
        }
    }-*/;

    private native void hideAnnotations() /*-{
        if (typeof top['hideAnnotations'] != "undefined") {
            top['hideAnnotations']();
        }
    }-*/;

}

@@ -707,16 +707,120 @@
 .view;%0A%0A
+import com.google.gwt.event.dom.client.ClickEvent;%0Aimport com.google.gwt.event.dom.client.ClickHandler;%0A
 import o
@@ -1623,54 +1623,8 @@
     
- annotationController.isAnnotationsVisible() ?
  tra
@@ -1633,36 +1633,36 @@
 lationConstants.
-hide
+show
 Annotations()%0A  
@@ -1658,19 +1658,18 @@
 ations()
+,
 %0A
-  
         
@@ -1679,16 +1679,8 @@
     
-       :
  tra
@@ -1689,36 +1689,36 @@
 lationConstants.
-show
+hide
 Annotations());%0A
@@ -1800,17 +1800,16 @@
 setDown(
-!
 annotati
@@ -1846,17 +1846,16 @@
 ble());%0A
-%0A
         
@@ -1869,22 +1869,21 @@
 addClick
-Listen
+Handl
 er(new C
@@ -1890,21 +1890,42 @@
 lick
-Listen
+Handl
 er() %7B%0A
+            @Override%0A
     
@@ -1956,21 +1956,24 @@
 ick(
-Widget sender
+ClickEvent event
 ) %7B%0A
@@ -1992,17 +1992,16 @@
     if (
-!
 button.i
@@ -2035,357 +2035,51 @@
     
-button.setTitle(translationConstants.hideAnnotations());%0A                    button.setText(translationConstants.hideAnnotations());%0A                    showAnnotations();%0A                %7D else %7B%0A                    button.setTitle(translationConstants.showAnnotations());%0A                    button.setText(translationConstants.showAnnotations());
+showAnnotations();%0A                %7D else %7B
 %0A   
@@ -2158,17 +2158,16 @@
     %7D);%0A
-%0A
         

fix hide/show annotations behaviour