1 11 package org.eclipse.jdt.internal.ui.javaeditor.saveparticipant; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 import org.eclipse.core.runtime.preferences.IScopeContext; 19 20 import org.eclipse.core.resources.IProject; 21 import org.eclipse.core.resources.ProjectScope; 22 23 import org.eclipse.jdt.internal.corext.fix.CleanUpPostSaveListener; 24 25 import org.eclipse.jdt.internal.ui.JavaPlugin; 26 import org.eclipse.jdt.internal.ui.fix.CleanUpSaveParticipantPreferenceConfiguration; 27 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider; 28 29 45 public final class SaveParticipantRegistry { 46 47 private static final IPostSaveListener[] EMPTY_ARRAY= new IPostSaveListener[0]; 48 49 50 private Map fDescriptors; 51 52 55 public SaveParticipantRegistry() { 56 } 57 58 64 public synchronized SaveParticipantDescriptor[] getSaveParticipantDescriptors() { 65 ensureRegistered(); 66 return (SaveParticipantDescriptor[]) fDescriptors.values().toArray(new SaveParticipantDescriptor[fDescriptors.size()]); 67 } 68 69 76 public synchronized SaveParticipantDescriptor getSaveParticipantDescriptor(String id) { 77 ensureRegistered(); 78 return (SaveParticipantDescriptor) fDescriptors.get(id); 79 } 80 81 85 private void ensureRegistered() { 86 if (fDescriptors == null) 87 reloadDescriptors(); 88 } 89 90 97 private void reloadDescriptors() { 98 Map map= new HashMap (); 99 SaveParticipantDescriptor desc= new SaveParticipantDescriptor(new CleanUpPostSaveListener()) { 100 103 public ISaveParticipantPreferenceConfiguration createPreferenceConfiguration() { 104 return new CleanUpSaveParticipantPreferenceConfiguration(); 105 } 106 }; 107 map.put(desc.getId(), desc); 108 109 fDescriptors= map; 110 } 111 112 public void dispose() { 113 } 114 115 121 public synchronized boolean hasSettingsInScope(IScopeContext context) { 122 ensureRegistered(); 123 124 for (Iterator iterator= fDescriptors.values().iterator(); iterator.hasNext();) { 125 SaveParticipantDescriptor descriptor= (SaveParticipantDescriptor)iterator.next(); 126 if (descriptor.getPreferenceConfiguration().hasSettingsInScope(context)) 127 return true; 128 } 129 130 return false; 131 } 132 133 public IPostSaveListener[] getEnabledPostSaveListeners(IProject project) { 134 return getEnabledPostSaveListeners(new ProjectScope(project)); 135 } 136 137 144 public synchronized IPostSaveListener[] getEnabledPostSaveListeners(IScopeContext context) { 145 ensureRegistered(); 146 147 ArrayList result= null; 148 for (Iterator iterator= fDescriptors.values().iterator(); iterator.hasNext();) { 149 SaveParticipantDescriptor descriptor= (SaveParticipantDescriptor)iterator.next(); 150 if (descriptor.getPreferenceConfiguration().isEnabled(context)) { 151 if (result == null) { 152 result= new ArrayList (); 153 } 154 result.add(descriptor.getPostSaveListener()); 155 } 156 } 157 158 if (result == null) { 159 return EMPTY_ARRAY; 160 } else { 161 return (IPostSaveListener[])result.toArray(new IPostSaveListener[result.size()]); 162 } 163 } 164 165 } 166 | Popular Tags |