KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > part > services > StatusFactory


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
21  * Constructs status messages associated with the given plugin bundle.
22  *
23  * Not intended to be subclassed by clients
24  *
25  * @since 3.1
26  */

27 public class StatusFactory implements IStatusFactory {
28
29     private Bundle pluginBundle;
30     
31     public StatusFactory(Bundle context) {
32         this.pluginBundle = context;
33     }
34     
35     /* (non-Javadoc)
36      * @see org.eclipse.ui.component.services.IErrorContext#getStatus(java.lang.Throwable)
37      */

38     public IStatus newError(Throwable JavaDoc t) {
39         String JavaDoc message = StatusUtil.getLocalizedMessage(t);
40         
41         return newError(message, t);
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.ui.component.services.IErrorContext#getStatus(java.lang.String, java.lang.Throwable)
46      */

47     public IStatus newError(String JavaDoc message, Throwable JavaDoc t) {
48         String JavaDoc pluginId = pluginBundle.getSymbolicName();
49         int errorCode = IStatus.OK;
50         
51         // If this was a CoreException, keep the original plugin ID and error code
52
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     /* (non-Javadoc)
63      * @see org.eclipse.ui.component.services.IErrorContext#getStatus(int, java.lang.String)
64      */

65     public IStatus newStatus(int severity, String JavaDoc message) {
66         return new Status(severity, pluginBundle.getSymbolicName(), Status.OK, message, null);
67     }
68
69     public IStatus newMessage(String JavaDoc message) {
70         return newStatus(IStatus.INFO, message);
71     }
72 }
73
Popular Tags