[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Missing ModifyEvent after switching parents with setParent()

Hi,

I have a problem with missing ModifyEventCalls after switching the parent of a control from one to another shell with setParent() and diposing the old shell.

my scenario:
create shell
create Text
create new shell
switch parent of control from shell to new shell
dispose shell

the ModifyListener is still there, but no ModifyEvent(SWT.Modify) is thrown. When I didn't dispose the old shell, everthing works fine...
the weird thing is that other listeners, like focus- and verifylistener are still working correctly.


is there an intention for this behavior? why? is something missing by creating the new shell?

here some code to illustrate the problem:

public static void main(String[] args) throws Exception {
	Display.getDefault().addFilter(SWT.Modify, new Listener() {

		public void handleEvent(Event event) {
			System.out.println("Modify");
		}

	});
	Shell shell = new Shell(Display.getDefault());
	shell.setSize(1000, 700);
	shell.setText("OldShell");
	shell.setLayout(new FillLayout());
	final Text t = new Text(shell, SWT.SINGLE | SWT.BORDER);
	t.addModifyListener(new ModifyListener() {

		public void modifyText(ModifyEvent e) {
			System.out.println("Text modified");
		}

	});
	t.addFocusListener(new FocusListener() {

		public void focusGained(FocusEvent e) {
			System.out.println("focus gained");
		}

		public void focusLost(FocusEvent e) {
			System.out.println("focus lost");
		}

	});
	t.addVerifyListener(new VerifyListener() {

		public void verifyText(VerifyEvent e) {
			System.out.println("verified");
		}

	});

	for (Listener l : t.getListeners(SWT.Modify))
		System.out.println(l);

	/* alternativ 1: start */
	// 	shell.open();
	//	while (!shell.isDisposed()) {
	//		if (!Display.getDefault().readAndDispatch())
	//				Display.getDefault().sleep();
	//		}
	/* alternativ 1: end */


/* alternative 2: start */ Shell newShell = new Shell(Display.getDefault()); t.setParent(newShell); Button b = new Button(newShell, SWT.PUSH); b.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } public void widgetSelected(SelectionEvent e) { System.out.println("entered string: " + t.getText()); } });

	shell.dispose();
	newShell.setText("NewShell");
	newShell.setLayout(new FillLayout());
	newShell.setSize(300, 200);
	newShell.open();
	while (!newShell.isDisposed()) {
		if (!Display.getDefault().readAndDispatch())
			Display.getDefault().sleep();
	}
	/* alternative 2: end */
	Display.getDefault().dispose();
	System.exit(0);
}

thanks, Johannes