1 11 package org.eclipse.jdt.internal.ui.preferences.formatter; 12 13 import java.util.Map ; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.events.SelectionAdapter; 17 import org.eclipse.swt.events.SelectionEvent; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.widgets.Button; 20 import org.eclipse.swt.widgets.Composite; 21 22 import org.eclipse.jface.dialogs.IDialogSettings; 23 24 import org.eclipse.jdt.ui.JavaUI; 25 26 import org.eclipse.jdt.internal.ui.JavaPlugin; 27 28 public abstract class FormatterTabPage extends ModifyDialogTabPage { 29 30 private final static String SHOW_INVISIBLE_PREFERENCE_KEY= JavaUI.ID_PLUGIN + ".formatter_page.show_invisible_characters"; 32 private JavaPreview fPreview; 33 private final IDialogSettings fDialogSettings; 34 private Button fShowInvisibleButton; 35 36 public FormatterTabPage(IModificationListener modifyListener, Map workingValues) { 37 super(modifyListener, workingValues); 38 39 fDialogSettings= JavaPlugin.getDefault().getDialogSettings(); 40 } 41 42 protected Composite doCreatePreviewPane(Composite composite, int numColumns) { 43 44 createLabel(numColumns - 1, composite, FormatterMessages.ModifyDialogTabPage_preview_label_text); 45 46 fShowInvisibleButton= new Button(composite, SWT.CHECK); 47 fShowInvisibleButton.setText(FormatterMessages.FormatterTabPage_ShowInvisibleCharacters_label); 48 fShowInvisibleButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, false)); 49 fShowInvisibleButton.addSelectionListener(new SelectionAdapter() { 50 public void widgetSelected(SelectionEvent e) { 51 fPreview.showInvisibleCharacters(fShowInvisibleButton.getSelection()); 52 fDialogSettings.put(SHOW_INVISIBLE_PREFERENCE_KEY, fShowInvisibleButton.getSelection()); 53 } 54 }); 55 fShowInvisibleButton.setSelection(isShowInvisible()); 56 57 fPreview= doCreateJavaPreview(composite); 58 fDefaultFocusManager.add(fPreview.getControl()); 59 fPreview.showInvisibleCharacters(fShowInvisibleButton.getSelection()); 60 61 final GridData gd= createGridData(numColumns, GridData.FILL_BOTH, 0); 62 gd.widthHint= 0; 63 gd.heightHint=0; 64 fPreview.getControl().setLayoutData(gd); 65 66 return composite; 67 } 68 69 private boolean isShowInvisible() { 70 return fDialogSettings.getBoolean(SHOW_INVISIBLE_PREFERENCE_KEY); 71 } 72 73 protected void doUpdatePreview() { 74 boolean showInvisible= isShowInvisible(); 75 fPreview.showInvisibleCharacters(showInvisible); 76 fShowInvisibleButton.setSelection(showInvisible); 77 } 78 79 } | Popular Tags |