KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > 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.ui.internal.editors.text;
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  * @since 3.1
22  */

23 public class StatusUtil {
24
25     /**
26      * Compares two instances of {@link IStatus}. The more severe is returned:
27      * An error is more severe than a warning, and a warning is more severe
28      * than OK. If the two statuses have the same severity, the second is returned.
29      *
30      * @param s1 a status object
31      * @param s2 a status object
32      * @return the more severe status
33      */

34     public static IStatus getMoreSevere(IStatus s1, IStatus s2) {
35         if (s1.getSeverity() > s2.getSeverity())
36             return s1;
37
38         return s2;
39     }
40
41     /**
42      * Finds the most severe status from a array of statuses.
43      * An error is more severe than a warning, and a warning is more severe
44      * than OK.
45      *
46      * @param status an array with status objects
47      * @return the most severe status object
48      */

49     public static IStatus getMostSevere(IStatus[] status) {
50         IStatus max= null;
51         for (int i= 0; i < status.length; i++) {
52             IStatus curr= status[i];
53             if (curr.matches(IStatus.ERROR)) {
54                 return curr;
55             }
56             if (max == null || curr.getSeverity() > max.getSeverity()) {
57                 max= curr;
58             }
59         }
60         return max;
61     }
62
63     /**
64      * Applies the status to the status line of a dialog page.
65      *
66      * @param page the dialog page
67      * @param status the status
68      */

69     public static void applyToStatusLine(DialogPage page, IStatus status) {
70         String JavaDoc message= status.getMessage();
71         switch (status.getSeverity()) {
72             case IStatus.OK:
73                 page.setMessage(message, IMessageProvider.NONE);
74                 page.setErrorMessage(null);
75                 break;
76             case IStatus.WARNING:
77                 page.setMessage(message, IMessageProvider.WARNING);
78                 page.setErrorMessage(null);
79                 break;
80             case IStatus.INFO:
81                 page.setMessage(message, IMessageProvider.INFORMATION);
82                 page.setErrorMessage(null);
83                 break;
84             default:
85                 if (message.length() == 0) {
86                     message= null;
87                 }
88                 page.setMessage(null);
89                 page.setErrorMessage(message);
90                 break;
91         }
92     }
93 }
94
Popular Tags