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