Search in sources :

Example 61 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class TypeMappingView method doRefreshTree.

protected void doRefreshTree() {
    ConsoleConfiguration configuration = KnownConfigurations.getInstance().find(getConsoleConfigurationName());
    viewer.setInput(new LazyDatabaseSchema(configuration));
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) LazyDatabaseSchema(org.hibernate.eclipse.console.workbench.LazyDatabaseSchema)

Example 62 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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 63 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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 64 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class GenerateInitWizardPage method createConsoleConfiguration.

private String createConsoleConfiguration() {
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    String dialect = determineDialect();
    String ccName = launchManager.generateLaunchConfigurationName(HibernateConsoleMessages.AddConfigurationAction_hibernate);
    ConsoleConfigurationPreferences prefs = new EclipseConsoleConfigurationPreferences(ccName, ConfigurationMode.JPA, getHibernateVersion(), jpaProject.getName(), true, null, null, null, new IPath[0], new IPath[0], null, null, getConnectionProfileName(), dialect);
    ConsoleConfiguration cc = new ConsoleConfiguration(prefs);
    KnownConfigurations.getInstance().addConfiguration(cc, false);
    return ccName;
}
Also used : EclipseConsoleConfigurationPreferences(org.hibernate.eclipse.console.EclipseConsoleConfigurationPreferences) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences) EclipseConsoleConfigurationPreferences(org.hibernate.eclipse.console.EclipseConsoleConfigurationPreferences) ILaunchManager(org.eclipse.debug.core.ILaunchManager)

Example 65 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class GenerateInitWizardPage method createControl.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = numColumns;
    layout.verticalSpacing = 10;
    outputdir = new StringButtonDialogField(new IStringButtonAdapter() {

        public void changeControlPressed(DialogField field) {
            IPath[] paths = DialogSelectionHelper.chooseFolderEntries(getShell(), PathHelper.pathOrNull(outputdir.getText()), HibernateConsoleMessages.CodeGenerationSettingsTab_select_output_dir, HibernateConsoleMessages.CodeGenerationSettingsTab_choose_dir_for_generated_files, false);
            if (paths != null && paths.length == 1) {
                outputdir.setText(((paths[0]).toOSString()));
            }
        }
    });
    outputdir.setText(getDefaultOutput());
    outputdir.setDialogFieldListener(fieldlistener);
    outputdir.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_output_dir);
    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;
    setPageComplete(!StringHelper.isEmpty(getOutputDir()));
    createChildControls(container);
    useConsoleConfiguration = new Button(container, SWT.CHECK);
    useConsoleConfiguration.setText(Messages.GenerateInitWizardPage_use_console_configuration);
    useConsoleConfiguration.setSelection(true);
    useConsoleConfiguration.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            consoleConfigurationName.setEnabled(useConsoleConfiguration.getSelection());
            hibernateVersion.setEnabled(!useConsoleConfiguration.getSelection());
            connectionProfileName.setEnabled(!useConsoleConfiguration.getSelection());
            schemaName.setEnabled(!useConsoleConfiguration.getSelection());
            dialectName.setEnabled(!useConsoleConfiguration.getSelection());
            dialogChanged();
        }
    });
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = numColumns;
    useConsoleConfiguration.setLayoutData(gd);
    consoleConfigurationName = new ComboDialogField(SWT.READ_ONLY);
    consoleConfigurationName.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_console_configuration);
    ConsoleConfiguration[] cfg = LaunchHelper.findFilteredSortedConsoleConfigs();
    String[] names = new String[cfg.length];
    for (int i = 0; i < cfg.length; i++) {
        ConsoleConfiguration configuration = cfg[i];
        names[i] = configuration.getName();
    }
    consoleConfigurationName.setItems(names);
    consoleConfigurationName.setText(jpaProject.getDefaultConsoleConfigurationName());
    consoleConfigurationName.setDialogFieldListener(fieldlistener);
    consoleConfigurationName.doFillIntoGrid(container, numColumns);
    hibernateVersion = new ComboDialogField(SWT.READ_ONLY);
    hibernateVersion.setLabelText(HibernateConsoleMessages.ConsoleConfigurationMainTab_0);
    hibernateVersion.setItems(ServiceLookup.getVersions());
    hibernateVersion.selectItem(0);
    hibernateVersion.setDialogFieldListener(fieldlistener);
    hibernateVersion.doFillIntoGrid(container, numColumns);
    hibernateVersion.setEnabled(false);
    createDBGroup(container, numColumns);
    setControl(container);
    if (StringHelper.isEmpty(consoleConfigurationName.getText())) {
        setPageComplete(false);
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) StringButtonDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField) IStringButtonAdapter(org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) ComboDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField) ComboDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField) StringButtonDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField) DialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)107 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)19 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)17 CoreException (org.eclipse.core.runtime.CoreException)16 PartInitException (org.eclipse.ui.PartInitException)13 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)12 KnownConfigurations (org.hibernate.console.KnownConfigurations)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)10 TreePath (org.eclipse.jface.viewers.TreePath)10 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 FileNotFoundException (java.io.FileNotFoundException)8 IPath (org.eclipse.core.runtime.IPath)8 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 IService (org.jboss.tools.hibernate.runtime.spi.IService)8 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)7 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)7 GridLayout (org.eclipse.swt.layout.GridLayout)6