Index: project.xml =================================================================== RCS file: /cvs/web/project/nbproject/project.xml,v retrieving revision 1.67 diff -u -r1.67 project.xml --- project.xml 7 Jun 2007 10:16:10 -0000 1.67 +++ project.xml 12 Jun 2007 11:06:33 -0000 @@ -93,6 +93,15 @@ + org.netbeans.modules.db + + + + 0-1 + 1.20 + + + org.netbeans.modules.j2ee.api.ejbmodule @@ -115,7 +124,6 @@ 1 - 1.10 @@ -123,7 +131,7 @@ - 1.6 + 1.0 @@ -149,7 +157,7 @@ 1 - 1.3 + 1.2 ? web_proj_ch ? web_proj_ch2 ? web_project_changes1.txt Index: Bundle.properties =================================================================== RCS file: /cvs/web/project/src/org/netbeans/modules/web/project/ui/Bundle.properties,v retrieving revision 1.44 diff -u -r1.44 Bundle.properties --- Bundle.properties 1 Jun 2007 02:59:01 -0000 1.44 +++ Bundle.properties 12 Jun 2007 11:17:47 -0000 @@ -108,4 +108,4 @@ LBL_J2eeServerMissing=<Missing Java EE Server> LBL_Fix_Missing_Server_Action=Resolve Missing Server Problem... - +LBL_Fix_Broken_Datasource_Action=Resolve Datasource Problem... Index: WebLogicalViewProvider.java =================================================================== RCS file: /cvs/web/project/src/org/netbeans/modules/web/project/ui/WebLogicalViewProvider.java,v retrieving revision 1.5 diff -u -r1.5 WebLogicalViewProvider.java --- WebLogicalViewProvider.java 11 Jun 2007 13:02:35 -0000 1.5 +++ WebLogicalViewProvider.java 12 Jun 2007 11:17:48 -0000 @@ -41,6 +41,8 @@ import javax.swing.JSeparator; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import org.netbeans.api.db.explorer.ConnectionListener; +import org.netbeans.api.db.explorer.ConnectionManager; import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; @@ -74,6 +76,8 @@ import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; +import org.netbeans.api.project.ui.OpenProjects; +import org.netbeans.modules.j2ee.common.ui.BrokenDatasourceSupport; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.ReferenceHelper; @@ -91,8 +95,10 @@ import org.netbeans.modules.web.project.WebProject; import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; import org.netbeans.modules.websvc.rest.spi.RestSupport; +import org.netbeans.spi.project.AuxiliaryConfiguration; import org.netbeans.spi.project.ui.support.NodeFactorySupport; import org.openide.util.ChangeSupport; +import org.w3c.dom.Element; /** * Support for creating logical views. @@ -101,6 +107,7 @@ public class WebLogicalViewProvider implements LogicalViewProvider { private static final RequestProcessor BROKEN_LINKS_RP = new RequestProcessor("WebLogicalViewProvider.BROKEN_LINKS_RP"); // NOI18N + private static final RequestProcessor BROKEN_DATASOURCE_RP = new RequestProcessor("WebLogicalViewProvider.BROKEN_DATASOURCE_RP"); //NOI18N private final WebProject project; private final UpdateHelper helper; @@ -243,6 +250,7 @@ private final Action brokenLinksAction; private final BrokenServerAction brokenServerAction; + private final BrokenDatasourceAction brokenDatasourceAction; private boolean broken; // icon badging >>> @@ -268,6 +276,7 @@ } brokenLinksAction = new BrokenLinksAction(); brokenServerAction = new BrokenServerAction(); + brokenDatasourceAction = new BrokenDatasourceAction(); J2eeModuleProvider moduleProvider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); moduleProvider.addInstanceListener((InstanceListener)WeakListeners.create( InstanceListener.class, brokenServerAction, moduleProvider)); @@ -424,12 +433,12 @@ public Image getMyIcon( int type ) { Image original = super.getIcon( type ); - return broken || brokenServerAction.isEnabled() ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original; + return broken || brokenServerAction.isEnabled() || brokenDatasourceAction.isEnabled() ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original; } public Image getMyOpenedIcon( int type ) { Image original = super.getOpenedIcon(type); - return broken || brokenServerAction.isEnabled() ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original; + return broken || brokenServerAction.isEnabled() || brokenDatasourceAction.isEnabled() ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original; } public String getHtmlDisplayName() { @@ -439,7 +448,7 @@ } catch (CharConversionException ex) { return dispName; } - return broken || brokenServerAction.isEnabled() ? "" + dispName + "" : null; //NOI18N + return broken || brokenServerAction.isEnabled() || brokenDatasourceAction.isEnabled() ? "" + dispName + "" : null; //NOI18N } public Action[] getActions( boolean context ) { @@ -513,6 +522,9 @@ if (brokenServerAction.isEnabled()) { actions.add(brokenServerAction); } + if (brokenDatasourceAction.isEnabled()) { + actions.add(brokenDatasourceAction); + } actions.add(CommonProjectActions.customizeProjectAction()); return actions.toArray(new Action[actions.size()]); @@ -635,7 +647,112 @@ } } } - } + + + // For checking projects that use database connections to see if these connections are available + private class BrokenDatasourceAction extends AbstractAction implements Runnable, ConnectionListener { + private volatile boolean brokenDatasource; + private volatile boolean firstTime = false; + private RequestProcessor.Task task = null; + + public BrokenDatasourceAction() { + ConnectionManager.getDefault().addConnectionListener(this); + + // For now make sure BrokenDatasourceAction only applies to visualweb/Creator projects + // The if-statement here can be expanded to support other types of projects + if (!isVisualWebLegacyProject()) { + putValue(Action.NAME, + NbBundle.getMessage(WebLogicalViewProvider.class, + "LBL_Fix_Broken_Datasource_Action")); //NOI18N + checkMissingDatabaseConnection(); + } + } + + // Used to check to see if project is a visualweb or Creator project + private boolean isVisualWebLegacyProject() { + boolean isLegacyProject = false; + + // Check if Web module is a visualweb 5.5.x or Creator project + AuxiliaryConfiguration ac = (AuxiliaryConfiguration)project.getLookup().lookup(AuxiliaryConfiguration.class); + Element auxElement = ac.getConfigurationFragment("creator-data", "http://www.sun.com/creator/ns", true); //NOI18N + + // if project is a visualweb or creator project then find out whether it is a legacy project + if (auxElement != null) { + String version = auxElement.getAttribute("jsf.project.version"); //NOI18N + if (version != null) { + if (!version.equals("4.0")) { //NOI18N + isLegacyProject = true; + } + } + } + + return isLegacyProject; + } + + public boolean isEnabled() { + return brokenDatasource; + } + + public void actionPerformed(ActionEvent e) {// + BrokenDatasourceSupport.fixDatasources(project); + checkMissingDatabaseConnection(); + } + + private void checkMissingDatabaseConnection() { + // Checking for valid database connections for each datasource + // may take awhile, so run in a separate thread + if (task == null) { + task = BROKEN_DATASOURCE_RP.create(this); + } + + task.schedule(100); + } + + public void run() { + doCheckMissingDatabaseConnection(); + } + + /* + * Badge project node, change font color of display name to red and + * post an alert dialog if not the first time + */ + private void doCheckMissingDatabaseConnection() { + boolean old = brokenDatasource; + brokenDatasource = BrokenDatasourceSupport.isBroken(project); + if (old != brokenDatasource) { + // make changes in EDT thread + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + setEnabled(brokenDatasource); + fireIconChange(); + fireOpenedIconChange(); + fireDisplayNameChange(null, null); + if (brokenDatasource && !firstTime) { + BrokenDatasourceSupport.showAlert(); + firstTime = true; + } + } + }); + } + + // if no open projects have broken datasources then remove the connection listener + Project[] openProjects = OpenProjects.getDefault().getOpenProjects(); + boolean anyBroken = false; + for (int i = 0; i < openProjects.length; i++) { + if (BrokenDatasourceSupport.isBroken(openProjects[i])){ + anyBroken = true; + } + } + if (!anyBroken) { + ConnectionManager.getDefault().removeConnectionListener(this); + } + } + + public void connectionsChanged() { + checkMissingDatabaseConnection(); + } + } + } /** Factory for project actions.
* XXX This class is a candidate for move to org.netbeans.spi.project.ui.support