1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.message;
14 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.core.runtime.Status;
18 * A concrete IDetailStatus implementation, suitable either for instantiating or
21 * This class can be used without OSGi running.
24 public class DetailStatus extends Status implements IDetailStatus {
28 private String detailedDescription;
31 * Creates a new status object. The created status has no children.
33 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
34 * <code>INFO</code>, <code>WARNING</code>, <code>CANCEL</code>, or
36 * @param pluginId the unique identifier of the relevant plug-in
37 * @param code the plug-in-specific status code, or <code>OK</code>
38 * @param message a human-readable message, localized to the current locale
39 * @param exception a low-level exception, or <code>null</code> if not
42 public DetailStatus(int severity, String pluginId, int code, String message, Throwable exception) {
43 super(severity, pluginId, code, message, exception);
44 setDetailedDescription(null);
48 * Creates a new status object. The created status has no children.
50 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
51 * <code>INFO</code>, <code>WARNING</code>, <code>CANCEL</code>, or
53 * @param pluginId the unique identifier of the relevant plug-in
54 * @param code the plug-in-specific status code, or <code>OK</code>
55 * @param message a human-readable message, localized to the current locale
56 * @param detailedDescription a human-readable detailed message, localized
57 * to the current locale
58 * @param exception a low-level exception, or <code>null</code> if not
61 public DetailStatus(int severity, String pluginId, int code, String message, String detailedDescription, Throwable exception) {
62 super(severity, pluginId, code, message, exception);
63 setDetailedDescription(detailedDescription);
67 * Simplified constructor of a new status object; assumes that code is
68 * <code>OK</code>. The created status has no children.
70 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
71 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code>
72 * @param pluginId the unique identifier of the relevant plug-in
73 * @param message a human-readable message, localized to the current locale
74 * @param exception a low-level exception, or <code>null</code> if not
77 public DetailStatus(int severity, String pluginId, String message, Throwable exception) {
78 super(severity, pluginId, OK, message, exception);
79 setDetailedDescription(null);
83 * Simplified constructor of a new status object; assumes that code is
84 * <code>OK</code>. The created status has no children.
86 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
87 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code>
88 * @param pluginId the unique identifier of the relevant plug-in
89 * @param message a human-readable message, localized to the current locale
90 * @param detailedDescription a human-readable detailed message, localized
91 * to the current locale
92 * @param exception a low-level exception, or <code>null</code> if not
95 public DetailStatus(int severity, String pluginId, String message, String detailedDescription, Throwable exception) {
96 super(severity, pluginId, OK, message, exception);
97 setDetailedDescription(detailedDescription);
101 * Simplified constructor of a new status object; assumes that code is <code>OK</code> and
102 * exception is <code>null</code>. The created status has no children.
104 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
105 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code>
106 * @param pluginId the unique identifier of the relevant plug-in
107 * @param message a human-readable message, localized to the
110 public DetailStatus(int severity, String pluginId, String message) {
111 super(severity, pluginId, OK, message, null);
112 setDetailedDescription(null);
116 * Simplified constructor of a new status object; assumes that code is
117 * <code>OK</code> and exception is <code>null</code>. The created status
120 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
121 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code>
122 * @param pluginId the unique identifier of the relevant plug-in
123 * @param message a human-readable message, localized to the current locale
124 * @param detailedDescription a human-readable detailed message, localized
125 * to the current locale
127 public DetailStatus(int severity, String pluginId, String message, String detailedDescription) {
128 super(severity, pluginId, OK, message, null);
129 setDetailedDescription(detailedDescription);
136 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
137 * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code>
140 protected void setSeverity(int severity) {
141 Assert.isLegal(severity == OK || severity == ERROR || severity == WARNING || severity == INFO || severity == CANCEL || severity == DEBUG);
142 this.severity = severity;
146 * @see org.eclipse.core.runtime.Status#getSeverity()
149 public int getSeverity() {
154 * @see org.simantics.message.IStatus2#getDetailedDescription()
157 public String getDetailedDescription() {
158 return detailedDescription;
162 * @param detailedDescription
164 public void setDetailedDescription(String detailedDescription) {
165 if (detailedDescription == null)
166 this.detailedDescription = ""; //$NON-NLS-1$
168 this.detailedDescription = detailedDescription;
172 * Returns a string representation of the status, suitable
173 * for debugging purposes only.
176 public String toString() {
177 StringBuffer buf = new StringBuffer();
178 buf.append("Status2 "); //$NON-NLS-1$
179 if (severity == OK) {
180 buf.append("OK"); //$NON-NLS-1$
181 } else if (severity == ERROR) {
182 buf.append("ERROR"); //$NON-NLS-1$
183 } else if (severity == WARNING) {
184 buf.append("WARNING"); //$NON-NLS-1$
185 } else if (severity == INFO) {
186 buf.append("INFO"); //$NON-NLS-1$
187 } else if (severity == CANCEL) {
188 buf.append("CANCEL"); //$NON-NLS-1$
189 } else if (severity == DEBUG) {
190 buf.append("DEBUG"); //$NON-NLS-1$
192 buf.append("severity="); //$NON-NLS-1$
193 buf.append(severity);
195 buf.append(": "); //$NON-NLS-1$
196 buf.append(getPlugin());
197 buf.append(" code="); //$NON-NLS-1$
198 buf.append(getCode());
200 buf.append(getMessage());
202 buf.append(getDetailedDescription());
204 buf.append(getException());
205 return buf.toString();