KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > ExtMethodPreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui;
12
13
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.preference.IPreferenceStore;
17 import org.eclipse.jface.preference.PreferencePage;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.SelectionAdapter;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.*;
24 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
25 import org.eclipse.team.internal.ccvs.core.IConnectionMethod;
26 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
27 import org.eclipse.team.internal.ui.SWTUtils;
28 import org.eclipse.ui.*;
29 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
30
31 public class ExtMethodPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
32
33     Text cvsRsh;
34     Text cvsServer;
35     Text cvsRshParameters;
36     private Button useExternal;
37     private Button useInternal;
38     private Combo methodType;
39     private Control internal, external;
40
41     /*
42      * @see PreferencePage#createContents(Composite)
43      */

44     protected Control createContents(Composite parent) {
45         Composite composite = new Composite(parent, SWT.NULL);
46         GridLayout layout = new GridLayout();
47         layout.marginWidth = 0;
48         layout.marginHeight = 0;
49         layout.numColumns = 1;
50         composite.setLayout(layout);
51         composite.setLayoutData(new GridData());
52         
53         SelectionAdapter selectionListener = new SelectionAdapter() {
54             public void widgetSelected(SelectionEvent e) {
55                 updateEnablements();
56             }
57         };
58         
59         useExternal = createRadioButton(composite, CVSUIMessages.ExtMethodPreferencePage_0, 1);
60         useExternal.addSelectionListener(selectionListener);
61         external = createExternalArea(composite);
62         
63         useInternal = createRadioButton(composite, CVSUIMessages.ExtMethodPreferencePage_1, 1);
64         useInternal.addSelectionListener(selectionListener);
65         internal = createInternalArea(composite);
66         
67         SWTUtils.createPreferenceLink((IWorkbenchPreferenceContainer) getContainer(), composite, CVSUIMessages.CVSPreferencesPage_52, CVSUIMessages.CVSPreferencesPage_53);
68         
69         SWTUtils.createPreferenceLink((IWorkbenchPreferenceContainer) getContainer(), composite, CVSUIMessages.CVSPreferencesPage_54, CVSUIMessages.CVSPreferencesPage_55);
70
71         initializeDefaults();
72         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.EXT_PREFERENCE_PAGE);
73         Dialog.applyDialogFont(parent);
74         return composite;
75     }
76     
77     private void updateEnablements() {
78         external.setEnabled(useExternal.getSelection());
79         cvsRsh.setEnabled(useExternal.getSelection());
80         cvsRshParameters.setEnabled(useExternal.getSelection());
81         cvsServer.setEnabled(useExternal.getSelection());
82         internal.setEnabled(!useExternal.getSelection());
83         methodType.setEnabled(!useExternal.getSelection());
84     }
85
86     private Control createInternalArea(Composite parent) {
87         Composite composite = new Composite(parent, SWT.NULL);
88         GridLayout layout = new GridLayout();
89         layout.marginWidth = 5;
90         layout.marginHeight = 5;
91         layout.numColumns = 2;
92         composite.setLayout(layout);
93         composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
94         
95         Label intro = new Label(composite, SWT.LEFT | SWT.WRAP);
96         intro.setText(CVSUIMessages.ExtMethodPreferencePage_2);
97         GridData data = new GridData();
98         data.horizontalSpan = 2;
99         data.horizontalAlignment = GridData.FILL;
100         data.widthHint = 300;
101         intro.setLayoutData(data);
102         
103         createLabel(composite, CVSUIMessages.CVSPropertiesPage_connectionType, 1);
104         methodType = createCombo(composite);
105         
106         return composite;
107     }
108     protected Control createExternalArea(Composite parent) {
109         Composite composite = new Composite(parent, SWT.NULL);
110         GridLayout layout = new GridLayout();
111         layout.marginWidth = 5;
112         layout.marginHeight = 5;
113         layout.numColumns = 3;
114         composite.setLayout(layout);
115         composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
116         
117         Label intro = new Label(composite, SWT.LEFT | SWT.WRAP);
118         intro.setText(CVSUIMessages.ExtMethodPreferencePage_message);
119         GridData data = new GridData();
120         data.horizontalSpan = 3;
121         data.horizontalAlignment = GridData.FILL;
122         data.widthHint = 300;
123         intro.setLayoutData(data);
124         
125         new Label(composite, SWT.LEFT).setText(CVSUIMessages.ExtMethodPreferencePage_CVS_RSH);
126         cvsRsh = new Text(composite, SWT.BORDER);
127         cvsRsh.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
128         
129         final Button b = new Button(composite, SWT.NONE);
130         b.setText(CVSUIMessages.ExtMethodPreferencePage_Browse);
131         data = new GridData();
132         data.horizontalAlignment = GridData.FILL;
133         int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
134         data.widthHint = Math.max(widthHint, b.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
135         b.setLayoutData(data);
136         b.addListener(SWT.MouseDown, new Listener() {
137             public void handleEvent (Event event) {
138                 FileDialog d = new FileDialog(getShell());
139                 d.setText(CVSUIMessages.ExtMethodPreferencePage_Details);
140                 String JavaDoc file = d.open();
141                 if(file!=null) {
142                     setCvsRshText(file);
143                 }
144             }
145         });
146         
147         new Label(composite, SWT.LEFT).setText(CVSUIMessages.ExtMethodPreferencePage_CVS_RSH_Parameters);
148         cvsRshParameters = new Text(composite, SWT.BORDER);
149         data = new GridData();
150         data.horizontalSpan = 2;
151         data.horizontalAlignment = GridData.FILL;
152         cvsRshParameters.setLayoutData(data);
153
154         new Label(composite, SWT.LEFT).setText(CVSUIMessages.ExtMethodPreferencePage_CVS_SERVER__7);
155         cvsServer = new Text(composite, SWT.BORDER);
156         data = new GridData();
157         data.horizontalSpan = 2;
158         data.horizontalAlignment = GridData.FILL;
159         cvsServer.setLayoutData(data);
160         
161         PlatformUI.getWorkbench().getHelpSystem().setHelp(cvsRsh, IHelpContextIds.EXT_PREFERENCE_RSH);
162         PlatformUI.getWorkbench().getHelpSystem().setHelp(cvsRshParameters, IHelpContextIds.EXT_PREFERENCE_PARAM);
163         PlatformUI.getWorkbench().getHelpSystem().setHelp(cvsServer, IHelpContextIds.EXT_PREFERENCE_SERVER);
164         return composite;
165     }
166     
167     private void initializeDefaults() {
168         IPreferenceStore store = getPreferenceStore();
169         String JavaDoc rsh = store.getString(ICVSUIConstants.PREF_CVS_RSH);
170         String JavaDoc parameter = store.getString(ICVSUIConstants.PREF_CVS_RSH_PARAMETERS);
171         String JavaDoc server = store.getString(ICVSUIConstants.PREF_CVS_SERVER);
172         String JavaDoc method = store.getString(ICVSUIConstants.PREF_EXT_CONNECTION_METHOD_PROXY);
173         initializeDefaults(rsh, parameter, server, method);
174     }
175     
176     /*
177      * Set CVS_RSH program
178      */

179      protected void setCvsRshText(String JavaDoc s) {
180         cvsRsh.setText(s);
181      }
182     
183     /*
184      * @see IWorkbenchPreferencePage#init(IWorkbench)
185      */

186     public void init(IWorkbench workbench) {
187     }
188     
189     /*
190      * @see IPreferencePage#performOk()
191      */

192     public boolean performOk() {
193         IPreferenceStore store = getPreferenceStore();
194         String JavaDoc method;
195         if (useExternal.getSelection()) {
196             method = "ext"; //$NON-NLS-1$
197
store.setValue(ICVSUIConstants.PREF_CVS_RSH, cvsRsh.getText());
198             store.setValue(ICVSUIConstants.PREF_CVS_RSH_PARAMETERS, cvsRshParameters.getText());
199             store.setValue(ICVSUIConstants.PREF_CVS_SERVER, cvsServer.getText());
200             CVSProviderPlugin.getPlugin().setCvsRshCommand(cvsRsh.getText());
201             CVSProviderPlugin.getPlugin().setCvsRshParameters(cvsRshParameters.getText());
202             CVSProviderPlugin.getPlugin().setCvsServer(cvsServer.getText());
203         } else {
204             method = methodType.getText();
205         }
206         store.setValue(ICVSUIConstants.PREF_EXT_CONNECTION_METHOD_PROXY, method);
207         CVSRepositoryLocation.setExtConnectionMethodProxy(method);
208         CVSUIPlugin.getPlugin().savePluginPreferences();
209         return super.performOk();
210     }
211     
212     /*
213      * @see PreferencePage#performDefaults()
214      */

215     protected void performDefaults() {
216         IPreferenceStore store = getPreferenceStore();
217         String JavaDoc rsh = store.getDefaultString(ICVSUIConstants.PREF_CVS_RSH);
218         String JavaDoc parameter = store.getDefaultString(ICVSUIConstants.PREF_CVS_RSH_PARAMETERS);
219         String JavaDoc server = store.getDefaultString(ICVSUIConstants.PREF_CVS_SERVER);
220         String JavaDoc method = store.getDefaultString(ICVSUIConstants.PREF_EXT_CONNECTION_METHOD_PROXY);
221         initializeDefaults(rsh, parameter, server, method);
222         super.performDefaults();
223     }
224     
225     private void initializeDefaults(String JavaDoc rsh, String JavaDoc parameters, String JavaDoc server, String JavaDoc method) {
226         cvsRsh.setText(rsh);
227         cvsRshParameters.setText(parameters);
228         cvsServer.setText(server);
229         IConnectionMethod[] methods = CVSRepositoryLocation.getPluggedInConnectionMethods();
230         for (int i = 0; i < methods.length; i++) {
231             String JavaDoc name = methods[i].getName();
232             if (!name.equals("ext")) { //$NON-NLS-1$
233
methodType.add(name);
234             }
235         }
236         if (method.equals("ext")) { //$NON-NLS-1$
237
methodType.select(0);
238         } else {
239             methodType.select(methodType.indexOf(method));
240         }
241         useExternal.setSelection(method.equals("ext")); //$NON-NLS-1$
242
useInternal.setSelection(!method.equals("ext")); //$NON-NLS-1$
243
updateEnablements();
244     }
245     
246     /*
247      * @see PreferencePage#doGetPreferenceStore()
248      */

249     protected IPreferenceStore doGetPreferenceStore() {
250         return CVSUIPlugin.getPlugin().getPreferenceStore();
251     }
252     
253     protected Button createRadioButton(Composite parent, String JavaDoc label, int span) {
254         Button button = new Button(parent, SWT.RADIO);
255         button.setText(label);
256         GridData data = new GridData();
257         data.horizontalSpan = span;
258         button.setLayoutData(data);
259         return button;
260     }
261     
262     protected Label createLabel(Composite parent, String JavaDoc text, int span) {
263         Label label = new Label(parent, SWT.LEFT);
264         label.setText(text);
265         GridData data = new GridData();
266         data.horizontalSpan = span;
267         data.horizontalAlignment = GridData.FILL;
268         label.setLayoutData(data);
269         return label;
270     }
271     protected Combo createCombo(Composite parent) {
272         Combo combo = new Combo(parent, SWT.READ_ONLY);
273         GridData data = new GridData(GridData.FILL_HORIZONTAL);
274         data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
275         data.horizontalSpan = 1;
276         combo.setLayoutData(data);
277         return combo;
278     }
279 }
280
Popular Tags