/* * The contents of this file are subject to the terms of the Common Development * and Distribution License (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the License at http://www.netbeans.org/cddl.html * or http://www.netbeans.org/cddl.txt. * * When distributing Covered Code, include this CDDL Header Notice in each file * and include the License file at http://www.netbeans.org/cddl.txt. * If applicable, add the following below the CDDL Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.visualweb.dataconnectivity.ui; import java.awt.Dialog; import java.util.Set; import javax.swing.JButton; import javax.swing.SwingUtilities; import org.netbeans.api.project.Project; import org.netbeans.modules.visualweb.dataconnectivity.datasource.DataSourceResolver; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.util.NbBundle; /** * Support for managing broken/missing Databases. * * PLEASE NOTE! This is just a temporary solution. BrokenReferencesSupport from * the java project support currently does not allow to plug in a check for missing * Databases. Once BrokenReferencesSupport will support it, this class should be * removed. */ public class BrokenDatabaseSupport { /** Last time in ms when the Broken References alert was shown. */ private static long brokenAlertLastTime = 0; /** Is Broken References alert shown now? */ private static boolean brokenAlertShown = false; /** Timeout within which request to show alert will be ignored. */ private static int BROKEN_ALERT_TIMEOUT = 1000; private BrokenDatabaseSupport() {} /** * Checks whether the project has a broken/missing Database problem. * * @param project * @return true server instance of the specified id doesn't exist */ public static boolean isBroken(Project project) { Set problemDatasources = DataSourceResolver.getInstance().getProblemDataSources(project); if (problemDatasources == null) return false; else return !problemDatasources.isEmpty(); } /** * Shows UI customizer which gives users chance to fix encountered problems, * i.e. choose appropriate application server. * * @param project * @return selected application server. Might be null. */ public static String selectDatabaseConnection(final Project project) { return NoSelectedDatabaseConnectionWarning.selectDatabaseDialog( NbBundle.getMessage(BrokenDataSourceSupport.class, "LBL_Resolve_Missing_DataSource_Title"), NbBundle.getMessage(BrokenDataSourceSupport.class, "ACSD_Resolve_Missing_DataSource"), project); // NOI18N } /** * Show alert message box informing user that a project has missing * database connections. This method can be safely called from any thread, e.g. during * the project opening, and it will take care about showing message box only * once for several subsequent calls during a timeout. * The alert box has also "show this warning again" check box. */ public static synchronized void showAlert() { if (Boolean.getBoolean("j2eeserver.no.server.instance.check")) { return; } brokenAlertShown = true; SwingUtilities.invokeLater(new Runnable() { public void run() { try { BrokenDatabaseAlertPanel alert = new BrokenDatabaseAlertPanel(); JButton close = new JButton( NbBundle.getMessage(BrokenDatabaseSupport.class, "LBL_BrokenDatabaseCustomizer_Close")); close.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(BrokenDatabaseSupport.class, "ACSD_BrokenDatabaseCustomizer_Close")); DialogDescriptor dd = new DialogDescriptor( alert, NbBundle.getMessage(BrokenDatabaseAlertPanel.class, "MSG_Broken_Database_Title"), true, new Object[] {close}, close, DialogDescriptor.DEFAULT_ALIGN, null, null); dd.setMessageType(DialogDescriptor.WARNING_MESSAGE); Dialog dlg = DialogDisplayer.getDefault().createDialog(dd); dlg.setVisible(true); } finally { synchronized (BrokenDatabaseSupport.class) { brokenAlertLastTime = System.currentTimeMillis(); brokenAlertShown = false; } } } }); } public static boolean addDataSourceAndConnection(Project project, String item) { return DataSourceResolver.getInstance().addDataSource(project, item); } public static boolean dataSourceExistsCheck(Project project, String item) { return DataSourceResolver.getInstance().dataSourceExists(project, item); } }