public GridImpl(ViewContextEx viewContext, String sessionName) {
    myViewContext = viewContext;
    mySessionName = sessionName;

    Disposer.register(myViewContext, this);
    Disposer.register(this, myTopSplit);

    Placeholder left = new Placeholder();
    myPlaceInGrid2Cell.put(
        PlaceInGrid.left, new GridCellImpl(myViewContext, this, left, PlaceInGrid.left));
    Placeholder center = new Placeholder();
    myPlaceInGrid2Cell.put(
        PlaceInGrid.center, new GridCellImpl(myViewContext, this, center, PlaceInGrid.center));
    Placeholder right = new Placeholder();
    myPlaceInGrid2Cell.put(
        PlaceInGrid.right, new GridCellImpl(myViewContext, this, right, PlaceInGrid.right));
    Placeholder bottom = new Placeholder();
    myPlaceInGrid2Cell.put(
        PlaceInGrid.bottom, new GridCellImpl(myViewContext, this, bottom, PlaceInGrid.bottom));

    setContent(mySplitter);
    setOpaque(false);
    setFocusCycleRoot(true);

    myTopSplit.setFirstComponent(left);
    myTopSplit.setInnerComponent(center);
    myTopSplit.setLastComponent(right);
    myTopSplit.setMinSize(48);
    mySplitter.setFirstComponent(myTopSplit);
    mySplitter.setSecondComponent(bottom);
  }
  public ActionCallback restoreLastUiState() {
    final ActionCallback result = new ActionCallback(myPlaceInGrid2Cell.values().size());
    for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) {
      cell.restoreLastUiState().notifyWhenDone(result);
    }

    return result;
  }
 @Override
 public GridCellImpl getCellFor(final Content content) {
   // check if the content is already in some cell
   GridCellImpl current = myContent2Cell.get(content);
   if (current != null) return current;
   // view may be shared between several contents with the same ID in different cells
   // (temporary contents like "Dump Stack" or "Console Result")
   View view = getStateFor(content);
   final GridCellImpl cell = myPlaceInGrid2Cell.get(view.getPlaceInGrid());
   assert cell != null : "Unknown place in grid: " + view.getPlaceInGrid().name();
   return cell;
 }
  void saveSplitterProportions(final PlaceInGrid placeInGrid) {
    if (getRootPane() == null) return;
    final Rectangle bounds = getBounds();
    if (bounds.width == 0 && bounds.height == 0) return;

    final GridCellImpl cell = myPlaceInGrid2Cell.get(placeInGrid);

    if (!cell.isValidForCalculateProportions()) return;

    final TabImpl tab = (TabImpl) getTab();

    if (tab != null) {
      switch (placeInGrid) {
        case left:
          tab.setLeftProportion(getLeftProportion());
          break;
        case right:
          tab.setRightProportion(getRightProportion());
          break;
        case bottom:
          tab.setBottomProportion(getBottomPropertion());
        case center:
          break;
      }
    }
  }
 void add(final Content content) {
   GridCellImpl cell = getCellFor(content);
   cell.add(content);
   myContents.add(content);
   myContent2Cell.put(content, cell);
   Collections.sort(myContents, myContentComparator);
 }
 public List<SwitchTarget> getTargets(boolean onlyVisible) {
   Collection<GridCellImpl> cells = myPlaceInGrid2Cell.values();
   ArrayList<SwitchTarget> result = new ArrayList<SwitchTarget>();
   for (GridCellImpl each : cells) {
     result.addAll(each.getTargets(onlyVisible));
   }
   return result;
 }
  public boolean updateGridUI() {
    for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) {
      cell.setHideTabs(myContents.size() == 1);
    }

    final Content onlyContent = myContents.get(0);

    return onlyContent.getSearchComponent() != null;
  }
  public void processAddToUi(boolean restoreProportions) {
    if (restoreProportions) {
      for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) {
        cell.restoreProportions();
      }
    }

    updateSelection(true);
  }
  @Nullable
  public SwitchTarget getCellFor(Component c) {
    Component eachParent = c;
    while (eachParent != null) {
      for (GridCellImpl eachCell : myContent2Cell.values()) {
        if (eachCell.contains(eachParent)) {
          return eachCell.getTargetForSelection();
        }
      }

      eachParent = eachParent.getParent();
    }

    return null;
  }
 @Nullable
 public GridCellImpl findCell(final Content content) {
   return myContent2Cell.get(content);
 }
 public void saveUiState() {
   for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) {
     cell.saveUiState();
   }
 }
 public boolean isEmpty() {
   return myContent2Cell.isEmpty();
 }
 public void setToolbarHorizontal(boolean horizontal) {
   for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) {
     cell.setToolbarHorizontal(horizontal);
   }
 }
 void remove(final Content content) {
   getCellFor(content).remove(content);
   myContents.remove(content);
   myContent2Cell.remove(content);
 }
 private void updateSelection(boolean isShowing) {
   for (GridCellImpl each : myPlaceInGrid2Cell.values()) {
     each.updateSelection(isShowing);
   }
 }