1 11 package org.eclipse.ui.internal.part.services; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.ui.internal.misc.StatusUtil; 17 import org.eclipse.ui.internal.part.components.services.IStatusFactory; 18 import org.osgi.framework.Bundle; 19 20 27 public class StatusFactory implements IStatusFactory { 28 29 private Bundle pluginBundle; 30 31 public StatusFactory(Bundle context) { 32 this.pluginBundle = context; 33 } 34 35 38 public IStatus newError(Throwable t) { 39 String message = StatusUtil.getLocalizedMessage(t); 40 41 return newError(message, t); 42 } 43 44 47 public IStatus newError(String message, Throwable t) { 48 String pluginId = pluginBundle.getSymbolicName(); 49 int errorCode = IStatus.OK; 50 51 if (t instanceof CoreException) { 53 CoreException ce = (CoreException)t; 54 pluginId = ce.getStatus().getPlugin(); 55 errorCode = ce.getStatus().getCode(); 56 } 57 58 return new Status(IStatus.ERROR, pluginId, errorCode, message, 59 StatusUtil.getCause(t)); 60 } 61 62 65 public IStatus newStatus(int severity, String message) { 66 return new Status(severity, pluginBundle.getSymbolicName(), Status.OK, message, null); 67 } 68 69 public IStatus newMessage(String message) { 70 return newStatus(IStatus.INFO, message); 71 } 72 } 73 | Popular Tags |