Reputation: 71
How can I implement Workspace Browse
and EPackages Browse
in SWT / jface
?
The below code browse File System not Workspace.
Button button = new Button(grpModelProperties, SWT.PUSH);
button.setText("Browse Workspace...");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.NULL);
String path = dialog.open();
if (path != null) {
File file = new File(path);
if (file.isFile())
displayFiles(new String[] { file.toString()});
else
displayFiles(file.list());
}
}
});
I also tried the solution presented in SWT Component for choose file only from workspace by @sambi reddy but I have the below error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/osgi/util/NLS
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.ui.dialogs.SelectionDialog.<clinit>(SelectionDialog.java:55)
at mypackage.FrontPage.createControl(FrontPage.java:38)
at org.eclipse.jface.wizard.Wizard.createPageControls(Wizard.java:175)
at org.eclipse.jface.wizard.WizardDialog.createPageControls(WizardDialog.java:705)
at org.eclipse.jface.wizard.WizardDialog.createContents(WizardDialog.java:597)
at org.eclipse.jface.window.Window.create(Window.java:430)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1096)
at org.eclipse.jface.window.Window.open(Window.java:792)
at mypackage.ReservationWizard.main(ReservationWizard.java:76)
Caused by: java.lang.ClassNotFoundException: org.eclipse.osgi.util.NLS
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 21 more
I also don't have an idea about EPackages browse.
edit: When I run the below code, no entries available although workspace has projects:
Button button2 = new Button(grpModelProperties1, SWT.PUSH);
button2.setText("Browse Workspace...");
final GridData button2Data = new GridData(SWT.RIGHT, SWT.CENTER, true, true);
button2.setLayoutData(button2Data);
button2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e2) {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
Display.getDefault().getActiveShell(),
new WorkbenchLabelProvider(),
new BaseWorkbenchContentProvider());
dialog.open();
}
});
Upvotes: 0
Views: 178
Reputation: 111162
You can only access the Eclipse workspace in an Eclipse plugin, it is not available in a plain Java app because of the large amount of initialization that is required.
In your ElementTreeSelectionDialog
dialog you must call setInput
to tell the dialog about the elements to be displayed:
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
Display.getDefault().getActiveShell(),
new WorkbenchLabelProvider(),
new BaseWorkbenchContentProvider());
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.open();
This displays the entire workspace, by changing the input to a IProject or IFolder you can restrict the display to part of the workspace.
Upvotes: 1