protected MasterDetailsComponent(MasterDetailsState state) {
    myState = state;

    mySplitter =
        isNewProjectSettings() ? new OnePixelSplitter(false, .2f) : new JBSplitter(false, .2f);
    mySplitter.setSplitterProportionKey("ProjectStructure.SecondLevelElements");
    mySplitter.setHonorComponentsMinimumSize(true);

    installAutoScroll();
    reInitWholePanelIfNeeded();
  }
Example #2
0
  @Override
  public JComponent createComponent() {
    myComponent = new MyPanel();

    mySplitter = new JBSplitter(false, .15f);
    mySplitter.setSplitterProportionKey("ProjectStructure.TopLevelElements");
    mySplitter.setHonorComponentsMinimumSize(true);
    if (Registry.is("ide.new.project.settings")) {
      mySplitter.setOnePixelMode();
    }

    initSidePanel();

    final JPanel left =
        new JPanel(new BorderLayout()) {
          @Override
          public Dimension getMinimumSize() {
            final Dimension original = super.getMinimumSize();
            return new Dimension(Math.max(original.width, 100), original.height);
          }
        };

    final DefaultActionGroup toolbarGroup = new DefaultActionGroup();
    toolbarGroup.add(new BackAction(myComponent));
    toolbarGroup.add(new ForwardAction(myComponent));
    final ActionToolbar toolbar =
        ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, toolbarGroup, true);
    toolbar.setTargetComponent(myComponent);
    myToolbarComponent = toolbar.getComponent();
    if (Registry.is("ide.new.project.settings")) {
      left.setBackground(UIUtil.getSidePanelColor());
    } else {
      left.add(myToolbarComponent, BorderLayout.NORTH);
    }
    left.add(mySidePanel, BorderLayout.CENTER);

    mySplitter.setFirstComponent(left);
    mySplitter.setSecondComponent(myDetails);

    myComponent.add(mySplitter, BorderLayout.CENTER);
    myErrorsComponent = new ConfigurationErrorsComponent(myProject);
    if (!Registry.is("ide.new.project.settings")) {
      myComponent.add(myErrorsComponent, BorderLayout.SOUTH);
    }

    myUiInitialized = true;

    return myComponent;
  }
  public ResourceBundleEditor(@NotNull ResourceBundle resourceBundle) {
    myProject = resourceBundle.getProject();

    final JPanel splitPanel = new JPanel();
    myValuesPanel = new JPanel();
    myStructureViewPanel = new JPanel();
    JBSplitter splitter = new JBSplitter(false);
    splitter.setFirstComponent(myStructureViewPanel);
    splitter.setSecondComponent(myValuesPanel);
    splitter.setShowDividerControls(true);
    splitter.setHonorComponentsMinimumSize(true);
    splitter.setAndLoadSplitterProportionKey(getClass() + ".splitter");
    splitPanel.setLayout(new BorderLayout());
    splitPanel.add(splitter, BorderLayout.CENTER);

    myResourceBundle = resourceBundle;
    myStructureViewComponent = new ResourceBundleStructureViewComponent(myResourceBundle, this);
    myStructureViewPanel.setLayout(new BorderLayout());
    myStructureViewPanel.add(myStructureViewComponent, BorderLayout.CENTER);

    myStructureViewComponent
        .getTree()
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              private IProperty selectedProperty;
              private PropertiesFile selectedPropertiesFile;

              @Override
              public void valueChanged(TreeSelectionEvent e) {
                // filter out temp unselect/select events
                if (Comparing.equal(e.getNewLeadSelectionPath(), e.getOldLeadSelectionPath())
                    || getSelectedProperty() == null) return;
                if (!arePropertiesEquivalent(selectedProperty, getSelectedProperty())
                    || !Comparing.equal(selectedPropertiesFile, getSelectedPropertiesFile())) {

                  if (e.getOldLeadSelectionPath() != null) {
                    for (Map.Entry<PropertiesFile, Editor> entry : myEditors.entrySet()) {
                      if (entry.getValue() == mySelectedEditor) {
                        writeEditorPropertyValue(
                            mySelectedEditor, entry.getKey(), selectedProperty.getName());
                        break;
                      }
                    }
                  }

                  selectedProperty = getSelectedProperty();
                  selectedPropertiesFile = getSelectedPropertiesFile();
                  selectionChanged();
                }
              }

              private boolean arePropertiesEquivalent(
                  @Nullable IProperty p1, @Nullable IProperty p2) {
                if (p1 == p2) {
                  return true;
                }
                if (p1 == null || p2 == null) {
                  return false;
                }
                return p1.getPsiElement().isEquivalentTo(p2.getPsiElement());
              }
            });
    installPropertiesChangeListeners();

    myEditors = new THashMap<PropertiesFile, Editor>();
    myTitledPanels = new THashMap<PropertiesFile, JPanel>();
    recreateEditorsPanel();

    TreeElement[] children = myStructureViewComponent.getTreeModel().getRoot().getChildren();
    if (children.length != 0) {
      TreeElement child = children[0];
      String propName =
          ((ResourceBundlePropertyStructureViewElement) child).getProperty().getUnescapedKey();
      setState(new ResourceBundleEditorState(propName));
    }
    myDataProviderPanel = new DataProviderPanel(splitPanel);

    myProject
        .getMessageBus()
        .connect(myProject)
        .subscribe(
            FileEditorManagerListener.FILE_EDITOR_MANAGER,
            new FileEditorManagerAdapter() {
              @Override
              public void selectionChanged(@NotNull FileEditorManagerEvent event) {
                onSelectionChanged(event);
              }
            });
  }
  protected void reInitWholePanelIfNeeded() {
    if (!myToReInitWholePanel) return;

    myWholePanel =
        new JPanel(new BorderLayout()) {
          public void addNotify() {
            super.addNotify();
            MasterDetailsComponent.this.addNotify();

            TreeModel m = myTree.getModel();
            if (m instanceof DefaultTreeModel) {
              DefaultTreeModel model = (DefaultTreeModel) m;
              for (int eachRow = 0; eachRow < myTree.getRowCount(); eachRow++) {
                TreePath eachPath = myTree.getPathForRow(eachRow);
                Object component = eachPath.getLastPathComponent();
                if (component instanceof TreeNode) {
                  model.nodeChanged((TreeNode) component);
                }
              }
            }
          }
        };
    mySplitter.setHonorComponentsMinimumSize(true);
    myWholePanel.add(mySplitter, BorderLayout.CENTER);

    JPanel left =
        new JPanel(new BorderLayout()) {
          public Dimension getMinimumSize() {
            final Dimension original = super.getMinimumSize();
            return new Dimension(Math.max(original.width, 100), original.height);
          }
        };

    if (isNewProjectSettings()) {
      ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree);
      DefaultActionGroup group = createToolbarActionGroup();
      if (group != null) {
        decorator.setActionGroup(group);
      }
      // left.add(myNorthPanel, BorderLayout.NORTH);
      myMaster =
          decorator.setAsUsualTopToolbar().setPanelBorder(JBUI.Borders.empty()).createPanel();
      myNorthPanel.setVisible(false);
    } else {
      left.add(myNorthPanel, BorderLayout.NORTH);
      myMaster = ScrollPaneFactory.createScrollPane(myTree);
    }
    left.add(myMaster, BorderLayout.CENTER);
    mySplitter.setFirstComponent(left);

    final JPanel right = new JPanel(new BorderLayout());
    right.add(myDetails.getComponent(), BorderLayout.CENTER);
    if (!isNewProjectSettings()) {
      myWholePanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    }

    mySplitter.setSecondComponent(right);

    GuiUtils.replaceJSplitPaneWithIDEASplitter(myWholePanel);

    myToReInitWholePanel = false;
  }