Author: akazakov
Date: 2009-01-15 08:04:15 -0500 (Thu, 15 Jan 2009)
New Revision: 13058
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamProjectsSet.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.properties
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3535 Let user change seam war parent project in
seam settings page.
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamProjectsSet.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamProjectsSet.java 2009-01-15
09:36:08 UTC (rev 13057)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamProjectsSet.java 2009-01-15
13:04:15 UTC (rev 13058)
@@ -76,6 +76,16 @@
}
}
+ /**
+ * @return default deploy type for Seam project set
+ */
+ public String getDefaultDeployType() {
+ if(ejb!=null && war!=ejb) {
+ return ISeamFacetDataModelProperties.DEPLOY_AS_EAR;
+ }
+ return ISeamFacetDataModelProperties.DEPLOY_AS_WAR;
+ }
+
public boolean isWarConfiguration() {
if(prefs==null) {
return false;
@@ -115,6 +125,10 @@
return test;
}
+ public IContainer getDefaultActionFolder() {
+ return getDefaultEjbSourceFolder();
+ }
+
/**
*
* @return the action folder (this folder is not guaranteed to exist!)
@@ -125,48 +139,74 @@
folderPath = prefs.get(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER,
null);
}
if(folderPath==null || folderPath.length()==0) {
- return getSourceFolder();
+ return getDefaultActionFolder();
}
return (IContainer)ResourcesPlugin.getWorkspace().getRoot().findMember(folderPath);
}
/**
- *
* @return the model folder if exists (this folder is not guaranteed to exist!)
*/
+ public IContainer getDefaultModelFolder() {
+ return getDefaultEjbSourceFolder();
+ }
+
+ /**
+ * @return the model folder if exists (this folder is not guaranteed to exist!)
+ */
public IContainer getModelFolder() {
String folderPath = null;
if(prefs!=null) {
folderPath = prefs.get(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER,
null);
}
if(folderPath==null || folderPath.length()==0) {
- return getSourceFolder();
+ return getDefaultModelFolder();
}
return (IContainer)ResourcesPlugin.getWorkspace().getRoot().findMember(folderPath);
}
- private IContainer getSourceFolder() {
+ public IContainer getDefaultEjbSourceFolder() {
+ return getSrc(ejb);
+ }
+
+ public IContainer getDefaultTestSourceFolder() {
+ return getSrc(test);
+ }
+
+ public IContainer getDefaultWarSourceFolder() {
IFolder webSrcFolder = findWebSrcFolder();
if(webSrcFolder!=null) {
return webSrcFolder;
}
- IJavaProject javaProject = EclipseResourceUtil.getJavaProject(war);
- if(javaProject==null) {
- return war;
+ return getSrc(war);
+ }
+
+ private IContainer getSrc(IProject project) {
+ if(project==null) {
+ project = war;
}
- try {
- IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
- for (int i = 0; i < roots.length; i++) {
- if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE && roots[i].isOpen())
{
- return (IFolder)roots[i].getResource();
- }
+ IResource resource = EclipseResourceUtil.getJavaSourceRoot(project);
+ if(resource!=null) {
+ return (IContainer) resource;
+ }
+ return project;
+ }
+
+ /**
+ * Returns default web contents folder.
+ * @return
+ */
+ public IContainer getDefaultViewsFolder() {
+ IVirtualComponent com = ComponentCore.createComponent(war);
+ if(com!=null) {
+ IVirtualFolder webRootFolder = com.getRootFolder().getFolder(new Path("/"));
//$NON-NLS-1$
+ if(webRootFolder!=null) {
+ return (IFolder)webRootFolder.getUnderlyingFolder();
}
- } catch (JavaModelException e) {
- SeamCorePlugin.getPluginLog().logError(e);
}
- return (IFolder)javaProject.getResource();
+ return getWarProject();
}
/**
@@ -179,14 +219,7 @@
folderPath = prefs.get(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER, null);
}
if(folderPath==null || folderPath.length()==0) {
- IVirtualComponent com = ComponentCore.createComponent(war);
- if(com!=null) {
- IVirtualFolder webRootFolder = com.getRootFolder().getFolder(new
Path("/")); //$NON-NLS-1$
- if(webRootFolder!=null) {
- return (IFolder)webRootFolder.getUnderlyingFolder();
- }
- }
- return getWarProject();
+ return getDefaultViewsFolder();
}
return (IContainer)ResourcesPlugin.getWorkspace().getRoot().findMember(folderPath);
@@ -202,7 +235,7 @@
folderPath = prefs.get(ISeamFacetDataModelProperties.TEST_SOURCE_FOLDER, null);
}
if(folderPath==null || folderPath.length()==0) {
- return getSourceFolder();
+ return getDefaultTestSourceFolder();
}
return (IContainer)ResourcesPlugin.getWorkspace().getRoot().findMember(folderPath);
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.java 2009-01-15
09:36:08 UTC (rev 13057)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.java 2009-01-15
13:04:15 UTC (rev 13058)
@@ -53,6 +53,10 @@
public static String SEAM_SETTINGS_PREFERENCE_PAGE_EJB_PROJECT_DOES_NOT_EXIST;
+ public static String SEAM_SETTINGS_PREFERENCE_PAGE_MAIN_SEAM_PROJECT_DOES_NOT_EXIST;
+
+ public static String SEAM_SETTINGS_PREFERENCE_PAGE_MAIN_SEAM_PROJECT_IS_EMPTY;
+
public static String SEAM_SETTINGS_PREFERENCE_PAGE_VIEW_FOLDER_DOES_NOT_EXIST;
public static String SEAM_SETTINGS_PREFERENCE_PAGE_MODEL_SOURCE_FOLDER_DOES_NOT_EXIST;
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.properties
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.properties 2009-01-15
09:36:08 UTC (rev 13057)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.properties 2009-01-15
13:04:15 UTC (rev 13058)
@@ -99,6 +99,8 @@
SEAM_SETTINGS_PREFERENCE_PAGE_MODEL_SOURCE_FOLDER_DOES_NOT_EXIST=Model source folder
"{0}" does not exist.
SEAM_SETTINGS_PREFERENCE_PAGE_ACTION_SOURCE_FOLDER_DOES_NOT_EXIST=Action/Form/Conversation
source folder "{0}" does not exist.
SEAM_SETTINGS_PREFERENCE_PAGE_TEST_PROJECT_DOES_NOT_EXIST=Seam test project
"{0}" does not exist.
+SEAM_SETTINGS_PREFERENCE_PAGE_MAIN_SEAM_PROJECT_DOES_NOT_EXIST=Main Seam project
"{0}" does not exist.
+SEAM_SETTINGS_PREFERENCE_PAGE_MAIN_SEAM_PROJECT_IS_EMPTY=Main Seam project name is
empty.
SEAM_SETTINGS_PREFERENCE_PAGE_TEST_SOURCE_FOLDER_DOES_NOT_EXIST=Test source folder
"{0}" does not exist.
SEAM_SETTINGS_PREFERENCE_PAGE_PACKAGE_IS_BLANK=the use of the default package is
discouraged.
SEAM_SETTINGS_PREFERENCE_PAGE_MODEL_PACKAGE_IS_NOT_VALID=Model package name: {0}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java 2009-01-15
09:36:08 UTC (rev 13057)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamSettingsPreferencePage.java 2009-01-15
13:04:15 UTC (rev 13058)
@@ -85,6 +85,7 @@
private IProject warProject;
private IEclipsePreferences preferences;
private ISeamProject warSeamProject;
+ private SeamProjectsSet seamProjectSet;
private boolean suportSeam;
private boolean runtimeIsSelected;
private List<Group> groups = new ArrayList<Group>();
@@ -97,13 +98,18 @@
public void setElement(IAdaptable element) {
super.setElement(element);
project = (IProject) getElement().getAdapter(IProject.class);
- warProject = SeamWizardUtils.getRootSeamProject(project);
+ setWarProject(SeamWizardUtils.getRootSeamProject(project));
+ }
+
+ private void setWarProject(IProject warProject) {
+ this.warProject = warProject;
if(warProject!=null) {
preferences = SeamCorePlugin.getSeamPreferences(warProject);
warSeamProject = SeamCorePlugin.getSeamProject(warProject, false);
} else {
- preferences = SeamCorePlugin.getSeamPreferences(project);
+ preferences = SeamCorePlugin.getSeamPreferences(this.project);
}
+ seamProjectSet = new SeamProjectsSet(getSeamProject());
}
/* (non-Javadoc)
@@ -156,13 +162,20 @@
registerEditor(seamRuntimeEditor, generalGroup);
IFieldEditor projectNameEditor =
- IFieldEditorFactory.INSTANCE.createUneditableTextEditor(
- IParameter.SEAM_PROJECT_NAME,
+ SeamWizardFactory.createSeamProjectSelectionFieldEditor(
+ IParameter.SEAM_PROJECT_NAME,
SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCES_PAGE_SEAM_PROJECT,
- getPrefValue(
- IParameter.SEAM_PROJECT_NAME,
- getSeamProjectName()));
-
+ getPrefValue(IParameter.SEAM_PROJECT_NAME, getSeamProjectName()),
+ false,
+ false);
+ projectNameEditor.addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ IProject project = getMainProjectFromField();
+ if(project!=null) {
+ setWarProject(project);
+ }
+ }
+ });
registerEditor(projectNameEditor, generalGroup);
IFieldEditor connProfileEditor =
SeamWizardFactory.createConnectionProfileSelectionFieldEditor(getConnectionProfile(),
ValidatorFactory.NO_ERRORS_VALIDATOR, true);
@@ -306,6 +319,15 @@
return root;
}
+ private IProject getMainProjectFromField() {
+ String name = getValue(IParameter.SEAM_PROJECT_NAME).trim();
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
+ if(project!=null && project.exists()) {
+ return project;
+ }
+ return null;
+ }
+
private boolean shouldCreateTests() {
String value = getPrefValue(ISeamFacetDataModelProperties.TEST_CREATING,
"false");
return Boolean.parseBoolean(value);
@@ -352,8 +374,7 @@
}
private String getDefaultModelSourceFolder() {
- SeamProjectsSet set = new SeamProjectsSet(project);
- IContainer f = set.getModelFolder();
+ IContainer f = seamProjectSet.getDefaultModelFolder();
return f!=null?f.getFullPath().toString():"";
}
@@ -399,7 +420,7 @@
}
private String getDefaultTestPackageName() {
- return "org.domain." + SeamUtil.getSeamPackageName(getSeamProjectName()) +
".test";
+ return "org.domain." +
SeamUtil.getSeamPackageName(getSeamProject().getName()) + ".test";
}
private String getActionSourceFolder() {
@@ -414,8 +435,7 @@
}
private String getDefaultActionSourceFolder() {
- SeamProjectsSet set = new SeamProjectsSet(project);
- IContainer f = set.getActionFolder();
+ IContainer f = seamProjectSet.getDefaultActionFolder();
return f!=null?f.getFullPath().toString():"";
}
@@ -431,8 +451,7 @@
}
private String getDefaultTestSourceFolder() {
- SeamProjectsSet set = new SeamProjectsSet(project);
- IContainer f = set.getTestsFolder();
+ IContainer f = seamProjectSet.getDefaultTestSourceFolder();
return f!=null?f.getFullPath().toString():"";
}
@@ -448,8 +467,7 @@
}
private String getDefaultViewFolder() {
- SeamProjectsSet set = new SeamProjectsSet(project);
- IContainer f = set.getViewsFolder();
+ IContainer f = seamProjectSet.getDefaultViewsFolder();
return f!=null?f.getFullPath().toString():"";
}
@@ -487,7 +505,7 @@
if(preferences!=null) {
return preferences.get(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS,
ISeamFacetDataModelProperties.DEPLOY_AS_WAR);
}
- return ISeamFacetDataModelProperties.DEPLOY_AS_WAR;
+ return seamProjectSet.getDefaultDeployType();
}
private boolean warning;
@@ -529,11 +547,12 @@
}
}
}
+ validateProjectName(SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCE_PAGE_MAIN_SEAM_PROJECT_DOES_NOT_EXIST,
SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCE_PAGE_MAIN_SEAM_PROJECT_IS_EMPTY,
IParameter.SEAM_PROJECT_NAME, false);
boolean deployAsEar =
ISeamFacetDataModelProperties.DEPLOY_AS_EAR.equals(getValue(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS));
if(deployAsEar) {
- validateProjectName(SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCE_PAGE_EJB_PROJECT_DOES_NOT_EXIST,
- ISeamFacetDataModelProperties.SEAM_EJB_PROJECT);
+ validateProjectName(SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCE_PAGE_EJB_PROJECT_DOES_NOT_EXIST,
null,
+ ISeamFacetDataModelProperties.SEAM_EJB_PROJECT, true);
}
String viewFolder =
getValue(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER).trim();
@@ -566,7 +585,7 @@
validateSourceFolder(SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCE_PAGE_TEST_SOURCE_FOLDER_DOES_NOT_EXIST,
ISeamFacetDataModelProperties.TEST_SOURCE_FOLDER,
ISeamFacetDataModelProperties.TEST_CASES_PACKAGE_NAME);
- validateProjectName(SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCE_PAGE_TEST_PROJECT_DOES_NOT_EXIST,
ISeamFacetDataModelProperties.SEAM_TEST_PROJECT);
+ validateProjectName(SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCE_PAGE_TEST_PROJECT_DOES_NOT_EXIST,
null, ISeamFacetDataModelProperties.SEAM_TEST_PROJECT, true);
validateJavaPackageName(SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCE_PAGE_TEST_PACKAGE_IS_NOT_VALID,
SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCE_PAGE_TEST_PACKAGE_HAS_WARNING,
ISeamFacetDataModelProperties.TEST_CASES_PACKAGE_NAME);
@@ -611,17 +630,25 @@
return true;
}
- private boolean validateProjectName(String errorMessageKey, String editorName) {
+ private boolean validateProjectName(String errorMessageKeyForNonexistedProject, String
errorMessageKeyForEmptyProject, String editorName, boolean canBeEmpty) {
String projectName = getValue(editorName).trim();
- if(projectName.length()>0) {
- if(!ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).exists()) {
+ if(projectName.length()==0) {
+ if(!canBeEmpty) {
if(!error) {
- setErrorMessage(NLS.bind(errorMessageKey, new String[]{projectName}));
+ setErrorMessage(errorMessageKeyForEmptyProject);
+ setValid(false);
}
error = true;
setValid(false);
return false;
}
+ } else if(!ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).exists())
{
+ if(!error) {
+ setErrorMessage(NLS.bind(errorMessageKeyForNonexistedProject, new
String[]{projectName}));
+ }
+ error = true;
+ setValid(false);
+ return false;
}
return true;
}
@@ -655,9 +682,21 @@
}
private String getSeamProjectName() {
- return warProject!=null ? warProject.getName() : project.getName();
+ return getSeamProject().getName();
}
+ private String getDefaultTestProjectName() {
+ IProject testProject = seamProjectSet.getTestProject();
+ if(testProject!=null) {
+ return testProject.getName();
+ }
+ return getSeamProjectName();
+ }
+
+ private IProject getSeamProject() {
+ return warProject!=null ? warProject : project;
+ }
+
private String getTestProjectName() {
String projectName = "";
if(preferences!=null) {
@@ -686,20 +725,25 @@
@Override
public boolean performOk() {
if (isSeamSupported()) {
- addSeamSupport();
- storeSettigs();
+ addSeamSupport(project);
+ addSeamSupport(warProject);
+ storeSettings();
} else {
removeSeamSupport();
}
return true;
}
- private void storeSettigs() {
+ private void storeSettings() {
+ IScopeContext projectScope = new ProjectScope(project);
+ IEclipsePreferences childProjectPrefs =
projectScope.getNode(SeamCorePlugin.PLUGIN_ID);
IEclipsePreferences prefs = preferences;
if(prefs==null) {
- IScopeContext projectScope = new ProjectScope(project);
- prefs = projectScope.getNode(SeamCorePlugin.PLUGIN_ID);
+ prefs = childProjectPrefs;
}
+ if(project!=getSeamProject()) {
+ childProjectPrefs.put(ISeamFacetDataModelProperties.SEAM_PARENT_PROJECT,
getValue(IParameter.SEAM_PROJECT_NAME));
+ }
prefs.put(ISeamFacetDataModelProperties.SEAM_SETTINGS_VERSION,
ISeamFacetDataModelProperties.SEAM_SETTINGS_VERSION_1_1);
@@ -732,6 +776,9 @@
try {
prefs.flush();
+ if(prefs!=childProjectPrefs) {
+ childProjectPrefs.flush();
+ }
} catch (BackingStoreException e) {
SeamGuiPlugin.getPluginLog().logError(e);
}
@@ -815,7 +862,10 @@
protected void performDefaults() {
getEditor(SeamPreferencesMessages.SEAM_SETTINGS_PREFERENCE_PAGE_SEAM_SUPPORT).setValue(Boolean.TRUE);
getEditor(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).setValue(getDefaultRuntimeName());
- getEditor(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS).setValue(ISeamFacetDataModelProperties.DEPLOY_AS_WAR);
+ IProject mainProject = SeamWizardUtils.getRootSeamProject(project);
+ getEditor(IParameter.SEAM_PROJECT_NAME).setValue(mainProject!=null?mainProject.getName():project.getName());
+ getEditor(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS).setValue(seamProjectSet.getDefaultDeployType());
+ getEditor(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT).setValue(seamProjectSet.getEjbProject()==null?project.getName():seamProjectSet.getEjbProject().getName());
getEditor(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER).setValue(getDefaultViewFolder());
getEditor(ISeamFacetDataModelProperties.SEAM_CONNECTION_PROFILE).setValue(getDefaultConnectionProfile());
getEditor(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER).setValue(getDefaultModelSourceFolder());
@@ -823,7 +873,7 @@
getEditor(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER).setValue(getDefaultActionSourceFolder());
getEditor(ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME).setValue(getDefaultActionPackageName());
getEditor(ISeamFacetDataModelProperties.TEST_CREATING).setValue(Boolean.TRUE);
- getEditor(ISeamFacetDataModelProperties.SEAM_TEST_PROJECT).setValue(project.getName());
+ getEditor(ISeamFacetDataModelProperties.SEAM_TEST_PROJECT).setValue(getDefaultTestProjectName());
getEditor(ISeamFacetDataModelProperties.TEST_SOURCE_FOLDER).setValue(getDefaultTestSourceFolder());
getEditor(ISeamFacetDataModelProperties.TEST_CASES_PACKAGE_NAME).setValue(getDefaultTestPackageName());
setEnabledSeamSuport(true);
@@ -831,7 +881,7 @@
}
private String getDefaultRuntimeName() {
- SeamRuntime runtime =
SeamRuntimeManager.getDefaultRuntimeForProject(warProject!=null?warProject:project);
+ SeamRuntime runtime =
SeamRuntimeManager.getDefaultRuntimeForProject(getSeamProject());
if(runtime==null) {
List<String> names = getRuntimeNames();
if(names.size()>0) {
@@ -875,7 +925,10 @@
}
}
- private void addSeamSupport() {
+ private void addSeamSupport(IProject project) {
+ if(project==null) {
+ return;
+ }
try {
EclipseResourceUtil.addNatureToProject(project, ISeamProject.NATURE_ID);
} catch (CoreException e) {