Search in sources :

Example 1 with KnownConfigurationsAdapter

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

the class HibernateJptPlugin method start.

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    KnownConfigurations.getInstance().addConsoleConfigurationListener(new KnownConfigurationsAdapter() {

        private void revalidateProjects(ConsoleConfiguration ccfg) {
            // INFO: should revalidate project to calculate correct naming strategy's values
            JpaProjectManager manager = (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
            Iterator<JpaProject> jpaProjects = manager.getJpaProjects().iterator();
            while (jpaProjects.hasNext()) {
                JpaProject jpaProject = jpaProjects.next();
                if (jpaProject instanceof HibernateJpaProject) {
                    String ccName = ((HibernateJpaProject) jpaProject).getDefaultConsoleConfigurationName();
                    if (ccfg.getName().equals(ccName)) {
                        rebuildJpaProject(jpaProject.getJavaProject().getProject());
                    // jpaProject.getJavaProject().getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
                    }
                }
            }
        }

        @Override
        public void configurationBuilt(ConsoleConfiguration ccfg) {
            if (ccfg.getConfiguration() == null) {
                return;
            }
            revalidateProjects(ccfg);
        }

        @Override
        public void configurationRemoved(ConsoleConfiguration root, boolean forUpdate) {
            if (forUpdate) {
                return;
            }
            revalidateProjects(root);
        }
    });
}
Also used : KnownConfigurationsAdapter(org.hibernate.console.KnownConfigurationsAdapter) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) JpaProjectManager(org.eclipse.jpt.jpa.core.JpaProjectManager) Iterator(java.util.Iterator) JpaProject(org.eclipse.jpt.jpa.core.JpaProject)

Example 2 with KnownConfigurationsAdapter

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

the class ConfigurationCombo method createControl.

protected Control createControl(Composite parent) {
    selectionAdapter = new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            editor.setConsoleConfigurationName(comboControl.getText());
        }
    };
    Control control = super.createControl(parent);
    listener = new KnownConfigurationsAdapter() {

        public void sessionFactoryClosing(ConsoleConfiguration configuration, ISessionFactory closingFactory) {
        }

        public void sessionFactoryBuilt(ConsoleConfiguration ccfg, ISessionFactory builtFactory) {
        }

        public void configurationRemoved(ConsoleConfiguration root, boolean forUpdate) {
            populateComboBox();
        }

        public void configurationAdded(ConsoleConfiguration root) {
            populateComboBox();
        }
    };
    KnownConfigurations.getInstance().addConsoleConfigurationListener(listener);
    return control;
}
Also used : Control(org.eclipse.swt.widgets.Control) KnownConfigurationsAdapter(org.hibernate.console.KnownConfigurationsAdapter) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory)

Example 3 with KnownConfigurationsAdapter

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

the class HibernateConsolePlugin method listenForConfigurations.

