KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > data > ParserStatusUtility


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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
12 package org.eclipse.ui.internal.cheatsheets.data;
13
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.MultiStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource;
18 import org.eclipse.ui.internal.cheatsheets.Messages;
19
20 public class ParserStatusUtility {
21     
22     public final static int PARSER_ERROR = 1001; // TODO is there another number that would be more meaningful
23

24     /**
25      * Modify an existing IStatus to add information about a new error/warning.
26      * If the old status is OK return a status reflecting the new error condition, otherwise
27      * add to the existing status making it a MultiStatus if necessary.
28      */

29     public static IStatus addStatus(IStatus status, int severity, String JavaDoc message, Throwable JavaDoc exception) {
30         Status newStatus = new Status(severity, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, PARSER_ERROR, message, exception);
31         if (status.isOK()) {
32             return newStatus;
33         } else if (status instanceof MultiStatus) {
34             ((MultiStatus)status).add(newStatus);
35             return status;
36         } else {
37             MultiStatus multiStatus = new MultiStatus(ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK,
38                     Messages.ERROR_MULTIPLE_ERRORS, exception);
39             multiStatus.add(status);
40             multiStatus.add(newStatus);
41             return multiStatus;
42         }
43     }
44
45 }
46
Popular Tags