75c22ebaf18bb0cc9ccab8ba96882b7b83aae27c
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / util / PHPProjectSelector.java
1 package net.sourceforge.phpdt.internal.ui.util;
2
3 import net.sourceforge.phpdt.core.JavaCore;
4 import net.sourceforge.phpdt.internal.ui.dialogs.ElementListSelectionDialog;
5 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
6
7 import org.eclipse.core.resources.IProject;
8 import org.eclipse.swt.widgets.Composite;
9 import org.eclipse.ui.model.WorkbenchLabelProvider;
10
11 public class PHPProjectSelector extends ResourceSelector {
12
13         public PHPProjectSelector(Composite parent) {
14                 super(parent);
15
16                 browseDialogTitle = "Project Selection";
17         }
18
19         public IProject getSelection() {
20                 String projectName = getSelectionText();
21                 if (projectName != null && !projectName.equals(""))
22                         return PHPeclipsePlugin.getWorkspace().getRoot().getProject(
23                                         projectName);
24
25                 return null;
26         }
27
28         protected void handleBrowseSelected() {
29                 ElementListSelectionDialog dialog = new ElementListSelectionDialog(
30                                 getShell(), new WorkbenchLabelProvider());
31                 dialog.setTitle(browseDialogTitle);
32                 dialog.setMessage(browseDialogMessage);
33                 dialog.setElements(JavaCore.getPHPProjects());
34                 dialog.setInitialElementSelections(null);
35
36                 if (dialog.open() == ElementListSelectionDialog.OK) {
37                         textField.setText(((IProject) dialog.getFirstResult()).getName());
38                 }
39         }
40
41         protected String validateResourceSelection() {
42                 IProject project = getSelection();
43                 return project == null ? EMPTY_STRING : project.getName();
44         }
45 }