@Override
 protected ActionList getActionsForRow(JTable table, int row) {
   ModelItem item = (ModelItem) getModelItemAt(row);
   try {
     return item == null ? null : ActionListBuilder.buildActions(item);
   } catch (Exception e) {
     return null;
   }
 }
Пример #2
0
    public void keyPressed(KeyEvent e) {
      TreePath selectionPath = mainTree.getSelectionPath();
      if (selectionPath == null || mainTree.getSelectionCount() == 0) {
        return;
      }

      if (mainTree.getSelectionCount() == 1) {
        SoapUITreeNode lastPathComponent = (SoapUITreeNode) selectionPath.getLastPathComponent();
        ActionList actions = lastPathComponent.getActions();
        if (actions != null) {
          actions.dispatchKeyEvent(e);
        }

        if (!e.isConsumed()) {
          KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
          if (ks.equals(UISupport.getKeyStroke("alt C"))) {
            mainTree.collapsePath(selectionPath);
            e.consume();
          } else if (ks.equals(UISupport.getKeyStroke("alt E"))) {
            mainTree.collapsePath(selectionPath);
            int row = mainTree.getSelectionRows()[0];
            TreePath nextPath = mainTree.getPathForRow(row + 1);

            TreePath path = mainTree.getPathForRow(row);
            while (path != null && !path.equals(nextPath)) {
              mainTree.expandRow(row);
              path = mainTree.getPathForRow(++row);
            }

            e.consume();
          }
        }
      } else {
        TreePath[] selectionPaths = mainTree.getSelectionPaths();
        List<ModelItem> targets = new ArrayList<ModelItem>();
        for (TreePath treePath : selectionPaths) {
          SoapUITreeNode node = (SoapUITreeNode) treePath.getLastPathComponent();
          targets.add(node.getModelItem());
        }

        if (targets.size() > 0) {
          ActionList actions =
              ActionListBuilder.buildMultiActions(targets.toArray(new ModelItem[targets.size()]));
          if (actions.getActionCount() > 0) {
            actions.dispatchKeyEvent(e);
          }
        }
      }
    }
Пример #3
0
    private void showPopup(MouseEvent e) {
      if (mainTree.getSelectionCount() < 2) {
        TreePath path =
            mainTree.getPathForLocation((int) e.getPoint().getX(), (int) e.getPoint().getY());
        if (path == null) {
          int row = (int) e.getPoint().getY() / mainTree.getRowHeight();
          if (row != -1) {
            JPopupMenu collapsePopup = new JPopupMenu();
            collapsePopup.add("Collapse").addActionListener(new CollapseRowAction(row));
            collapsePopup.add("Expand").addActionListener(new ExpandRowAction(row));
            showToolTipLessPopupMenu(collapsePopup, e.getX(), e.getY());
          }

          return;
        }
        SoapUITreeNode node = (SoapUITreeNode) path.getLastPathComponent();

        JPopupMenu popupMenu = node.getPopup();
        if (popupMenu == null) {
          return;
        }

        mainTree.setSelectionPath(path);

        showToolTipLessPopupMenu(popupMenu, e.getX(), e.getY());
      } else {
        TreePath[] selectionPaths = mainTree.getSelectionPaths();
        List<ModelItem> targets = new ArrayList<ModelItem>();
        for (TreePath treePath : selectionPaths) {
          SoapUITreeNode node = (SoapUITreeNode) treePath.getLastPathComponent();
          targets.add(node.getModelItem());
        }

        if (targets.size() > 0) {
          ActionList actions =
              ActionListBuilder.buildMultiActions(targets.toArray(new ModelItem[targets.size()]));
          if (actions.getActionCount() > 0) {
            JPopupMenu popup = new JPopupMenu();
            ActionSupport.addActions(actions, popup);
            showToolTipLessPopupMenu(popup, e.getX(), e.getY());
          }
        }
      }
    }