Exemplo n.º 1
0
  /**
   * Set the currently selected Variable.
   *
   * @param v select this Variable, must be already in the tree.
   */
  public void setSelected(VariableIF v) {
    if (v == null) return;

    // construct chain of variables
    List<VariableIF> vchain = new ArrayList<>();
    vchain.add(v);

    VariableIF vp = v;
    while (vp.isMemberOfStructure()) {
      vp = vp.getParentStructure();
      vchain.add(0, vp); // reverse
    }

    // construct chain of groups
    List<Group> gchain = new ArrayList<>();
    Group gp = vp.getParentGroup();

    gchain.add(gp);
    while (gp.getParentGroup() != null) {
      gp = gp.getParentGroup();
      gchain.add(0, gp); // reverse
    }

    List<Object> pathList = new ArrayList<>();

    // start at root, work down through the nested groups, if any
    GroupNode gnode = (GroupNode) model.getRoot();
    pathList.add(gnode);
    Group parentGroup = gchain.get(0); // always the root group

    for (int i = 1; i < gchain.size(); i++) {
      parentGroup = gchain.get(i);
      gnode = gnode.findNestedGroup(parentGroup);
      assert gnode != null;
      pathList.add(gnode);
    }

    vp = vchain.get(0);
    VariableNode vnode = gnode.findNestedVariable(vp);
    if (vnode == null) return; // not found
    pathList.add(vnode);

    // now work down through the structure members, if any
    for (int i = 1; i < vchain.size(); i++) {
      vp = vchain.get(i);
      vnode = vnode.findNestedVariable(vp);
      if (vnode == null) return; // not found
      pathList.add(vnode);
    }

    // convert to TreePath, and select it
    Object[] paths = pathList.toArray();
    TreePath treePath = new TreePath(paths);
    tree.setSelectionPath(treePath);
    tree.scrollPathToVisible(treePath);
  }
Exemplo n.º 2
0
    void makeChildren() {
      children = new ArrayList<>();

      List dims = group.getDimensions();
      for (int i = 0; i < dims.size(); i++)
        children.add(new DimensionNode(this, (Dimension) dims.get(i)));

      List vars = group.getVariables();
      for (int i = 0; i < vars.size(); i++)
        children.add(new VariableNode(this, (VariableIF) vars.get(i)));

      List groups = group.getGroups();
      for (int i = 0; i < groups.size(); i++)
        children.add(new GroupNode(this, (Group) groups.get(i)));

      if (debugTree) System.out.println("children=" + group.getFullName() + " ");
    }
Exemplo n.º 3
0
  private void reset(
      final Keymap keymap,
      final QuickList[] allQuickLists,
      String filter,
      @Nullable KeyboardShortcut shortcut) {
    myKeymap = keymap;

    final PathsKeeper pathsKeeper = new PathsKeeper();
    pathsKeeper.storePaths();

    myRoot.removeAllChildren();

    ActionManager actionManager = ActionManager.getInstance();
    Project project =
        CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myComponent));
    Group mainGroup =
        ActionsTreeUtil.createMainGroup(
            project,
            myKeymap,
            allQuickLists,
            filter,
            true,
            ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut, filter, true));
    if ((filter != null && filter.length() > 0 || shortcut != null)
        && mainGroup.initIds().isEmpty()) {
      mainGroup =
          ActionsTreeUtil.createMainGroup(
              project,
              myKeymap,
              allQuickLists,
              filter,
              false,
              ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut, filter, false));
    }
    myRoot = ActionsTreeUtil.createNode(mainGroup);
    myMainGroup = mainGroup;
    MyModel model = (MyModel) myTree.getModel();
    model.setRoot(myRoot);
    model.nodeStructureChanged(myRoot);

    pathsKeeper.restorePaths();
  }
Exemplo n.º 4
0
  public void selectAction(String actionId) {
    final JTree tree = myTree;

    String path = myMainGroup.getActionQualifiedPath(actionId);
    if (path == null) {
      return;
    }
    final DefaultMutableTreeNode node = getNodeForPath(path);
    if (node == null) {
      return;
    }

    TreeUtil.selectInTree(node, true, tree);
  }
Exemplo n.º 5
0
  private static boolean isGroupChanged(Group group, Keymap oldKeymap, Keymap newKeymap) {
    if (!newKeymap.canModify()) return false;

    ArrayList children = group.getChildren();
    for (Object child : children) {
      if (child instanceof Group) {
        if (isGroupChanged((Group) child, oldKeymap, newKeymap)) {
          return true;
        }
      } else if (child instanceof String) {
        String actionId = (String) child;
        if (isActionChanged(actionId, oldKeymap, newKeymap)) {
          return true;
        }
      } else if (child instanceof QuickList) {
        String actionId = ((QuickList) child).getActionId();
        if (isActionChanged(actionId, oldKeymap, newKeymap)) {
          return true;
        }
      }
    }
    return false;
  }
