Search in sources :

Example 1 with ConsoleConfigurationPreferences

use of org.hibernate.console.preferences.ConsoleConfigurationPreferences in project jbosstools-hibernate by jbosstools.

the class HibernateJpaProject method synchronizeJpaFiles.

@Override
protected boolean synchronizeJpaFiles(IFile file, int deltaKind) {
    boolean result = super.synchronizeJpaFiles(file, deltaKind);
    ConsoleConfiguration cc = getDefaultConsoleConfiguration();
    if (cc != null) {
        ConsoleConfigurationPreferences preferences = cc.getPreferences();
        if (file.getLocation().toFile().equals(preferences.getPropertyFile())) {
            switch(deltaKind) {
                case IResourceDelta.ADDED:
                case IResourceDelta.REMOVED:
                case IResourceDelta.CHANGED:
                    stateChanged();
                    revalidate();
            }
        }
    }
    return result;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences)

Example 2 with ConsoleConfigurationPreferences

use of org.hibernate.console.preferences.ConsoleConfigurationPreferences in project jbosstools-hibernate by jbosstools.

the class HibernateSearchEnabledPropertyTesterTest method containsHibernateSearchLib.

@Test
public void containsHibernateSearchLib() throws MalformedURLException {
    ConsoleConfiguration consoleConfiguration = mock(ConsoleConfiguration.class);
    ConsoleConfigurationPreferences prefs = mock(ConsoleConfigurationPreferences.class);
    when(consoleConfiguration.getPreferences()).thenReturn(prefs);
    when(prefs.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "hibernate-search-orm-version") });
    TreePath treePath = new TreePath(new Object[] { consoleConfiguration });
    ITreeSelection receiver = new TreeSelection(treePath);
    HibernateSearchEnabledPropertyTester tester = new HibernateSearchEnabledPropertyTester();
    assertTrue(tester.test(receiver, "doesn't matter", null, null));
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeSelection(org.eclipse.jface.viewers.TreeSelection) URL(java.net.URL) HibernateSearchEnabledPropertyTester(org.jboss.tools.hibernate.search.property.testers.HibernateSearchEnabledPropertyTester) Test(org.junit.Test)

Example 3 with ConsoleConfigurationPreferences

use of org.hibernate.console.preferences.ConsoleConfigurationPreferences in project jbosstools-hibernate by jbosstools.

the class ExportAntCodeGenWizardPage method checkCodeGenLaunchConfig.

protected String checkCodeGenLaunchConfig(ILaunchConfiguration lc) {
    String checkMessage = null;
    ExporterAttributes attributes = null;
    try {
        attributes = new ExporterAttributes(lc);
        checkMessage = attributes.checkExporterAttributes();
    } catch (CoreException e) {
        checkMessage = e.getMessage();
    }
    if (checkMessage != null) {
        checkMessage = NLS.bind(HibernateConsoleMessages.ExportAntCodeGenWizardPage_error_in_hibernate_code_generation_configuration, checkMessage);
    }
    if (checkMessage == null && attributes != null) {
        String consoleConfigName = attributes.getConsoleConfigurationName();
        ConsoleConfigurationPreferences consoleConfigPrefs = getConsoleConfigPreferences(consoleConfigName);
        String connProfileName = consoleConfigPrefs == null ? null : consoleConfigPrefs.getConnectionProfileName();
        if (!CodeGenXMLFactory.isEmpty(connProfileName)) {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            String externalPropFileName = CodeGenXMLFactory.propFileNameSuffix;
            // $NON-NLS-1$
            externalPropFileName = getFileName() + "." + externalPropFileName;
            String problemMessage = NLS.bind(HibernateConsoleMessages.ExportAntCodeGenWizardPage_warning, externalPropFileName);
            IPath resourcePath = getContainerFullPath().append(externalPropFileName);
            if (workspace.getRoot().getFile(resourcePath).exists()) {
                checkMessage = problemMessage;
            }
        }
    }
    return checkMessage;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences) IWorkspace(org.eclipse.core.resources.IWorkspace) ExporterAttributes(org.hibernate.eclipse.launch.ExporterAttributes)

Example 4 with ConsoleConfigurationPreferences

use of org.hibernate.console.preferences.ConsoleConfigurationPreferences in project jbosstools-hibernate by jbosstools.

the class HibernateConsolePlugin method readStateFrom.

void readStateFrom(File f) {
    try {
        EclipseConsoleConfigurationPreferences[] preferences = EclipseConsoleConfigurationPreferences.readStateFrom(f);
        for (int i = 0; i < preferences.length; i++) {
            ConsoleConfigurationPreferences prefs = preferences[i];
            // TODO: do we need to broadcast every time when reading state ?
            KnownConfigurations.getInstance().addConfiguration(new EclipseConsoleConfiguration(prefs), false);
        }
    } catch (HibernateConsoleRuntimeException hcr) {
        logErrorMessage(HibernateConsoleMessages.HibernateConsolePlugin_error_while_reading_console_config, hcr);
    }
}
Also used : ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException)

Example 5 with ConsoleConfigurationPreferences

use of org.hibernate.console.preferences.ConsoleConfigurationPreferences 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

ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)12 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)7 URL (java.net.URL)5 CoreException (org.eclipse.core.runtime.CoreException)5 Test (org.junit.Test)4 IPath (org.eclipse.core.runtime.IPath)3 ArrayList (java.util.ArrayList)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2 ILaunchManager (org.eclipse.debug.core.ILaunchManager)2 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)2 TreePath (org.eclipse.jface.viewers.TreePath)2 TreeSelection (org.eclipse.jface.viewers.TreeSelection)2 KnownConfigurations (org.hibernate.console.KnownConfigurations)2 HibernateSearchEnabledPropertyTester (org.jboss.tools.hibernate.search.property.testers.HibernateSearchEnabledPropertyTester)2 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1