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