Author: max.andersen(a)jboss.com
Date: 2007-06-22 06:19:32 -0400 (Fri, 22 Jun 2007)
New Revision: 2158
Modified:
trunk/seam/plugins/org.jboss.ide.seam.gen/META-INF/MANIFEST.MF
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/QuestionDialog.java
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/SeamGenProperty.java
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/SeamGenAction.java
Log:
EXIN-331 seamgen dependency on RDB should change to DTP
Modified: trunk/seam/plugins/org.jboss.ide.seam.gen/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/plugins/org.jboss.ide.seam.gen/META-INF/MANIFEST.MF 2007-06-22 02:17:32 UTC
(rev 2157)
+++ trunk/seam/plugins/org.jboss.ide.seam.gen/META-INF/MANIFEST.MF 2007-06-22 10:19:32 UTC
(rev 2158)
@@ -14,7 +14,9 @@
org.eclipse.jdt.launching,
org.eclipse.ui.externaltools,
org.eclipse.ant.ui,
- org.eclipse.core.filesystem
+ org.eclipse.core.filesystem,
+ org.eclipse.datatools.connectivity,
+ org.eclipse.datatools.connectivity.db.generic
Bundle-ClassPath: org.jboss.ide.seam.gen.jar
Export-Package: org.jboss.ide.seam.gen,
org.jboss.ide.seam.gen.actions
Modified:
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/QuestionDialog.java
===================================================================
---
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/QuestionDialog.java 2007-06-22
02:17:32 UTC (rev 2157)
+++
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/QuestionDialog.java 2007-06-22
10:19:32 UTC (rev 2158)
@@ -106,6 +106,7 @@
Map properties = questions;
Properties existing = new Properties();
+
ILaunchConfiguration configuration;
try {
configuration = SeamGenAction.findLaunchConfig( "seamgen" );
@@ -118,6 +119,8 @@
SeamGenPlugin.logError( "Error while preloading build.properties", e1 );
}
+
+
updating = true;
Text firstField = null;
Iterator iterator = properties.entrySet().iterator();
@@ -138,7 +141,7 @@
if(sgp.getInputType()==sgp.YES_NO) {
Button button = new Button(composite, SWT.CHECK);
propertyToField.put( name, button );
- sgp.applyValue( existing, button );
+ sgp.applyValue( existing, button );
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
data.horizontalSpan= 2;
button.setLayoutData(data);
@@ -190,12 +193,11 @@
label.setText( " " );
propertyToDefaultLabel.put( name, label );
- updating = false;
- //updateStatus();
-
+
}
+ updating = false;
+ // all properties have been set
-
Label label = new Label(defaultComposite, SWT.NONE); // here to make gtk less ugly.
//label.setText( "--------------" );
@@ -284,7 +286,10 @@
void updateStatus() {
if(!updating) {
setMessage( null );
- getButton( IDialogConstants.OK_ID ).setEnabled( true );
+ Button button = getButton( IDialogConstants.OK_ID );
+ if(button!=null) {
+ button.setEnabled( true );
+ }
updating = true;
// Big ineffective hack!
Map others = internalGetResult();
@@ -297,23 +302,23 @@
Map.Entry element = (Map.Entry) iter.next();
SeamGenProperty gp = (SeamGenProperty) element.getValue();
- Label text = (Label) propertyToDefaultLabel.get( element.getKey() );
+ Label defaultLabel = (Label) propertyToDefaultLabel.get( element.getKey() );
String defaultValue = gp.getDefaultValue( properties );
- text.setText( defaultValue==null?"":defaultValue );
+ defaultLabel.setText( defaultValue==null?"":defaultValue );
- String text2 = getText( element, text );
+ String text2 = getText( element, defaultLabel );
if(haveNoWarning) {
String msg = gp.valid(text2.trim());
if(text2.trim().length()>0 && msg!=null) {
setMessage( msg, IMessageProvider.ERROR );
haveNoWarning = false;
- getButton( IDialogConstants.OK_ID ).setEnabled( false );
- } else if(gp.isRequired() && text2.trim().length()==0 &&
text.getText().trim().length()==0 ) {
+ button.setEnabled( false );
+ } else if(gp.isRequired() && text2.trim().length()==0 &&
defaultLabel.getText().trim().length()==0 ) {
setMessage( "'" + gp.getDescription() + "' requires a
value", IMessageProvider.ERROR );
haveNoWarning = false;
- getButton( IDialogConstants.OK_ID ).setEnabled( false );
+ button.setEnabled( false );
}
}
@@ -343,11 +348,11 @@
}*/
}
- private String getText(Map.Entry element, Label text) {
+ private String getText(Map.Entry element, Label defaultText) {
Control object = (Control) propertyToField.get(element.getKey());
if(object instanceof Button) {
Button b = (Button) object;
- b.setToolTipText( text.getText() );
+ b.setToolTipText( defaultText.getText() );
if(b.getSelection()) {
return "y";
} else {
@@ -356,7 +361,7 @@
} else {
Text enteredValue = (Text) object;
- enteredValue.setToolTipText( text.getText() );
+ enteredValue.setToolTipText( defaultText.getText() );
return enteredValue.getText();
}
}
Modified:
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/SeamGenProperty.java
===================================================================
---
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/SeamGenProperty.java 2007-06-22
02:17:32 UTC (rev 2157)
+++
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/SeamGenProperty.java 2007-06-22
10:19:32 UTC (rev 2158)
@@ -65,7 +65,6 @@
public void applyValue(Properties existing, Control control) {
- try {
String property = existing.getProperty( getDefaultPropertyName() );
if(property!=null) {
if(control instanceof Text) {
@@ -80,10 +79,6 @@
System.out.println(getDefaultPropertyName() + " " + property);
}
}
- } catch(Exception e) {
- e.printStackTrace();
- }
-
}
public String getDefaultPropertyName() {
Modified:
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/SeamGenAction.java
===================================================================
---
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/SeamGenAction.java 2007-06-22
02:17:32 UTC (rev 2157)
+++
trunk/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/actions/SeamGenAction.java 2007-06-22
10:19:32 UTC (rev 2158)
@@ -23,6 +23,17 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
+import org.eclipse.datatools.connectivity.ConnectionProfileException;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.ProfileManager;
+import org.eclipse.datatools.connectivity.db.generic.IDBConnectionProfileConstants;
+import org.eclipse.datatools.connectivity.db.generic.IDBDriverDefinitionConstants;
+import org.eclipse.datatools.connectivity.drivers.DriverInstance;
+import org.eclipse.datatools.connectivity.drivers.DriverManager;
+import org.eclipse.datatools.connectivity.drivers.DriverMgmtMessages;
+import org.eclipse.datatools.connectivity.drivers.IDriverMgmtConstants;
+import org.eclipse.datatools.connectivity.drivers.IPropertySet;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
@@ -44,6 +55,8 @@
import org.jboss.ide.seam.gen.QuestionDialog;
import org.jboss.ide.seam.gen.SeamGenPlugin;
+import com.sun.tools.corba.se.idl.som.cff.Messages;
+
public abstract class SeamGenAction implements IWorkbenchWindowActionDelegate {
private final class LaunchListener implements ILaunchesListener2 {
@@ -76,40 +89,92 @@
}
if(MessageDialog.openQuestion( getShell(), "Create DB
Connection", "Create DB Connection ?" )) {
-// DatabaseDefinition definition = RDBCorePlugin
-// .getDefault().getDatabaseDefinitionRegistry()
-// .getDefinition( "Generic JDBC",
"1.0" );
-//
-// ConnectionInfo connection = RDBCorePlugin.getDefault()
-// .getConnectionManager().createConnectionInfo(
-// definition,
-// NewCWJDBCPage.createUniqueConnectionName(
NewCWJDBCPage.getExistingConnectionNamesList(), "seamgen-connection"));
-
-
-// Properties seamGenProperties = getSeamGenProperties(
launch2.getLaunchConfiguration() );
-//
-// if(seamGenProperties!=null) {
-// connection.setDatabaseName("SeamGen database");
-// connection.setURL(seamGenProperties.getProperty(
"hibernate.connection.url", "" ));
-// connection.setDriverClassName(seamGenProperties.getProperty(
"hibernate.connection.driver_class", "" ));
-// connection.setLoadingPath(seamGenProperties.getProperty(
"driver.jar", "" ));
-// connection.setUserName( seamGenProperties.getProperty(
"hibernate.connection.username", "" ) );
-// connection.setPassword( seamGenProperties.getProperty(
"hibernate.connection.password", "" ) );
-// connection.setCustomProperty(
"JDBC_DRIVER","Other");
-// try {
-// connection.saveConnectionInfo();
-// }
-// catch (Exception e) {
-// SeamGenPlugin.logError( "Could not save connection info", e);
-// }
-// } else {
-// MessageDialog.openError( getShell(), "Could not read database
settings", "Could not read database settings. See Error log for details"
);
-// }
+ createDatabaseConnection(launch2);
+ }
+ }
-
+ public DriverInstance createNewDriverInstance(String templateID,
+ String name, String jarList, String driverClass) {
+ if (templateID == null) return null;
+ if (name == null) return null;
+ if (jarList == null) return null;
+
+ DriverInstance existing =
DriverManager.getInstance().getDriverInstanceByName(name);
+ int number = 0;
+ String origName = name;
+ while(existing!=null ) {
+ number++;
+ name = origName+number;
+ existing =
DriverManager.getInstance().getDriverInstanceByName("DriverDefn."+name);
+ }
+
+ IPropertySet pset =
DriverManager.getInstance().createDefaultInstance(templateID);
+ pset.setName(name);
+ String prefix = DriverMgmtMessages
+ .getString("NewDriverDialog.text.id_prefix"); //$NON-NLS-1$
+ String id = prefix + name;
+ pset.setID(id);
+ Properties props = pset.getBaseProperties();
+ props.setProperty(IDriverMgmtConstants.PROP_DEFN_JARLIST, jarList);
+ props.setProperty(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID,
driverClass);
+ DriverManager.getInstance().addDriverInstance(pset);
+ return DriverManager.getInstance().getDriverInstanceByID(pset.getID());
+ }
- }
- }
+
+ private void createDatabaseConnection(
+ final ILaunch launch2) {
+
+ Properties seamGenProperties = getSeamGenProperties(
launch2.getLaunchConfiguration() );
+ String projectName = seamGenProperties.getProperty( "project.name"
);
+
+ Properties dbProperties = new Properties();
+ if(seamGenProperties!=null) {
+ DriverInstance driverInstance =
createNewDriverInstance("org.eclipse.datatools.connectivity.db.generic.genericDriverTemplate",
+ projectName + "
seamgen-driver",
+
seamGenProperties.getProperty("driver.jar", ""),
+
seamGenProperties.getProperty( "hibernate.connection.driver_class", ""
));
+
+ dbProperties.setProperty(ConnectionProfileConstants.PROP_DRIVER_DEFINITION_ID,
driverInstance.getId());
+ dbProperties.setProperty(IDBConnectionProfileConstants.DRIVER_CLASS_PROP_ID,
seamGenProperties.getProperty( "hibernate.connection.driver_class", ""
));
+ dbProperties.setProperty(IDBConnectionProfileConstants.DATABASE_VENDOR_PROP_ID,
"Generic JDBC");
+ dbProperties.setProperty(IDBConnectionProfileConstants.DATABASE_VERSION_PROP_ID,
"1.0");
+ dbProperties.setProperty(IDBConnectionProfileConstants.DATABASE_NAME_PROP_ID,
"SeamGen database");
+ dbProperties.setProperty(IDBConnectionProfileConstants.PASSWORD_PROP_ID,
seamGenProperties.getProperty( "hibernate.connection.password", ""
));
+ dbProperties.setProperty(IDBConnectionProfileConstants.USERNAME_PROP_ID,
seamGenProperties.getProperty( "hibernate.connection.username", ""
));
+ dbProperties.setProperty(IDBConnectionProfileConstants.URL_PROP_ID,
seamGenProperties.getProperty( "hibernate.connection.url", "" ));
+
+
+ //connection.setLoadingPath(seamGenProperties.getProperty(
"driver.jar", "" ));
+
+ //connection.setCustomProperty( "JDBC_DRIVER","Other");
+
+ try {
+ String name = projectName + " seamgen-connection";
+ IConnectionProfile existing =
ProfileManager.getInstance().getProfileByName(name);
+ int number = 0;
+ String origName = name;
+ while(existing!=null) {
+ number++;
+ name=origName+number;
+ existing =
ProfileManager.getInstance().getProfileByName(name);
+ }
+
+ ProfileManager.getInstance().createProfile(name,
+ "Database created for seam-gen project",
+ IDBConnectionProfileConstants.CONNECTION_PROFILE_ID,
+ dbProperties
+ );
+ // TODO unique name ? NewCWJDBCPage.createUniqueConnectionName(
NewCWJDBCPage.getExistingConnectionNamesList(), "seamgen-connection"));
+ } catch (ConnectionProfileException e) {
+ SeamGenPlugin.logError("Could not create database connection",
e);
+ MessageDialog.openError( getShell(), "Could not create database
connection", "Could not create database connection. See Error log for
details" );
+ }
+
+ } else {
+ MessageDialog.openError( getShell(), "Could not read database
settings", "Could not read database settings. See Error log for details"
);
+ }
+ }
});
return;
}
@@ -275,6 +340,7 @@
} catch (CoreException e) {
SeamGenPlugin.logError( "Exception when trying to launch seamgen", e );
+ MessageDialog.openError(getShell(), "Seam-gen could not start",
e.getMessage());
}
}
@@ -372,7 +438,7 @@
}
return p;
} else {
- return null;
+ return new Properties(); // no exsting settings.
}
}