1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import com.ibm.icu.text.Collator; 14 15 import java.util.ArrayList ; 16 import java.util.Arrays ; 17 import java.util.Comparator ; 18 19 import org.eclipse.core.runtime.Assert; 20 import org.eclipse.core.runtime.IAdaptable; 21 import org.eclipse.core.runtime.preferences.IScopeContext; 22 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.layout.GridLayout; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Control; 28 29 import org.eclipse.jface.preference.IPreferencePageContainer; 30 import org.eclipse.jface.preference.PreferencePage; 31 32 import org.eclipse.jdt.internal.ui.JavaPlugin; 33 import org.eclipse.jdt.internal.ui.javaeditor.saveparticipant.ISaveParticipantPreferenceConfiguration; 34 import org.eclipse.jdt.internal.ui.javaeditor.saveparticipant.SaveParticipantDescriptor; 35 import org.eclipse.jdt.internal.ui.javaeditor.saveparticipant.SaveParticipantRegistry; 36 37 42 class SaveParticipantConfigurationBlock implements IPreferenceAndPropertyConfigurationBlock { 43 44 private interface IDelegateOperation { 45 public void run(ISaveParticipantPreferenceConfiguration block); 46 } 47 48 private final PreferencePage fPreferencePage; 49 private final IScopeContext fContext; 50 private final ArrayList fConfigurations; 51 52 public SaveParticipantConfigurationBlock(IScopeContext context, PreferencePage preferencePage) { 53 Assert.isNotNull(context); 54 Assert.isNotNull(preferencePage); 55 56 fContext= context; 57 fPreferencePage= preferencePage; 58 fConfigurations= new ArrayList (); 59 } 60 61 65 public Control createControl(Composite parent) { 66 Composite composite= new Composite(parent, SWT.NONE); 67 composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 68 GridLayout gridLayout= new GridLayout(2, false); 69 gridLayout.marginHeight= 0; 70 gridLayout.marginWidth= 0; 71 composite.setLayout(gridLayout); 72 73 SaveParticipantRegistry registry= JavaPlugin.getDefault().getSaveParticipantRegistry(); 74 SaveParticipantDescriptor[] descriptors= registry.getSaveParticipantDescriptors(); 75 76 if (descriptors.length == 0) 77 return composite; 78 79 Arrays.sort(descriptors, new Comparator () { 80 public int compare(Object o1, Object o2) { 81 SaveParticipantDescriptor d1= (SaveParticipantDescriptor)o1; 82 SaveParticipantDescriptor d2= (SaveParticipantDescriptor)o2; 83 return Collator.getInstance().compare(d1.getPostSaveListener().getName(), d2.getPostSaveListener().getName()); 84 } 85 }); 86 87 IPreferencePageContainer container= fPreferencePage.getContainer(); 88 for (int i= 0; i < descriptors.length; i++) { 89 final SaveParticipantDescriptor descriptor= descriptors[i]; 90 ISaveParticipantPreferenceConfiguration configuration= descriptor.createPreferenceConfiguration(); 91 configuration.createControl(composite, container); 92 fConfigurations.add(configuration); 93 } 94 95 return composite; 96 } 97 98 101 public void dispose() { 102 delegateToPreferenceConfiguration(new IDelegateOperation() { 103 public void run(ISaveParticipantPreferenceConfiguration block) { 104 block.dispose(); 105 } 106 }); 107 } 108 109 112 public void initialize() { 113 delegateToPreferenceConfiguration(new IDelegateOperation() { 114 public void run(ISaveParticipantPreferenceConfiguration block) { 115 IAdaptable element= null; 116 if (fPreferencePage instanceof PropertyAndPreferencePage) { 117 element= ((PropertyAndPreferencePage)fPreferencePage).getElement(); 118 } 119 block.initialize(fContext, element); 120 } 121 }); 122 } 123 124 127 public void performDefaults() { 128 delegateToPreferenceConfiguration(new IDelegateOperation() { 129 public void run(ISaveParticipantPreferenceConfiguration block) { 130 block.performDefaults(); 131 } 132 }); 133 } 134 135 138 public void performOk() { 139 delegateToPreferenceConfiguration(new IDelegateOperation() { 140 public void run(ISaveParticipantPreferenceConfiguration block) { 141 block.performOk(); 142 } 143 }); 144 } 145 146 149 public void enableProjectSettings() { 150 delegateToPreferenceConfiguration(new IDelegateOperation() { 151 public void run(ISaveParticipantPreferenceConfiguration block) { 152 block.enableProjectSettings(); 153 } 154 }); 155 } 156 157 160 public void disableProjectSettings() { 161 delegateToPreferenceConfiguration(new IDelegateOperation() { 162 public void run(ISaveParticipantPreferenceConfiguration block) { 163 block.disableProjectSettings(); 164 } 165 }); 166 } 167 168 private void delegateToPreferenceConfiguration(IDelegateOperation op) { 169 for (int i= 0; i < fConfigurations.size(); i++) { 170 ISaveParticipantPreferenceConfiguration block= (ISaveParticipantPreferenceConfiguration)fConfigurations.get(i); 171 op.run(block); 172 } 173 } 174 } 175 | Popular Tags |