Display only one Shell if the shell if previously open not display another shell

467 Views Asked by At

I am developing a rcp application .I am using a Novocode swt balloon window . I need to display one BaloonWindow on button click.but whenever I click on button each time create a new balloon window

My code is below

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;
}

anybody can help me.how to show only one balloon window at time.if a balloon window is open then another balloon window should not be allowed to open or there should remain only one balloon window open at any given point of time.

1

There are 1 best solutions below

3
On

I'm not quite sure I understood you ultimate goal, so here are two possibilities:


First (at most one BalloonWindow at a time)

Create a static boolean field isOpen in your class containing the execute() method. Set this variable to true once you created the BalloonWindow and check this variable each time you enter execute(). If it is false, create a new BalloonWindow, if it is true, return.


Second (close the BalloonWindow)

The BalloonWindow has a method open(). Use this method to open it instead of setVisible(true). If you want to close the BalloonWindow, just call close(). setVisible(false) would have the same visual effect (the window is gone), but it would still be there (only invisible). close really closes the window.