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