1 package net.sourceforge.phpdt.internal.ui.util;
3 import net.sourceforge.phpdt.internal.ui.dialog.ElementListSelectionDialog;
4 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
6 import org.eclipse.core.resources.IFile;
7 import org.eclipse.core.resources.IProject;
8 import org.eclipse.core.resources.IResource;
9 import org.eclipse.core.runtime.CoreException;
10 import org.eclipse.core.runtime.IPath;
11 import org.eclipse.core.runtime.Path;
12 import org.eclipse.jface.util.Assert;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.ui.model.WorkbenchLabelProvider;
16 public class PHPFileSelector extends ResourceSelector {
17 protected PHPProjectSelector phpProjectSelector;
19 public PHPFileSelector(Composite parent, PHPProjectSelector aProjectSelector) {
21 Assert.isNotNull(aProjectSelector);
22 phpProjectSelector = aProjectSelector;
24 browseDialogTitle = "File Selection";
27 protected Object[] getPHPFiles() {
28 IProject phpProject = phpProjectSelector.getSelection();
29 if (phpProject == null)
32 PHPElementVisitor visitor = new PHPElementVisitor();
34 phpProject.accept(visitor);
35 } catch(CoreException e) {
36 PHPeclipsePlugin.log(e);
38 return visitor.getCollectedPHPFiles();
41 public IFile getSelection() {
42 String fileName = getSelectionText();
43 if (fileName != null && !fileName.equals("")) {
44 IPath filePath = new Path(fileName);
45 IProject project = phpProjectSelector.getSelection();
46 if (project != null && project.exists(filePath))
47 return project.getFile(filePath);
53 protected void handleBrowseSelected() {
54 ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new WorkbenchLabelProvider());
55 dialog.setTitle(browseDialogTitle);
56 dialog.setMessage(browseDialogMessage);
57 dialog.setElements(getPHPFiles());
59 if (dialog.open() == ElementListSelectionDialog.OK) {
60 textField.setText(((IResource) dialog.getFirstResult()).getProjectRelativePath().toString());
64 protected String validateResourceSelection() {
65 IFile selection = getSelection();
66 return selection == null ? EMPTY_STRING : selection.getProjectRelativePath().toString();