0

A 类中的方法 A(非 GUI)

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

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

B 类 - GUI 对话框

在调用 Class B.updateTable() 之前,我想检查并确保 Class B 的 GUI 是打开的并且没有被释放。

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

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

如果我可以添加一个检查并确保在我尝试更新表格之前没有处理小部件。

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

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

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

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

4

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.

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.

于 2012-10-29T20:38:16.067 回答