Author: scabanovich
Date: 2011-09-07 20:36:21 -0400 (Wed, 07 Sep 2011)
New Revision: 34576
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/NewBeansXMLCreationWizard.java
Log:
JBIDE-9678
https://issues.jboss.org/browse/JBIDE-9678
New beans.xml wizard is initialized with existing beans.xml location whatever selection
was, and warning of existing beans.xml displayed right away.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/NewBeansXMLCreationWizard.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/NewBeansXMLCreationWizard.java 2011-09-07
21:30:41 UTC (rev 34575)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/NewBeansXMLCreationWizard.java 2011-09-08
00:36:21 UTC (rev 34576)
@@ -25,6 +25,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
@@ -137,6 +138,11 @@
public WizardNewBeansXMLFileCreationPage(String pageName, IStructuredSelection
selection) {
super(pageName, selection);
}
+
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+ validatePage();
+ }
protected void initialPopulateContainerNameField() {
super.initialPopulateContainerNameField();
@@ -152,20 +158,31 @@
boolean needMetaInf = false;
IPath current = getContainerFullPath();
IProject p = r.getProject();
- IPath path = ProjectHome.getWebInfPath(p);
- if(current != null && current.equals(path)) return;
+ //Prefer location of existing beans.xml to any other location.
+ IPath path = getContainerWithExistingBeansXML(p);
+
if(path == null) {
-
+ //If no beans.xml exist, prefer WEB-INF if it exists
+ path = ProjectHome.getWebInfPath(p);
+ }
+ if(current != null && current.equals(path)) {
+ return;
+ }
+ if(path == null) {
Set<IFolder> fs = EclipseResourceUtil.getSourceFolders(p);
- if(fs != null) for (IFolder f: fs) {
+ for (IFolder f: fs) {
IFolder fm = f.getFolder("META-INF");
if(!fm.exists()) {
needMetaInf = true;
fm = f;
}
IPath pth = fm.getFullPath();
- if(current != null && current.equals(pth)) return;
- if(path == null) path = pth;
+ if(pth.equals(current) && !needMetaInf) {
+ return;
+ }
+ if(path == null || pth.equals(current)) {
+ path = pth;
+ }
}
}
if(path != null) {
@@ -210,7 +227,7 @@
if(path == null) {
boolean needMetaInf = false;
Set<IFolder> fs = EclipseResourceUtil.getSourceFolders(p);
- if(fs != null) for (IFolder f: fs) {
+ for (IFolder f: fs) {
IFolder fm = f.getFolder("META-INF");
IPath pth = fm.getFullPath();
if(path == null) {
@@ -225,4 +242,29 @@
return path;
}
+ /**
+ * Returns path to folder that contains existing beans.xml,
+ * or null, if there is no beans.xml in WEB-INF or META-INF folders.
+ *
+ * @param p
+ * @return
+ */
+ public static IPath getContainerWithExistingBeansXML(IProject p) {
+ IPath path = ProjectHome.getWebInfPath(p);
+ if(path != null) {
+ IFile f = p.getParent().getFile(path.append("beans.xml"));
+ if(f.exists()) {
+ return path;
+ }
+ }
+ Set<IFolder> fs = EclipseResourceUtil.getSourceFolders(p);
+ for (IFolder f: fs) {
+ IFolder fm = f.getFolder("META-INF");
+ if(fm.exists() && fm.getFile("beans.xml").exists()) {
+ return fm.getFullPath();
+ }
+ }
+ return null;
+ }
+
}