Search in sources :

Example 61 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project jbosstools-hibernate by jbosstools.

the class ProjectDefaultConfigurationChange method perform.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
    try {
        IScopeContext scope = new ProjectScope(project);
        Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
        String oldName = node.get(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, null);
        node.putBoolean(HibernatePropertiesConstants.HIBERNATE3_ENABLED, true);
        node.put(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, newConsoleName);
        node.flush();
        return new ProjectDefaultConfigurationChange(project, oldName);
    } catch (BackingStoreException e) {
        HibernateConsolePlugin.openError(new Shell(), Messages.ProjectDefaultConfigurationChange_error_title, e.getLocalizedMessage(), e, HibernateConsolePlugin.PERFORM_SYNC_EXEC);
        return new NullChange();
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) Shell(org.eclipse.swt.widgets.Shell) NullChange(org.eclipse.ltk.core.refactoring.NullChange) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 62 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project jbosstools-hibernate by jbosstools.

the class HibernateRefactoringUtil method isProjectAffected.

private static boolean isProjectAffected(IProject project, String oldCCName) throws CoreException {
    if (project.isOpen() && project.hasNature(HibernateNature.ID)) {
        IScopeContext scope = new ProjectScope(project);
        Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
        // $NON-NLS-1$
        String defaultConfiguration = node.get(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, "");
        return defaultConfiguration.equals(oldCCName);
    }
    return false;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) Preferences(org.osgi.service.prefs.Preferences)

Example 63 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project jbosstools-hibernate by jbosstools.

the class HibernateJpaProject method isNamingStrategyEnabled.

public boolean isNamingStrategyEnabled() {
    // rebuilding ( == creating new instance) of jpa project we cache it
    if (this.cachedNamingStrategyEnable == null) {
        IScopeContext scope = new ProjectScope(getProject());
        Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
        if (node != null) {
            this.cachedNamingStrategyEnable = node.getBoolean(HibernatePropertiesConstants.NAMING_STRATEGY_ENABLED, true);
        } else {
            this.cachedNamingStrategyEnable = true;
        }
    }
    return this.cachedNamingStrategyEnable;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) Preferences(org.osgi.service.prefs.Preferences) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences)

Example 64 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project jbosstools-hibernate by jbosstools.

the class ProjectUtils method toggleHibernateOnProject.

public static boolean toggleHibernateOnProject(IProject project, boolean enable, String defaultConsoleName) {
    IScopeContext scope = new ProjectScope(project);
    Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
    if (node != null) {
        node.putBoolean(HibernatePropertiesConstants.HIBERNATE3_ENABLED, enable);
        node.put(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, defaultConsoleName);
        try {
            node.flush();
        } catch (BackingStoreException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.ProjectUtils_could_not_save_changes_to_preferences, e);
            return false;
        }
    } else {
        return false;
    }
    try {
        if (enable) {
            return ProjectUtils.addProjectNature(project, HibernatePropertiesConstants.HIBERNATE_NATURE, new NullProgressMonitor());
        } else {
            return ProjectUtils.removeProjectNature(project, HibernatePropertiesConstants.HIBERNATE_NATURE, new NullProgressMonitor());
        }
    } catch (CoreException ce) {
        HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.ProjectUtils_could_not_activate_hibernate_nature_on_project + project.getName(), ce);
        HibernateConsolePlugin.getDefault().log(ce.getStatus());
        return false;
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) BackingStoreException(org.osgi.service.prefs.BackingStoreException) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences) Preferences(org.osgi.service.prefs.Preferences)

Example 65 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project jbosstools-hibernate by jbosstools.

the class HibernatePropertyPage method loadValues.

public void loadValues() {
    IProject project = getProject();
    IScopeContext scope = new ProjectScope(project);
    Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
    if (node != null) {
        initEnableHibernate = node.getBoolean(HibernatePropertiesConstants.HIBERNATE3_ENABLED, false);
        enableHibernate.setSelection(initEnableHibernate);
        String cfg = node.get(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, project.getName());
        ConsoleConfiguration configuration = KnownConfigurations.getInstance().find(cfg);
        if (configuration == null) {
            selectedConfiguration.select(0);
            details.setEnabled(false);
        } else {
            initConsoleConfiguration = cfg;
            selectedConfiguration.setText(cfg);
        }
        initNamingStrategy = node.getBoolean(HibernatePropertiesConstants.NAMING_STRATEGY_ENABLED, true);
        enableNamingStrategy.setSelection(initNamingStrategy);
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) EditConsoleConfiguration(org.hibernate.eclipse.console.actions.EditConsoleConfiguration) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Preferences(org.osgi.service.prefs.Preferences) IProject(org.eclipse.core.resources.IProject)

Aggregations

IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)74 ProjectScope (org.eclipse.core.resources.ProjectScope)42 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)17 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)16 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)15 BackingStoreException (org.osgi.service.prefs.BackingStoreException)15 Preferences (org.osgi.service.prefs.Preferences)14 IProject (org.eclipse.core.resources.IProject)13 CoreException (org.eclipse.core.runtime.CoreException)8 ArrayList (java.util.ArrayList)6 IResource (org.eclipse.core.resources.IResource)6 ILiferayProjectProvider (com.liferay.ide.core.ILiferayProjectProvider)5 Iterator (java.util.Iterator)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 IFile (org.eclipse.core.resources.IFile)4 IAdaptable (org.eclipse.core.runtime.IAdaptable)4 PreferencesAccess (org.eclipse.jdt.internal.ui.preferences.PreferencesAccess)4 FormatterProfileStore (org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore)4