public void insertTab(
      final VirtualFile file,
      final Icon icon,
      final JComponent comp,
      final String tooltip,
      final int indexToInsert) {

    TabInfo tab = myTabs.findInfo(file);
    if (tab != null) return;

    tab =
        new TabInfo(comp)
            .setText(calcTabTitle(myProject, file))
            .setIcon(icon)
            .setTooltipText(tooltip)
            .setObject(file)
            .setTabColor(calcTabColor(myProject, file))
            .setDragOutDelegate(myDragOutDelegate);
    tab.setTestableUi(new MyQueryable(tab));

    final DefaultActionGroup tabActions = new DefaultActionGroup();
    tabActions.add(new CloseTab(comp, tab));

    tab.setTabLabelActions(tabActions, ActionPlaces.EDITOR_TAB);
    myTabs.addTab(tab, indexToInsert);
  }
 @Override
 public void mouseClicked(MouseEvent e) {
   if (UIUtil.isActionClick(e, MouseEvent.MOUSE_CLICKED)
       && (e.isMetaDown() || (!SystemInfo.isMac && e.isControlDown()))) {
     final TabInfo info = myTabs.findInfo(e);
     if (info != null && info.getObject() != null) {
       final VirtualFile vFile = (VirtualFile) info.getObject();
       ShowFilePathAction.show(vFile, e);
     }
   }
 }
 @Override
 public void mouseReleased(MouseEvent e) {
   if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) {
     final TabInfo info = myTabs.findInfo(e);
     if (info != null) {
       IdeEventQueue.getInstance().blockNextEvents(e);
       FileEditorManagerEx.getInstanceEx(myProject)
           .closeFile((VirtualFile) info.getObject(), myWindow);
     }
   }
 }
 public ActionCallback removeTabAt(
     final int componentIndex, int indexToSelect, boolean transferFocus) {
   TabInfo toSelect =
       indexToSelect >= 0 && indexToSelect < myTabs.getTabCount()
           ? myTabs.getTabAt(indexToSelect)
           : null;
   final TabInfo info = myTabs.getTabAt(componentIndex);
   // removing hidden tab happens on end of drag-out, we've already selected the correct tab for
   // this case in dragOutStarted
   if (info.isHidden()) {
     toSelect = null;
   }
   final ActionCallback callback = myTabs.removeTab(info, toSelect, transferFocus);
   return myProject.isOpen() ? callback : new ActionCallback.Done();
 }
    @Override
    public void dragOutStarted(MouseEvent mouseEvent, TabInfo info) {
      final TabInfo previousSelection = info.getPreviousSelection();
      final Image img = myTabs.getComponentImage(info);
      info.setHidden(true);
      if (previousSelection != null) {
        myTabs.select(previousSelection, true);
      }

      myFile = (VirtualFile) info.getObject();
      Presentation presentation = new Presentation(info.getText());
      presentation.setIcon(info.getIcon());
      mySession =
          getDockManager()
              .createDragSession(
                  mouseEvent, new DockableEditor(img, myFile, presentation, myWindow));
    }
 public List<SwitchTarget> getTargets(final boolean onlyVisible, boolean originalProvider) {
   final ArrayList<SwitchTarget> result = new ArrayList<SwitchTarget>();
   TabInfo selected = myTabs.getSelectedInfo();
   new AwtVisitor(selected.getComponent()) {
     @Override
     public boolean visit(Component component) {
       if (component instanceof JBTabs) {
         JBTabs tabs = (JBTabs) component;
         if (tabs != myTabs) {
           result.addAll(tabs.getTargets(onlyVisible, false));
           return true;
         }
       }
       return false;
     }
   };
   return result;
 }
    @Override
    public void dragOutCancelled(TabInfo source) {
      source.setHidden(false);
      if (mySession != null) {
        mySession.cancel();
      }

      myFile = null;
      mySession = null;
    }
    public SwitchTarget getCurrentTarget() {
      TabInfo selected = myTabs.getSelectedInfo();
      final Ref<SwitchTarget> targetRef = new Ref<SwitchTarget>();
      new AwtVisitor(selected.getComponent()) {
        @Override
        public boolean visit(Component component) {
          if (component instanceof JBTabs) {
            JBTabs tabs = (JBTabs) component;
            if (tabs != myTabs) {
              targetRef.set(tabs.getCurrentTarget());
              return true;
            }
          }
          return false;
        }
      };

      return targetRef.get();
    }
  public void close() {
    TabInfo selected = myTabs.getTargetInfo();
    if (selected == null) return;

    final VirtualFile file = (VirtualFile) selected.getObject();
    final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject);

    AsyncResult<EditorWindow> window = mgr.getActiveWindow();
    window.doWhenDone(
        new AsyncResult.Handler<EditorWindow>() {
          @Override
          public void run(EditorWindow wnd) {
            if (wnd != null) {
              if (wnd.findFileComposite(file) != null) {
                mgr.closeFile(file, wnd);
              }
            }
          }
        });
  }
    @Override
    public void dragOutFinished(MouseEvent event, TabInfo source) {
      boolean copy = event.isMetaDown() || (!SystemInfo.isMac && event.isControlDown());
      if (!copy) {
        myFile.putUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN, Boolean.TRUE);
        FileEditorManagerEx.getInstanceEx(myProject).closeFile(myFile, myWindow);
      } else {
        source.setHidden(false);
      }

      mySession.process(event);
      if (!copy) {
        myFile.putUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN, null);
      }

      myFile = null;
      mySession = null;
    }
    public void actionPerformed(final AnActionEvent e) {
      final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject);
      EditorWindow window;
      final VirtualFile file = (VirtualFile) myTabInfo.getObject();
      if (ActionPlaces.EDITOR_TAB.equals(e.getPlace())) {
        window = myWindow;
      } else {
        window = mgr.getCurrentWindow();
      }

      if (window != null) {
        if ((e.getModifiers() & InputEvent.ALT_MASK) != 0) {
          window.closeAllExcept(file);
        } else {
          if (window.findFileComposite(file) != null) {
            mgr.closeFile(file, window);
          }
        }
      }
    }
 public Component getComponentAt(final int i) {
   final TabInfo tab = myTabs.getTabAt(i);
   return tab.getComponent();
 }
 public void putInfo(@NotNull Map<String, String> info) {
   info.put("editorTab", myTab.getText());
 }
 @Nullable
 public Object getSelectedComponent() {
   final TabInfo info = myTabs.getTargetInfo();
   return info != null ? info.getComponent() : null;
 }
 public void setWaveColor(final int index, @Nullable final Color color) {
   final TabInfo tab = myTabs.getTabAt(index);
   tab.setDefaultStyle(
       color == null ? SimpleTextAttributes.STYLE_PLAIN : SimpleTextAttributes.STYLE_WAVED);
   tab.setDefaultWaveColor(color);
 }