@Override
  public void valueChanged(@Nullable TreeSelectionEvent e) {
    Component selectedComponent = myContentPanel.getSelectedComponent();

    if (selectedComponent == myColorPickerPanel) {
      Color color = myColorPicker.getColor();
      myNewResourceAction.setEnabled(false);
      myResultResourceName = ResourceHelper.colorToString(color);
      updateResourceNameStatus();
    } else {
      boolean isProjectPanel = selectedComponent == myProjectPanel.myComponent;
      ResourcePanel panel = isProjectPanel ? myProjectPanel : mySystemPanel;
      ResourceItem element = getSelectedElement(panel.myTreeBuilder, ResourceItem.class);
      setOKActionEnabled(element != null);
      myNewResourceAction.setEnabled(
          isProjectPanel && !panel.myTreeBuilder.getSelectedElements().isEmpty());

      if (element == null) {
        myResultResourceName = null;
      } else {
        String prefix = panel == myProjectPanel ? "@" : ANDROID;
        myResultResourceName = prefix + element.getName();
      }

      panel.showPreview(element);
    }
    notifyResourcePickerListeners(myResultResourceName);
  }
  public ChooseResourceDialog(
      @NotNull Module module,
      @NotNull ResourceType[] types,
      @Nullable String value,
      @Nullable XmlTag tag,
      ResourceNameVisibility resourceNameVisibility,
      @Nullable String colorName) {
    super(module.getProject());
    myModule = module;
    myTag = tag;
    myResourceNameVisibility = resourceNameVisibility;

    setTitle("Resources");

    AndroidFacet facet = AndroidFacet.getInstance(module);
    myProjectPanel = new ResourcePanel(facet, types, false);
    mySystemPanel = new ResourcePanel(facet, types, true);

    myContentPanel = new JBTabbedPane();
    myContentPanel.addTab("Project", myProjectPanel.myComponent);
    myContentPanel.addTab("System", mySystemPanel.myComponent);

    myProjectPanel.myTreeBuilder.expandAll(null);
    mySystemPanel.myTreeBuilder.expandAll(null);

    boolean doSelection = value != null;

    if (types == COLOR_TYPES) {
      Color color = ResourceHelper.parseColor(value);
      myColorPicker =
          new ColorPicker(
              myDisposable,
              color,
              true,
              new ColorPickerListener() {
                @Override
                public void colorChanged(Color color) {
                  notifyResourcePickerListeners(ResourceHelper.colorToString(color));
                }

                @Override
                public void closed(@Nullable Color color) {}
              });
      myColorPicker.pickARGB();

      JPanel colorPickerContent = new JPanel(new BorderLayout());
      myColorPickerPanel = new JBScrollPane(colorPickerContent);
      myColorPickerPanel.setBorder(null);
      colorPickerContent.add(myColorPicker);
      myContentPanel.addTab("Color", myColorPickerPanel);

      if (myResourceNameVisibility != ResourceNameVisibility.HIDE) {
        ResourceDialogSouthPanel resourceDialogSouthPanel = new ResourceDialogSouthPanel();
        myResourceNameField = resourceDialogSouthPanel.getResourceNameField();
        myResourceNameField.getDocument().addDocumentListener(new ValidatingDocumentListener());
        if (colorName != null) {
          myResourceNameField.setText(colorName);
        }
        myResourceNameMessage = resourceDialogSouthPanel.getResourceNameMessage();
        Color backgroundColor =
            EditorColorsManager.getInstance()
                .getGlobalScheme()
                .getColor(EditorColors.NOTIFICATION_BACKGROUND);
        myResourceNameMessage.setBackground(
            backgroundColor == null ? JBColor.YELLOW : backgroundColor);
        colorPickerContent.add(resourceDialogSouthPanel.getFullPanel(), BorderLayout.SOUTH);
        updateResourceNameStatus();
      }

      if (color != null) {
        myContentPanel.setSelectedIndex(2);
        doSelection = false;
      }
      myValidator =
          ResourceNameValidator.create(
              false,
              AppResourceRepository.getAppResources(module, true),
              ResourceType.COLOR,
              false);
    }
    if (doSelection && value.startsWith("@")) {
      value = StringUtil.replace(value, "+", "");
      int index = value.indexOf('/');
      if (index != -1) {
        ResourcePanel panel;
        String type;
        String name = value.substring(index + 1);
        if (value.startsWith(ANDROID)) {
          panel = mySystemPanel;
          type = value.substring(ANDROID.length(), index);
        } else {
          panel = myProjectPanel;
          type = value.substring(1, index);
        }
        myContentPanel.setSelectedComponent(panel.myComponent);
        panel.select(type, name);
      }
    }

    myContentPanel.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent e) {
            valueChanged(null);
          }
        });

    valueChanged(null);
    init();
  }