Display only one shell if the shell, if previously opened, does not display another shell

I am developing an rcp application. I am using Novocode window ball window. I need to display one BaloonWindow on the click.but button, every time I click the button, every time I 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; } 

can anyone help me. Show only one ball window at a time. If the balloon window is open, the other balloon window should not open or only one balloon window should remain open at any given time.

+4
source share
1 answer

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


First (no more than one BalloonWindow at a time)

Create a static boolean isOpen in your class containing the execute() method. Set this variable to true after creating BalloonWindow and check this variable every time you type execute() . If it is false , create a new BalloonWindow , if it is true , return .


Second (close BalloonWindow )

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

0
source

Source: https://habr.com/ru/post/1440924/


All Articles