[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] is this normal behavior for filedialog?
|
I am running below snippet code on 3138 swt dll in windows xp sp2 and
1.5.0_01-b08
After a few loop, File dialog is mysteriously crashes in the middle of
operation.
No jvm dump. it just exits....
you have to be a little bit patient to reproduce this.
make some empty test.txt in desktop. It only happens at desktop.
I was not able to reproduce with other folder.
1. launch client and open up file dialog and open test.txt in desktop
2. By exiting client, we dispose display but new display and shell will be
created.
3. make a copy of test.txt. So modification of file system should happen
in winodows desktop.
4. try to open and browse and select test.txt...
5. try several times and jvm exits.
Question, what am I doing wrong? maybe, I am not understanding Display
class correctly. Should I not dispose display? Instead, I should recycle
display. My application is network application and I was trying to
reproduce. I am pulling my hair off on this...
Any help would be much appreciated. thanks ahead.
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
public class FileDialogExample {
Display d;
Shell s;
FileDialogExample() {
d = new Display();
s = new Shell(d);
s.setSize(400, 400);
s.setText("A MessageBox Example");
// create the menu system
Menu m = new Menu(s, SWT.BAR);
// create a file menu and add an exit item
final MenuItem file = new MenuItem(m, SWT.CASCADE);
file.setText("&File");
final Menu filemenu = new Menu(s, SWT.DROP_DOWN);
file.setMenu(filemenu);
final MenuItem openItem = new MenuItem(filemenu, SWT.PUSH);
openItem.setText("&Open\tCTRL+O");
openItem.setAccelerator(SWT.CTRL + 'O');
final MenuItem saveItem = new MenuItem(filemenu, SWT.PUSH);
saveItem.setText("&Save\tCTRL+S");
saveItem.setAccelerator(SWT.CTRL + 'S');
final MenuItem separator = new MenuItem(filemenu, SWT.SEPARATOR);
final MenuItem exitItem = new MenuItem(filemenu, SWT.PUSH);
exitItem.setText("E&xit");
class Open implements SelectionListener {
public void widgetSelected(SelectionEvent event) {
FileDialog fd = new FileDialog(s, SWT.OPEN);
fd.setText("Open");
fd.setFilterPath("C:/");
String[] filterExt = { "*.txt", "*.doc", ".rtf", "*.*" };
fd.setFilterExtensions(filterExt);
String selected = fd.open();
// OS.SendMessage()
System.out.println(selected);
}
public void widgetDefaultSelected(SelectionEvent event) {
}
}
class Save implements SelectionListener {
public void widgetSelected(SelectionEvent event) {
FileDialog fd = new FileDialog(s, SWT.SAVE);
fd.setText("Save");
fd.setFilterPath("C:/");
String[] filterExt = { "*.txt", "*.doc", ".rtf", "*.*" };
fd.setFilterExtensions(filterExt);
String selected = fd.open();
System.out.println(selected);
}
public void widgetDefaultSelected(SelectionEvent event) {
}
}
openItem.addSelectionListener(new Open());
saveItem.addSelectionListener(new Save());
exitItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
MessageBox messageBox = new MessageBox(s, SWT.ICON_QUESTION
| SWT.YES | SWT.NO);
messageBox.setMessage("Do you really want to exit?");
messageBox.setText("Exiting Application");
int response = messageBox.open();
if (response == SWT.YES)
s.close();
}
});
s.setMenuBar(m);
s.open();
while (!s.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
public static void main(String[] argv) {
while (true) {
new FileDialogExample();
//at each loop, make file modification in windows Desktop.
//after file modification. open up filedialog and browse to desktop.
//try several times... try to select file jvm exits....
}
}
}