KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > dialogs > StatusUtil


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.ui.dialogs;
12
13 import org.eclipse.core.runtime.IStatus;
14
15 import org.eclipse.jface.dialogs.DialogPage;
16 import org.eclipse.jface.dialogs.IMessageProvider;
17
18 /**
19  * A utility class to work with IStatus.
20  */

21 public class StatusUtil {
22
23     /**
24      * Compares two instances of <code>IStatus</code>. The more severe is returned:
25      * An error is more severe than a warning, and a warning is more severe
26      * than ok. If the two stati have the same severity, the second is returned.
27      */

28     public static IStatus getMoreSevere(IStatus s1, IStatus s2) {
29         if (s1.getSeverity() > s2.getSeverity()) {
30             return s1;
31         } else {
32             return s2;
33         }
34     }
35
36     /**
37      * Finds the most severe status from a array of stati.
38      * An error is more severe than a warning, and a warning is more severe
39      * than ok.
40      */

41     public static IStatus getMostSevere(IStatus[] status) {
42         IStatus max= null;
43         for (int i= 0; i < status.length; i++) {
44             IStatus curr= status[i];
45             if (curr.matches(IStatus.ERROR)) {
46                 return curr;
47             }
48             if (max == null || curr.getSeverity() > max.getSeverity()) {
49                 max= curr;
50             }
51         }
52         return max;
53     }
54         
55     /**
56      * Applies the status to the status line of a dialog page.
57      */

58     public static void applyToStatusLine(DialogPage page, IStatus status) {
59         String JavaDoc message= status.getMessage();
60         switch (status.getSeverity()) {
61             case IStatus.OK:
62                 page.setMessage(message, IMessageProvider.NONE);
63                 page.setErrorMessage(null);
64                 break;
65             case IStatus.WARNING:
66                 page.setMessage(message, IMessageProvider.WARNING);
67                 page.setErrorMessage(null);
68                 break;
69             case IStatus.INFO:
70                 page.setMessage(message, IMessageProvider.INFORMATION);
71                 page.setErrorMessage(null);
72                 break;
73             default:
74                 if (message.length() == 0) {
75                     message= null;
76                 }
77                 page.setMessage(null);
78                 page.setErrorMessage(message);
79                 break;
80         }
81     }
82 }
83
Popular Tags