private void listenForConfigurations() {
    final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    kcl = new KnownConfigurationsAdapter() {

        /**
         * @param root
         * @param forUpdate - shows whether physical removal necessary
         */
        public void configurationRemoved(ConsoleConfiguration root, boolean forUpdate) {
            if (!forUpdate) {
                try {
                    removeConfiguration(root.getName());
                } catch (CoreException e) {
                    logErrorMessage(HibernateConsoleMessages.HibernateConsolePlugin_could_not_delete_launch_config_for + root.getName(), e);
                }
            }
        }
    };
    KnownConfigurations.getInstance().addConsoleConfigurationListener(kcl);
    icl = new ILaunchConfigurationListener() {

        boolean isConsoleConfiguration(ILaunchConfiguration configuration) {
            try {
                return configuration.getType().getIdentifier().equals(ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID);
            } catch (CoreException e) {
            // HibernateConsolePlugin.getDefault().log( e );
            // ignore since it occurs on delete
            }
            return false;
        }

        public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
            ConsoleConfiguration cfg = KnownConfigurations.getInstance().find(configuration.getName());
            if (cfg != null) {
                // file system removal have been made already.
                KnownConfigurations.getInstance().removeConfiguration(cfg, true);
            }
        }

        public void launchConfigurationChanged(ILaunchConfiguration configuration) {
            if (configuration.isWorkingCopy() || isTemporary(configuration)) {
                return;
            }
            if (isConsoleConfiguration(configuration)) {
                KnownConfigurations instance = KnownConfigurations.getInstance();
                ConsoleConfiguration oldcfg = instance.find(configuration.getName());
                if (oldcfg != null) {
                    // reset it no matter what.
                    oldcfg.reset();
                } else {
                    // A new one!
                    ConsoleConfigurationPreferences adapter = buildConfigurationPreferences(configuration);
                    instance.addConfiguration(new ConsoleConfiguration(adapter), true);
                }
            }
        }

        private ConsoleConfigurationPreferences buildConfigurationPreferences(ILaunchConfiguration configuration) {
            return new EclipseLaunchConsoleConfigurationPreferences(configuration);
        }

        public void launchConfigurationAdded(ILaunchConfiguration configuration) {
            if (isConsoleConfiguration(configuration)) {
                ILaunchConfiguration movedFrom = launchManager.getMovedFrom(configuration);
                if (movedFrom != null && isConsoleConfiguration(movedFrom)) {
                    KnownConfigurations instance = KnownConfigurations.getInstance();
                    ConsoleConfiguration oldcfg = instance.find(movedFrom.getName());
                    if (oldcfg != null) {
                        // call this before we remove old configuration
                        refactor(movedFrom, configuration);
                        // reset it no matter what.
                        oldcfg.reset();
                        instance.removeConfiguration(oldcfg, false);
                    }
                }
                KnownConfigurations instance = KnownConfigurations.getInstance();
                ConsoleConfigurationPreferences adapter = buildConfigurationPreferences(configuration);
                boolean temporary = isTemporary(configuration);
                if (!temporary) {
                    instance.addConfiguration(new ConsoleConfiguration(adapter), true);
                }
            }
        }

        private void refactor(ILaunchConfiguration oldConfiguration, ILaunchConfiguration newConfiguration) {
            if (!oldConfiguration.getName().equals(newConfiguration.getName())) {
                // only rename of console configuration refactoring is supported.
                ConsoleConfigurationRenameProcessor proc = new ConsoleConfigurationRenameProcessor(oldConfiguration, newConfiguration.getName());
                // Refactor for rename
                PerformRefactoringOperation refOperation = new PerformRefactoringOperation(new ProcessorBasedRefactoring(proc), CheckConditionsOperation.ALL_CONDITIONS);
                try {
                    ResourcesPlugin.getWorkspace().run(refOperation, null);
                } catch (OperationCanceledException oce) {
                    throw new OperationCanceledException();
                } catch (CoreException ce) {
                    HibernateConsolePlugin.openError(new Shell(), HibernateConsoleMessages.EditConsoleConfiguration_rename_refactoring_error_totle, ce.getLocalizedMessage(), ce, HibernateConsolePlugin.PERFORM_SYNC_EXEC);
                }
            }
        }

        private boolean isTemporary(ILaunchConfiguration configuration) {
            boolean temporary = true;
            try {
                temporary = configuration.getAttribute(AddConfigurationAction.TEMPORARY_CONFIG_FLAG, false);
            } catch (CoreException e) {
                HibernateConsolePlugin.getDefault().showError(getShell(), HibernateConsoleMessages.HibernateConsolePlugin_problem_to_get_flag, e);
            }
            return temporary;
        }
    };
    launchManager.addLaunchConfigurationListener(icl);
}
Also used : KnownConfigurationsAdapter(org.hibernate.console.KnownConfigurationsAdapter) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ConsoleConfigurationRenameProcessor(org.hibernate.eclipse.launch.core.refactoring.ConsoleConfigurationRenameProcessor) ILaunchManager(org.eclipse.debug.core.ILaunchManager) PerformRefactoringOperation(org.eclipse.ltk.core.refactoring.PerformRefactoringOperation) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) ILaunchConfigurationListener(org.eclipse.debug.core.ILaunchConfigurationListener) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences) KnownConfigurations(org.hibernate.console.KnownConfigurations)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)3 KnownConfigurationsAdapter (org.hibernate.console.KnownConfigurationsAdapter)3 Iterator (java.util.Iterator)1 CoreException (org.eclipse.core.runtime.CoreException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 ILaunchConfigurationListener (org.eclipse.debug.core.ILaunchConfigurationListener)1 ILaunchManager (org.eclipse.debug.core.ILaunchManager)1 JpaProject (org.eclipse.jpt.jpa.core.JpaProject)1 JpaProjectManager (org.eclipse.jpt.jpa.core.JpaProjectManager)1 PerformRefactoringOperation (org.eclipse.ltk.core.refactoring.PerformRefactoringOperation)1 ProcessorBasedRefactoring (org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Control (org.eclipse.swt.widgets.Control)1 Shell (org.eclipse.swt.widgets.Shell)1 KnownConfigurations (org.hibernate.console.KnownConfigurations)1 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)1 ConsoleConfigurationRenameProcessor (org.hibernate.eclipse.launch.core.refactoring.ConsoleConfigurationRenameProcessor)1 ISessionFactory (org.jboss.tools.hibernate.runtime.spi.ISessionFactory)1