コード例 #1
0
  private void checkForEmptyAndDuplicatedNames(
      MyNode rootNode,
      String prefix,
      String title,
      Class<? extends NamedConfigurable> configurableClass,
      boolean recursively)
      throws ConfigurationException {
    final Set<String> names = new HashSet<String>();
    for (int i = 0; i < rootNode.getChildCount(); i++) {
      final MyNode node = (MyNode) rootNode.getChildAt(i);
      final NamedConfigurable scopeConfigurable = node.getConfigurable();

      if (configurableClass.isInstance(scopeConfigurable)) {
        final String name = scopeConfigurable.getDisplayName();
        if (name.trim().length() == 0) {
          selectNodeInTree(node);
          throw new ConfigurationException("Name should contain non-space characters");
        }
        if (names.contains(name)) {
          final NamedConfigurable selectedConfigurable = getSelectedConfigurable();
          if (selectedConfigurable == null
              || !Comparing.strEqual(selectedConfigurable.getDisplayName(), name)) {
            selectNodeInTree(node);
          }
          throw new ConfigurationException(
              CommonBundle.message("smth.already.exist.error.message", prefix, name), title);
        }
        names.add(name);
      }

      if (recursively) {
        checkForEmptyAndDuplicatedNames(node, prefix, title, configurableClass, true);
      }
    }
  }
コード例 #2
0
 @Nullable
 public Icon getIcon(boolean expanded) {
   // thanks to invokeLater() in TreeUtil.showAndSelect(), we can get calls to getIcon() after
   // the tree has been disposed
   final NamedConfigurable configurable = getConfigurable();
   if (configurable != null) {
     return configurable.getIcon(expanded);
   }
   return null;
 }
コード例 #3
0
 @Nullable
 public Object getSelectedObject() {
   final TreePath selectionPath = myTree.getSelectionPath();
   if (selectionPath != null && selectionPath.getLastPathComponent() instanceof MyNode) {
     MyNode node = (MyNode) selectionPath.getLastPathComponent();
     final NamedConfigurable configurable = node.getConfigurable();
     LOG.assertTrue(configurable != null, "already disposed");
     return configurable.getEditableObject();
   }
   return null;
 }
コード例 #4
0
  protected void removePaths(final TreePath... paths) {
    MyNode parentNode = null;
    int idx = -1;
    for (TreePath path : paths) {
      final MyNode node = (MyNode) path.getLastPathComponent();
      final NamedConfigurable namedConfigurable = node.getConfigurable();
      final Object editableObject = namedConfigurable.getEditableObject();
      parentNode = (MyNode) node.getParent();
      idx = parentNode.getIndex(node);
      ((DefaultTreeModel) myTree.getModel()).removeNodeFromParent(node);
      myHasDeletedItems |= wasObjectStored(editableObject);
      fireItemsChangeListener(editableObject);
      onItemDeleted(editableObject);
      namedConfigurable.disposeUIResources();
    }

    if (paths.length > 0) {
      if (parentNode != null && idx != -1) {
        DefaultMutableTreeNode toSelect = null;
        if (idx < parentNode.getChildCount()) {
          toSelect = (DefaultMutableTreeNode) parentNode.getChildAt(idx);
        } else {
          if (idx > 0 && parentNode.getChildCount() > 0) {
            if (idx - 1 < parentNode.getChildCount()) {
              toSelect = (DefaultMutableTreeNode) parentNode.getChildAt(idx - 1);
            } else {
              toSelect = (DefaultMutableTreeNode) parentNode.getFirstChild();
            }
          } else {
            if (parentNode.isRoot() && myTree.isRootVisible()) {
              toSelect = parentNode;
            } else if (parentNode.getChildCount() > 0) {
              toSelect = (DefaultMutableTreeNode) parentNode.getFirstChild();
            }
          }
        }

        if (toSelect != null) {
          TreeUtil.selectInTree(toSelect, true, myTree);
        }
      } else {
        TreeUtil.selectFirstNode(myTree);
      }
    }
  }
コード例 #5
0
  protected void updateSelection(@Nullable NamedConfigurable configurable) {
    myDetails.setText(configurable != null ? configurable.getBannerSlogan() : null);

    myCurrentConfigurable = configurable;

    if (configurable != null) {
      final JComponent comp = configurable.createComponent();
      if (comp == null) {
        setEmpty();
        LOG.error("createComponent() returned null. configurable=" + configurable);
      } else {
        myDetails.setContent(comp);
        ensureInitialized(configurable);
        myHistory.pushPlaceForElement(TREE_OBJECT, configurable.getEditableObject());
      }
    } else {
      setEmpty();
    }
  }
コード例 #6
0
 @NotNull
 public String getDisplayName() {
   final NamedConfigurable configurable = ((NamedConfigurable) getUserObject());
   LOG.assertTrue(configurable != null, "Tree was already disposed");
   return configurable.getDisplayName();
 }
コード例 #7
0
 public String getHelpTopic() {
   if (myCurrentConfigurable != null) {
     return myCurrentConfigurable.getHelpTopic();
   }
   return null;
 }
コード例 #8
0
 public void ensureInitialized(NamedConfigurable configurable) {
   if (!isInitialized(configurable)) {
     configurable.reset();
     initializeConfigurable(configurable);
   }
 }