6199901ad854b0aa1f5304e51418eaa3cf0b5fe0
[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.internal.ui.dialog.ElementListSelectionDialog;
4 import net.sourceforge.phpeclipse.PHPCore;
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(projectName);
23                         
24                 return null;
25         }
26
27         protected void handleBrowseSelected() {
28                 ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new WorkbenchLabelProvider());
29                 dialog.setTitle(browseDialogTitle);
30                 dialog.setMessage(browseDialogMessage);
31                 dialog.setElements(PHPCore.getPHPProjects());
32
33                 if (dialog.open() == ElementListSelectionDialog.OK) {
34                         textField.setText(((IProject) dialog.getFirstResult()).getName());
35                 }
36         }
37
38         protected String validateResourceSelection() {
39                 IProject project = getSelection();
40                 return project == null ? EMPTY_STRING : project.getName();
41         }
42 }