1 11 package org.eclipse.ui.internal.ide; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.MultiStatus; 19 import org.eclipse.core.runtime.Status; 20 21 30 public class StatusUtil { 31 32 35 protected static List flatten(IStatus aStatus) { 36 List result = new ArrayList (); 37 38 if (aStatus.isMultiStatus()) { 39 IStatus[] children = aStatus.getChildren(); 40 for (int i = 0; i < children.length; i++) { 41 IStatus currentChild = children[i]; 42 if (currentChild.isMultiStatus()) { 43 Iterator childStatiiEnum = flatten(currentChild).iterator(); 44 while (childStatiiEnum.hasNext()) { 45 result.add(childStatiiEnum.next()); 46 } 47 } else { 48 result.add(currentChild); 49 } 50 } 51 } else { 52 result.add(aStatus); 53 } 54 55 return result; 56 } 57 58 63 protected static IStatus newStatus(IStatus[] stati, String message, 64 Throwable exception) { 65 66 if (message == null || message.trim().length() == 0) { 67 throw new IllegalArgumentException (); 68 } 69 return new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, IStatus.ERROR, 70 stati, message, exception); 71 } 72 73 78 public static IStatus newStatus(int severity, String message, 79 Throwable exception) { 80 81 String statusMessage = message; 82 if (message == null || message.trim().length() == 0) { 83 if (exception == null) { 84 throw new IllegalArgumentException (); 85 } else if (exception.getMessage() == null) { 86 statusMessage = exception.toString(); 87 } else { 88 statusMessage = exception.getMessage(); 89 } 90 } 91 92 return new Status(severity, IDEWorkbenchPlugin.IDE_WORKBENCH, severity, 93 statusMessage, exception); 94 } 95 96 101 public static IStatus newStatus(List children, String message, 102 Throwable exception) { 103 104 List flatStatusCollection = new ArrayList (); 105 Iterator iter = children.iterator(); 106 while (iter.hasNext()) { 107 IStatus currentStatus = (IStatus) iter.next(); 108 Iterator childrenIter = flatten(currentStatus).iterator(); 109 while (childrenIter.hasNext()) { 110 flatStatusCollection.add(childrenIter.next()); 111 } 112 } 113 114 IStatus[] stati = new IStatus[flatStatusCollection.size()]; 115 flatStatusCollection.toArray(stati); 116 return newStatus(stati, message, exception); 117 } 118 } 119 | Popular Tags |