1 12 package org.eclipse.jdt.internal.ui.preferences.cleanup; 13 14 import java.util.Map ; 15 import java.util.Observable ; 16 import java.util.Observer ; 17 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.widgets.Button; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Group; 23 import org.eclipse.swt.widgets.Label; 24 25 import org.eclipse.jface.dialogs.Dialog; 26 27 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; 28 29 import org.eclipse.jdt.internal.ui.fix.CodeFormatCleanUp; 30 import org.eclipse.jdt.internal.ui.fix.CommentFormatCleanUp; 31 import org.eclipse.jdt.internal.ui.fix.ICleanUp; 32 import org.eclipse.jdt.internal.ui.fix.ImportsCleanUp; 33 import org.eclipse.jdt.internal.ui.fix.SortMembersCleanUp; 34 import org.eclipse.jdt.internal.ui.preferences.formatter.JavaPreview; 35 import org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialog; 36 37 public final class CodeFormatingTabPage extends CleanUpTabPage { 38 39 private final Map fValues; 40 private CleanUpPreview fPreview; 41 42 public CodeFormatingTabPage(ModifyDialog dialog, Map values) { 43 this(dialog, values, false); 44 } 45 46 public CodeFormatingTabPage(IModificationListener listener, Map values, boolean isSaveParticipantConfiguration) { 47 super(listener, values, isSaveParticipantConfiguration); 48 fValues= values; 49 } 50 51 protected ICleanUp[] createPreviewCleanUps(Map values) { 52 return new ICleanUp[] { 53 new ImportsCleanUp(values), 54 new CommentFormatCleanUp(values), 55 new CodeFormatCleanUp(values), 56 new SortMembersCleanUp(values) 57 }; 58 } 59 60 protected JavaPreview doCreateJavaPreview(Composite parent) { 61 fPreview= (CleanUpPreview)super.doCreateJavaPreview(parent); 62 fPreview.showInvisibleCharacters(true); 63 fPreview.setFormat(CleanUpConstants.TRUE.equals(fValues.get(CleanUpConstants.FORMAT_SOURCE_CODE))); 64 return fPreview; 65 } 66 67 protected void doCreatePreferences(Composite composite, int numColumns) { 68 69 Group group= createGroup(numColumns, composite, CleanUpMessages.CodeFormatingTabPage_GroupName_Formatter); 70 71 if (!isSaveAction()) { 72 final CheckboxPreference format= createCheckboxPref(group, numColumns, CleanUpMessages.CodeFormatingTabPage_CheckboxName_FormatSourceCode, CleanUpConstants.FORMAT_SOURCE_CODE, CleanUpModifyDialog.FALSE_TRUE); 73 registerPreference(format); 74 format.addObserver(new Observer () { 75 public void update(Observable o, Object arg) { 76 fPreview.setFormat(format.getChecked()); 77 fPreview.update(); 78 } 79 }); 80 } 81 82 final CheckboxPreference whiteSpace= createCheckboxPref(group, numColumns, CleanUpMessages.CodeFormatingTabPage_RemoveTrailingWhitespace_checkbox_text, CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES, CleanUpModifyDialog.FALSE_TRUE); 83 intent(group); 84 final RadioPreference allPref= createRadioPref(group, 1, CleanUpMessages.CodeFormatingTabPage_RemoveTrailingWhitespace_all_radio, CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_ALL, CleanUpModifyDialog.FALSE_TRUE); 85 final RadioPreference ignoreEmptyPref= createRadioPref(group, 1, CleanUpMessages.CodeFormatingTabPage_RemoveTrailingWhitespace_ignoreEmpty_radio, CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_IGNORE_EMPTY, CleanUpModifyDialog.FALSE_TRUE); 86 registerSlavePreference(whiteSpace, new RadioPreference[] {allPref, ignoreEmptyPref}); 87 88 if (!isSaveAction()) { 89 createLabel(numColumns, group, CleanUpMessages.CodeFormatingTabPage_FormatterSettings_Description).setFont(composite.getFont()); 90 91 Group importsGroup= createGroup(numColumns, composite, CleanUpMessages.CodeFormatingTabPage_Imports_GroupName); 92 CheckboxPreference organizeImports= createCheckboxPref(importsGroup, numColumns, CleanUpMessages.CodeFormatingTabPage_OrganizeImports_CheckBoxLable, CleanUpConstants.ORGANIZE_IMPORTS, CleanUpModifyDialog.FALSE_TRUE); 93 registerPreference(organizeImports); 94 createLabel(numColumns, importsGroup, CleanUpMessages.CodeFormatingTabPage_OrganizeImportsSettings_Description).setFont(composite.getFont()); 95 } 96 97 Group sortMembersGroup= createGroup(numColumns, composite, CleanUpMessages.CodeFormatingTabPage_SortMembers_GroupName); 98 99 final CheckboxPreference sortMembersPref= createCheckboxPref(sortMembersGroup, numColumns, CleanUpMessages.CodeFormatingTabPage_SortMembers_CheckBoxLabel, CleanUpConstants.SORT_MEMBERS, CleanUpModifyDialog.FALSE_TRUE); 100 intent(sortMembersGroup); 101 final RadioPreference sortAllPref= createRadioPref(sortMembersGroup, numColumns - 1, CleanUpMessages.CodeFormatingTabPage_SortMembersFields_CheckBoxLabel, CleanUpConstants.SORT_MEMBERS_ALL, CleanUpModifyDialog.FALSE_TRUE); 102 intent(sortMembersGroup); 103 final Button nullRadio= new Button(sortMembersGroup, SWT.RADIO); 104 nullRadio.setText(CleanUpMessages.CodeFormatingTabPage_SortMembersExclusive_radio0); 105 nullRadio.setLayoutData(createGridData(numColumns - 1, GridData.FILL_HORIZONTAL, SWT.DEFAULT)); 106 nullRadio.setFont(composite.getFont()); 107 intent(sortMembersGroup); 108 final Label warningImage= new Label(sortMembersGroup, SWT.LEFT | SWT.WRAP); 109 warningImage.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING)); 110 warningImage.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false)); 111 final Label warningLabel= createLabel(numColumns - 2, sortMembersGroup, CleanUpMessages.CodeFormatingTabPage_SortMembersSemanticChange_warning); 112 113 registerSlavePreference(sortMembersPref, new RadioPreference[] {sortAllPref}); 114 sortMembersPref.addObserver(new Observer () { 115 public void update(Observable o, Object arg) { 116 nullRadio.setEnabled(sortMembersPref.getChecked()); 117 118 boolean warningEnabled= sortMembersPref.getChecked() && sortAllPref.getChecked(); 119 warningImage.setEnabled(warningEnabled); 120 warningLabel.setEnabled(warningEnabled); 121 } 122 }); 123 sortAllPref.addObserver(new Observer () { 124 public void update(Observable o, Object arg) { 125 boolean warningEnabled= sortMembersPref.getChecked() && sortAllPref.getChecked(); 126 warningImage.setEnabled(warningEnabled); 127 warningLabel.setEnabled(warningEnabled); 128 } 129 }); 130 nullRadio.setEnabled(sortMembersPref.getChecked()); 131 nullRadio.setSelection(CleanUpConstants.FALSE.equals(fValues.get(CleanUpConstants.SORT_MEMBERS_ALL))); 132 boolean warningEnabled= sortMembersPref.getChecked() && sortAllPref.getChecked(); 133 warningImage.setEnabled(warningEnabled); 134 warningLabel.setEnabled(warningEnabled); 135 136 createLabel(numColumns, sortMembersGroup, CleanUpMessages.CodeFormatingTabPage_SortMembers_Description); 137 } 138 139 } 140 | Popular Tags |