Java Code Examples for org.osgi.service.prefs.Preferences#get()

The following examples show how to use org.osgi.service.prefs.Preferences#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectNameFilterAwareWorkingSetManager.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IStatus restoreState(final IProgressMonitor monitor) {
	final IStatus superRestoreResult = super.restoreState(monitor);

	if (superRestoreResult.isOK()) {

		final Preferences node = getPreferences();
		final String orderedFilters = node.get(ORDERED_FILTERS_KEY, EMPTY_STRING);
		if (!Strings.isNullOrEmpty(orderedFilters)) {
			orderedWorkingSetFilters.clear();
			orderedWorkingSetFilters.addAll(Arrays.asList(orderedFilters.split(SEPARATOR)));
		}

		discardWorkingSetCaches();
		return statusHelper.OK();

	}

	return superRestoreResult;
}
 
Example 2
Source File: WorkingSetManagerImpl.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IStatus restoreState(final IProgressMonitor monitor) {

	final Preferences node = getPreferences();

	// Restore ordered labels.
	final String orderedLabels = node.get(ORDERED_IDS_KEY, EMPTY_STRING);
	if (!Strings.isNullOrEmpty(orderedLabels)) {
		orderedWorkingSetIds.clear();
		orderedWorkingSetIds.addAll(Arrays.asList(orderedLabels.split(SEPARATOR)));
	}

	// Restore visible labels.
	final String visibleLabels = node.get(VISIBLE_IDS_KEY, EMPTY_STRING);
	if (!Strings.isNullOrEmpty(visibleLabels)) {
		visibleWorkingSetIds.clear();
		visibleWorkingSetIds.addAll(Arrays.asList(visibleLabels.split(SEPARATOR)));
	}

	discardWorkingSetCaches();

	return statusHelper.OK();
}
 
Example 3
Source File: WorkingSetManagerBrokerImpl.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private IStatus restoreState() {

		final Preferences node = getPreferences();
		// Top level element.
		workingSetTopLevel.set(node.getBoolean(IS_WORKINGSET_TOP_LEVEL_KEY, false));

		// Active working set manager.
		final String value = node.get(ACTIVE_MANAGER_KEY, "");
		WorkingSetManager workingSetManager = contributions.get().get(value);
		if (workingSetManager == null) {
			if (!contributions.get().isEmpty()) {
				workingSetManager = contributions.get().values().iterator().next();
			}
		}
		if (workingSetManager != null) {
			setActiveManager(workingSetManager);
		}

		return Status.OK_STATUS;
	}
 
Example 4
Source File: Theme.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
protected void storeDefaults()
{
	// Don't store builtin themes default copy in prefs!
	if (getThemeManager().isBuiltinTheme(getName()))
	{
		return;
	}
	// Only save to defaults if it has never been saved there. Basically take a snapshot of first version and
	// use that as the "default"
	IEclipsePreferences prefs = EclipseUtil.defaultScope().getNode(ThemePlugin.PLUGIN_ID);
	if (prefs == null)
	{
		return; // TODO Log something?
	}
	Preferences preferences = prefs.node(ThemeManager.THEMES_NODE);
	if (preferences == null)
	{
		return;
	}
	String value = preferences.get(getName(), null);
	if (value == null)
	{
		save(EclipseUtil.defaultScope());
	}
}
 
Example 5
Source File: Ruleset.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
public Ruleset(Preferences subPrefs) throws BackingStoreException {
	String[] keys = subPrefs.keys();
	for (String key : keys) {
		switch (key) {
			case "SelectedVersion":
				this.selectedVersion = subPrefs.get(key, "");
				break;
			case "CheckboxState":
				this.isChecked = subPrefs.getBoolean(key, false);
				break;
			case "FolderName":
				this.folderName = subPrefs.get(key, "");
				break;
			case "Url":
				this.url = subPrefs.get(key, "");
				break;
			default:
				break;
		}
	}
}
 
Example 6
Source File: CommandState.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> getCurrentState() {
	Map<String, String> map = new HashMap<String, String>(1);
	boolean enableOption = false;
	Preferences preferences = InstanceScope.INSTANCE.getNode("com.hybris.hyeclipse.preferences");
	String platformHomeStr = preferences.get("platform_home", null);
	if (platformHomeStr == null) {
		IProject platformProject = ResourcesPlugin.getWorkspace().getRoot().getProject("platform");
		IPath platformProjectPath = platformProject.getLocation();
		if (platformProjectPath != null) {
			enableOption = true;
		}
	}
	else {
		enableOption = true;
	}
	
	if (enableOption) {
		map.put(ID, ENABLED);
	}
	else {
		map.put(ID, DISABLED);
	}
	return map;
}
 
Example 7
Source File: AddInPreferencePage.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets the manifest URL.
 * 
 * @return the manifest URL
 */
