Search in sources :

Example 6 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project sling by apache.

the class ProjectUtil method getSyncDirectoryValue.

/**
     * Returns the value of the sync directory configured for a project.
     * 
     * <p>
     * The value is returned as a relative path to the project's location. If the property value is not set, it defaults
     * to {@value #PROPERTY_SYNC_ROOT_DEFAULT_VALUE}.
     * </p>
     * 
     * @param project the project, must not be null
     * @return the value of the sync directory
     */
public static IPath getSyncDirectoryValue(IProject project) {
    // for compatibility reasons, read the old value first
    String oldValue = null;
    try {
        oldValue = project.getPersistentProperty(PROPERTY_SYNC_ROOT_OLD);
    } catch (CoreException e) {
        Activator.getDefault().getPluginLogger().trace("Failed retrieving old values for content sync root for project " + project.getName(), e);
    }
    // read a value from the new store, returning a default if none is found 
    IScopeContext projectScope = new ProjectScope(project);
    IEclipsePreferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
    if (projectNode == null) {
        String value;
        // try to read from old values
        if (oldValue != null) {
            value = oldValue;
        } else {
            value = PROPERTY_SYNC_ROOT_DEFAULT_VALUE;
        }
        return Path.fromOSString(value);
    }
    // if no new value if found and an old value exists, use the old value and save it in the new store
    String value = projectNode.get(PROPERTY_SYNC_ROOT, null);
    if (value == null && oldValue != null) {
        value = oldValue;
        setSyncDirectoryPath(project, Path.fromPortableString(value));
    }
    // it is now safe to delete the value from the old store
    if (oldValue != null) {
        try {
            project.setPersistentProperty(PROPERTY_SYNC_ROOT_OLD, null);
        } catch (CoreException e) {
            Activator.getDefault().getPluginLogger().error(e.getMessage(), e);
        }
    }
    // TODO central place for defaults
    if (value == null) {
        return Path.fromOSString(PROPERTY_SYNC_ROOT_DEFAULT_VALUE);
    } else {
        return Path.fromPortableString(value);
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) CoreException(org.eclipse.core.runtime.CoreException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 7 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project sling by apache.

the class ProjectUtil method getProvisioningModelPath.

public static IPath getProvisioningModelPath(IProject project) {
    if (project == null || !project.isOpen() || !ProjectHelper.isLaunchpadProject(project)) {
        return null;
    }
    IScopeContext projectScope = new ProjectScope(project);
    IEclipsePreferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
    if (projectNode == null) {
        return null;
    }
    String propertyValue = projectNode.get(PROPERTY_PROVISIONING_MODEL_DIR, null);
    if (propertyValue == null) {
        return null;
    }
    return Path.fromPortableString(propertyValue);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 8 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project che by eclipse.

the class JavaProject method getEclipsePreferences.

/**
     * Returns the project custom preference pool.
     * Project preferences may include custom encoding.
     * @return IEclipsePreferences or <code>null</code> if the project
     * 	does not have a java nature.
     */
public IEclipsePreferences getEclipsePreferences() {
    if (!org.eclipse.jdt.internal.core.JavaProject.hasJavaNature(this.project))
        return null;
    // Get cached preferences if exist
    PerProjectInfo perProjectInfo = getJavaModelManager().getPerProjectInfo(this.project, true);
    if (perProjectInfo.preferences != null)
        return perProjectInfo.preferences;
    // Init project preferences
    IScopeContext context = new ProjectScope(getProject());
    final IEclipsePreferences eclipsePreferences = context.getNode(JavaCore.PLUGIN_ID);
    //        updatePreferences(eclipsePreferences);
    perProjectInfo.preferences = eclipsePreferences;
    //        eclipsePreferences.addPreferenceChangeListener(this.preferencesChangeListener);
    return eclipsePreferences;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) PerProjectInfo(org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 9 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project che 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 10 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project che by eclipse.

the class PreferenceConstants method getPreference.

//	/**
//	 * Sets the completion proposal categories which are excluded from the
//	 * default proposal list and reloads the registry.
//	 *
//	 * @param categories the array with the IDs of the excluded categories
//	 * @see #CODEASSIST_EXCLUDED_CATEGORIES
//	 * @since 3.4
//	 */
//	public static void setExcludedCompletionProposalCategories(String[] categories) {
//		Assert.isLegal(categories != null);
//		StringBuffer buf = new StringBuffer(50 * categories.length);
//		for (int i = 0; i < categories.length; i++) {
//			buf.append(categories[i]);
//			buf.append('\0');
//		}
//		getPreferenceStore().setValue(CODEASSIST_EXCLUDED_CATEGORIES, buf.toString());
//		CompletionProposalComputerRegistry.getDefault().reload();
//	}
/**
	 * Returns the value for the given key in the given context.
	 * @param key The preference key
	 * @param project The current context or <code>null</code> if no context is available and the
	 * workspace setting should be taken. Note that passing <code>null</code> should
	 * be avoided.
	 * @return Returns the current value for the string.
	 * @since 3.1
	 */
public static String getPreference(String key, IJavaProject project) {
    String val;
    if (project != null) {
        val = new ProjectScope(project.getProject()).getNode(ID_PLUGIN).get(key, null);
        if (val != null && !val.isEmpty()) {
            return val;
        }
    }
    val = InstanceScope.INSTANCE.getNode(ID_PLUGIN).get(key, null);
    if (val != null) {
        return val;
    }
    return getPreferenceStore().getString(key);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope)

Aggregations

ProjectScope (org.eclipse.core.resources.ProjectScope)15 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)10 IProject (org.eclipse.core.resources.IProject)6 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)5 Preferences (org.osgi.service.prefs.Preferences)5 File (java.io.File)2 IPath (org.eclipse.core.runtime.IPath)2 BackingStoreException (org.osgi.service.prefs.BackingStoreException)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 URL (java.net.URL)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 PerProjectInfo (org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo)1 ICoreService (org.talend.core.ICoreService)1