Register new file extensions for the php-editor:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / dialogs / StatusUtil.java
1 /*
2  * (c) Copyright IBM Corp. 2000, 2001.
3  * All Rights Reserved.
4  */
5 package net.sourceforge.phpdt.internal.ui.dialogs;
6
7 import org.eclipse.core.runtime.IStatus;
8 import org.eclipse.jface.dialogs.DialogPage;
9
10 /**
11  * A utility class to work with IStatus.
12  */
13 public class StatusUtil {
14
15         /**
16          * Compares two instances of <code>IStatus</code>. The more severe is returned:
17          * An error is more severe than a warning, and a warning is more severe
18          * than ok. If the two stati have the same severity, the second is returned.
19          */
20         public static IStatus getMoreSevere(IStatus s1, IStatus s2) {
21                 if (s1.getSeverity() > s2.getSeverity()) {
22                         return s1;
23                 } else {
24                         return s2;
25                 }
26         }
27
28         /**
29          * Finds the most severe status from a array of stati.
30          * An error is more severe than a warning, and a warning is more severe
31          * than ok.
32          */
33         public static IStatus getMostSevere(IStatus[] status) {
34                 IStatus max= null;
35                 for (int i= 0; i < status.length; i++) {
36                         IStatus curr= status[i];
37                         if (curr.matches(IStatus.ERROR)) {
38                                 return curr;
39                         }
40                         if (max == null || curr.getSeverity() > max.getSeverity()) {
41                                 max= curr;
42                         }
43                 }
44                 return max;
45         }
46                 
47         /**
48          * Applies the status to the status line of a dialog page.
49          */
50         public static void applyToStatusLine(DialogPage page, IStatus status) {
51                 String message= status.getMessage();
52                 switch (status.getSeverity()) {
53                         case IStatus.OK:
54                                 page.setMessage(message, DialogPage.NONE);
55                                 page.setErrorMessage(null);
56                                 break;
57                         case IStatus.WARNING:
58                                 page.setMessage(message, DialogPage.WARNING);
59                                 page.setErrorMessage(null);
60                                 break;                          
61                         case IStatus.INFO:
62                                 page.setMessage(message, DialogPage.INFORMATION);
63                                 page.setErrorMessage(null);
64                                 break;                  
65                         default:
66                                 if (message.length() == 0) {
67                                         message= null;
68                                 }
69                                 page.setMessage(null);
70                                 page.setErrorMessage(message);
71                                 break;          
72                 }
73         }
74 }