Search in sources :

Example 11 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project liferay-ide by liferay.

the class LiferayUIPlugin method _installLiferayFormatterProfile.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void _installLiferayFormatterProfile() {
    PreferencesAccess access = PreferencesAccess.getOriginalPreferences();
    ProfileVersioner profileVersioner = new ProfileVersioner();
    IScopeContext instanceScope = access.getInstanceScope();
    try {
        FormatterProfileStore store = new FormatterProfileStore(profileVersioner);
        List profiles = store.readProfiles(instanceScope);
        if (profiles == null) {
            profiles = new ArrayList();
        }
        // add liferay profile
        Profile eclipseProfile = new CustomProfile("Liferay [plug-in]", getLiferaySettings(), profileVersioner.getCurrentVersion(), profileVersioner.getProfileKind());
        profiles.add(eclipseProfile);
        store.writeProfiles(profiles, instanceScope);
        // ProfileManager manager = new FormatterProfileManager(profiles,
        // instanceScope, access, profileVersioner);
        // manager.setSelected(eclipseProfile);
        // manager.commitChanges(instanceScope);
        instanceScope.getNode(JavaUI.ID_PLUGIN).flush();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            instanceScope.getNode(JavaCore.PLUGIN_ID).flush();
        } catch (BackingStoreException bse) {
        }
    }
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) ProfileVersioner(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileVersioner) ArrayList(java.util.ArrayList) BackingStoreException(org.osgi.service.prefs.BackingStoreException) PreferencesAccess(org.eclipse.jdt.internal.ui.preferences.PreferencesAccess) List(java.util.List) ArrayList(java.util.ArrayList) CustomProfile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile) FormatterProfileStore(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore) Profile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile) CustomProfile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 12 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project liferay-ide by liferay.

the class JSFModuleProjectProviderDefaultValueService method compute.

@Override
protected String compute() {
    String defaultProjectBuildType = "maven-jsf";
    IScopeContext[] prefContexts = { DefaultScope.INSTANCE, InstanceScope.INSTANCE };
    String buildType = Platform.getPreferencesService().getString(ProjectCore.PLUGIN_ID, ProjectCore.PREF_DEFAULT_JSF_MODULE_PROJECT_BUILD_TYPE_OPTION, null, prefContexts);
    if (buildType == null) {
        return "maven-jsf";
    }
    ILiferayProjectProvider provider = LiferayCore.getProvider(buildType);
    if (provider != null) {
        return provider.getShortName();
    }
    return defaultProjectBuildType;
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) ILiferayProjectProvider(com.liferay.ide.core.ILiferayProjectProvider)

Example 13 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project liferay-ide by liferay.

the class SDKUtil method getSDK.

public static SDK getSDK(IProject project) {
    SDK retval = null;
    // try to determine SDK based on project location
    IPath projectLocation = project.getRawLocation();
    if (projectLocation == null) {
        projectLocation = project.getLocation();
    }
    if (projectLocation != null) {
        IPath sdkLocation = projectLocation.removeLastSegments(2);
        retval = SDKManager.getInstance().getSDK(sdkLocation);
        if (retval == null) {
            retval = createSDKFromLocation(sdkLocation);
            if (retval != null) {
                SDK newSDK = retval;
                SDKManager.getInstance().addSDK(newSDK);
            }
        }
    }
    if (retval == null) {
        /**
         *  this means the sdk could not be determined by location (user is
         *using out-of-sdk style projects)
         *so we should check to see if the sdk name is persisted to the
         *project prefs
         */
        IScopeContext[] context = { new ProjectScope(project) };
        String sdkName = Platform.getPreferencesService().getString(SDKCorePlugin.PLUGIN_ID, SDKCorePlugin.PREF_KEY_SDK_NAME, null, context);
        retval = SDKManager.getInstance().getSDK(sdkName);
    }
    return retval;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IPath(org.eclipse.core.runtime.IPath)

Example 14 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project eclipse.jdt.ls by eclipse.

the class StubUtility method getLineDelimiterPreference.

public static String getLineDelimiterPreference(IProject project) {
    IScopeContext[] scopeContext;
    if (project != null) {
        // project preference
        scopeContext = new IScopeContext[] { new ProjectScope(project) };
        String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
        if (lineDelimiter != null) {
            return lineDelimiter;
        }
    }
    // workspace preference
    scopeContext = new IScopeContext[] { InstanceScope.INSTANCE };
    // $NON-NLS-1$ //$NON-NLS-2$
    String platformDefault = System.getProperty("line.separator", "\n");
    return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, platformDefault, scopeContext);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext)

Example 15 with IScopeContext

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

the class ContentAssistTest method testEnableHibernateNature.

@Test
public void testEnableHibernateNature() throws BackingStoreException, CoreException {
    IJavaProject prj = hcth.getProject().getIJavaProject();
    IScopeContext scope = new ProjectScope(prj.getProject());
    Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
    node.putBoolean(HibernatePropertiesConstants.HIBERNATE3_ENABLED, true);
    // $NON-NLS-1$
    node.put(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, "testcfg");
    node.flush();
    ProjectUtils.addProjectNature(prj.getProject(), HibernatePropertiesConstants.HIBERNATE_NATURE, new NullProgressMonitor());
    ProjectUtils.removeProjectNature(prj.getProject(), HibernatePropertiesConstants.HIBERNATE_NATURE, new NullProgressMonitor());
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) Preferences(org.osgi.service.prefs.Preferences) Test(org.junit.Test)

Aggregations

IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)73 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