FileSelectionDialog open up with no entries [message #72706] |
Thu, 12 June 2003 16:52  |
Eclipse User |
|
|
|
Originally posted by: none.none.com
I am trying to get the FileSelectionDialog to work with the following
sample code. The dialog opens up with no entries. What am i doing wrong?
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject proj = root.getProject("Sample");
//need to get a handle on the right project
IJavaProject project = JavaCore.create(proj);
IClasspathEntry[] classpath = project.getResolvedClasspath(true);
ArrayList pathList = new ArrayList();
FileSystemElement parent = null;
for (int i=0;i<classpath.length;i++) {
IClasspathEntry entry = classpath[i];
if (entry.getEntryKind()==entry.CPE_LIBRARY) {
IPath path = entry.getPath();
IJavaElement element = project.findPackageFragmentRoot(path);
parent = new FileSystemElement("Test",null,false);
if (element!=null) {
pathList.add(new
FileSystemElement(element.getElementName().toString(),parent ,false));
}
}
FileSelectionDialog dialog =
new FileSelectionDialog(this.getShell(),parent,"Select Jar file" );
dialog.setInitialSelections(pathList.toArray());
dialog.setMessage("Choose Jar/Zip file...");
dialog.open();
Object[] result = dialog.getResult();
}
catch (JavaModelException jme) {
jme.printStackTrace();
}
|
|
|
Re: FileSelectionDialog open up with no entries [message #74105 is a reply to message #72706] |
Fri, 13 June 2003 15:37  |
Eclipse User |
|
|
|
Originally posted by: knut_radloff.oti.com
1) FileSelectionDialog is deprecated, it advises you to use the SWT FileDialog instead. However, it doesn't seem like you really
want to display file system objects. I'm not sure if there already is a dialog that does what you want.
2) If you choose to continue using the FileSelectionDialog you need to know that it displays directories in the left hand tree
viewer and files in the right hand list viewer. In order to display all the Jars in the list viewer they all need to have the same
parent. Like so:
ArrayList pathList = new ArrayList();
FileSystemElement parent = new FileSystemElement(project.getElementName(),null,true);;
pathList.add(parent);
for (int i=0;i<classpath.length;i++) {
IClasspathEntry entry = classpath[i];
if (entry.getEntryKind()==entry.CPE_LIBRARY) {
IPath path = entry.getPath();
IJavaElement element = project.findPackageFragmentRoot(path);
if (element!=null) {
pathList.add(new FileSystemElement(element.getElementName().toString(),parent ,false));
}
}
}
Knut
"Kapil" <none@none.com> wrote in message news:bcap61$qtv$1@rogue.oti.com...
> I am trying to get the FileSelectionDialog to work with the following
> sample code. The dialog opens up with no entries. What am i doing wrong?
>
> try {
> IWorkspace workspace = ResourcesPlugin.getWorkspace();
> IWorkspaceRoot root = workspace.getRoot();
> IProject proj = root.getProject("Sample");
> //need to get a handle on the right project
> IJavaProject project = JavaCore.create(proj);
> IClasspathEntry[] classpath = project.getResolvedClasspath(true);
> ArrayList pathList = new ArrayList();
> FileSystemElement parent = null;
> for (int i=0;i<classpath.length;i++) {
> IClasspathEntry entry = classpath[i];
> if (entry.getEntryKind()==entry.CPE_LIBRARY) {
> IPath path = entry.getPath();
> IJavaElement element = project.findPackageFragmentRoot(path);
> parent = new FileSystemElement("Test",null,false);
> if (element!=null) {
> pathList.add(new
> FileSystemElement(element.getElementName().toString(),parent ,false));
>
> }
> }
> FileSelectionDialog dialog =
> new FileSelectionDialog(this.getShell(),parent,"Select Jar file" );
> dialog.setInitialSelections(pathList.toArray());
> dialog.setMessage("Choose Jar/Zip file...");
> dialog.open();
> Object[] result = dialog.getResult();
> }
> catch (JavaModelException jme) {
> jme.printStackTrace();
> }
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04254 seconds