/*
 * Copyright 2000-2016 JetBrains s.r.o.
 *
 * 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.intellij.vcs.log.ui.history;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import com.intellij.ui.JBSplitter;
import com.intellij.ui.OnePixelSplitter;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.SideBorder;
import com.intellij.vcs.log.data.VcsLogData;
import com.intellij.vcs.log.ui.frame.DetailsPanel;
import com.intellij.vcs.log.ui.table.VcsLogGraphTable;
import com.intellij.vcs.log.visible.VisiblePack;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;

public class FileHistoryPanel extends JPanel implements Disposable {
  @NotNull private final VcsLogGraphTable myGraphTable;
  @NotNull private final DetailsPanel myDetailsPanel;
  @NotNull private final JBSplitter myDetailsSplitter;
  @NotNull private final VcsLogData myLogData;

  @NotNull private Runnable myContainingBranchesListener;
  @NotNull private Runnable myMiniDetailsLoadedListener;

  public FileHistoryPanel(@NotNull FileHistoryUi ui, @NotNull VcsLogData logData, @NotNull VisiblePack visiblePack) {
    myLogData = logData;
    myGraphTable = new VcsLogGraphTable(ui, logData, visiblePack);
    myDetailsPanel = new DetailsPanel(logData, ui.getColorManager(), this);

    myDetailsSplitter = new OnePixelSplitter(true, "vcs.log.history.details.splitter.proportion", 0.7f);
    myDetailsSplitter.setFirstComponent(setupScrolledGraph());
    myDetailsSplitter.setSecondComponent(ui.isShowDetails() ? myDetailsPanel : null);

    myDetailsPanel.installCommitSelectionListener(myGraphTable);
    updateWhenDetailsAreLoaded();

    setLayout(new BorderLayout());
    add(myDetailsSplitter, BorderLayout.CENTER);

    Disposer.register(ui, this);
  }

  @NotNull
  private JScrollPane setupScrolledGraph() {
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myGraphTable, SideBorder.TOP);
    myGraphTable.viewportSet(scrollPane.getViewport());
    return scrollPane;
  }

  private void updateWhenDetailsAreLoaded() {
    myMiniDetailsLoadedListener = () -> {
      myGraphTable.initColumnSize();
      myGraphTable.repaint();
    };
    myContainingBranchesListener = () -> {
      myDetailsPanel.branchesChanged();
      myGraphTable.repaint(); // we may need to repaint highlighters
    };
    myLogData.getMiniDetailsGetter().addDetailsLoadedListener(myMiniDetailsLoadedListener);
    myLogData.getContainingBranchesGetter().addTaskCompletedListener(myContainingBranchesListener);
  }

  @NotNull
  public VcsLogGraphTable getGraphTable() {
    return myGraphTable;
  }

  public void updateDataPack(@NotNull VisiblePack visiblePack, boolean permanentGraphChanged) {
    myGraphTable.updateDataPack(visiblePack, permanentGraphChanged);
  }

  public void showDetails(boolean show) {
    myDetailsSplitter.setSecondComponent(show ? myDetailsPanel : null);
  }

  @Override
  public void dispose() {
    myLogData.getMiniDetailsGetter().removeDetailsLoadedListener(myMiniDetailsLoadedListener);
    myLogData.getContainingBranchesGetter().removeTaskCompletedListener(myContainingBranchesListener);

    myDetailsSplitter.dispose();
  }
}

@@ -672,24 +672,82 @@
 Disposable;%0A
+import com.intellij.openapi.progress.util.ProgressWindow;%0A
 import com.i
@@ -773,24 +773,24 @@
 l.Disposer;%0A
-
 import com.i
@@ -975,16 +975,65 @@
 ogData;%0A
+import com.intellij.vcs.log.data.VcsLogProgress;%0A
 import c
@@ -1075,16 +1075,69 @@
 sPanel;%0A
+import com.intellij.vcs.log.ui.frame.ProgressStripe;%0A
 import c
@@ -1998,24 +1998,689 @@
 (), this);%0A%0A
+    ProgressStripe progressStripe =%0A      new ProgressStripe(setupScrolledGraph(), this, ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS) %7B%0A        @Override%0A        public void updateUI() %7B%0A          super.updateUI();%0A          if (myDecorator != null && myLogData.getProgress().isRunning()) startLoadingImmediately();%0A        %7D%0A      %7D;%0A    myLogData.getProgress().addProgressIndicatorListener(new VcsLogProgress.ProgressListener() %7B%0A      @Override%0A      public void progressStarted() %7B%0A        progressStripe.startLoading();%0A      %7D%0A%0A      @Override%0A      public void progressStopped() %7B%0A        progressStripe.stopLoading();%0A      %7D%0A    %7D, this);%0A%0A
     myDetail
@@ -2812,36 +2812,30 @@
 mponent(
-setupScrolledGraph()
+progressStripe
 );%0A    m

add progress indicator