01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.cheatsheets.data;
11:
12: import org.eclipse.core.runtime.IStatus;
13: import org.eclipse.core.runtime.MultiStatus;
14: import org.eclipse.core.runtime.Status;
15: import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource;
16: import org.eclipse.ui.internal.cheatsheets.Messages;
17:
18: public class ParserStatusUtility {
19:
20: public final static int PARSER_ERROR = 1001; // TODO is there another number that would be more meaningful
21:
22: /**
23: * Modify an existing IStatus to add information about a new error/warning.
24: * If the old status is OK return a status reflecting the new error condition, otherwise
25: * add to the existing status making it a MultiStatus if necessary.
26: */
27: public static IStatus addStatus(IStatus status, int severity,
28: String message, Throwable exception) {
29: Status newStatus = new Status(severity,
30: ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID,
31: PARSER_ERROR, message, exception);
32: if (status.isOK()) {
33: return newStatus;
34: } else if (status instanceof MultiStatus) {
35: ((MultiStatus) status).add(newStatus);
36: return status;
37: } else {
38: MultiStatus multiStatus = new MultiStatus(
39: ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID,
40: IStatus.OK, Messages.ERROR_MULTIPLE_ERRORS,
41: exception);
42: multiStatus.add(status);
43: multiStatus.add(newStatus);
44: return multiStatus;
45: }
46: }
47:
48: }
|