use of org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties in project jbosstools-hibernate by jbosstools.
the class HibernatePropertiesComposite method getSourcePackageFragmentRoots.
public IPackageFragmentRoot[] getSourcePackageFragmentRoots() {
BasicHibernateProperties props = getSubject();
if (props != null) {
IProject project = props.getJpaProject().getProject();
IJavaProject jProject = JavaCore.create(project);
if (jProject != null) {
try {
IPackageFragmentRoot[] allPackageFragmentRoots = jProject.getAllPackageFragmentRoots();
List<IPackageFragmentRoot> sources = new LinkedList<IPackageFragmentRoot>();
for (IPackageFragmentRoot iPackageFragmentRoot : allPackageFragmentRoots) {
if (!iPackageFragmentRoot.isArchive() && iPackageFragmentRoot.isOpen()) {
sources.add(iPackageFragmentRoot);
}
}
return sources.toArray(new IPackageFragmentRoot[0]);
} catch (JavaModelException e) {
// ignore
}
}
}
return new IPackageFragmentRoot[0];
}
use of org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties in project jbosstools-hibernate by jbosstools.
the class HibernateJpaProject method getDefaultSchema.
/*
* The sequence is(from biggest priority to lowest):
* 1) Configuration.getProperty() (if cc.hasConfiguration())
* 2) ConsoleConfiguration.getPreference().getProperty()-uses hibernate.properties
* 3) JpaProject user overrides
* 4) persistence.xml
* 5) logic from superclass
*/
@Override
public String getDefaultSchema() {
String schema = null;
ConsoleConfiguration cc = getDefaultConsoleConfiguration();
if (cc != null) {
if (cc.hasConfiguration()) {
// was not build yet
IConfiguration configuration = cc.getConfiguration();
if (configuration.getProperties().containsKey(getEnvironment().getDefaultSchema())) {
schema = configuration.getProperty(getEnvironment().getDefaultSchema());
}
}
Properties properties = cc.getPreferences().getProperties();
if (properties != null && properties.containsKey(getEnvironment().getDefaultSchema())) {
schema = properties.getProperty(getEnvironment().getDefaultSchema());
}
}
if (schema == null) {
BasicHibernateProperties prop = getBasicHibernateProperties();
if (getUserOverrideDefaultSchema() != null) {
schema = getUserOverrideDefaultSchema();
} else if (prop != null && prop.getSchemaDefault() != null) {
schema = prop.getSchemaDefault();
}
}
return schema != null ? schema : super.getDefaultSchema();
}
use of org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties in project jbosstools-hibernate by jbosstools.
the class HibernateJpaProject method getDefaultCatalog.
/*
* The sequence is(from biggest priority to lowest):
* 1) Configuration.getProperty() (if cc.hasConfiguration())
* 2) ConsoleConfiguration.getPreference().getProperty()-uses hibernate.properties
* 3) JpaProject user overrides
* 4) persistence.xml
* 5) logic from superclass
*/
@Override
public String getDefaultCatalog() {
String catalog = null;
BasicHibernateProperties prop = getBasicHibernateProperties();
ConsoleConfiguration cc = getDefaultConsoleConfiguration();
if (cc != null) {
if (cc.hasConfiguration()) {
// was not build yet
IConfiguration configuration = cc.getConfiguration();
if (configuration.getProperties().containsKey(getEnvironment().getDefaultCatalog())) {
catalog = configuration.getProperty(getEnvironment().getDefaultCatalog());
}
}
Properties properties = cc.getPreferences().getProperties();
if (properties != null && properties.containsKey(getEnvironment().getDefaultCatalog())) {
catalog = properties.getProperty(getEnvironment().getDefaultCatalog());
}
}
if (catalog == null) {
if (getUserOverrideDefaultCatalog() != null) {
catalog = getUserOverrideDefaultCatalog();
} else if (prop != null && prop.getCatalogDefault() != null) {
catalog = prop.getCatalogDefault();
}
}
return catalog != null ? catalog : super.getDefaultCatalog();
}
use of org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties in project jbosstools-hibernate by jbosstools.
the class HibernatePropertiesComposite method initializeLayout.
@Override
protected void initializeLayout(Composite container) {
GridLayout gl = new GridLayout(3, false);
container.setLayout(gl);
this.helper = new DriverClassHelpers();
final SimpleListValueModel<String> lvmDialect = new SimpleListValueModel<String>(Arrays.asList(this.helper.getDialectNames()));
PropertyValueModel<BasicHibernateProperties> p = (PropertyValueModel<BasicHibernateProperties>) getSubjectHolder();
List<String> drivers = new ArrayList<String>();
BasicHibernateProperties props = p.getValue();
if (props != null) {
String dialectClass = this.helper.getDialectClass(props.getDialect());
String[] driverClasses = this.helper.getDriverClasses(dialectClass);
drivers.addAll(Arrays.asList(driverClasses));
}
final SimpleListValueModel<String> lvmDriver = new SimpleListValueModel<String>(drivers);
List<String> urls = new ArrayList<String>();
if (props != null) {
String driverClass = props.getDriver();
String[] connectionURLS = this.helper.getConnectionURLS(driverClass);
urls.addAll(Arrays.asList(connectionURLS));
}
final SimpleListValueModel<String> lvmUrl = new SimpleListValueModel<String>(urls);
ModifiablePropertyValueModel<String> dialectHolder = buildDialectHolder();
final ModifiablePropertyValueModel<String> driverHolder = buildDriverHolder();
final ModifiablePropertyValueModel<String> urlHolder = buildUrlHolder();
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
this.addLabel(container, HibernateConsoleMessages.ConsoleConfigurationPropertySource_config_file + ':');
this.cfgFile = this.addText(container, buildConfigFileHolder());
Button b = this.addButton(container, HibernateConsoleMessages.CodeGenerationSettingsTab_setup, createSetupAction());
cfgFile.setLayoutData(gd);
// Button b = addButton(section, HibernateConsoleMessages.CodeGenerationSettingsTab_setup, createSetupAction());
// this.cfgFile = addLabeledText(container,
// HibernateConsoleMessages.ConsoleConfigurationPropertySource_config_file + ':', buildConfigFileHolder(),
// b, null);
gd = new GridData(GridData.FILL_HORIZONTAL);
this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_database_dialect);
Control c = this.addEditableCombo(container, lvmDialect, dialectHolder, TransformerTools.<String>objectToStringTransformer(), (String) null);
gd.horizontalSpan = 2;
c.setLayoutData(gd);
// addLabeledEditableCombo(
// section,
// HibernateConsoleMessages.NewConfigurationWizardPage_database_dialect,
// lvmDialect,
// dialectHolder,
// StringConverter.Default.<String>instance(),
// null);
this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_driver_class);
c = this.addEditableCombo(container, lvmDriver, driverHolder, TransformerTools.<String>objectToStringTransformer(), (String) null);
c.setLayoutData(gd);
// addLabeledEditableCombo(
// section,
// HibernateConsoleMessages.NewConfigurationWizardPage_driver_class,
// lvmDriver,
// driverHolder,
// StringConverter.Default.<String>instance(),
// null);
this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_connection_url);
c = this.addEditableCombo(container, lvmUrl, urlHolder, TransformerTools.<String>objectToStringTransformer(), (String) null);
c.setLayoutData(gd);
// addLabeledEditableCombo(
// section,
// HibernateConsoleMessages.NewConfigurationWizardPage_connection_url,
// lvmUrl,
// urlHolder,
// StringConverter.Default.<String>instance(),
// null);
dialectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, SWTListenerTools.wrap(new PropertyChangeListener() {
@Override
public void propertyChanged(PropertyChangeEvent event) {
String dialectClass = HibernatePropertiesComposite.this.helper.getDialectClass((String) event.getNewValue());
String[] driverClasses = HibernatePropertiesComposite.this.helper.getDriverClasses(dialectClass);
// save value
String driver = driverHolder.getValue();
lvmDriver.clear();
lvmDriver.addAll(Arrays.asList(driverClasses));
// restore value
driverHolder.setValue(driver);
}
}));
driverHolder.addPropertyChangeListener(PropertyValueModel.VALUE, SWTListenerTools.wrap(new PropertyChangeListener() {
@Override
public void propertyChanged(PropertyChangeEvent event) {
String driverClass = (String) event.getNewValue();
String[] connectionURLS = HibernatePropertiesComposite.this.helper.getConnectionURLS(driverClass);
// save value
String url = urlHolder.getValue();
lvmUrl.clear();
lvmUrl.addAll(Arrays.asList(connectionURLS));
// restore value
urlHolder.setValue(url);
}
}));
this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_default_schema);
c = this.addText(container, buildSchemaDefaultHolder());
c.setLayoutData(gd);
// addLabeledText(
// section,
// HibernateConsoleMessages.NewConfigurationWizardPage_default_schema,
// buildSchemaDefaultHolder());
this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_default_catalog);
c = this.addText(container, buildCatalogDefaultHolder());
c.setLayoutData(gd);
// addLabeledText(
// section,
// HibernateConsoleMessages.NewConfigurationWizardPage_default_catalog,
// buildCatalogDefaultHolder());
this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_user_name);
c = this.addText(container, buildUsernameHolder());
c.setLayoutData(gd);
// addLabeledText(
// section,
// HibernateConsoleMessages.NewConfigurationWizardPage_user_name,
// buildUsernameHolder());
this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_password);
c = this.addText(container, buildPasswordHolder());
c.setLayoutData(gd);
// addLabeledText(
// section,
// HibernateConsoleMessages.NewConfigurationWizardPage_password,
// buildPasswordHolder());
}
Aggregations