Search in sources :

Example 6 with IEclipsePreferences

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

the class PersistUtils method setPreferenceValue.

/**
	 * Save value to plugin preference of instance scope
	 * 
	 * @param pluginId String
	 * @param key the key
	 * @param value the value
	 */
public static void setPreferenceValue(String pluginId, String key, String value) {
    IEclipsePreferences prefs = getPreference(pluginId);
    prefs.put(key, value);
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        prefs = null;
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 7 with IEclipsePreferences

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

the class PersistUtils method getXMLMemento.

/**
	 * Get the node XML memento from instance scope preference
	 * 
	 * @param pluginId String
	 * @param key String
	 * @return IXMLMemento
	 */
public static IXMLMemento getXMLMemento(String pluginId, String key) {
    IEclipsePreferences preference = getPreference(pluginId);
    String xmlString = preference.get(key, "");
    if (xmlString == null || xmlString.length() == 0) {
        return null;
    }
    try {
        ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
        return XMLMemento.loadMemento(in);
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ByteArrayInputStream(java.io.ByteArrayInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 8 with IEclipsePreferences

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

the class BrokerTblColumnSetHelp method loadSetting.

/**
	 * 
	 * Load broker interval settings from plugin preference
	 * 
	 * @param <T> the generic type which is the sub type of IColumnSetting
	 * @param statusColumn the instance of StatusColumn enumeration
	 * @param ts the instance of generic array
	 */
public <T extends IColumnSetting> void loadSetting(StatusColumn statusColumn, T[] ts) {
    synchronized (this) {
        IEclipsePreferences preference = new InstanceScope().getNode(CubridManagerUIPlugin.PLUGIN_ID);
        String xmlString = preference.get(statusColumn.name(), "");
        if (xmlString != null && xmlString.length() > 0) {
            try {
                ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
                IXMLMemento memento = XMLMemento.loadMemento(in);
                IXMLMemento[] children = memento.getChildren(statusColumn.name());
                for (IXMLMemento child : children) {
                    for (T t : ts) {
                        t.setValue(child.getInteger(t.getNick()));
                    }
                }
            } catch (Exception e) {
                LOGGER.error(e.getMessage());
            }
        }
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope)

Example 9 with IEclipsePreferences

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

the class BrokerTblColumnSetHelp method saveSetting.

/**
	 * 
	 * Save broker interval to plugin preference
	 * 
	 * @param <T> the generic type which is the sub type of IColumnSetting
	 * @param statusColumn the instance of StatusColumn enumeration
	 * @param ts the instance of generic array
	 */
public <T extends IColumnSetting> void saveSetting(StatusColumn statusColumn, T[] ts) {
    synchronized (this) {
        try {
            XMLMemento memento = XMLMemento.createWriteRoot(statusColumn.name());
            IXMLMemento child = memento.createChild(statusColumn.name());
            for (T column : ts) {
                child.putString(column.getNick(), String.valueOf(column.getValue()));
            }
            String xmlString = memento.saveToString();
            IEclipsePreferences preference = new InstanceScope().getNode(CubridManagerUIPlugin.PLUGIN_ID);
            preference.put(statusColumn.name(), 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 10 with IEclipsePreferences

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

the class BrokerIntervalSettingManager method loadBrokerIntervalSettings.

/**
	 *
	 * Load broker interval settings from plugin preference
	 *
	 */
protected void loadBrokerIntervalSettings() {
    synchronized (this) {
        IEclipsePreferences preference = new InstanceScope().getNode(CubridManagerUIPlugin.PLUGIN_ID);
        String xmlString = preference.get(CUBRID_BROKER_INTERVAL_XML_CONTENT, "");
        if (xmlString != null && xmlString.length() > 0) {
            try {
                ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
                IXMLMemento memento = XMLMemento.loadMemento(in);
                IXMLMemento[] children = memento.getChildren("BrokerIntervalSetting");
                for (int i = 0; i < children.length; i++) {
                    String serverName = children[i].getString("serverName");
                    String brokerName = children[i].getString("brokerName");
                    String isOn = children[i].getString("isOn");
                    String interval = children[i].getString("interval");
                    BrokerIntervalSetting brokerInterval = new BrokerIntervalSetting(serverName, brokerName, interval, isOn != null && isOn.equals("true"));
                    brokerIntervalSettingList.add(brokerInterval);
                }
            } catch (Exception e) {
                LOGGER.error(e.getMessage());
            }
        }
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope)

Aggregations

IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)27 BackingStoreException (org.osgi.service.prefs.BackingStoreException)12 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)9 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ProjectScope (org.eclipse.core.resources.ProjectScope)5 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)4 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 PerProjectInfo (org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo)2 JavaModelManager.getJavaModelManager (org.eclipse.jdt.internal.core.JavaModelManager.getJavaModelManager)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1