1 11 package org.eclipse.pde.internal.ui.preferences; 12 13 import java.util.*; 14 15 import org.eclipse.core.boot.BootLoader; 16 import org.eclipse.core.runtime.Preferences; 17 import org.eclipse.jface.dialogs.Dialog; 18 import org.eclipse.jface.preference.PreferencePage; 19 import org.eclipse.pde.internal.core.*; 20 import org.eclipse.pde.internal.ui.*; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.layout.*; 23 import org.eclipse.swt.widgets.*; 24 import org.eclipse.ui.*; 25 import org.eclipse.ui.help.WorkbenchHelp; 26 27 29 public class TargetEnvironmentPreferencePage 30 extends PreferencePage 31 implements IWorkbenchPreferencePage, IEnvironmentVariables { 32 private static final String KEY_DESCRIPTION = 33 "Preferences.TargetEnvironmentPage.Description"; public static final String KEY_OS = "Preferences.TargetEnvironmentPage.os"; public static final String KEY_WS = "Preferences.TargetEnvironmentPage.ws"; public static final String KEY_NL = "Preferences.TargetEnvironmentPage.nl"; public static final String KEY_ARCH = 38 "Preferences.TargetEnvironmentPage.arch"; 40 private Combo os; 41 private Combo ws; 42 private Combo nl; 43 private Combo arch; 44 45 private Preferences preferences; 46 47 public TargetEnvironmentPreferencePage() { 48 setDescription(PDEPlugin.getResourceString(KEY_DESCRIPTION)); 49 preferences = PDECore.getDefault().getPluginPreferences(); 50 } 51 52 55 protected Control createContents(Composite parent) { 56 Composite container = new Composite(parent, SWT.NULL); 57 GridLayout layout = new GridLayout(); 58 layout.numColumns = 2; 59 container.setLayout(layout); 60 61 Label label = new Label(container, SWT.NULL); 62 label.setText(PDEPlugin.getResourceString(KEY_OS)); 63 64 os = new Combo(container, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); 65 os.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 66 os.setItems(BootLoader.knownOSValues()); 67 68 label = new Label(container, SWT.NULL); 69 label.setText(PDEPlugin.getResourceString(KEY_WS)); 70 71 ws = new Combo(container, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); 72 ws.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 73 ws.setItems(BootLoader.knownWSValues()); 74 75 label = new Label(container, SWT.NULL); 76 label.setText(PDEPlugin.getResourceString(KEY_NL)); 77 78 nl = new Combo(container, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); 79 nl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 80 nl.setItems(getLocales()); 81 82 label = new Label(container, SWT.NULL); 83 label.setText(PDEPlugin.getResourceString(KEY_ARCH)); 84 85 arch = new Combo(container, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); 86 arch.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 87 arch.setItems(BootLoader.knownOSArchValues()); 88 89 Dialog.applyDialogFont(container); 90 91 os.setText(preferences.getString(OS)); 92 ws.setText(preferences.getString(WS)); 93 nl.setText(expandLocaleName(preferences.getString(NL))); 94 arch.setText(preferences.getString(ARCH)); 95 96 WorkbenchHelp.setHelp(container, IHelpContextIds.TARGET_ENVIRONMENT_PREFERENCE_PAGE); 97 98 return container; 99 } 100 101 104 protected void performDefaults() { 105 os.setText(preferences.getDefaultString(OS)); 106 ws.setText(preferences.getDefaultString(WS)); 107 nl.setText(expandLocaleName(preferences.getDefaultString(NL))); 108 arch.setText(preferences.getDefaultString(ARCH)); 109 } 110 111 112 public boolean performOk() { 113 preferences.setValue(OS, os.getText().trim()); 114 preferences.setValue(WS, ws.getText().trim()); 115 String locale = nl.getText().trim(); 116 int dash = locale.indexOf("-"); if (dash != -1) 118 locale = locale.substring(0, dash); 119 locale = locale.trim(); 120 preferences.setValue(NL, locale); 121 preferences.setValue(ARCH, arch.getText().trim()); 122 123 PDEPlugin.getDefault().savePluginPreferences(); 124 return super.performOk(); 125 } 126 127 132 public void init(IWorkbench workbench) { 133 } 134 135 private String expandLocaleName(String name) { 136 String language = ""; String country = ""; String variant = ""; 140 StringTokenizer tokenizer = new StringTokenizer(name, "_"); if (tokenizer.hasMoreTokens()) 142 language = tokenizer.nextToken(); 143 if (tokenizer.hasMoreTokens()) 144 country = tokenizer.nextToken(); 145 if (tokenizer.hasMoreTokens()) 146 variant = tokenizer.nextToken(); 147 148 Locale locale = new Locale(language, country, variant); 149 return locale.toString() + " - " + locale.getDisplayName(); } 151 152 private static String [] getLocales() { 153 Locale[] locales = Locale.getAvailableLocales(); 154 String [] result = new String [locales.length]; 155 for (int i = 0; i < locales.length; i++) { 156 Locale locale = locales[i]; 157 result[i] = locale.toString() + " - " + locale.getDisplayName(); } 159 return result; 160 } 161 162 } 163 | Popular Tags |