1 11 package org.eclipse.update.operations; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.Vector ; 16 17 import org.eclipse.update.core.*; 18 import org.eclipse.update.internal.configurator.*; 19 import org.eclipse.update.internal.operations.*; 20 21 32 public class OperationsManager { 33 private static IOperationValidator validator; 34 private static IOperationFactory operationFactory; 35 private static Vector listeners = new Vector (); 36 private static Vector pendingOperations = new Vector (); 37 38 private static boolean inProgress; 39 40 private OperationsManager() { 41 } 42 43 48 public static IOperationFactory getOperationFactory() { 49 if (operationFactory == null) 50 operationFactory = new OperationFactory(); 51 return operationFactory; 52 } 53 54 61 public static IFeatureOperation findPendingOperation(IFeature feature) { 62 for (int i = 0; i < pendingOperations.size(); i++) { 63 IFeatureOperation operation = 64 (IFeatureOperation) pendingOperations.elementAt(i); 65 if (operation.getFeature().equals(feature)) 66 return operation; 67 } 68 return null; 69 } 70 71 75 public static void addPendingOperation(IOperation operation) { 76 pendingOperations.add(operation); 77 } 79 80 84 public static void removePendingOperation(IOperation operation) { 85 pendingOperations.remove(operation); 86 } 88 89 93 public static void addUpdateModelChangedListener(IUpdateModelChangedListener listener) { 94 if (!listeners.contains(listener)) 95 listeners.add(listener); 96 } 97 98 102 public static void removeUpdateModelChangedListener(IUpdateModelChangedListener listener) { 103 if (listeners.contains(listener)) 104 listeners.remove(listener); 105 } 106 107 112 public static void fireObjectsAdded(Object parent, Object [] children) { 113 for (Iterator iter = listeners.iterator(); iter.hasNext();) { 114 IUpdateModelChangedListener listener = 115 (IUpdateModelChangedListener) iter.next(); 116 listener.objectsAdded(parent, children); 117 } 118 } 119 120 125 public static void fireObjectsRemoved(Object parent, Object [] children) { 126 for (Iterator iter = listeners.iterator(); iter.hasNext();) { 127 IUpdateModelChangedListener listener = 128 (IUpdateModelChangedListener) iter.next(); 129 listener.objectsRemoved(parent, children); 130 } 131 } 132 133 138 public static void fireObjectChanged(Object object, String property) { 139 for (Iterator iter = listeners.iterator(); iter.hasNext();) { 140 IUpdateModelChangedListener listener = 141 (IUpdateModelChangedListener) iter.next(); 142 listener.objectChanged(object, property); 143 } 144 } 145 146 151 public static boolean hasSelectedJobsWithLicenses(IInstallFeatureOperation[] jobs) { 152 for (int i = 0; i < jobs.length; i++) { 153 if (UpdateUtils.hasLicense(jobs[i].getFeature())) 154 return true; 155 } 156 return false; 157 } 158 159 164 public static boolean hasSelectedJobsWithOptionalFeatures(IInstallFeatureOperation[] jobs) { 165 for (int i = 0; i < jobs.length; i++) { 166 if (UpdateUtils.hasOptionalFeatures(jobs[i].getFeature())) 167 return true; 168 } 169 return false; 170 } 171 172 177 public static IInstallFeatureOperation[] getSelectedJobsWithLicenses(IInstallFeatureOperation[] jobs) { 178 ArrayList list = new ArrayList (); 179 for (int i = 0; i < jobs.length; i++) { 180 if (UpdateUtils.hasLicense(jobs[i].getFeature())) 181 list.add(jobs[i]); 182 } 183 return (IInstallFeatureOperation[]) list.toArray( 184 new IInstallFeatureOperation[list.size()]); 185 } 186 187 192 public static IInstallFeatureOperation[] getSelectedJobsWithOptionalFeatures(IInstallFeatureOperation[] jobs) { 193 ArrayList list = new ArrayList (); 194 for (int i = 0; i < jobs.length; i++) { 195 if (UpdateUtils.hasOptionalFeatures(jobs[i].getFeature())) 196 list.add(jobs[i]); 197 } 198 return (IInstallFeatureOperation[]) list.toArray( 199 new IInstallFeatureOperation[list.size()]); 200 } 201 202 206 public static synchronized void setInProgress(boolean inProgress) { 207 OperationsManager.inProgress = inProgress; 208 } 209 210 214 public static synchronized boolean isInProgress() { 215 return inProgress; 216 } 217 218 222 public static IOperationValidator getValidator() { 223 if (validator == null) 224 validator = new OperationValidator(); 225 return validator; 226 } 227 228 232 public static void setValidator(IOperationValidator validator) { 233 OperationsManager.validator = validator; 234 } 235 236 241 public static void applyChangesNow() { 242 ConfigurationActivator configurator = ConfigurationActivator.getConfigurator(); 243 configurator.installBundles(); 244 pendingOperations.clear(); 245 } 246 } 247 | Popular Tags |