1 11 package org.eclipse.jdt.internal.ui.preferences.formatter; 12 13 import java.util.Map ; 14 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Group; 17 18 import org.eclipse.jdt.core.JavaCore; 19 import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; 20 21 22 23 public class NewLinesTabPage extends FormatterTabPage { 24 25 28 private static String [] FALSE_TRUE = { 29 DefaultCodeFormatterConstants.FALSE, 30 DefaultCodeFormatterConstants.TRUE 31 }; 32 33 36 private static String [] DO_NOT_INSERT_INSERT = { 37 JavaCore.DO_NOT_INSERT, 38 JavaCore.INSERT 39 }; 40 41 42 private final String PREVIEW= 43 createPreviewHeader(FormatterMessages.NewLinesTabPage_preview_header) + 44 "public class Empty {}\n" + "class Example {" + " static int [] fArray= {1, 2, 3, 4, 5 };" + " Listener fListener= new Listener() {" + " };\n" + " @Deprecated @Override " + " public void\nbar\n()\n {}" + " void foo() {" + " ;;" + " do {} while (false);" + " for (;;) {}" + " }" + "}"+ "\n" + "enum MyEnum {" + " UNDEFINED(0) { }" + "}" + "enum EmptyEnum { }" + "@interface EmptyAnnotation { }"; 64 65 protected CheckboxPreference fThenStatementPref, fSimpleIfPref; 66 67 private CompilationUnitPreview fPreview; 68 69 public NewLinesTabPage(ModifyDialog modifyDialog, Map workingValues) { 70 super(modifyDialog, workingValues); 71 } 72 73 protected void doCreatePreferences(Composite composite, int numColumns) { 74 75 final Group newlinesGroup= createGroup(numColumns, composite, FormatterMessages.NewLinesTabPage_newlines_group_title); 76 createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_class_body, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_TYPE_DECLARATION, DO_NOT_INSERT_INSERT); 77 createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_anonymous_class_body, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ANONYMOUS_TYPE_DECLARATION, DO_NOT_INSERT_INSERT); 78 createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_method_body, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_METHOD_BODY, DO_NOT_INSERT_INSERT); 79 createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_block, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_BLOCK, DO_NOT_INSERT_INSERT); 80 createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_enum_declaration, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ENUM_DECLARATION, DO_NOT_INSERT_INSERT); 81 createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_enum_constant, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ENUM_CONSTANT, DO_NOT_INSERT_INSERT); 82 createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_annotation_decl_body, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ANNOTATION_DECLARATION, DO_NOT_INSERT_INSERT); 83 createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_end_of_file, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AT_END_OF_FILE_IF_MISSING, DO_NOT_INSERT_INSERT); 84 85 final Group arrayInitializerGroup= createGroup(numColumns, composite, FormatterMessages.NewLinesTabPage_arrayInitializer_group_title); 86 createPref(arrayInitializerGroup, numColumns, FormatterMessages.NewLinesTabPage_array_group_option_after_opening_brace_of_array_initializer, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, DO_NOT_INSERT_INSERT); 87 createPref(arrayInitializerGroup, numColumns, FormatterMessages.NewLinesTabPage_array_group_option_before_closing_brace_of_array_initializer, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER, DO_NOT_INSERT_INSERT); 88 89 90 final Group emptyStatementsGroup= createGroup(numColumns, composite, FormatterMessages.NewLinesTabPage_empty_statement_group_title); 91 createPref(emptyStatementsGroup, numColumns, FormatterMessages.NewLinesTabPage_emtpy_statement_group_option_empty_statement_on_new_line, DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, FALSE_TRUE); 92 93 final Group annotationsGroup= createGroup(numColumns, composite, FormatterMessages.NewLinesTabPage_annotations_group_title); 94 createPref(annotationsGroup, numColumns, FormatterMessages.NewLinesTabPage_annotations_group_option_after_annotation, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION, DO_NOT_INSERT_INSERT); 95 96 } 97 98 protected void initializePage() { 99 fPreview.setPreviewText(PREVIEW); 100 } 101 102 protected JavaPreview doCreateJavaPreview(Composite parent) { 103 fPreview= new CompilationUnitPreview(fWorkingValues, parent); 104 return fPreview; 105 } 106 107 protected void doUpdatePreview() { 108 super.doUpdatePreview(); 109 fPreview.update(); 110 } 111 112 private CheckboxPreference createPref(Composite composite, int numColumns, String message, String key, String [] values) { 113 return createCheckboxPref(composite, numColumns, message, key, values); 114 } 115 } 116 | Popular Tags |