如何判断窗口小部件是否仍处于活动状态且未处理?

时间:2022-04-22 16:58:23

Method A in Class A (Non GUI)

A类方法A(非GUI)

public void add() {
   if(etc...) {
      add data to a arraylist ..... 
   }
   Class B.updateTable();
 }

The method above basically adds data to a arraylist and then updates the tableViewer in class b.

上面的方法基本上将数据添加到arraylist,然后更新类b中的tableViewer。

Class B - GUI Dialog

B类 - GUI对话框

Before I call Class B.updateTable(), I would like to check and make sure that Class B's GUI is open and not disposed.

在我调用类B.updateTable()之前,我想检查并确保B类的GUI是打开的而不是处理掉的。

The user can use Class A(non gui) without Class B GUI being open. Because Class A builds a user selected ArrayList and Class B displays it. So they can add data without ever trying to display it.

用户可以使用A类(非gui)而不打开B类GUI。因为A类构建了一个用户选择的ArrayList,而B类显示它。因此,他们可以添加数据,而无需尝试显示它。

If I run B.updateTable() currently and Class B is not open, I get a widget disposed error.

如果我当前运行B.updateTable()并且B类未打开,我会得到一个小部件处理错误。

If I can add a check and make sure the widget is not disposed before I try to update the table.

如果我可以添加检查并确保在尝试更新表之前未放置窗口小部件。

Can I check the value from Class A or do I need to write a static boolean method is Class B that returns something like shell.isDisposed?

我可以检查A类中的值,还是需要编写一个静态布尔方法,B类返回类似shell.isDisposed的内容?

Then in Class A method I could just add the check.

然后在A类方法中我可以添加检查。

  public void add() {
     if(etc...) {
        add data to a arraylist ..... 
     }
     if(!Class B.isShellDisposed()) {       
        Class B.updateTable();
     }
  }

Is this possible or even the right way to handle the error?

这可能是甚至是处理错误的正确方法吗?

1 个解决方案

#1


0  

The issue I was having was refreshing my table viewer, while the GUI was closed. When my user would close the GUI to add more data to the arraylist via the Main Application. I had code in the add method to refresh the table viewer in the GUI. The main problem was even though the GUI was closed, the table viewer was not null. So my code was trying to refresh something that was already disposed. Knowing I do not need to refresh the table viewer when the GUI is closed. I set the table viewer to null in the Close Button code. Then checked the viewer for null in the update method.

我关心的问题是在GUI关闭时刷新我的表查看器。当我的用户关闭GUI以通过主应用程序向arraylist添加更多数据时。我在add方法中有代码来刷新GUI中的表查看器。主要问题是即使GUI关闭,表查看器也不为空。所以我的代码试图刷新已经处理好的东西。知道在GUI关闭时我不需要刷新表查看器。我在关闭按钮代码中将表查看器设置为null。然后在update方法中检查查看器是否为null。

static public void updateTableViewer() {

  if(getViewer() != null) {
     viewer.refresh();
  }
}

So now when the GUI is closed the table viewer is NULL and when it is open the table viewer is not null. This seems to work for me.

所以现在当GUI关闭时,表查看器为NULL,当它打开时,表查看器不为空。这似乎对我有用。

#1


0  

The issue I was having was refreshing my table viewer, while the GUI was closed. When my user would close the GUI to add more data to the arraylist via the Main Application. I had code in the add method to refresh the table viewer in the GUI. The main problem was even though the GUI was closed, the table viewer was not null. So my code was trying to refresh something that was already disposed. Knowing I do not need to refresh the table viewer when the GUI is closed. I set the table viewer to null in the Close Button code. Then checked the viewer for null in the update method.

我关心的问题是在GUI关闭时刷新我的表查看器。当我的用户关闭GUI以通过主应用程序向arraylist添加更多数据时。我在add方法中有代码来刷新GUI中的表查看器。主要问题是即使GUI关闭,表查看器也不为空。所以我的代码试图刷新已经处理好的东西。知道在GUI关闭时我不需要刷新表查看器。我在关闭按钮代码中将表查看器设置为null。然后在update方法中检查查看器是否为null。

static public void updateTableViewer() {

  if(getViewer() != null) {
     viewer.refresh();
  }
}

So now when the GUI is closed the table viewer is NULL and when it is open the table viewer is not null. This seems to work for me.

所以现在当GUI关闭时,表查看器为NULL,当它打开时,表查看器不为空。这似乎对我有用。