Ejemplo n.º 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);
      }
    }
  }
 protected boolean isEnabled() {
   final TreePath selectionPath = myTree.getSelectionPath();
   if (selectionPath != null) {
     final MyNode node = (MyNode) selectionPath.getLastPathComponent();
     return !node.isDisplayInBold();
   } else {
     return false;
   }
 }
Ejemplo n.º 3
0
 @Nullable
 public NamedConfigurable getSelectedConfigurable() {
   final TreePath selectionPath = myTree.getSelectionPath();
   if (selectionPath != null) {
     MyNode node = (MyNode) selectionPath.getLastPathComponent();
     final NamedConfigurable configurable = node.getConfigurable();
     LOG.assertTrue(configurable != null, "already disposed");
     return configurable;
   }
   return null;
 }
    private boolean removeFromModel(final TreePath selectionPath) {
      final Object last = selectionPath.getLastPathComponent();

      if (!(last instanceof MyNode)) return false;

      final MyNode node = (MyNode) last;
      final NamedConfigurable configurable = node.getConfigurable();
      final Object editableObject = configurable.getEditableObject();

      return removeObject(editableObject);
    }
 @Nullable
 public ProjectStructureElement getSelectedElement() {
   final TreePath selectionPath = myTree.getSelectionPath();
   if (selectionPath != null && selectionPath.getLastPathComponent() instanceof MyNode) {
     MyNode node = (MyNode) selectionPath.getLastPathComponent();
     final NamedConfigurable configurable = node.getConfigurable();
     if (configurable instanceof ProjectStructureElementConfigurable) {
       return ((ProjectStructureElementConfigurable) configurable).getProjectStructureElement();
     }
   }
   return null;
 }
Ejemplo n.º 6
0
  private static String getNodePathString(final MyNode node) {
    StringBuilder path = new StringBuilder();
    MyNode current = node;
    while (current != null) {
      final Object userObject = current.getUserObject();
      if (!(userObject instanceof NamedConfigurable)) break;
      final String displayName = current.getDisplayName();
      if (StringUtil.isEmptyOrSpaces(displayName)) break;
      if (path.length() > 0) {
        path.append('|');
      }
      path.append(displayName);

      final TreeNode parent = current.getParent();
      if (!(parent instanceof MyNode)) break;
      current = (MyNode) parent;
    }
    return path.toString();
  }
  public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) {
    if (place == null) return new ActionCallback.Done();

    final Object object = place.getPath(TREE_OBJECT);
    final String byName = (String) place.getPath(TREE_NAME);

    if (object == null && byName == null) return new ActionCallback.Done();

    final MyNode node = object == null ? null : findNodeByObject(myRoot, object);
    final MyNode nodeByName = byName == null ? null : findNodeByName(myRoot, byName);

    if (node == null && nodeByName == null) return new ActionCallback.Done();

    final NamedConfigurable config;
    if (node != null) {
      config = node.getConfigurable();
    } else {
      config = nodeByName.getConfigurable();
    }

    final ActionCallback result =
        new ActionCallback()
            .doWhenDone(
                new Runnable() {
                  public void run() {
                    myAutoScrollEnabled = true;
                  }
                });

    myAutoScrollEnabled = false;
    myAutoScrollHandler.cancelAllRequests();
    final MyNode nodeToSelect = node != null ? node : nodeByName;
    selectNodeInTree(nodeToSelect, requestFocus)
        .doWhenDone(
            new Runnable() {
              public void run() {
                setSelectedNode(nodeToSelect);
                Place.goFurther(config, place, requestFocus).notifyWhenDone(result);
              }
            });

    return result;
  }
Ejemplo n.º 8
0
 protected void clearChildren() {
   TreeUtil.traverseDepth(
       myRoot,
       new TreeUtil.Traverse() {
         public boolean accept(Object node) {
           if (node instanceof MyNode) {
             final MyNode treeNode = ((MyNode) node);
             treeNode.getConfigurable().disposeUIResources();
             if (!(treeNode instanceof MyRootNode)) {
               treeNode.setUserObject(null);
             }
           }
           return true;
         }
       });
   myRoot.removeAllChildren();
 }
Ejemplo n.º 9
0
  public void reset() {
    loadComponentState();
    myHasDeletedItems = false;
    ((DefaultTreeModel) myTree.getModel()).reload();
    // myTree.requestFocus();
    myState.getProportions().restoreSplitterProportions(myWholePanel);

    final Enumeration enumeration = myRoot.breadthFirstEnumeration();
    boolean selected = false;
    while (enumeration.hasMoreElements()) {
      final MyNode node = (MyNode) enumeration.nextElement();
      if (node instanceof MyRootNode) continue;
      final String path = getNodePathString(node);
      if (!selected && Comparing.strEqual(path, myState.getLastEditedConfigurable())) {
        TreeUtil.selectInTree(node, false, myTree);
        selected = true;
      }
    }
    if (!selected) {
      TreeUtil.selectFirstNode(myTree);
    }
    updateSelectionFromTree();
  }
Ejemplo n.º 10
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);
      }
    }
  }
Ejemplo n.º 11
0
 protected void setSelectedNode(@Nullable MyNode node) {
   if (node != null) {
     myState.setLastEditedConfigurable(getNodePathString(node));
   }
   updateSelection(node != null ? node.getConfigurable() : null);
 }