034d691becdc80db22080b314210677479e2e3b6
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / 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.phpeclipse.ui.WebUI;
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.dialogs.ElementListSelectionDialog;
10 import org.eclipse.ui.model.WorkbenchLabelProvider;
11
12 public class PHPProjectSelector extends ResourceSelector {
13
14         public PHPProjectSelector(Composite parent) {
15                 super(parent);
16
17                 browseDialogTitle = "Project Selection";
18         }
19
20         public IProject getSelection() {
21                 String projectName = getSelectionText();
22                 if (projectName != null && !projectName.equals(""))
23                         return WebUI.getWorkspace().getRoot().getProject(
24                                         projectName);
25
26                 return null;
27         }
28
29         protected void handleBrowseSelected() {
30                 ElementListSelectionDialog dialog = new ElementListSelectionDialog(
31                                 getShell(), new WorkbenchLabelProvider());
32                 dialog.setTitle(browseDialogTitle);
33                 dialog.setMessage(browseDialogMessage);
34                 dialog.setElements(JavaCore.getPHPProjects());
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 }