8a686f7eba070609685169620604c8ca50e53c96
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / internal / ui / util / DirectorySelector.java
1 package net.sourceforge.phpdt.internal.ui.util;
2
3 import java.io.File;
4
5 import org.eclipse.swt.widgets.Composite;
6 import org.eclipse.swt.widgets.DirectoryDialog;
7
8 public class DirectorySelector extends ResourceSelector {
9
10         public DirectorySelector(Composite parent) {
11                 super(parent);
12         }
13
14         protected void handleBrowseSelected() {
15                 DirectoryDialog dialog = new DirectoryDialog(getShell());
16                 dialog.setMessage(browseDialogMessage);
17                 String currentWorkingDir = textField.getText();
18                 if (!currentWorkingDir.trim().equals("")) {
19                         File path = new File(currentWorkingDir);
20                         if (path.exists()) {
21                                 dialog.setFilterPath(currentWorkingDir);
22                         }
23                 }
24
25                 String selectedDirectory = dialog.open();
26                 if (selectedDirectory != null) {
27                         textField.setText(selectedDirectory);
28                 }
29         }
30
31         protected String validateResourceSelection() {
32                 String directory = textField.getText();
33                 File directoryFile = new File(directory);
34                 if (directoryFile.exists() && directoryFile.isDirectory())
35                         return directory;
36                 return EMPTY_STRING;
37         }
38 }