// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.client.change;

import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.changes.ChangeInfo;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.user.client.ui.Image;

class Reload extends Image implements ClickHandler,
    MouseOverHandler, MouseOutHandler {
  private Change.Id changeId;
  private boolean in;

  Reload() {
    setResource(Resources.I.reload_black());
    addClickHandler(this);
    addMouseOverHandler(this);
    addMouseOutHandler(this);
  }

  void set(ChangeInfo info) {
    changeId = info.legacy_id();
  }

  void reload() {
    Gerrit.display(PageLinks.toChange2(changeId));
  }

  @Override
  public void onMouseOver(MouseOverEvent event) {
    if (!in) {
      in = true;
      setResource(Resources.I.reload_white());
    }
  }

  @Override
  public void onMouseOut(MouseOutEvent event) {
    if (in) {
      in = false;
      setResource(Resources.I.reload_black());
    }
  }

  @Override
  public void onClick(ClickEvent e) {
    e.preventDefault();
    e.stopPropagation();
  }
}

@@ -828,16 +828,55 @@
 Change;%0A
+import com.google.gwt.core.client.GWT;%0A
 import c
@@ -914,24 +914,24 @@
 ClickEvent;%0A
-
 import com.g
@@ -1185,32 +1185,73 @@
 useOverHandler;%0A
+import com.google.gwt.user.client.Event;%0A
 import com.googl
@@ -1277,16 +1277,73 @@
 i.Image;
+%0Aimport com.google.gwt.user.client.ui.impl.HyperlinkImpl;
 %0A%0Aclass 
@@ -1428,16 +1428,93 @@
 ndler %7B%0A
+  private static final HyperlinkImpl link = GWT.create(HyperlinkImpl.class);%0A
   privat
@@ -2199,24 +2199,91 @@
 kEvent e) %7B%0A
+    if (link.handleAsClick(e.getNativeEvent().%3CEvent%3E cast())) %7B%0A  
     e.preven
@@ -2294,16 +2294,18 @@
 ault();%0A
+  
     e.st
@@ -2317,18 +2317,40 @@
 pagation();%0A
+      reload();%0A    %7D%0A
   %7D%0A%7D%0A

Fix reload icon to actually reload onclick