private String getManifestURL() {
    final String res;

    final Preferences preferences = InstanceScope.INSTANCE.getNode(AddInPreferenceInitializer.SCOPE);
    final String host = preferences.get(AddInPreferenceInitializer.HOST_PREFERENCE,
            AddInPreferenceInitializer.DEFAULT_HOST);
    final String port = preferences.get(AddInPreferenceInitializer.PORT_PREFERENCE,
            String.valueOf(AddInPreferenceInitializer.DEFAULT_PORT));
    if (AddInPreferenceInitializer.DEFAULT_HOST.equals(host)) {
        res = "http://localhost:" + port + "/assets/manifest.xml";
    } else {
        res = "http://" + host + ":" + port + "/assets/manifest.xml";
    }

    return res;
}
 
Example 8
Source File: PlatformHomePropertyTester.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean test(Object arg0, String arg1, Object[] arg2, Object arg3) {
	
	boolean enableOption = false;
	Preferences preferences = InstanceScope.INSTANCE.getNode("com.hybris.hyeclipse.preferences");
	String platformHomeStr = preferences.get("platform_home", null);
	if (platformHomeStr == null) {
		IProject platformProject = ResourcesPlugin.getWorkspace().getRoot().getProject("platform");
		IPath platformProjectPath = platformProject.getLocation();
		if (platformProjectPath != null) {
			enableOption = true;
		}
	}
	else {
		enableOption = true;
	}
	
	return enableOption;
}
 
Example 9
Source File: Activator.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
public File getPlatformHome() {
	if (platformHome == null) {

		// Get platform home from workspace preferences
		Preferences preferences = InstanceScope.INSTANCE.getNode("com.hybris.hyeclipse.preferences");
		String platformHomeStr = preferences.get("platform_home", null);
		if (platformHomeStr == null) {
			IProject platformProject = ResourcesPlugin.getWorkspace().getRoot().getProject("platform");
			IPath platformProjectPath = platformProject.getLocation();
			if (platformProjectPath != null) {
				setPlatformHome(platformProjectPath.toFile());
			}
		} else {
			setPlatformHome(new File(platformHomeStr));
		}
	}
	return platformHome;
}
 
Example 10
Source File: AddInPreferencePage.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Starts the server.
 */
private void startServer() {
    final Preferences preferences = InstanceScope.INSTANCE.getNode(AddInPreferenceInitializer.SCOPE);
    final String host = preferences.get(AddInPreferenceInitializer.HOST_PREFERENCE,
            AddInPreferenceInitializer.DEFAULT_HOST);
    final String port = preferences.get(AddInPreferenceInitializer.PORT_PREFERENCE,
            String.valueOf(AddInPreferenceInitializer.DEFAULT_PORT));
    M2DocAddInPlugin.getPlugin().startServer(host, Integer.valueOf(port));
}
 
Example 11
Source File: SynchronizePlatformWizard.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Workhorse to do the actual import of the projects into this workspace.
 */
private void synchronizePlatform()
{
	boolean autobuildEnabled = isAutoBuildEnabled();
	enableAutoBuild( false );
	final boolean fixClasspath = page1.isFixClasspath();
	final boolean removeHybrisBuilder = page1.isRemoveHybrisGenerator();
	final boolean createWorkingSets = page1.isCreateWorkingSets();
	final boolean useMultiThread = page1.isUseMultiThread();
	final boolean skipJarScanning = page1.isSkipJarScanning();
		
	Preferences preferences = InstanceScope.INSTANCE.getNode("com.hybris.hyeclipse.preferences");
	final String platformDir = preferences.get("platform_home", null);
	
	if (platformDir == null)
	{
		throw new IllegalStateException("not platform has been set, try importing again");
	}
	
	IRunnableWithProgress importer = new IRunnableWithProgress()
	{
		public void run( IProgressMonitor monitor ) throws InvocationTargetException
		{
			List<IProject> projects = Arrays.asList( ResourcesPlugin.getWorkspace().getRoot().getProjects() );
			synchronizePlatform( monitor, projects, new File(platformDir), fixClasspath, removeHybrisBuilder, createWorkingSets, useMultiThread, skipJarScanning);
		}
	};
	try
	{
		new ProgressMonitorDialog( getContainer().getShell() ).run( true, false, importer );
	}
	catch( InvocationTargetException | InterruptedException e )
	{
		Activator.logError("Failed to synchronize platform", e);
		Throwable t = (e instanceof InvocationTargetException) ? e.getCause() : e;
		MessageDialog.openError( this.page1.getControl().getShell(), "Error", t.toString() );
		enableAutoBuild( autobuildEnabled );
	}
	enableAutoBuild( autobuildEnabled );
}
 
Example 12
Source File: BazelProjectSupport.java    From eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Return the {@link BazelInstance} corresponding to the given <code>project</code>. It looks for
 * the instance that runs for the workspace root configured for that project.
 *
 * @throws BazelNotFoundException
 */
public static BazelCommand.BazelInstance getBazelCommandInstance(IProject project)
    throws BackingStoreException, IOException, InterruptedException, BazelNotFoundException {
  IScopeContext projectScope = new ProjectScope(project.getProject());
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  File workspaceRoot =
      new File(projectNode.get("workspaceRoot", project.getLocation().toFile().toString()));
  return Activator.getDefault().getCommand().getInstance(workspaceRoot);
}
 
