KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > preferences > UpdateSettingsPreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.update.internal.ui.preferences;
12
13 import java.net.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.jface.preference.*;
18 import org.eclipse.swt.*;
19 import org.eclipse.swt.events.*;
20 import org.eclipse.swt.layout.*;
21 import org.eclipse.swt.widgets.*;
22 import org.eclipse.ui.*;
23 import org.eclipse.update.internal.core.*;
24 import org.eclipse.update.internal.operations.*;
25 import org.eclipse.update.internal.ui.UpdateUIMessages;
26
27 /**
28  * Insert the type's description here.
29  * @see PreferencePage
30  */

31 public class UpdateSettingsPreferencePage
32     extends PreferencePage
33     implements IWorkbenchPreferencePage {
34     private Text mappingsFile;
35
36     /**
37      * The constructor.
38      */

39     public UpdateSettingsPreferencePage() {
40         setDescription(UpdateUIMessages.UpdateSettingsPreferencePage_description);
41     }
42
43     /**
44      * Insert the method's description here.
45      */

46     public void init(IWorkbench workbench) {
47     }
48
49     public Control createContents(Composite parent) {
50         Composite container = new Composite(parent, SWT.NULL);
51         GridLayout layout = new GridLayout();
52         container.setLayout(layout);
53         layout.marginWidth = layout.marginHeight = 0;
54         layout.numColumns = 2;
55         Label label = new Label(container, SWT.NULL);
56         label.setText(UpdateUIMessages.UpdateSettingsPreferencePage_label);
57         mappingsFile = new Text(container, SWT.SINGLE | SWT.BORDER);
58
59         initialize();
60         mappingsFile.addModifyListener(new ModifyListener() {
61             public void modifyText(ModifyEvent e) {
62                 textChanged();
63             }
64         });
65         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
66         mappingsFile.setLayoutData(gd);
67         return container;
68     }
69
70     private void initialize() {
71         Preferences pref = UpdateCore.getPlugin().getPluginPreferences();
72         String JavaDoc text = pref.getString(UpdateUtils.P_UPDATE_POLICY_URL);
73         mappingsFile.setText(text);
74         textChanged();
75     }
76
77     private void textChanged() {
78         String JavaDoc text = mappingsFile.getText();
79         if (text.length() > 0) {
80             try {
81                 new URL(text);
82             } catch (MalformedURLException e) {
83                 setValid(false);
84                 setErrorMessage(UpdateUIMessages.UpdateSettingsPreferencePage_invalid);
85                 return;
86             }
87         }
88         setValid(true);
89         setErrorMessage(null);
90     }
91
92     public boolean performOk() {
93         Preferences pref = UpdateCore.getPlugin().getPluginPreferences();
94         String JavaDoc text = mappingsFile.getText();
95         if (text.length() > 0)
96             pref.setValue(UpdateUtils.P_UPDATE_POLICY_URL, text);
97         else
98             pref.setToDefault(UpdateUtils.P_UPDATE_POLICY_URL);
99         UpdateCore.getPlugin().savePluginPreferences();
100         return true;
101     }
102
103     protected void performDefaults() {
104         mappingsFile.setText(""); //$NON-NLS-1$
105
super.performDefaults();
106     }
107
108     public void createControl(Composite parent) {
109         super.createControl(parent);
110         Dialog.applyDialogFont(getControl());
111         /*
112         WorkbenchHelp.setHelp(
113             parent,"org.eclipse.update.ui.AppServerPreferencePage");
114         */

115     }
116 }
117
Popular Tags