show HTML files as local resources (no 'http://' url prefix)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / wizards / BookmarkConnectionWizardPage.java
1 package com.quantum.wizards;
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.Label;
13 import org.eclipse.swt.widgets.Text;
14
15 import com.quantum.Messages;
16 import com.quantum.model.JDBCDriver;
17
18
19 class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
20         
21         /* use this to paint a more helpful UI for the JDBC URL */
22         private JDBCDriver driver;
23         private String userid;
24         private String password;
25         private String connectionURL;
26     private boolean prompt;
27     
28     /**
29          * Constructor for BookmarkPage.
30          * @param pageName
31          */
32         public BookmarkConnectionWizardPage(String pageName) {
33                 super(pageName);
34                 setTitle(Messages.getString(getClass(), "title"));
35                 setDescription(Messages.getString(getClass(), "description"));
36         }
37         public void createControl(Composite parent) {
38                 setPageComplete(false);
39                 
40                 Composite container = new Composite(parent, SWT.NULL);
41                 GridLayout layout = new GridLayout();
42                 container.setLayout(layout);
43                 layout.numColumns = 3;
44                 layout.verticalSpacing = 9;
45
46                 Label label = new Label(container, SWT.NULL);
47                 label.setText(Messages.getString(getClass(), "userid")); //$NON-NLS-1$
48                 Text username = new Text(container, SWT.BORDER | SWT.SINGLE);
49                 
50                 
51                 GridData fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
52                 fullHorizontal.horizontalSpan = 2;
53                 username.setLayoutData(fullHorizontal);
54                 username.addModifyListener(new ModifyListener() {
55                         public void modifyText(ModifyEvent event) {
56                                 String userid = ((Text) event.getSource()).getText();
57                                 setUserid(userid);
58                                 updateButtonState();
59                         }
60                 });
61
62                 label = new Label(container, SWT.NULL);
63                 label.setText(Messages.getString(getClass(), "password")); //$NON-NLS-1$
64                 final Text password = new Text(container, SWT.BORDER | SWT.SINGLE);
65                 password.setEchoChar('*');
66                 fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
67                 fullHorizontal.horizontalSpan = 2;
68                 password.setLayoutData(fullHorizontal);
69                 password.addModifyListener(new ModifyListener() {
70                         public void modifyText(ModifyEvent event) {
71                                 String password = ((Text) event.getSource()).getText();
72                                 setPassword(password);
73                                 updateButtonState();
74                         }
75                 });
76
77         Button prompt = new Button(container, SWT.CHECK);
78                 prompt.setText(Messages.getString(getClass(), "prompt")); //$NON-NLS-1$
79                 fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
80                 fullHorizontal.horizontalSpan = 3;
81         prompt.setLayoutData(fullHorizontal);
82  
83                 label = new Label(container, SWT.NULL);
84                 label.setText(Messages.getString(getClass(), "url")); //$NON-NLS-1$
85                 
86                 Text connect = new Text(container, SWT.BORDER | SWT.SINGLE);
87                 fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
88                 fullHorizontal.horizontalSpan = 2;
89                 connect.setLayoutData(fullHorizontal);
90                 connect.addModifyListener(new ModifyListener() {
91                         public void modifyText(ModifyEvent event) {
92                                 String connectionURL = ((Text) event.getSource()).getText();
93                                 setConnectionURL(connectionURL);
94                                 updateButtonState();
95                         }
96                 });
97         prompt.addSelectionListener(new SelectionAdapter() {
98             public void widgetSelected(SelectionEvent event) {
99                 Button prompt = ((Button) event.getSource());
100                 password.setEditable(!prompt.getSelection());
101                 setPrompt(prompt.getSelection());
102                 updateButtonState();
103             }
104         });
105
106                 setControl(container);
107         }
108         
109         /**
110          * @return Returns the driver.
111          */
112         public JDBCDriver getDriver() {
113                 return this.driver;
114         }
115         /**
116          * @param driver The driver to set.
117          */
118         public void setDriver(JDBCDriver driver) {
119                 this.driver = driver;
120         }
121         /**
122          * 
123          */
124         private void updateButtonState() {
125                 boolean complete = true;
126                 complete &= (this.connectionURL != null 
127                                 && this.connectionURL.trim().length() > 0);
128                 complete &= (this.userid != null 
129                                 && this.userid.trim().length() > 0);
130                 setPageComplete(complete);
131         }
132         /**
133          * @return Returns the userid.
134          */
135         public String getUserid() {
136                 return this.userid;
137         }
138         /**
139          * @param userid The userid to set.
140          */
141         public void setUserid(String userid) {
142                 if (userid != null && !userid.equals(this.userid)) {
143                         String original = this.userid;
144                         this.userid = userid;
145                         firePropertyChange("userid", original, userid);
146                 }
147         }
148         /**
149          * @return Returns the prompt.
150          */
151         public boolean isPrompt() {
152                 return this.prompt;
153         }
154         /**
155          * @param prompt The prompt to set.
156          */
157         public void setPrompt(boolean prompt) {
158                 if (this.prompt != prompt) {
159                         boolean original = this.prompt;
160                         this.prompt = prompt;
161                         firePropertyChange("prompt", original, prompt);
162                 }
163         }
164         /**
165          * @return Returns the connectionURL.
166          */
167         public String getConnectionURL() {
168                 return this.connectionURL;
169         }
170         /**
171          * @param connectionURL The connectionURL to set.
172          */
173         public void setConnectionURL(String connectionURL) {
174                 if (connectionURL != null && !connectionURL.equals(this.connectionURL)) {
175                         String original = this.connectionURL;
176                         this.connectionURL = connectionURL;
177                         firePropertyChange("connectionURL", original, connectionURL);
178                 }
179         }
180         /**
181          * @return Returns the password.
182          */
183         public String getPassword() {
184                 return this.password;
185         }
186         /**
187          * @param password The password to set.
188          */
189         public void setPassword(String password) {
190                 if (password != null && !password.equals(this.password)) {
191                         String original = this.password;
192                         this.password = password;
193                         firePropertyChange("password", original, password);
194                 }
195         }
196 }