Example 13
Source File: PortFieldEditor.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean checkState() {
    boolean res;

    if (super.checkState()) {
        final Preferences preferences = InstanceScope.INSTANCE.getNode(AddInPreferenceInitializer.SCOPE);
        final String started = preferences.get(AddInPreferenceInitializer.STARTED_PREFERENCE,
                String.valueOf(false));
        final Text text = getTextControl();
        if (Boolean.valueOf(started)) {
            res = true;
            clearErrorMessage();
        } else if (text == null) {
            res = false;
        } else {
            try (ServerSocket socket = new ServerSocket(getIntValue(), 10, InetAddress.getByName("0.0.0.0"))) {
                res = true;
                clearErrorMessage();
            } catch (IOException e) {
                res = false;
                showErrorMessage(e.getMessage());
            }
        }
    } else {
        res = false; // messages handled by super.checkState()
    }

    return res;
}
 
Example 14
Source File: ManualAssociationAwareWorkingSetManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IStatus restoreState(final IProgressMonitor monitor) {
	final IStatus superRestoreResult = super.restoreState(monitor);

	if (superRestoreResult.isOK()) {

		final Preferences node = getPreferences();
		final String orderedFilters = node.get(ORDERED_ASSOCIATIONS_KEY, EMPTY_STRING);
		if (!Strings.isNullOrEmpty(orderedFilters)) {
			final ProjectAssociation association = jsonStringToProjectAssociation(orderedFilters);
			if (association == null) {
				final String message = "Error occurred while deserializing project associations: "
						+ "\"" + orderedFilters + "\"";
				LOGGER.error(message);
				return statusHelper.createError(message);
			}
			projectAssociations.clear();
			projectAssociations.putAll(association);
		}

		discardWorkingSetCaches();

		return statusHelper.OK();

	}

	return superRestoreResult;
}
 
Example 15
Source File: M2DocAddInPlugin.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    final Preferences preferences = InstanceScope.INSTANCE.getNode(AddInPreferenceInitializer.SCOPE);
    final String started = preferences.get(AddInPreferenceInitializer.STARTED_PREFERENCE,
            String.valueOf(false));
    if (Boolean.valueOf(started)) {
        final String host = preferences.get(AddInPreferenceInitializer.HOST_PREFERENCE,
                AddInPreferenceInitializer.DEFAULT_HOST);
        final String port = preferences.get(AddInPreferenceInitializer.PORT_PREFERENCE,
                String.valueOf(AddInPreferenceInitializer.DEFAULT_PORT));
        startServer(host, Integer.valueOf(port));
    }
}
 
Example 16
Source File: OsgiBinariesPreferenceStore.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Recursive read of the given preferences node based on the provided binary and its {@link Binary#getChildren()
 * children}. Information read from preference node is stored in the provided state instance (instance is mutated).
 *
 * @param state
 *            state instance to read to
 * @param node
 *            preferences node to read
 * @param binary
 *            the binary for which we read config
 */
private void recursivePreferencesRead(final Map<Binary, URI> state, final Preferences node,
		final Binary binary) {
	final String value = node.get(binary.getId(), "");
	if (!Strings.isNullOrEmpty(value)) {
		final File file = new File(value);
		if (file.isDirectory()) {
			state.put(binary, file.toURI());
		}
	}
	binary.getChildren().forEach(child -> recursivePreferencesRead(state, node, child));
}
 
Example 17
Source File: HlcExternalLibraryPreferenceStore.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ExternalLibraryPreferenceModel doLoad() {
	final Preferences node = InstanceScope.INSTANCE.getNode(QUALIFIER);
	final String jsonString = node.get(CONFIGURATION_KEY, "");
	if (isNullOrEmpty(jsonString)) {
		return ExternalLibraryPreferenceModel.createDefaultForN4Product();
	}
	return ExternalLibraryPreferenceModel.createFromJson(jsonString);
}
 
Example 18
Source File: GraphVizActivator.java    From eclipsegraphviz with Eclipse Public License 1.0 4 votes vote down vote up
/** Returns the preference with the given name */
public String getPreference(String preference_name) {
    Preferences node = Platform.getPreferencesService().getRootNode().node(InstanceScope.SCOPE)
            .node(GraphVizActivator.ID);
    return node.get(preference_name, null);
}
 
Example 19
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns whether the option for the given key is the same in the map and the preferences.
 * 
 * @param key the key of option to test
 * @param preferences the preferences
 * @param map the map
 * @return <code>true</code> if the options are the same in both maps
 * @since 3.6
 */
private static boolean equals(String key, Preferences preferences, Map<String, String> map) {
	String dummy= new String();
	String defaultValue= preferences.get(key, dummy);
	return defaultValue != null && defaultValue != dummy
			? map.containsKey(key) && equals(defaultValue, map.get(key))
			: !map.containsKey(key);
}