@Override
  @SuppressWarnings({"EmptyCatchBlock"})
  public void readExternal(final Element element) {
    myId = element.getAttributeValue(ID_ATTR);
    myWasRead = true;
    try {
      myActive = Boolean.valueOf(element.getAttributeValue(ACTIVE_ATTR)).booleanValue();
    } catch (NumberFormatException ignored) {
    }
    try {
      myAnchor = ToolWindowAnchor.fromText(element.getAttributeValue(ANCHOR_ATTR));
    } catch (IllegalArgumentException ignored) {
    }
    myAutoHide = Boolean.valueOf(element.getAttributeValue(AUTOHIDE_ATTR)).booleanValue();
    try {
      myInternalType = ToolWindowType.valueOf(element.getAttributeValue(INTERNAL_TYPE_ATTR));
    } catch (IllegalArgumentException ignored) {
    }
    try {
      setTypeAndCheck(ToolWindowType.valueOf(element.getAttributeValue(TYPE_ATTR)));
    } catch (IllegalArgumentException ignored) {
    }
    myVisible = Boolean.valueOf(element.getAttributeValue(VISIBLE_ATTR)).booleanValue();
    if (element.getAttributeValue(SHOW_STRIPE_BUTTON) != null) {
      myShowStripeButton =
          Boolean.valueOf(element.getAttributeValue(SHOW_STRIPE_BUTTON)).booleanValue();
    }
    try {
      myWeight = Float.parseFloat(element.getAttributeValue(WEIGHT_ATTR));
    } catch (NumberFormatException ignored) {
    }
    try {
      String value = element.getAttributeValue(SIDE_WEIGHT_ATTR);
      if (value != null) {
        mySideWeight = Float.parseFloat(value);
      }
    } catch (NumberFormatException ignored) {
    }
    try {
      myOrder = Integer.valueOf(element.getAttributeValue(ORDER_ATTR)).intValue();
    } catch (NumberFormatException ignored) {
    }
    try {
      int x = Integer.parseInt(element.getAttributeValue(X_ATTR));
      int y = Integer.parseInt(element.getAttributeValue(Y_ATTR));
      int width = Integer.parseInt(element.getAttributeValue(WIDTH_ATTR));
      int height = Integer.parseInt(element.getAttributeValue(HEIGHT_ATTR));
      myFloatingBounds = new Rectangle(x, y, width, height);
    } catch (NumberFormatException ignored) {
    }
    mySplitMode = Boolean.parseBoolean(element.getAttributeValue(SIDE_TOOL_ATTR));

    myContentUiType =
        ToolWindowContentUiType.getInstance(element.getAttributeValue(CONTENT_UI_ATTR));
  }
  @Nullable
  @SuppressWarnings({"HardCodedStringLiteral"})
  private JPanel readExternalPanel(
      final Element element, @Nullable JPanel panel, Ref<EditorWindow> currentWindow) {
    final Element splitterElement = element.getChild("splitter");
    if (splitterElement != null) {
      return readSplitter(panel, splitterElement, currentWindow);
    }

    final Element leaf = element.getChild("leaf");
    if (leaf == null) {
      return null;
    }

    EditorWindow window = (panel == null) ? new EditorWindow(this) : findWindowWith(panel);
    LOG.assertTrue(window != null);

    @SuppressWarnings("unchecked")
    final List<Element> children = ContainerUtil.newArrayList(leaf.getChildren("file"));
    if (UISettings.getInstance().ACTIVATE_RIGHT_EDITOR_ON_CLOSE) {
      Collections.reverse(children);
    }

    VirtualFile currentFile = null;
    for (final Element file : children) {
      try {
        final HistoryEntry entry =
            new HistoryEntry(getManager().getProject(), file.getChild(HistoryEntry.TAG), true);
        boolean isCurrent = Boolean.valueOf(file.getAttributeValue("current")).booleanValue();
        getManager().openFileImpl3(window, entry.myFile, false, entry, isCurrent);
        if (getManager().isFileOpen(entry.myFile)) {
          window.setFilePinned(
              entry.myFile, Boolean.valueOf(file.getAttributeValue("pinned")).booleanValue());
          if (Boolean.valueOf(file.getAttributeValue("current-in-tab")).booleanValue()) {
            currentFile = entry.myFile;
          }
        }
      } catch (InvalidDataException e) {
        // OK
      }
    }
    if (currentFile != null) {
      final EditorComposite editor = window.findFileComposite(currentFile);
      if (editor != null) {
        window.setSelectedEditor(editor, true);
      }
    }
    return window.myPanel;
  }
 private void writeComposite(
     final Element res,
     final VirtualFile file,
     final EditorWithProviderComposite composite,
     final boolean pinned,
     final EditorWithProviderComposite selectedEditor) {
   final Element fileElement = new Element("file");
   fileElement.setAttribute("leaf-file-name", file.getName()); // TODO: all files
   final HistoryEntry entry = composite.currentStateAsHistoryEntry();
   entry.writeExternal(fileElement, getManager().getProject());
   fileElement.setAttribute("pinned", Boolean.toString(pinned));
   fileElement.setAttribute(
       "current", Boolean.toString(composite.equals(getManager().getLastSelected())));
   fileElement.setAttribute("current-in-tab", Boolean.toString(composite.equals(selectedEditor)));
   res.addContent(fileElement);
 }
 @Override
 public void writeExternal(final Element element) {
   element.setAttribute(ID_ATTR, myId);
   element.setAttribute(ACTIVE_ATTR, Boolean.toString(myActive));
   element.setAttribute(ANCHOR_ATTR, myAnchor.toString());
   element.setAttribute(AUTOHIDE_ATTR, Boolean.toString(myAutoHide));
   element.setAttribute(INTERNAL_TYPE_ATTR, myInternalType.toString());
   element.setAttribute(TYPE_ATTR, myType.toString());
   element.setAttribute(VISIBLE_ATTR, Boolean.toString(myVisible));
   element.setAttribute(SHOW_STRIPE_BUTTON, Boolean.toString(myShowStripeButton));
   element.setAttribute(WEIGHT_ATTR, Float.toString(myWeight));
   element.setAttribute(SIDE_WEIGHT_ATTR, Float.toString(mySideWeight));
   element.setAttribute(ORDER_ATTR, Integer.toString(myOrder));
   element.setAttribute(SIDE_TOOL_ATTR, Boolean.toString(mySplitMode));
   element.setAttribute(CONTENT_UI_ATTR, myContentUiType.getName());
   if (myFloatingBounds != null) {
     element.setAttribute(X_ATTR, Integer.toString(myFloatingBounds.x));
     element.setAttribute(Y_ATTR, Integer.toString(myFloatingBounds.y));
     element.setAttribute(WIDTH_ATTR, Integer.toString(myFloatingBounds.width));
     element.setAttribute(HEIGHT_ATTR, Integer.toString(myFloatingBounds.height));
   }
 }
  @Nullable
  @SuppressWarnings({"HardCodedStringLiteral"})
  private JPanel readExternalPanel(
      final Element element, @Nullable JPanel panel, Ref<EditorWindow> currentWindow) {
    final Element splitterElement = element.getChild("splitter");
    if (splitterElement != null) {
      return readSplitter(panel, splitterElement, currentWindow);
    }

    final Element leaf = element.getChild("leaf");
    if (leaf == null) {
      return null;
    }

    final EditorWindow window = panel == null ? new EditorWindow(this) : findWindowWith(panel);
    LOG.assertTrue(window != null);

    @SuppressWarnings("unchecked")
    final List<Element> children = ContainerUtil.newArrayList(leaf.getChildren("file"));
    if (UISettings.getInstance().ACTIVATE_RIGHT_EDITOR_ON_CLOSE) {
      Collections.reverse(children);
    }

    // trim to EDITOR_TAB_LIMIT, ignoring CLOSE_NON_MODIFIED_FILES_FIRST policy
    for (Iterator<Element> iterator = children.iterator();
        iterator.hasNext() && UISettings.getInstance().EDITOR_TAB_LIMIT < children.size(); ) {
      Element child = iterator.next();
      if (!Boolean.valueOf(child.getAttributeValue(PINNED)).booleanValue()) {
        iterator.remove();
      }
    }

    VirtualFile currentFile = null;
    for (int i = 0; i < children.size(); i++) {
      final Element file = children.get(i);
      try {
        final FileEditorManagerImpl fileEditorManager = getManager();
        final HistoryEntry entry =
            new HistoryEntry(fileEditorManager.getProject(), file.getChild(HistoryEntry.TAG), true);
        final boolean isCurrent = Boolean.valueOf(file.getAttributeValue("current")).booleanValue();
        fileEditorManager.openFileImpl4(window, entry.myFile, false, entry, isCurrent, i);
        if (fileEditorManager.isFileOpen(entry.myFile)) {
          window.setFilePinned(
              entry.myFile, Boolean.valueOf(file.getAttributeValue(PINNED)).booleanValue());
          if (Boolean.valueOf(file.getAttributeValue("current-in-tab")).booleanValue()) {
            currentFile = entry.myFile;
          }
        }

      } catch (InvalidDataException e) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
          LOG.error(e);
        }
      }
    }
    if (currentFile != null) {
      final EditorComposite editor = window.findFileComposite(currentFile);
      if (editor != null) {
        window.setSelectedEditor(editor, true);
      }
    }
    return window.myPanel;
  }