KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > common > ui > BrokenServerSupport


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.j2ee.common.ui;
21
22 import java.awt.Dialog JavaDoc;
23 import javax.swing.JButton JavaDoc;
24 import javax.swing.SwingUtilities JavaDoc;
25 import org.netbeans.modules.j2ee.common.*;
26 import org.netbeans.modules.j2ee.common.ui.NoSelectedServerWarning;
27 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
28 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
29 import org.openide.DialogDescriptor;
30 import org.openide.DialogDisplayer;
31 import org.openide.util.NbBundle;
32
33 /**
34  * Support for managing broken/missing servers.
35  *
36  * PLEASE NOTE! This is just a temporary solution. BrokenReferencesSupport from
37  * the java project support currently does not allow to plug in a check for missing
38  * servers. Once BrokenReferencesSupport will support it, this class should be
39  * removed.
40  */

41 public class BrokenServerSupport {
42
43     /** Last time in ms when the Broken References alert was shown. */
44     private static long brokenAlertLastTime = 0;
45     
46     /** Is Broken References alert shown now? */
47     private static boolean brokenAlertShown = false;
48
49     /** Timeout within which request to show alert will be ignored. */
50     private static int BROKEN_ALERT_TIMEOUT = 1000;
51     
52     private BrokenServerSupport() {}
53
54     /**
55      * Checks whether the project has a broken/missing server problem.
56      *
57      * @param serverInstanceID server instance of which should be checked.
58      *
59      * @return true server instance of the specified id doesn't exist
60      */

61     public static boolean isBroken(String JavaDoc serverInstanceID) {
62         return Deployment.getDefault().getServerID(serverInstanceID) == null;
63     }
64     
65     /**
66      * Shows UI customizer which gives users chance to fix encountered problems,
67      * i.e. choose appropriate application server.
68      *
69      * @param j2eeSpec one of {@link J2eeModule#EJB}, {@link J2eeModule#EAR}
70      * @param moduleType
71      * @return selected application server. Might be <code>null</code>.
72      */

73     public static String JavaDoc selectServer(final String JavaDoc j2eeSpec, final Object JavaDoc moduleType) {
74         return NoSelectedServerWarning.selectServerDialog(
75                 new Object JavaDoc[] { moduleType }, j2eeSpec,
76                 NbBundle.getMessage(BrokenServerSupport.class, "LBL_Resolve_Missing_Server_Title"),
77                 NbBundle.getMessage(BrokenServerSupport.class, "ACSD_Resolve_Missing_Server")); // NOI18N
78
}
79
80     /**
81      * Show alert message box informing user that a project has missing
82      * server. This method can be safely called from any thread, e.g. during
83      * the project opening, and it will take care about showing message box only
84      * once for several subsequent calls during a timeout.
85      * The alert box has also "show this warning again" check box.
86      */

87     public static synchronized void showAlert() {
88         if (Boolean.getBoolean("j2eeserver.no.server.instance.check")) {
89             return;
90         }
91         // Do not show alert if it is already shown or if it was shown
92
// in last BROKEN_ALERT_TIMEOUT milliseconds or if user do not wish it.
93
if (brokenAlertShown
94             || brokenAlertLastTime+BROKEN_ALERT_TIMEOUT > System.currentTimeMillis()
95             || !J2EEUISettings.getDefault().isShowAgainBrokenServerAlert()) {
96                 return;
97         }
98         brokenAlertShown = true;
99         SwingUtilities.invokeLater(new Runnable JavaDoc() {
100                 public void run() {
101                     try {
102                         BrokenServerAlertPanel alert = new BrokenServerAlertPanel();
103                         JButton JavaDoc close = new JButton JavaDoc(
104                                 NbBundle.getMessage(BrokenServerSupport.class, "LBL_BrokenServerCustomizer_Close"));
105                         close.getAccessibleContext().setAccessibleDescription(
106                                 NbBundle.getMessage(BrokenServerSupport.class, "ACSD_BrokenServerCustomizer_Close"));
107                         DialogDescriptor dd = new DialogDescriptor(
108                                 alert,
109                                 NbBundle.getMessage(BrokenServerAlertPanel.class, "MSG_Broken_Server_Title"),
110                                 true,
111                                 new Object JavaDoc[] {close},
112                                 close,
113                                 DialogDescriptor.DEFAULT_ALIGN,
114                                 null,
115                                 null);
116                         dd.setMessageType(DialogDescriptor.WARNING_MESSAGE);
117                         Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(dd);
118                         dlg.setVisible(true);
119                     } finally {
120                         synchronized (BrokenServerSupport.class) {
121                             brokenAlertLastTime = System.currentTimeMillis();
122                             brokenAlertShown = false;
123                         }
124                     }
125                 }
126             });
127     }
128 }
129
Popular Tags