Author: scabanovich
Date: 2007-07-12 10:41:42 -0400 (Thu, 12 Jul 2007)
New Revision: 2402
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegete.java
Log:
EXIN-217 XModel configured in seam facet
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-12
13:56:17 UTC (rev 2401)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-12
14:41:42 UTC (rev 2402)
@@ -260,6 +260,10 @@
current = null;
c = getComponent(name);
} else {
+ if(loaded instanceof ISeamXmlComponentDeclaration) {
+ ISeamXmlComponentDeclaration xml = (ISeamXmlComponentDeclaration)loaded;
+ onXMLLoadedDeclaration(c, oldClassName, xml);
+ }
continue;
}
}
@@ -292,24 +296,7 @@
}
} else if(loaded instanceof ISeamXmlComponentDeclaration) {
ISeamXmlComponentDeclaration xml = (ISeamXmlComponentDeclaration)loaded;
- String className = xml.getClassName();
- List<Change> changes = null;
- if(isClassNameChanged(oldClassName, className)) {
- SeamComponentDeclaration[] ds1 = c.getAllDeclarations().toArray(new
SeamComponentDeclaration[0]);
- for (int i1 = 0; i1 < ds1.length; i1++) {
- if(!(ds1[i1] instanceof ISeamJavaComponentDeclaration)) continue;
- ISeamJavaComponentDeclaration jcd = (ISeamJavaComponentDeclaration)ds1[i1];
- if(jcd.getClassName().equals(className)) continue;
- c.removeDeclaration(jcd);
- changes = Change.addChange(changes, new Change(c, null, jcd, null));
- }
- }
- SeamJavaComponentDeclaration j = javaDeclarations.get(className);
- if(j != null) {
- c.addDeclaration(j);
- changes = Change.addChange(changes, new Change(c, null, null, j));
- }
- fireChanges(changes);
+ onXMLLoadedDeclaration(c, oldClassName, xml);
}
}
fireChanges(addedComponents);
@@ -350,6 +337,27 @@
if(newClassName == null || newClassName.length() == 0) return false;
return !oldClassName.equals(newClassName);
}
+
+ private void onXMLLoadedDeclaration(SeamComponent c, String oldClassName,
ISeamXmlComponentDeclaration xml) {
+ String className = xml.getClassName();
+ List<Change> changes = null;
+ if(isClassNameChanged(oldClassName, className)) {
+ SeamComponentDeclaration[] ds1 = c.getAllDeclarations().toArray(new
SeamComponentDeclaration[0]);
+ for (int i1 = 0; i1 < ds1.length; i1++) {
+ if(!(ds1[i1] instanceof ISeamJavaComponentDeclaration)) continue;
+ ISeamJavaComponentDeclaration jcd = (ISeamJavaComponentDeclaration)ds1[i1];
+ if(jcd.getClassName().equals(className)) continue;
+ c.removeDeclaration(jcd);
+ changes = Change.addChange(changes, new Change(c, null, jcd, null));
+ }
+ }
+ SeamJavaComponentDeclaration j = javaDeclarations.get(className);
+ if(j != null && !c.getAllDeclarations().contains(j)) {
+ c.addDeclaration(j);
+ changes = Change.addChange(changes, new Change(c, null, null, j));
+ }
+ fireChanges(changes);
+ }
/**
* Package local method called by builder.
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegete.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegete.java 2007-07-12
13:56:17 UTC (rev 2401)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/SeamFacetInstallDelegete.java 2007-07-12
14:41:42 UTC (rev 2402)
@@ -13,7 +13,9 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
@@ -27,9 +29,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.internal.core.JavaModel;
-import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
@@ -300,10 +299,11 @@
new FilterSetCollection(projectFilterSet), true);
}
+ writeXModel(project, model);
+
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
- //TODO check if template file org.jboss.tools.jst.web.xml is added to .settings
EclipseResourceUtil.addNatureToProject(project,
"org.jboss.tools.jsf.jsfnature");
EclipseResourceUtil.addNatureToProject(project, ISeamProject.NATURE_ID);
@@ -499,5 +499,55 @@
}
}
+ private void writeXModel(IProject project, IDataModel model) {
+ String projectName = project.getName();
+ String webContent = "WebContent";
+
+ //TODO This returns null. Why? How else can we get WebContent folder name?
+ webContent =
(String)model.getProperty(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER);
+
+ if(webContent == null) {
+ webContent = "WebContent";
+ }
+ String src = "src";
+
+ String[] srcs = EclipseResourceUtil.getJavaProjectSrcLocations(project);
+ if (srcs.length > 0) {
+ src =
srcs[0].replace('\\','/').substring(srcs[0].lastIndexOf('/') +
1);
+ }
+ File location = new
File(project.getLocation().toFile(),".settings/org.jboss.tools.jst.web.xml");
+
+ Object[] arguments = {
+ projectName,
+ webContent,
+ src
+ };
+ String body = MessageFormat.format(XMODEL, arguments);
+
+ org.jboss.tools.common.util.FileUtil.writeFile(location, body);
+ }
+ /**
+ * {0} - project name
+ * {1} - WebContent folder name
+ * {2} - src folder name
+ */
+ private static String XMODEL =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<FILESYSTEMS APPLICATION_NAME=\"{0}\"
ENTITY=\"FileSystems\"" +
+ " VERSION=\"2.0.0\" WORKSPACE_HOME=\"./{1}/WEB-INF\">"
+
+ "<FILESYSTEM ENTITY=\"FileSystemFolder\"
LOCATION=\"%redhat.workspace%\" NAME=\"WEB-INF\"/>" +
+ "<FILESYSTEM ENTITY=\"FileSystemFolder\"
INFO=\"Content-Type=Web\"" +
+ " LOCATION=\"%redhat.workspace%/..\"
NAME=\"WEB-ROOT\"/>" +
+ "<FILESYSTEM ENTITY=\"FileSystemFolder\"" +
+ " LOCATION=\"%redhat.workspace%/../../{2}\"
NAME=\"src\"/>" +
+ "<FILESYSTEM ENTITY=\"FileSystemFolder\"
LOCATION=\"%redhat.workspace%/lib\" NAME=\"lib\"/>" +
+ "<FILESYSTEM ENTITY=\"FileSystemFolder\"" +
+ " LOCATION=\"%redhat.workspace%/classes\"
NAME=\"classes\"/>" +
+ "<WEB ENTITY=\"JstWeb\" MODEL_PATH=\"/web.xml\"
SERVLET_VERSION=\"2.4\">" +
+ " <MODULE ENTITY=\"WebJSFModule\"
MODEL_PATH=\"/faces-config.xml\"" +
+ " ROOT=\"WEB-ROOT\" SRC=\"src\"
URI=\"/WEB-INF/faces-config.xml\"/>" +
+ "</WEB>" +
+ "</FILESYSTEMS>"
+ ;
}