In Eclipse RCP Application, how can i achieve my view to launch a shell to open a Dialog box to get the FileName to the String varibale say fileName?
public class View extends ViewPart {
public void createPartControl(Composite parent) {
Display display = new Display();
final Shell shell = new Shell(display);
FileDialog dlg = new FileDialog(shell, SWT.OPEN);
String fileName = dlg.open();
if (fileName != null) {
System.out.println(fileName);
}
.....
}
}
Imported Shell and Display Packages already..Returns error at launch..
In an Eclipse RCP you never create a new Display
. Only one display object is allowed and the RCP has already created it.
All you need to do here is open the file dialog with the current shell as the parent:
public void createPartControl(Composite parent) {
FileDialog dlg = new FileDialog(parent.getShell(), SWT.OPEN);
String fileName = dlg.open();
if (fileName != null) {
System.out.println(fileName);
}
}