1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.layout.GridData; 18 import org.eclipse.swt.layout.GridLayout; 19 import org.eclipse.swt.widgets.Button; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.swt.widgets.Control; 22 import org.eclipse.swt.widgets.Label; 23 import org.eclipse.swt.widgets.Text; 24 25 import org.eclipse.jface.dialogs.IDialogConstants; 26 import org.eclipse.jface.preference.IPreferenceStore; 27 import org.eclipse.jface.preference.PreferencePage; 28 29 import org.eclipse.ui.IWorkbench; 30 import org.eclipse.ui.IWorkbenchPreferencePage; 31 import org.eclipse.ui.PlatformUI; 32 33 import org.eclipse.jdt.internal.ui.JavaPlugin; 34 35 38 public class WorkInProgressPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { 39 40 private List fCheckBoxes; 41 private List fRadioButtons; 42 private List fTextControls; 43 44 47 public WorkInProgressPreferencePage() { 48 setPreferenceStore(getPreferenceStore()); 49 fRadioButtons= new ArrayList (); 50 fCheckBoxes= new ArrayList (); 51 fTextControls= new ArrayList (); 52 } 53 54 Button addCheckBox(Composite parent, String label, String key) { 55 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 56 57 Button button= new Button(parent, SWT.CHECK); 58 button.setText(label); 59 button.setData(key); 60 button.setLayoutData(gd); 61 62 button.setSelection(getPreferenceStore().getBoolean(key)); 63 64 fCheckBoxes.add(button); 65 return button; 66 } 67 68 71 public void createControl(Composite parent) { 72 super.createControl(parent); 73 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), "WORK_IN_PROGRESS_PREFERENCE_PAGE"); } 75 76 protected Control createContents(Composite parent) { 77 initializeDialogUnits(parent); 78 79 Composite result= new Composite(parent, SWT.NONE); 80 GridLayout layout= new GridLayout(); 81 layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 82 layout.marginWidth= 0; 83 layout.verticalSpacing= convertVerticalDLUsToPixels(10); 84 layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 85 result.setLayout(layout); 86 87 89 applyDialogFont(result); 90 return result; 91 } 92 93 94 97 public void init(IWorkbench workbench) { 98 } 99 100 protected void createSpacer(Composite composite, int columnSpan) { 101 Label label= new Label(composite, SWT.NONE); 102 GridData gd= new GridData(); 103 gd.horizontalSpan= columnSpan; 104 label.setLayoutData(gd); 105 } 106 107 110 protected IPreferenceStore doGetPreferenceStore() { 111 return JavaPlugin.getDefault().getPreferenceStore(); 112 } 113 114 117 protected void performDefaults() { 118 IPreferenceStore store= getPreferenceStore(); 119 for (int i= 0; i < fCheckBoxes.size(); i++) { 120 Button button= (Button) fCheckBoxes.get(i); 121 String key= (String ) button.getData(); 122 button.setSelection(store.getDefaultBoolean(key)); 123 } 124 for (int i= 0; i < fRadioButtons.size(); i++) { 125 Button button= (Button) fRadioButtons.get(i); 126 String [] info= (String []) button.getData(); 127 button.setSelection(info[1].equals(store.getDefaultString(info[0]))); 128 } 129 for (int i= 0; i < fTextControls.size(); i++) { 130 Text text= (Text) fTextControls.get(i); 131 String key= (String ) text.getData(); 132 text.setText(store.getDefaultString(key)); 133 } 134 135 super.performDefaults(); 136 } 137 138 141 public boolean performOk() { 142 IPreferenceStore store= getPreferenceStore(); 143 for (int i= 0; i < fCheckBoxes.size(); i++) { 144 Button button= (Button) fCheckBoxes.get(i); 145 String key= (String ) button.getData(); 146 store.setValue(key, button.getSelection()); 147 } 148 for (int i= 0; i < fRadioButtons.size(); i++) { 149 Button button= (Button) fRadioButtons.get(i); 150 if (button.getSelection()) { 151 String [] info= (String []) button.getData(); 152 store.setValue(info[0], info[1]); 153 } 154 } 155 for (int i= 0; i < fTextControls.size(); i++) { 156 Text text= (Text) fTextControls.get(i); 157 String key= (String ) text.getData(); 158 store.setValue(key, text.getText()); 159 } 160 161 JavaPlugin.getDefault().savePluginPreferences(); 162 return super.performOk(); 163 } 164 165 public static void initDefaults(IPreferenceStore store) { 166 } 168 } 169 | Popular Tags |