将删除图标列添加到 Eclipse 表

发布于 2025-01-02 05:53:35 字数 1637 浏览 0 评论 0 原文

我目前已经实现了 Table 带有 TableEditor 支持键盘支持的单元格级编辑(使用编辑器遍历单元格)。

我还需要一种删除行的方法,并且我不想采用在表旁边添加删除按钮的做法,因为它需要单击 2 次才能删除行(1 次选择行,1 次删除它) )。相反,我想要一个单独的列,其中填充了删除图标。我想到了两种方法来完成此任务,但都遇到了问题:

  1. Table 添加另一列,使用 TableItem.setImage()这种方法存在多个问题,您可以在下面看到它们:

    • 选择一行时,图标也会被选中
    • 将鼠标悬停在图标上时,它会显示图像的工具提示,该提示显然无法禁用
    • 似乎无法将图像在单元格内垂直居中
       

    删除列方法#1

  2. 添加 ScrolledComposite 在表格旁边,并用删除图标填充它。这听起来有点疯狂,但实际上我已经在这个方面取得了很大的进展。这个想法是用删除图标填充 ScrolledComposite ,强制它随表格的滚动条滚动,并在单击图标时删除相应的行。我用这种方法只遇到了一个阻塞问题:

    • 似乎无法隐藏滚动条
       

    删除列方法 #2

所以我的问题是:

  • 如何解决这两种方法中提到的问题?
  • 还有其他更好的方法吗?

I've currently implemented a Table with a TableEditor in my Eclipse plugin to support cell-level editing with keyboard support (to traverse cells with the editor).

I also need a way to delete rows, and I didn't want to go with the practice of adding a delete button next to the table as it requires 2 clicks to delete a row (1 to select a row, and 1 to delete it). Instead I want a separate column which is populated with delete icons. I've thought of 2 ways to accomplish this and have run into issues with both:

  1. Add another column to the Table, set the icon with TableItem.setImage(). There are multiple issues with this approach, and you can see them below:

    • When selecting a row, the icon gets selected too
    • When hovering over the icon, it gets a tooltip of the image which apparently can't be disabled
    • Can't seem to vertically center the image inside the cell
       

    Delete column approach #1

  2. Add a ScrolledComposite next to the table and fill it with delete icons. This sounds a little insane, but I've actually made it pretty far with this one. The idea is to fill a ScrolledComposite with delete icons, force it to scroll with the table's scrollbar, and delete the corresponding row when an icon is clicked. I've only run into one blocking issue with this approach:

    • Can't seem to hide the scrollbar
       

    Delete column approach #2

So my questions are:

  • How I can solve the issues mentioned for either of these approaches?
  • Is there some other better approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸩远一方 2025-01-09 05:53:36

我找到了一种隐藏第二种方法的滚动条的方法。基本上您需要做的就是:

// ScrolledComposite sc;
sc.setAlwaysShowScrollBars(true);
sc.getVerticalBar().setVisible(false);

然后将 ScrolledComposite 的宽度设置为 1 以消除不可见的 ScrollBar 占用的额外空间向上。

并保持滚动条同步:

// Table table;
// ScrolledComposite sc;
// int tableRowHeight;

protected void createTable() {

  ...

  // Set the listener that dictates the table row height.
  table.addListener(SWT.MeasureItem, new Listener() {
    @Override
    public void handleEvent(Event event) {
      event.height = tableRowHeight;
    }
  });

  // Set the listener for keeping the scrollbars in sync.
  table.getVerticalBar().addSelectionListener(new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {
      syncDeleteColumnScrollBar();
    }
  });
}

// This is extracted out into a method so it can also be called
// when removing a table row.
protected void syncDeleteColumnScrollBar() {
  sc.setOrigin(0, table.getVerticalBar().getSelection() * tableRowHeight);
}

结果:

Delete column image

I found a way to hide the scrollbar for my 2nd approach. Basically all you need to do is:

// ScrolledComposite sc;
sc.setAlwaysShowScrollBars(true);
sc.getVerticalBar().setVisible(false);

And then set the width of the ScrolledComposite to 1 to get rid of the extra space the invisible ScrollBar takes up.

And to keep the scrollbars in sync:

// Table table;
// ScrolledComposite sc;
// int tableRowHeight;

protected void createTable() {

  ...

  // Set the listener that dictates the table row height.
  table.addListener(SWT.MeasureItem, new Listener() {
    @Override
    public void handleEvent(Event event) {
      event.height = tableRowHeight;
    }
  });

  // Set the listener for keeping the scrollbars in sync.
  table.getVerticalBar().addSelectionListener(new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {
      syncDeleteColumnScrollBar();
    }
  });
}

// This is extracted out into a method so it can also be called
// when removing a table row.
protected void syncDeleteColumnScrollBar() {
  sc.setOrigin(0, table.getVerticalBar().getSelection() * tableRowHeight);
}

The result:

Delete column image

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文