KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > j2seimport > ui > WarningMessage


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.projectimport.j2seimport.ui;
21 import java.util.Iterator JavaDoc;
22 import org.netbeans.modules.projectimport.j2seimport.WarningContainer;
23 import org.netbeans.modules.projectimport.j2seimport.ImportProcess;
24 import org.netbeans.modules.projectimport.j2seimport.WarningContainer.Warning;
25 import org.openide.DialogDescriptor;
26 import org.openide.DialogDisplayer;
27 import org.openide.NotifyDescriptor;
28 import org.openide.util.NbBundle;
29
30
31 /**
32  *
33  * @author Radek Matous
34  */

35 public class WarningMessage {
36     public static void showMessages(final ImportProcess iProcess) {
37         WarningContainer warnings = iProcess.getWarnings();
38         
39         if (warnings != null) {
40             Iterator JavaDoc it = iProcess.getWarnings().getIterator();
41             String JavaDoc message = createHtmlString(NbBundle.getMessage(WarningMessage.class, "MSG_ProblemsOccured"), it, true, 10);//NOI18N
42
if (message != null) {
43                 NotifyDescriptor d = new DialogDescriptor.Message(message, NotifyDescriptor.WARNING_MESSAGE);
44                 DialogDisplayer.getDefault().notify(d);
45             }
46         }
47     }
48     
49     public static String JavaDoc createHtmlString(String JavaDoc msg, Iterator JavaDoc it, boolean userNotificationOnly, int itemsLimit) {
50         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
51         int items = 0;
52         sb.append("<html><b>").append(msg).append("</b><ul>");//NOI18N
53
while (it.hasNext()) {
54             WarningContainer.Warning warning = (Warning)it.next();
55             boolean add = (userNotificationOnly && !warning.isUserNotification()) ? false : true;
56             if (items < itemsLimit) {
57                 if (add) {
58                     items++;
59                     sb.append("<li>").append(warning.getMessage()).append("</li>");//NOI18N
60
}
61             } else {
62                 break;
63             }
64         }
65         
66         sb.append("</ul>");
67         sb.append("</html>");//NOI18N
68
return (items > 0) ? sb.toString() : null;
69     }
70     
71     /** Creates a new instance of WarningMessage */
72     private WarningMessage() {
73     }
74     
75 }
76
Popular Tags