Search in sources :

Example 11 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project cubrid-manager by CUBRID.

the class BrokerIntervalSettingManager method saveBrokerIntervals.

/**
	 *
	 * Save broker interval to plugin preference
	 *
	 */
public void saveBrokerIntervals() {
    synchronized (this) {
        if (!initialized) {
            init();
        }
        try {
            XMLMemento memento = XMLMemento.createWriteRoot("BrokerIntervalSettings");
            Iterator<BrokerIntervalSetting> iterator = brokerIntervalSettingList.iterator();
            while (iterator.hasNext()) {
                BrokerIntervalSetting brokerInterval = (BrokerIntervalSetting) iterator.next();
                IXMLMemento child = memento.createChild("BrokerIntervalSetting");
                child.putString("serverName", brokerInterval.getServerName());
                child.putString("brokerName", brokerInterval.getBrokerName());
                child.putString("isOn", brokerInterval.isOn() ? "true" : "false");
                child.putString("interval", brokerInterval.getInterval());
            }
            String xmlString = memento.saveToString();
            IEclipsePreferences preference = new InstanceScope().getNode(CubridManagerUIPlugin.PLUGIN_ID);
            preference.put(CUBRID_BROKER_INTERVAL_XML_CONTENT, xmlString);
            preference.flush();
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) XMLMemento(com.cubrid.cubridmanager.core.common.xml.XMLMemento) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope)

Example 12 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project cubrid-manager by CUBRID.

the class CubridStatusMonitorInstance method saveSetting.

/**
	 * Save the info of StatusMonInstanceData relevant to key into preference
	 * 
	 * @param key the key relevant to saving instance of StatusMonInstanceData
	 */
public void saveSetting(String key) {
    synchronized (this) {
        StatusMonInstanceData data = map.get(key);
        ObjectOutputStream objectOutputStream;
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        try {
            objectOutputStream = new ObjectOutputStream(byteStream);
            objectOutputStream.writeObject(data);
            objectOutputStream.close();
            byte[] bytes = byteStream.toByteArray();
            IEclipsePreferences preference = new InstanceScope().getNode(CubridManagerUIPlugin.PLUGIN_ID);
            preference.putByteArray(key, bytes);
            preference.flush();
        } catch (Exception ex) {
            LOGGER.error(ex.getMessage());
        }
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 13 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences 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 14 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences 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 15 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project eclipse.platform.text by eclipse.

the class DefaultEncodingSupport method initialize.

/**
 * Associates this encoding support to the given text editor and initializes this encoding.
 *
 * @param textEditor the editor
 */
public void initialize(StatusTextEditor textEditor) {
    fTextEditor = textEditor;
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES);
    fPreferenceChangeListener = new IPreferenceChangeListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            if (ResourcesPlugin.PREF_ENCODING.equals(event.getKey())) {
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        // null means: use default
                        setEncoding(null, false);
                    }
                };
                if (Display.getCurrent() != null)
                    runnable.run();
                else {
                    // Post runnable into UI thread
                    Shell shell;
                    if (fTextEditor != null)
                        shell = fTextEditor.getSite().getShell();
                    else
                        shell = getActiveWorkbenchShell();
                    Display display;
                    if (shell != null)
                        display = shell.getDisplay();
                    else
                        display = Display.getDefault();
                    display.asyncExec(runnable);
                }
            }
        }
    };
    prefs.addPreferenceChangeListener(fPreferenceChangeListener);
}
Also used : PreferenceChangeEvent(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) Shell(org.eclipse.swt.widgets.Shell) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Display(org.eclipse.swt.widgets.Display)

Aggregations

IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)79 BackingStoreException (org.osgi.service.prefs.BackingStoreException)15 Test (org.junit.Test)11 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)9 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)9 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)6 ProjectScope (org.eclipse.core.resources.ProjectScope)6 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)6 After (org.junit.After)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)3 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2