Index: WebLogicalViewProvider.java
===================================================================
RCS file: /cvs/web/project/src/org/netbeans/modules/web/project/ui/WebLogicalViewProvider.java,v
retrieving revision 1.4
diff -u -r1.4 WebLogicalViewProvider.java
--- WebLogicalViewProvider.java 1 Jun 2007 02:59:01 -0000 1.4
+++ WebLogicalViewProvider.java 7 Jun 2007 10:44:56 -0000
@@ -74,6 +74,7 @@
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
+import org.netbeans.modules.j2ee.common.ui.BrokenDatabaseSupport;
import org.netbeans.spi.project.support.ant.AntProjectHelper;
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
import org.netbeans.spi.project.support.ant.ReferenceHelper;
@@ -85,14 +86,17 @@
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener;
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
+import org.netbeans.modules.web.api.webmodule.WebModule;
import org.netbeans.modules.web.api.webmodule.WebProjectConstants;
import org.netbeans.modules.web.project.SourceRoots;
import org.netbeans.modules.web.project.UpdateHelper;
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.
@@ -255,6 +259,7 @@
private final Action brokenLinksAction;
private final BrokenServerAction brokenServerAction;
+ private final BrokenDatabaseAction brokenDatabaseAction;
private boolean broken;
// icon badging >>>
@@ -280,6 +285,7 @@
}
brokenLinksAction = new BrokenLinksAction();
brokenServerAction = new BrokenServerAction();
+ brokenDatabaseAction = new BrokenDatabaseAction();
J2eeModuleProvider moduleProvider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
moduleProvider.addInstanceListener((InstanceListener)WeakListeners.create(
InstanceListener.class, brokenServerAction, moduleProvider));
@@ -436,12 +442,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() || brokenDatabaseAction.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() || brokenDatabaseAction.isEnabled() ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original;
}
public String getHtmlDisplayName() {
@@ -451,7 +457,7 @@
} catch (CharConversionException ex) {
return dispName;
}
- return broken || brokenServerAction.isEnabled() ? "" + dispName + "" : null; //NOI18N
+ return broken || brokenServerAction.isEnabled() || brokenDatabaseAction.isEnabled() ? "" + dispName + "" : null; //NOI18N
}
public Action[] getActions( boolean context ) {
@@ -525,6 +531,9 @@
if (brokenServerAction.isEnabled()) {
actions.add(brokenServerAction);
}
+ if (brokenDatabaseAction.isEnabled()) {
+ actions.add(brokenDatabaseAction);
+ }
actions.add(CommonProjectActions.customizeProjectAction());
return actions.toArray(new Action[actions.size()]);
@@ -645,6 +654,91 @@
fireOpenedIconChange();
fireDisplayNameChange(null, null);
}
+ }
+ }
+
+ // For checking projects that use database connections to see if these connections are available
+ private class BrokenDatabaseAction extends AbstractAction implements Runnable {
+
+ // ensure updates to "brokenDatabase" are propagated to other threads
+ private volatile boolean brokenDatabase = false;
+
+ public BrokenDatabaseAction() {
+ // For now make sure BrokenDatabaseAction 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_Database_Action")); // NOI18N
+
+ checkMissingDatabase();
+ }
+ }
+
+ // Used to check to see if project is a visualweb or Creator project
+ private boolean isVisualWebLegacyProject() {
+ boolean isLegacyProject = false;
+
+ // If project is a Web module then check to see if Web module is a visualweb 5.5.x or Creator project
+ // Is there a better way to determine if a project is a Web Module ?
+ if (WebModule.getWebModule(project.getProjectDirectory()) != null) {
+ AuxiliaryConfiguration ac = (AuxiliaryConfiguration)project.getLookup().lookup(AuxiliaryConfiguration.class);
+ Element auxElement = ac.getConfigurationFragment("creator-data", "http://www.sun.com/creator/ns", true);
+
+ // if project is a visualweb or creator project then find out whether it is a legacy project
+ if (auxElement != null) {
+ String version = null;
+ version = auxElement.getAttribute("jsf.project.version");
+
+ if (version != null) {
+ if (version.equals("4.0-import")) {
+ isLegacyProject = true;
+ }
+ }
+ }
+ }
+
+ return isLegacyProject;
+ }
+
+ public boolean isEnabled() {
+ return brokenDatabase;
+ }
+
+ public void actionPerformed(ActionEvent e) {//
+ BrokenDatabaseSupport.selectDatasource(project);
+ BrokenDatabaseSupport.disposeIfEmpty();
+ checkMissingDatabase();
+ }
+
+ private void checkMissingDatabase() {
+ // Checking for valid database connections for each datasource
+ // may take awhile, so run in a separate thread
+ Thread dbThread = new Thread(this);
+ dbThread.start();
+ }
+
+ public synchronized void run() {
+ doCheckMissingDatabase();
+ }
+
+ private void doCheckMissingDatabase() {
+ // brokenDatabase is volatile so it sees previous settings and be set to the correct value
+ brokenDatabase = BrokenDatabaseSupport.isBroken(project);
+
+
+ // makes changes in EDT thread
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ setEnabled(brokenDatabase);
+ fireIconChange();
+ fireOpenedIconChange();
+ fireDisplayNameChange(null, null);
+ if (brokenDatabase) {
+ BrokenDatabaseSupport.showAlert();
+ }
+ }
+ });
}
}
}
Index: WebLogicalViewProvider.java
===================================================================
RCS file: /cvs/web/project/src/org/netbeans/modules/web/project/ui/WebLogicalViewProvider.java,v
retrieving revision 1.4
diff -u -r1.4 WebLogicalViewProvider.java
--- WebLogicalViewProvider.java 1 Jun 2007 02:59:01 -0000 1.4
+++ WebLogicalViewProvider.java 7 Jun 2007 10:46:44 -0000
@@ -74,6 +74,7 @@
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
+import org.netbeans.modules.j2ee.common.ui.BrokenDatabaseSupport;
import org.netbeans.spi.project.support.ant.AntProjectHelper;
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
import org.netbeans.spi.project.support.ant.ReferenceHelper;
@@ -85,14 +86,17 @@
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener;
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
+import org.netbeans.modules.web.api.webmodule.WebModule;
import org.netbeans.modules.web.api.webmodule.WebProjectConstants;
import org.netbeans.modules.web.project.SourceRoots;
import org.netbeans.modules.web.project.UpdateHelper;
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.
@@ -255,6 +259,7 @@
private final Action brokenLinksAction;
private final BrokenServerAction brokenServerAction;
+ private final BrokenDatabaseAction brokenDatabaseAction;
private boolean broken;
// icon badging >>>
@@ -280,6 +285,7 @@
}
brokenLinksAction = new BrokenLinksAction();
brokenServerAction = new BrokenServerAction();
+ brokenDatabaseAction = new BrokenDatabaseAction();
J2eeModuleProvider moduleProvider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
moduleProvider.addInstanceListener((InstanceListener)WeakListeners.create(
InstanceListener.class, brokenServerAction, moduleProvider));
@@ -436,12 +442,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() || brokenDatabaseAction.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() || brokenDatabaseAction.isEnabled() ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original;
}
public String getHtmlDisplayName() {
@@ -451,7 +457,7 @@
} catch (CharConversionException ex) {
return dispName;
}
- return broken || brokenServerAction.isEnabled() ? "" + dispName + "" : null; //NOI18N
+ return broken || brokenServerAction.isEnabled() || brokenDatabaseAction.isEnabled() ? "" + dispName + "" : null; //NOI18N
}
public Action[] getActions( boolean context ) {
@@ -525,6 +531,9 @@
if (brokenServerAction.isEnabled()) {
actions.add(brokenServerAction);
}
+ if (brokenDatabaseAction.isEnabled()) {
+ actions.add(brokenDatabaseAction);
+ }
actions.add(CommonProjectActions.customizeProjectAction());
return actions.toArray(new Action[actions.size()]);
@@ -645,6 +654,91 @@
fireOpenedIconChange();
fireDisplayNameChange(null, null);
}
+ }
+ }
+
+ // For checking projects that use database connections to see if these connections are available
+ private class BrokenDatabaseAction extends AbstractAction implements Runnable {
+
+ // ensure updates to "brokenDatabase" are propagated to other threads
+ private volatile boolean brokenDatabase = false;
+
+ public BrokenDatabaseAction() {
+ // For now make sure BrokenDatabaseAction 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_Database_Action")); // NOI18N
+
+ checkMissingDatabase();
+ }
+ }
+
+ // Used to check to see if project is a visualweb or Creator project
+ private boolean isVisualWebLegacyProject() {
+ boolean isLegacyProject = false;
+
+ // If project is a Web module then check to see if Web module is a visualweb 5.5.x or Creator project
+ // Is there a better way to determine if a project is a Web Module ?
+ if (WebModule.getWebModule(project.getProjectDirectory()) != null) {
+ AuxiliaryConfiguration ac = (AuxiliaryConfiguration)project.getLookup().lookup(AuxiliaryConfiguration.class);
+ Element auxElement = ac.getConfigurationFragment("creator-data", "http://www.sun.com/creator/ns", true);
+
+ // if project is a visualweb or creator project then find out whether it is a legacy project
+ if (auxElement != null) {
+ String version = null;
+ version = auxElement.getAttribute("jsf.project.version");
+
+ if (version != null) {
+ if (version.equals("4.0-import")) {
+ isLegacyProject = true;
+ }
+ }
+ }
+ }
+
+ return isLegacyProject;
+ }
+
+ public boolean isEnabled() {
+ return brokenDatabase;
+ }
+
+ public void actionPerformed(ActionEvent e) {//
+ BrokenDatabaseSupport.selectDatasource(project);
+ BrokenDatabaseSupport.disposeIfEmpty();
+ checkMissingDatabase();
+ }
+
+ private void checkMissingDatabase() {
+ // Checking for valid database connections for each datasource
+ // may take awhile, so run in a separate thread
+ Thread dbThread = new Thread(this);
+ dbThread.start();
+ }
+
+ public synchronized void run() {
+ doCheckMissingDatabase();
+ }
+
+ private void doCheckMissingDatabase() {
+ // brokenDatabase is volatile so it sees previous settings and be set to the correct value
+ brokenDatabase = BrokenDatabaseSupport.isBroken(project);
+
+
+ // makes changes in EDT thread
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ setEnabled(brokenDatabase);
+ fireIconChange();
+ fireOpenedIconChange();
+ fireDisplayNameChange(null, null);
+ if (brokenDatabase) {
+ BrokenDatabaseSupport.showAlert();
+ }
+ }
+ });
}
}
}