Search in sources :

Example 1 with BasicHibernateProperties

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];
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties) IProject(org.eclipse.core.resources.IProject) LinkedList(java.util.LinkedList) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 2 with BasicHibernateProperties

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();
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Properties(java.util.Properties) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties)

Example 3 with BasicHibernateProperties

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();
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Properties(java.util.Properties) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties)

Example 4 with BasicHibernateProperties

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());
}
Also used : PropertyChangeEvent(org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent) PropertyChangeListener(org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener) ArrayList(java.util.ArrayList) SimpleListValueModel(org.eclipse.jpt.common.utility.internal.model.value.SimpleListValueModel) ModifiablePropertyValueModel(org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel) PropertyValueModel(org.eclipse.jpt.common.utility.model.value.PropertyValueModel) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties) DriverClassHelpers(org.hibernate.eclipse.console.utils.DriverClassHelpers)

Aggregations

BasicHibernateProperties (org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties)4 Properties (java.util.Properties)2 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 IProject (org.eclipse.core.resources.IProject)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 SimpleListValueModel (org.eclipse.jpt.common.utility.internal.model.value.SimpleListValueModel)1 PropertyChangeEvent (org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent)1 PropertyChangeListener (org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener)1 ModifiablePropertyValueModel (org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel)1 PropertyValueModel (org.eclipse.jpt.common.utility.model.value.PropertyValueModel)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Control (org.eclipse.swt.widgets.Control)1 DriverClassHelpers (org.hibernate.eclipse.console.utils.DriverClassHelpers)1