Search in sources :

Example 86 with ProjectScope

use of org.eclipse.core.resources.ProjectScope 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 87 with ProjectScope

use of org.eclipse.core.resources.ProjectScope 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 88 with ProjectScope

use of org.eclipse.core.resources.ProjectScope 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 89 with ProjectScope

use of org.eclipse.core.resources.ProjectScope 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)

Example 90 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project jbosstools-hibernate by jbosstools.

the class HibernatePropertyPage method saveNamigStrategyChanges.

protected boolean saveNamigStrategyChanges() {
    if (initNamingStrategy == enableNamingStrategy.getSelection())
        return true;
    IScopeContext scope = new ProjectScope(getProject());
    Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
    if (node != null) {
        node.putBoolean(HibernatePropertiesConstants.NAMING_STRATEGY_ENABLED, enableNamingStrategy.getSelection());
        try {
            node.flush();
            return true;
        } catch (BackingStoreException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.ProjectUtils_could_not_save_changes_to_preferences, e);
        }
    }
    return false;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Aggregations

ProjectScope (org.eclipse.core.resources.ProjectScope)92 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)42 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)31 IProject (org.eclipse.core.resources.IProject)28 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)24 Preferences (org.osgi.service.prefs.Preferences)18 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)17 BackingStoreException (org.osgi.service.prefs.BackingStoreException)17 ScopedPreferenceStore (org.eclipse.ui.preferences.ScopedPreferenceStore)11 IFile (org.eclipse.core.resources.IFile)9 IResource (org.eclipse.core.resources.IResource)9 CoreException (org.eclipse.core.runtime.CoreException)8 IAdaptable (org.eclipse.core.runtime.IAdaptable)5 IPath (org.eclipse.core.runtime.IPath)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Path (org.eclipse.core.runtime.Path)4 Test (org.junit.Test)4 File (java.io.File)3