1 11 package org.eclipse.ui.views.markers.internal; 12 13 import org.eclipse.jface.preference.IntegerFieldEditor; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.events.SelectionAdapter; 16 import org.eclipse.swt.events.SelectionEvent; 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.Shell; 23 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 24 import org.eclipse.ui.preferences.ViewSettingsDialog; 25 26 33 public class MarkerViewPreferenceDialog extends ViewSettingsDialog { 34 35 String enablementKey; 36 37 String limitKey; 38 39 String dialogTitle; 40 41 private IntegerFieldEditor limitEditor; 42 43 private Button enablementButton; 44 45 private Composite editArea; 46 47 58 public MarkerViewPreferenceDialog(Shell parentShell, 59 String enablementPreference, String limitPreference, String title) { 60 super(parentShell); 61 enablementKey = enablementPreference; 62 limitKey = limitPreference; 63 dialogTitle = title; 64 65 } 66 67 72 protected void configureShell(Shell newShell) { 73 super.configureShell(newShell); 74 newShell.setText(dialogTitle); 75 } 76 77 82 protected Control createDialogArea(Composite parent) { 83 Composite topComposite = (Composite) super.createDialogArea(parent); 84 85 boolean checked = IDEWorkbenchPlugin.getDefault().getPreferenceStore() 86 .getBoolean(enablementKey); 87 enablementButton = new Button(topComposite, SWT.CHECK); 88 enablementButton.setText(MarkerMessages.MarkerPreferences_MarkerLimits); 89 enablementButton.setSelection(checked); 90 91 editArea = new Composite(topComposite, SWT.NONE); 92 editArea.setLayout(new GridLayout()); 93 GridData editData = new GridData(GridData.FILL_BOTH 94 | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL); 95 editData.horizontalIndent = 10; 96 editArea.setLayoutData(editData); 97 98 limitEditor = new IntegerFieldEditor( 99 "limit", MarkerMessages.MarkerPreferences_VisibleItems, editArea); limitEditor.setPreferenceStore(IDEWorkbenchPlugin.getDefault() 101 .getPreferenceStore()); 102 limitEditor.setPreferenceName(limitKey); 103 limitEditor.load(); 104 105 GridData checkedData = new GridData(SWT.FILL, SWT.NONE, true, false); 106 checkedData.horizontalSpan = limitEditor.getNumberOfControls(); 107 enablementButton.setLayoutData(checkedData); 108 109 enablementButton.addSelectionListener(new SelectionAdapter() { 110 public void widgetSelected(SelectionEvent e) { 111 setLimitEditorEnablement(editArea, enablementButton 112 .getSelection()); 113 } 114 }); 115 116 setLimitEditorEnablement(editArea, checked); 117 118 return topComposite; 119 } 120 121 128 private void setLimitEditorEnablement(Composite control, boolean checked) { 129 limitEditor.setEnabled(checked, control); 130 } 131 132 137 protected void okPressed() { 138 limitEditor.store(); 139 IDEWorkbenchPlugin.getDefault().getPreferenceStore().setValue( 140 enablementKey, enablementButton.getSelection()); 141 IDEWorkbenchPlugin.getDefault().savePluginPreferences(); 142 super.okPressed(); 143 } 144 145 150 protected void performDefaults() { 151 super.performDefaults(); 152 limitEditor.loadDefault(); 153 boolean checked = IDEWorkbenchPlugin.getDefault().getPreferenceStore() 154 .getDefaultBoolean(enablementKey); 155 enablementButton.setSelection(checked); 156 setLimitEditorEnablement(editArea, checked); 157 } 158 159 } 160 | Popular Tags |