Author: dgeraskov
Date: 2008-10-30 05:02:02 -0400 (Thu, 30 Oct 2008)
New Revision: 11317
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateDdlWizardPage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateEntitiesWizardPage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3051
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateDdlWizardPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateDdlWizardPage.java 2008-10-30
06:58:14 UTC (rev 11316)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateDdlWizardPage.java 2008-10-30
09:02:02 UTC (rev 11317)
@@ -42,7 +42,6 @@
private LocationValidator validator = new LocationValidator((Workspace)
ResourcesPlugin.getWorkspace());
-
protected GenerateDdlWizardPage(JpaProject jpaProject) {
super(jpaProject);
}
@@ -68,6 +67,7 @@
}
}
});
+ outputdir.setText(getDefaultOutput());
outputdir.setDialogFieldListener(fieldlistener);
outputdir.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_output_dir);
outputdir.setButtonLabel(HibernateConsoleMessages.CodeGenerationSettingsTab_browse);
@@ -86,6 +86,7 @@
}
protected void dialogChanged() {
+ setErrorMessage(null);
String msg = PathHelper.checkDirectory(getOutputDir(),
HibernateConsoleMessages.CodeGenerationSettingsTab_output_directory, false);
if (msg!=null) {
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateEntitiesWizardPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateEntitiesWizardPage.java 2008-10-30
06:58:14 UTC (rev 11316)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateEntitiesWizardPage.java 2008-10-30
09:02:02 UTC (rev 11317)
@@ -12,7 +12,14 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.PackageFragmentRoot;
+import org.eclipse.jdt.internal.corext.util.JavaConventionsUtil;
+import org.eclipse.jdt.internal.corext.util.Messages;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
@@ -26,6 +33,7 @@
import org.hibernate.eclipse.console.utils.DialogSelectionHelper;
import org.hibernate.eclipse.launch.PathHelper;
import org.hibernate.util.StringHelper;
+import org.jboss.tools.hibernate.jpt.ui.HibernateJptUIPlugin;
/**
* @author Dmitry Geraskov
@@ -65,10 +73,11 @@
}
}
});
+ outputdir.setText(getDefaultOutput());
outputdir.setDialogFieldListener(fieldlistener);
outputdir.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_output_dir);
- outputdir.setButtonLabel(HibernateConsoleMessages.CodeGenerationSettingsTab_browse);
-
+ outputdir.setButtonLabel(HibernateConsoleMessages.CodeGenerationSettingsTab_browse);
+
Control[] controls = outputdir.doFillIntoGrid(container, numColumns);
// Hack to tell the text field to stretch!
( (GridData)controls[1].getLayoutData() ).grabExcessHorizontalSpace = true;
@@ -77,31 +86,46 @@
packageName.setDialogFieldListener(fieldlistener);
packageName.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_package);
packageName.doFillIntoGrid(container, numColumns);
-
+
setPageComplete( false );
}
protected void dialogChanged() {
+ setMessage("");
+ /*validate package name*/
+ String packName= getPackageName();
+ if (packName.length() > 0) {
+ IStatus val= validatePackageName(packName, getJpaProject());
+ if (val.getSeverity() == IStatus.ERROR) {
+ setErrorMessage(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName,
val.getMessage()));
+ setPageComplete( false );
+ return;
+ } else if (val.getSeverity() == IStatus.WARNING) {
+ setWarningMessage(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName,
val.getMessage()));
+ }
+ } else {
+ setWarningMessage(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
+ }
+
String msg = PathHelper.checkDirectory(getOutputDir(),
HibernateConsoleMessages.CodeGenerationSettingsTab_output_directory, false);
-
+
if (msg!=null) {
setErrorMessage( msg );
setPageComplete( false );
return;
}
-
- if (StringHelper.isNotEmpty(getPackageName())){
- IStatus status= JavaConventions.validatePackageName(getPackageName() );
- if (status.getSeverity() == IStatus.ERROR || status.getSeverity() ==
IStatus.WARNING) {
- setErrorMessage( status.getMessage() );
- return;
- }
- }
super.dialogChanged();
}
+ private static IStatus validatePackageName(String text, JpaProject project) {
+ if (project == null || !project.getJavaProject().exists()) {
+ return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_3,
JavaCore.VERSION_1_3);
+ }
+ return JavaConventionsUtil.validatePackageName(text, project.getJavaProject());
+ }
+
public String getPackageName(){
return packageName.getText();
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java 2008-10-30
06:58:14 UTC (rev 11316)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java 2008-10-30
09:02:02 UTC (rev 11317)
@@ -24,6 +24,10 @@
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.PackageFragmentRoot;
+import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
@@ -201,8 +205,8 @@
setErrorMessage("Please, select connection profile");
return;
}
+
setPageComplete(true);
- setErrorMessage(null);
}
private String[] dtpConnectionProfileNames() {
@@ -305,4 +309,31 @@
public boolean isTemporaryConfiguration(){
return !selectMethod.getSelection();
}
+
+ public JpaProject getJpaProject(){
+ return jpaProject;
+ }
+
+ public void setWarningMessage(String warning){
+ setMessage(warning, WARNING);
+ }
+
+ protected String getDefaultOutput(){
+ try{
+ if (getJpaProject() == null) return "";
+ if (getJpaProject().getJavaProject() == null) return "";
+ if (!getJpaProject().getJavaProject().exists()) return "";
+ IPackageFragmentRoot[] roots =
getJpaProject().getJavaProject().getPackageFragmentRoots();
+ for (int i = 0; i < roots.length; i++) {
+ IPackageFragmentRoot root = roots[i];
+ if (root.getClass() == PackageFragmentRoot.class) {
+ if (root.exists()) return root.getResource().getFullPath().toOSString();
+ }
+ }
+ return getJpaProject().getJavaProject().getResource().getFullPath().toOSString();
+ } catch(JavaModelException e){
+ HibernateJptUIPlugin.logException(e);
+ return "";
+ }
+ }
}