Exemplo n.º 6
0
  @Nullable
  private String getPath(DefaultMutableTreeNode node) {
    final Object userObject = node.getUserObject();
    if (userObject instanceof String) {
      String actionId = (String) userObject;

      final TreeNode parent = node.getParent();
      if (parent instanceof DefaultMutableTreeNode) {
        final Object object = ((DefaultMutableTreeNode) parent).getUserObject();
        if (object instanceof Group) {
          return ((Group) object).getActionQualifiedPath(actionId);
        }
      }

      return myMainGroup.getActionQualifiedPath(actionId);
    }
    if (userObject instanceof Group) {
      return ((Group) userObject).getQualifiedPath();
    }
    if (userObject instanceof QuickList) {
      return ((QuickList) userObject).getDisplayName();
    }
    return null;
  }
Exemplo n.º 7
0
 public String getToolTipText() {
   return group.getNameAndAttributes();
 }
Exemplo n.º 8
0
 public String toString() {
   if (parent == null) // root group
   return currentDataset.getLocation();
   else return group.getShortName();
 }
Exemplo n.º 9
0
 public int getIndex(TreeNode child) {
   if (debugTree) System.out.println("getIndex=" + group.getFullName() + " " + child);
   return children.indexOf(child);
 }
Exemplo n.º 10
0
 GroupNode(GroupNode parent, Group group) {
   this.parent = parent;
   this.group = group;
   if (debugTree) System.out.println("new=" + group.getFullName() + " ");
   // firePropertyChangeEvent(new PropertyChangeEvent(this, "TreeNode", null, group));
 }
Exemplo n.º 11
0
    // Make sure that the text rendered by this method is 'searchable' via
    // com.intellij.openapi.keymap.impl.ui.ActionsTree.filter method.
    public void customizeCellRenderer(
        JTree tree,
        Object value,
        boolean selected,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      final boolean showIcons = UISettings.getInstance().SHOW_ICONS_IN_MENUS;
      Keymap originalKeymap = myKeymap != null ? myKeymap.getParent() : null;
      Icon icon = null;
      String text;
      boolean bound = false;
      setToolTipText(null);

      if (value instanceof DefaultMutableTreeNode) {
        Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
        boolean changed;
        if (userObject instanceof Group) {
          Group group = (Group) userObject;
          text = group.getName();

          changed = originalKeymap != null && isGroupChanged(group, originalKeymap, myKeymap);
          icon = group.getIcon();
          if (icon == null) {
            icon = CLOSE_ICON;
          }
        } else if (userObject instanceof String) {
          String actionId = (String) userObject;
          bound = myShowBoundActions && ((KeymapImpl) myKeymap).isActionBound(actionId);
          AnAction action = ActionManager.getInstance().getAction(actionId);
          if (action != null) {
            text = action.getTemplatePresentation().getText();
            if (text == null || text.length() == 0) { // fill dynamic presentation gaps
              text = actionId;
            }
            Icon actionIcon = action.getTemplatePresentation().getIcon();
            if (actionIcon != null) {
              icon = actionIcon;
            }
            setToolTipText(action.getTemplatePresentation().getDescription());
          } else {
            text = actionId;
          }
          changed = originalKeymap != null && isActionChanged(actionId, originalKeymap, myKeymap);
        } else if (userObject instanceof QuickList) {
          QuickList list = (QuickList) userObject;
          icon = AllIcons.Actions.QuickList;
          text = list.getDisplayName();

          changed =
              originalKeymap != null
                  && isActionChanged(list.getActionId(), originalKeymap, myKeymap);
        } else if (userObject instanceof Separator) {
          // TODO[vova,anton]: beautify
          changed = false;
          text = "-------------";
        } else {
          throw new IllegalArgumentException("unknown userObject: " + userObject);
        }

        if (showIcons) {
          setIcon(ActionsTree.getEvenIcon(icon));
        }

        Color foreground;
        if (selected) {
          foreground = UIUtil.getTreeSelectionForeground();
        } else {
          if (changed) {
            foreground = PlatformColors.BLUE;
          } else {
            foreground = UIUtil.getTreeForeground();
          }

          if (bound) {
            foreground = JBColor.MAGENTA;
          }
        }
        SearchUtil.appendFragments(
            myFilter,
            text,
            Font.PLAIN,
            foreground,
            selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground(),
            this);
      }
    }