1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import java.util.Map ; 14 15 import org.eclipse.core.runtime.IPath; 16 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Control; 19 20 import org.eclipse.jface.dialogs.Dialog; 21 import org.eclipse.jface.dialogs.MessageDialog; 22 import org.eclipse.jface.preference.PreferencePage; 23 24 import org.eclipse.ui.IWorkbench; 25 import org.eclipse.ui.IWorkbenchPreferencePage; 26 import org.eclipse.ui.PlatformUI; 27 28 import org.eclipse.jdt.core.JavaCore; 29 30 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 31 import org.eclipse.jdt.internal.ui.JavaPlugin; 32 import org.eclipse.jdt.internal.ui.wizards.buildpaths.VariableBlock; 33 34 public class ClasspathVariablesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { 35 36 public static final String ID= "org.eclipse.jdt.ui.preferences.ClasspathVariablesPreferencePage"; 38 public static final String DATA_SELECT_VARIABLE= "ClasspathVariablesPreferencePage.select_var"; 40 private VariableBlock fVariableBlock; 41 private String fStoredSettings; 42 43 46 public ClasspathVariablesPreferencePage() { 47 setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore()); 48 fVariableBlock= new VariableBlock(true, null); 49 fStoredSettings= null; 50 51 setTitle(PreferencesMessages.ClasspathVariablesPreferencePage_title); 53 setDescription(PreferencesMessages.ClasspathVariablesPreferencePage_description); 54 noDefaultAndApplyButton(); 55 } 56 57 61 public void createControl(Composite parent) { 62 super.createControl(parent); 63 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.CP_VARIABLES_PREFERENCE_PAGE); 64 } 65 66 69 protected Control createContents(Composite parent) { 70 Control result= fVariableBlock.createContents(parent); 71 Dialog.applyDialogFont(result); 72 return result; 73 } 74 75 78 public void init(IWorkbench workbench) { 79 } 80 81 84 protected void performDefaults() { 85 super.performDefaults(); 88 } 89 90 93 public boolean performOk() { 94 JavaPlugin.getDefault().savePluginPreferences(); 95 return fVariableBlock.performOk(); 96 } 97 98 101 public void setVisible(boolean visible) { 102 if (visible) { 104 if (fStoredSettings != null && !fStoredSettings.equals(getCurrentSettings())) { 105 fVariableBlock.refresh(null); 106 } 107 } else { 108 if (fVariableBlock.hasChanges()) { 109 String title= PreferencesMessages.ClasspathVariablesPreferencePage_savechanges_title; 110 String message= PreferencesMessages.ClasspathVariablesPreferencePage_savechanges_message; 111 if (MessageDialog.openQuestion(getShell(), title, message)) { 112 performOk(); 113 } 114 fVariableBlock.setChanges(false); } 116 fStoredSettings= getCurrentSettings(); 117 } 118 super.setVisible(visible); 119 } 120 121 private String getCurrentSettings() { 122 StringBuffer buf= new StringBuffer (); 123 String [] names= JavaCore.getClasspathVariableNames(); 124 for (int i= 0; i < names.length; i++) { 125 String curr= names[i]; 126 buf.append(curr).append('\0'); 127 IPath val= JavaCore.getClasspathVariable(curr); 128 if (val != null) { 129 buf.append(val.toString()); 130 } 131 buf.append('\0'); 132 } 133 return buf.toString(); 134 } 135 136 139 public void applyData(Object data) { 140 if (data instanceof Map ) { 141 Object id= ((Map ) data).get(DATA_SELECT_VARIABLE); 142 if (id instanceof String ) { 143 fVariableBlock.setSelection((String ) id); 144 } 145 } 146 super.applyData(data); 147 } 148 149 } 150 | Popular Tags |