1 11 12 package org.eclipse.ui.statushandlers; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.ILogListener; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Platform; 21 import org.eclipse.jface.dialogs.Dialog; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.application.WorkbenchAdvisor; 24 import org.eclipse.ui.internal.WorkbenchErrorHandlerProxy; 25 import org.eclipse.ui.internal.WorkbenchPlugin; 26 import org.eclipse.ui.internal.misc.StatusUtil; 27 import org.eclipse.ui.internal.progress.FinishedJobs; 28 import org.eclipse.ui.internal.progress.StatusAdapterHelper; 29 import org.eclipse.ui.internal.statushandlers.StatusHandlerRegistry; 30 import org.eclipse.ui.progress.IProgressConstants; 31 32 75 public class StatusManager { 76 81 public static final int NONE = 0; 82 83 86 public static final int LOG = 0x01; 87 88 93 public static final int SHOW = 0x02; 94 95 100 public static final int BLOCK = 0x04; 101 102 private static StatusManager MANAGER; 103 104 private AbstractStatusHandler workbenchHandler; 105 106 private List loggedStatuses = new ArrayList (); 107 108 113 public static StatusManager getManager() { 114 if (MANAGER == null) { 115 MANAGER = new StatusManager(); 116 } 117 return MANAGER; 118 } 119 120 private StatusManager() { 121 Platform.addLogListener(new StatusManagerLogListener()); 122 } 123 124 127 private AbstractStatusHandler getWorkbenchHandler() { 128 if (workbenchHandler == null) { 129 workbenchHandler = new WorkbenchErrorHandlerProxy(); 130 } 131 132 return workbenchHandler; 133 } 134 135 149 public void handle(StatusAdapter statusAdapter, int style) { 150 try { 151 if (!PlatformUI.isWorkbenchRunning()) { 155 if (style != StatusManager.NONE) { 156 logError(statusAdapter.getStatus()); 157 } 158 return; 159 } 160 161 if (StatusHandlerRegistry.getDefault() 163 .getDefaultHandlerDescriptor() != null) { 164 try { 165 StatusHandlerRegistry.getDefault() 166 .getDefaultHandlerDescriptor().getStatusHandler() 167 .handle(statusAdapter, style); 168 if (((style & StatusManager.SHOW) == StatusManager.SHOW || (style & StatusManager.BLOCK) == StatusManager.BLOCK) 174 && statusAdapter 175 .getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY) != Boolean.TRUE) { 176 FinishedJobs.getInstance().removeErrorJobs(); 177 StatusAdapterHelper.getInstance().clear(); 178 } 179 return; 180 } catch (CoreException ex) { 181 logError("Errors during the default handler creating", ex); } 183 } 184 185 getWorkbenchHandler().handle(statusAdapter, style); 187 188 if (((style & StatusManager.SHOW) == StatusManager.SHOW || (style & StatusManager.BLOCK) == StatusManager.BLOCK) 193 && statusAdapter 194 .getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY) != Boolean.TRUE) { 195 FinishedJobs.getInstance().removeErrorJobs(); 196 } 197 } catch (Throwable ex) { 198 logError(statusAdapter.getStatus()); 200 logError("Error occurred during status handling", ex); } 202 } 203 204 212 public void handle(StatusAdapter statusAdapter) { 213 handle(statusAdapter, StatusManager.LOG); 214 } 215 216 228 public void handle(IStatus status, int style) { 229 StatusAdapter statusAdapter = new StatusAdapter(status); 230 handle(statusAdapter, style); 231 } 232 233 240 public void handle(IStatus status) { 241 handle(status, StatusManager.LOG); 242 } 243 244 251 public void addLoggedStatus(IStatus status) { 252 loggedStatuses.add(status); 253 } 254 255 private void logError(String message, Throwable ex) { 256 IStatus status = StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH, 257 message, ex); 258 addLoggedStatus(status); 259 WorkbenchPlugin.log(status); 260 } 261 262 private void logError(IStatus status) { 263 addLoggedStatus(status); 264 WorkbenchPlugin.log(status); 265 } 266 267 274 private class StatusManagerLogListener implements ILogListener { 275 276 282 public void logging(IStatus status, String plugin) { 283 if (!loggedStatuses.contains(status)) { 284 handle(status, StatusManager.NONE); 285 } else { 286 loggedStatuses.remove(status); 287 } 288 } 289 } 290 } 291 | Popular Tags |