1) Moved net.sourceforge.phpeclipse.ui\src\net\sourceforge\phpdt back to net.sourcefo...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / util / ResourceSelector.java
1 package net.sourceforge.phpdt.internal.ui.util;
2
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.events.ModifyEvent;
5 import org.eclipse.swt.events.ModifyListener;
6 import org.eclipse.swt.events.SelectionAdapter;
7 import org.eclipse.swt.events.SelectionEvent;
8 import org.eclipse.swt.layout.GridData;
9 import org.eclipse.swt.layout.GridLayout;
10 import org.eclipse.swt.widgets.Button;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.swt.widgets.Shell;
13 import org.eclipse.swt.widgets.Text;
14
15 public abstract class ResourceSelector {
16         protected final static String EMPTY_STRING = "";
17
18         protected Composite composite;
19
20         protected Button browseButton;
21
22         protected Text textField;
23
24         protected String browseDialogMessage = EMPTY_STRING;
25
26         protected String browseDialogTitle = EMPTY_STRING;
27
28         protected String validatedSelectionText = EMPTY_STRING;
29
30         public ResourceSelector(Composite parent) {
31                 composite = new Composite(parent, SWT.NONE);
32                 GridLayout compositeLayout = new GridLayout();
33                 compositeLayout.marginWidth = 0;
34                 compositeLayout.marginHeight = 0;
35                 compositeLayout.numColumns = 2;
36                 composite.setLayout(compositeLayout);
37
38                 textField = new Text(composite, SWT.SINGLE | SWT.BORDER);
39                 textField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
40                 textField.addModifyListener(new ModifyListener() {
41                         public void modifyText(ModifyEvent e) {
42                                 validatedSelectionText = validateResourceSelection();
43                         }
44                 });
45
46                 browseButton = new Button(composite, SWT.PUSH);
47                 browseButton.setText("Browse...");
48                 browseButton.addSelectionListener(new SelectionAdapter() {
49                         public void widgetSelected(SelectionEvent e) {
50                                 handleBrowseSelected();
51                         }
52                 });
53         }
54
55         protected abstract void handleBrowseSelected();
56
57         protected abstract String validateResourceSelection();
58
59         protected Shell getShell() {
60                 return composite.getShell();
61         }
62
63         public void setLayoutData(Object layoutData) {
64                 composite.setLayoutData(layoutData);
65         }
66
67         public void addModifyListener(ModifyListener aListener) {
68                 textField.addModifyListener(aListener);
69         }
70
71         public void setBrowseDialogMessage(String aMessage) {
72                 browseDialogMessage = aMessage;
73         }
74
75         public void setBrowseDialogTitle(String aTitle) {
76                 browseDialogTitle = aTitle;
77         }
78
79         public void setEnabled(boolean enabled) {
80                 composite.setEnabled(enabled);
81                 textField.setEnabled(enabled);
82                 browseButton.setEnabled(enabled);
83         }
84
85         public String getSelectionText() {
86                 return textField.getText();
87         }
88
89         public String getValidatedSelectionText() {
90                 return validatedSelectionText;
91         }
92
93         public void setSelectionText(String newText) {
94                 textField.setText(newText);
95         }
96 }