/*
 * 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.actions;

import com.intellij.ide.actions.CloseTabToolbarAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.ContentManager;
import com.intellij.ui.content.TabbedContent;
import com.intellij.util.ContentUtilEx;
import com.intellij.vcs.log.impl.VcsLogContentProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class CloseLogTabAction extends CloseTabToolbarAction {
  @Override
  public void update(@NotNull AnActionEvent e) {
    super.update(e);
    if (e.getProject() == null) {
      e.getPresentation().setEnabledAndVisible(false);
      return;
    }
    if (getTabbedContent(getContentManager(e.getProject())) == null) {
      e.getPresentation().setEnabledAndVisible(false);
      return;
    }
    e.getPresentation().setEnabledAndVisible(true);
  }

  public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    assert project != null;

    ContentManager contentManager = getContentManager(project);
    TabbedContent tabbedContent = getTabbedContent(contentManager);
    if (tabbedContent == null) return;

    if (tabbedContent.getTabs().size() > 1) {
      JComponent component = tabbedContent.getComponent();
      tabbedContent.removeContent(component);
      contentManager.setSelectedContent(tabbedContent, true, true);
    }
    else {
      contentManager.removeContent(tabbedContent, true);
    }
  }

  @Nullable
  private static TabbedContent getTabbedContent(@NotNull ContentManager contentManager) {
    TabbedContent tabbedContent = ContentUtilEx.findTabbedContent(contentManager, VcsLogContentProvider.TAB_NAME);
    if (tabbedContent != contentManager.getSelectedContent()) return null;
    return tabbedContent;
  }

  @NotNull
  private static ContentManager getContentManager(@NotNull Project project) {
    return ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.VCS).getContentManager();
  }
}

@@ -792,16 +792,59 @@
 roject;%0A
+import com.intellij.openapi.wm.ToolWindow;%0A
 import c
@@ -880,16 +880,16 @@
 ndowId;%0A
-
 import c
@@ -1490,29 +1490,40 @@
     
-if (getTabbedContent(
+ContentManager contentManager = 
 getC
@@ -1551,16 +1551,83 @@
 oject())
+;%0A    if (contentManager == null %7C%7C getTabbedContent(contentManager
 ) == nul
@@ -1948,24 +1948,64 @@
 r(project);%0A
+    if (contentManager == null) return;%0A
     TabbedCo
@@ -2731,22 +2731,23 @@
  %7D%0A%0A  @N
-otN
 ull
+able
 %0A  priva
@@ -2821,22 +2821,39 @@
 ) %7B%0A    
-return
+ToolWindow toolWindow =
  ToolWin
@@ -2915,16 +2915,80 @@
 wId.VCS)
+;%0A    if (toolWindow == null) return null;%0A    return toolWindow
 .getCont

fix actions test