1 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 31 public class UpdateSettingsPreferencePage 32 extends PreferencePage 33 implements IWorkbenchPreferencePage { 34 private Text mappingsFile; 35 36 39 public UpdateSettingsPreferencePage() { 40 setDescription(UpdateUIMessages.UpdateSettingsPreferencePage_description); 41 } 42 43 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 text = pref.getString(UpdateUtils.P_UPDATE_POLICY_URL); 73 mappingsFile.setText(text); 74 textChanged(); 75 } 76 77 private void textChanged() { 78 String 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 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(""); super.performDefaults(); 106 } 107 108 public void createControl(Composite parent) { 109 super.createControl(parent); 110 Dialog.applyDialogFont(getControl()); 111 115 } 116 } 117 | Popular Tags |