代码之家  ›  专栏  ›  技术社区  ›  Andreas Sewe

删除资源管理器视图中不在TopComponent中的节点

  •  0
  • Andreas Sewe  · 技术社区  · 8 年前

    我正在使用资源管理器视图( OutlineView DialogDescriptor

    @ActionID(category = "Example", id = "org.example.Test")
    @ActionRegistration(displayName = "Test")
    @ActionReference(path = "Menu/File", position = 0)
    public class SomeAction implements ActionListener {
    
      @Override
      public void actionPerformed(ActionEvent e) {
        DialogDescriptor dd = new DialogDescriptor(new MyPanel(), "Titel", true, null);
        DialogDisplayer.getDefault().notify(dd);
      }
    }
    
    class MyPanel extends JPanel implements ExplorerManager.Provider {
      private final ExplorerManager em;
    
      public MyPanel() {
        em = new ExplorerManager();
        em.setRootContext(new MyNode());
        add(new OutlineView());
      }
    
      @Override
      public ExplorerManager getExplorerManager() {
        return em;
      }
    }
    
    class MyNode extends AbstractNode {
      public MyNode() { super(Children.LEAF); }
    
      @Override
      public Action[] getActions(boolean context) {
        return new Action[] { SystemAction.get(DeleteAction.class) };
      }
    
      @Override
      public boolean canDestroy() {
        return true;
      }
    
      @Override
      public void destroy() {
        // Never called
      }
    }
    

    调用该操作时,将显示对话框,大纲视图将显示根节点。但是,选择 TopComponent 后面 模态对话框。如何制作 系统操作是否考虑对话框中的选择?我想我需要这样的东西

    ActionMap map = getActionMap();
    map.put("delete", ExplorerUtils.actionDelete(em, true));
    associateLookup(ExplorerUptils.createLookup(em, map));
    

    取自 但不知道出了什么问题。因此,任何指针都是非常值得赞赏的。

    1 回复  |  直到 8 年前
        1
  •  2
  •   Adam Kanz    8 年前

    在MyPanel构造函数中,必须将delete操作添加到outline视图的操作映射中:

    OutlineView outlineView = new OutlineView();
    DeleteAction delAction = SystemAction.get(DeleteAction.class);
    
    outlineView.getOutline().getActionMap().put(delAction.getActionMapKey(), ExplorerUtils.actionDelete(em,true));
    

    如果还想启用删除键,则必须将相同的操作映射键放入outline view的输入映射:

    KeyStroke delKey = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
    outlineView.getOutline().getInputMap().put(delKey, delAction.getActionMapKey());
    
    推荐文章