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);
  }
 public void setTabLayoutPolicy(final int policy) {
   switch (policy) {
     case JTabbedPane.SCROLL_TAB_LAYOUT:
       myTabs.getPresentation().setSingleRow(true);
       break;
     case JTabbedPane.WRAP_TAB_LAYOUT:
       myTabs.getPresentation().setSingleRow(false);
       break;
     default:
       throw new IllegalArgumentException("Unsupported tab layout policy: " + policy);
   }
 }
 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();
 }
 public void setTabPlacement(final int tabPlacement) {
   switch (tabPlacement) {
     case SwingConstants.TOP:
       myTabs.getPresentation().setTabsPosition(JBTabsPosition.top);
       break;
     case SwingConstants.BOTTOM:
       myTabs.getPresentation().setTabsPosition(JBTabsPosition.bottom);
       break;
     case SwingConstants.LEFT:
       myTabs.getPresentation().setTabsPosition(JBTabsPosition.left);
       break;
     case SwingConstants.RIGHT:
       myTabs.getPresentation().setTabsPosition(JBTabsPosition.right);
       break;
     default:
       throw new IllegalArgumentException("Unknown tab placement code=" + tabPlacement);
   }
 }
  private void updateTabBorder() {
    if (!myProject.isOpen()) return;

    ToolWindowManagerEx mgr = (ToolWindowManagerEx) ToolWindowManager.getInstance(myProject);

    String[] ids = mgr.getToolWindowIds();

    Insets border = new Insets(0, 0, 0, 0);

    UISettings uiSettings = UISettings.getInstance();

    List<String> topIds = mgr.getIdsOn(ToolWindowAnchor.TOP);
    List<String> bottom = mgr.getIdsOn(ToolWindowAnchor.BOTTOM);
    List<String> rightIds = mgr.getIdsOn(ToolWindowAnchor.RIGHT);
    List<String> leftIds = mgr.getIdsOn(ToolWindowAnchor.LEFT);

    if (!uiSettings.HIDE_TOOL_STRIPES) {
      border.top = topIds.size() > 0 ? 1 : 0;
      border.bottom = bottom.size() > 0 ? 1 : 0;
      border.left = leftIds.size() > 0 ? 1 : 0;
      border.right = rightIds.size() > 0 ? 1 : 0;
    }

    for (String each : ids) {
      ToolWindow eachWnd = mgr.getToolWindow(each);
      if (!eachWnd.isAvailable()) continue;

      if (eachWnd.isVisible() && eachWnd.getType() == ToolWindowType.DOCKED) {
        ToolWindowAnchor eachAnchor = eachWnd.getAnchor();
        if (eachAnchor == ToolWindowAnchor.TOP) {
          border.top = 0;
        } else if (eachAnchor == ToolWindowAnchor.BOTTOM) {
          border.bottom = 0;
        } else if (eachAnchor == ToolWindowAnchor.LEFT) {
          border.left = 0;
        } else if (eachAnchor == ToolWindowAnchor.RIGHT) {
          border.right = 0;
        }
      }
    }

    myTabs
        .getPresentation()
        .setPaintBorder(border.top, border.left, border.right, border.bottom)
        .setTabSidePaintBorder(5);
  }
  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);
              }
            }
          }
        });
  }
 @Nullable
 public Object getSelectedComponent() {
   final TabInfo info = myTabs.getTargetInfo();
   return info != null ? info.getComponent() : null;
 }
 public void setBackgroundColorAt(final int index, final Color color) {
   myTabs.getTabAt(index).setTabColor(color);
 }
 public ActionCallback setSelectedIndex(final int indexToSelect, boolean focusEditor) {
   return myTabs.select(myTabs.getTabAt(indexToSelect), focusEditor);
 }
 public void requestFocus(boolean forced) {
   if (myTabs != null) {
     IdeFocusManager.getInstance(myProject).requestFocus(myTabs.getComponent(), forced);
   }
 }
 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);
 }
 public void setForegroundAt(final int index, final Color color) {
   myTabs.getTabAt(index).setDefaultForeground(color);
 }
 public int getSelectedIndex() {
   return myTabs.getIndexOf(myTabs.getSelectedInfo());
 }
 public Component getComponent() {
   return myTabs.getComponent();
 }
 public void setIconAt(final int index, final Icon icon) {
   myTabs.getTabAt(index).setIcon(icon);
 }
 public boolean isEmptyVisible() {
   return myTabs.isEmptyVisible();
 }
 public void setTitleAt(final int index, final String text) {
   myTabs.getTabAt(index).setText(text);
 }
 public Component getComponentAt(final int i) {
   final TabInfo tab = myTabs.getTabAt(i);
   return tab.getComponent();
 }
 public void setToolTipTextAt(final int index, final String text) {
   myTabs.getTabAt(index).setTooltipText(text);
 }
  EditorTabbedContainer(final EditorWindow window, Project project, final int tabPlacement) {
    myWindow = window;
    myProject = project;
    final ActionManager actionManager = ActionManager.getInstance();
    myTabs = new JBEditorTabs(project, actionManager, IdeFocusManager.getInstance(project), this);
    myTabs
        .setDataProvider(new MyDataProvider())
        .setPopupGroup(
            new Getter<ActionGroup>() {
              public ActionGroup get() {
                return (ActionGroup)
                    CustomActionsSchema.getInstance()
                        .getCorrectedAction(IdeActions.GROUP_EDITOR_TAB_POPUP);
              }
            },
            ActionPlaces.EDITOR_TAB_POPUP,
            false)
        .setNavigationActionsEnabled(false)
        .addTabMouseListener(new TabMouseListener())
        .getPresentation()
        .setTabDraggingEnabled(true)
        .setUiDecorator(
            new UiDecorator() {
              @NotNull
              public UiDecoration getDecoration() {
                return new UiDecoration(
                    null,
                    new Insets(
                        TabsUtil.TAB_VERTICAL_PADDING, 10, TabsUtil.TAB_VERTICAL_PADDING, 10));
              }
            })
        .setTabLabelActionsMouseDeadzone(TimedDeadzone.NULL)
        .setGhostsAlwaysVisible(true)
        .setTabLabelActionsAutoHide(false)
        .setActiveTabFillIn(
            EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground())
        .setPaintFocus(false)
        .getJBTabs()
        .addListener(
            new TabsListener.Adapter() {
              public void selectionChanged(final TabInfo oldSelection, final TabInfo newSelection) {
                final FileEditorManager editorManager = FileEditorManager.getInstance(myProject);
                final FileEditor oldEditor =
                    oldSelection != null
                        ? editorManager.getSelectedEditor((VirtualFile) oldSelection.getObject())
                        : null;
                if (oldEditor != null) {
                  oldEditor.deselectNotify();
                }

                final FileEditor newEditor =
                    editorManager.getSelectedEditor((VirtualFile) newSelection.getObject());
                if (newEditor != null) {
                  newEditor.selectNotify();
                }
              }
            })
        .setAdditionalSwitchProviderWhenOriginal(new MySwitchProvider())
        .setSelectionChangeHandler(
            new JBTabs.SelectionChangeHandler() {
              @Override
              public ActionCallback execute(
                  TabInfo info, boolean requestFocus, final ActiveRunnable doChangeSelection) {
                final ActionCallback result = new ActionCallback();
                CommandProcessor.getInstance()
                    .executeCommand(
                        myProject,
                        new Runnable() {
                          @Override
                          public void run() {
                            ((IdeDocumentHistoryImpl) IdeDocumentHistory.getInstance(myProject))
                                .onSelectionChanged();
                            result.notify(doChangeSelection.run());
                          }
                        },
                        "EditorChange",
                        null);
                return result;
              }
            })
        .getPresentation()
        .setRequestFocusOnLastFocusedComponent(true);

    setTabPlacement(UISettings.getInstance().EDITOR_TAB_PLACEMENT);

    updateTabBorder();

    ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject))
        .addToolWindowManagerListener(
            new ToolWindowManagerAdapter() {
              public void stateChanged() {
                updateTabBorder();
              }

              public void toolWindowRegistered(@NotNull final String id) {
                updateTabBorder();
              }
            });

    UISettings.getInstance()
        .addUISettingsListener(
            new UISettingsListener() {
              public void uiSettingsChanged(UISettings source) {
                updateTabBorder();
              }
            },
            this);

    Disposer.register(project, this);
  }
 public int getTabCount() {
   return myTabs.getTabCount();
 }