如果先前打开的shell不显示另一个shell,则仅显示一个Shell

时间:2012-10-20 06:57:19

标签: java swt eclipse-rcp balloon

我正在开发一个rcp应用程序。我正在使用Novocode swt气球窗口。我需要在按钮点击时显示一个BaloonWindow。但每当我点击按钮每次创建一个新的气球窗口

我的代码在

下面
public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
        BalloonWindow baloonWindow=new BalloonWindow(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),SWT.ON_TOP|SWT.TOOL|SWT.CLOSE);
        baloonWindow.setText("XYZ");            
        baloonWindow.setAnchor(SWT.RIGHT|SWT.TOP);
        baloonWindow.setLocation(1290, 90);
        Composite c = baloonWindow.getContents();
        String array[]=new String[2];               
        array[0]="A";
        array[1]="B";                       
        c.setLayout(new FillLayout());
        TableViewer t=new TableViewer(c,SWT.NONE);
        t.setContentProvider(new ArrayContentProvider());
        t.setInput(array);
        c.pack(true);   
        baloonWindow.setVisible(true);

    } catch (Exception e) {         
        e.printStackTrace();
    }
    return null;
}

任何人都可以帮助我。如果时间只显示一个气球窗口。如果气球窗口打开,则不允许打开另一个气球窗口,或者在任何给定的时间点应该只保留一个气球窗口。

1 个答案:

答案 0 :(得分:0)

我不太确定我理解你的最终目标,所以这里有两种可能性:


首先(一次最多一个BalloonWindow

在您的班级中创建包含static方法的boolean isOpen字段execute()。创建true后,将此变量设置为BalloonWindow,并在每次输入execute()时检查此变量。如果是false,请创建新的BalloonWindow,如果是truereturn


第二次(关闭BalloonWindow

BalloonWindow有方法open()。使用此方法打开它而不是setVisible(true)。如果您要关闭BalloonWindow,只需致电close()即可。 setVisible(false)会有相同的视觉效果(窗口消失了),但它仍然存在(只有不可见)。 close真的关闭了窗口。