1 12 package org.eclipse.jdt.internal.ui.preferences.formatter; 13 14 import java.util.List ; 15 import java.util.Observable ; 16 import java.util.Observer ; 17 18 import org.eclipse.core.runtime.preferences.IScopeContext; 19 20 import org.eclipse.core.resources.IProject; 21 22 import org.eclipse.swt.layout.GridData; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Shell; 25 26 import org.eclipse.jdt.ui.JavaUI; 27 28 import org.eclipse.jdt.internal.ui.preferences.PreferencesAccess; 29 import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile; 30 31 32 33 36 37 public class CodeFormatterConfigurationBlock extends ProfileConfigurationBlock { 38 39 private static final String FORMATTER_DIALOG_PREFERENCE_KEY= "formatter_page"; 41 private static final String DIALOGSTORE_LASTSAVELOADPATH= JavaUI.ID_PLUGIN + ".codeformatter"; 43 46 protected final String PREVIEW= "/**\n* " + FormatterMessages.CodingStyleConfigurationBlock_preview_title + 48 "\n*/\n\n" + "package mypackage; import java.util.LinkedList; public class MyIntStack {" + "private final LinkedList fStack;" + "public MyIntStack(){fStack= new LinkedList();}" + "public int pop(){return ((Integer)fStack.removeFirst()).intValue();}" + "public void push(int elem){fStack.addFirst(new Integer(elem));}" + "public boolean isEmpty() {return fStack.isEmpty();}" + "}"; 57 private class PreviewController implements Observer { 58 59 public PreviewController(ProfileManager profileManager) { 60 profileManager.addObserver(this); 61 fJavaPreview.setWorkingValues(profileManager.getSelected().getSettings()); 62 fJavaPreview.update(); 63 } 64 65 public void update(Observable o, Object arg) { 66 final int value= ((Integer )arg).intValue(); 67 switch (value) { 68 case ProfileManager.PROFILE_CREATED_EVENT: 69 case ProfileManager.PROFILE_DELETED_EVENT: 70 case ProfileManager.SELECTION_CHANGED_EVENT: 71 case ProfileManager.SETTINGS_CHANGED_EVENT: 72 fJavaPreview.setWorkingValues(((ProfileManager)o).getSelected().getSettings()); 73 fJavaPreview.update(); 74 } 75 } 76 77 } 78 79 80 83 private JavaPreview fJavaPreview; 84 85 88 public CodeFormatterConfigurationBlock(IProject project, PreferencesAccess access) { 89 super(project, access, DIALOGSTORE_LASTSAVELOADPATH); 90 } 91 92 protected IProfileVersioner createProfileVersioner() { 93 return new ProfileVersioner(); 94 } 95 96 protected ProfileStore createProfileStore(IProfileVersioner versioner) { 97 return new FormatterProfileStore(versioner); 98 } 99 100 protected ProfileManager createProfileManager(List profiles, IScopeContext context, PreferencesAccess access, IProfileVersioner profileVersioner) { 101 return new FormatterProfileManager(profiles, context, access, profileVersioner); 102 } 103 104 protected void configurePreview(Composite composite, int numColumns, ProfileManager profileManager) { 105 createLabel(composite, FormatterMessages.CodingStyleConfigurationBlock_preview_label_text, numColumns); 106 CompilationUnitPreview result= new CompilationUnitPreview(profileManager.getSelected().getSettings(), composite); 107 result.setPreviewText(PREVIEW); 108 fJavaPreview= result; 109 110 final GridData gd = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL); 111 gd.horizontalSpan = numColumns; 112 gd.verticalSpan= 7; 113 gd.widthHint = 0; 114 gd.heightHint = 0; 115 fJavaPreview.getControl().setLayoutData(gd); 116 117 new PreviewController(profileManager); 118 } 119 120 121 protected ModifyDialog createModifyDialog(Shell shell, Profile profile, ProfileManager profileManager, ProfileStore profileStore, boolean newProfile) { 122 return new FormatterModifyDialog(shell, profile, profileManager, profileStore, newProfile, FORMATTER_DIALOG_PREFERENCE_KEY, DIALOGSTORE_LASTSAVELOADPATH); 123 } 124 } 125 | Popular Tags |