Пример #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;
   }
 }
Пример #3
0
    public void nodeAdded(String fqn) {
      MyNode n, p;

      n = root.add(fqn);
      if (n != null) {
        p = (MyNode) n.getParent();
        tree_model.reload(p);
        jtree.scrollPathToVisible(new TreePath(n.getPath()));
      }
    }
    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);
    }
Пример #5
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;
 }
Пример #6
0
  private String textGen(TreePath p) {

    MyNode selectedNode = (MyNode) p.getLastPathComponent();
    String text = "men allt som";
    int n = selectedNode.getPath().length;

    for (int i = n - 1; i >= 0; i--) {
      text = text + " är " + selectedNode.getPath()[i].toString();
    }
    return text;
  }
 @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;
 }
Пример #8
0
    public void nodeRemoved(String fqn) {
      MyNode n;
      TreeNode par;

      n = root.findNode(fqn);
      if (n != null) {
        n.removeAllChildren();
        par = n.getParent();
        n.removeFromParent();
        tree_model.reload(par);
      }
    }
Пример #9
0
      MyNode findNode(String fqn) {
        MyNode curr, n;
        StringTokenizer tok;
        String child_name;

        if (fqn == null) return null;
        curr = this;
        tok = new StringTokenizer(fqn, ReplicatedTreeView.SEP);

        while (tok.hasMoreTokens()) {
          child_name = tok.nextToken();
          n = curr.findChild(child_name);
          if (n == null) return null;
          curr = n;
        }
        return curr;
      }
  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;
  }
Пример #11
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();
  }
Пример #12
0
  private void showDetails(TreePath p) {

    if (p == null) {
      return;
    }

    MyNode selectedNode = (MyNode) p.getLastPathComponent();
    String textPath = textGen(p);

    JOptionPane.showMessageDialog(
        this,
        selectedNode.getLevelName()
            + ": "
            + selectedNode.getUserObject()
            + "\n"
            + selectedNode.getText()
            + "\n"
            + textPath);
  }
Пример #13
0
      /**
       * Adds a new node to the view. Intermediary nodes will be created if they don't yet exist.
       * Returns the first node that was created or null if node already existed
       */
      public MyNode add(String fqn) {
        MyNode curr, n, ret = null;
        StringTokenizer tok;
        String child_name;

        if (fqn == null) return null;
        curr = this;
        tok = new StringTokenizer(fqn, ReplicatedTreeView.SEP);

        while (tok.hasMoreTokens()) {
          child_name = tok.nextToken();
          n = curr.findChild(child_name);
          if (n == null) {
            n = new MyNode(child_name);
            if (ret == null) ret = n;
            curr.add(n);
          }
          curr = n;
        }
        return ret;
      }
Пример #14
0
  private MyNode readNode() {

    String text = null;
    String level = null;
    String name = null;
    MyNode retNode = null;

    if (s.hasNextLine()) {

      try {
        String[] lineArray = thisLine.split("> ");
        text = lineArray[1];
        level = lineArray[0].split(" namn=")[0];
        name = lineArray[0].split(" namn=")[1];

        if (!level.startsWith("<") | !name.startsWith("\"") | !name.endsWith("\"")) {
          throw new Exception();
        } else {
          level = level.substring(1);
          name = name.substring(1, name.length() - 1);
        }
      } catch (Exception e) {
        System.err.println("Parse error");
        e.printStackTrace();
        System.exit(1);
      }

      retNode = new MyNode(name, level, text);
      thisLine = s.nextLine();

      while (!thisLine.startsWith("</")) {
        retNode.add(readNode());
        thisLine = s.nextLine();
      }
    }
    return retNode;
  }
Пример #15
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();
 }
Пример #16
0
    /** Recursively adds GUI nodes starting from fqn */
    void addGuiNode(String fqn) {
      Set children;
      String child_name;

      if (fqn == null) return;

      // 1 . Add myself
      root.add(fqn);

      // 2. Then add my children
      children = tree.getChildrenNames(fqn);
      if (children != null) {
        for (Iterator it = children.iterator(); it.hasNext(); ) {
          child_name = (String) it.next();
          addGuiNode(fqn + SEP + child_name);
        }
      }
    }
Пример #17
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();
  }
Пример #18
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);
      }
    }
  }
Пример #19
0
 protected void setSelectedNode(@Nullable MyNode node) {
   if (node != null) {
     myState.setLastEditedConfigurable(getNodePathString(node));
   }
   updateSelection(node != null ? node.getConfigurable() : null);
 }