Search in sources :

Example 1 with PreferenceStore

use of org.eclipse.jface.preference.PreferenceStore in project cubrid-manager by CUBRID.

the class DBParameter method loadDatabases.

/**
	 *
	 * Load added databases from workspace path
	 *
	 * @param workspacePath String
	 * @return boolean whether imported
	 */
public boolean loadDatabases(String workspacePath) {
    synchronized (this) {
        String settingPath = workspacePath + File.separator + ".metadata" + File.separator + ".plugins" + File.separator + "org.eclipse.core.runtime" + File.separator + ".settings" + File.separator;
        String serverPath = settingPath + File.separator + "com.cubrid.cubridmanager.ui.prefs";
        PreferenceStore preference = new PreferenceStore(serverPath);
        int size = databaseMap.size();
        try {
            preference.load();
            String xmlString = preference.getString(DATABASE_XML_CONTENT);
            if (xmlString == null || xmlString.trim().length() == 0) {
                return false;
            }
            ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
            IXMLMemento memento = XMLMemento.loadMemento(in);
            loadDatabases(memento);
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
        boolean isImported = size != databaseMap.size();
        if (isImported) {
            saveDatabases();
        }
        return isImported;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) IOException(java.io.IOException) PreferenceStore(org.eclipse.jface.preference.PreferenceStore)

Example 2 with PreferenceStore

use of org.eclipse.jface.preference.PreferenceStore in project cubrid-manager by CUBRID.

the class CMGroupNodePersistManager method loadGroupNode.

/**
	 * Load group nodes from file preference.
	 *
	 * @param workspacePath String
	 * @return boolean whether import
	 */
public boolean loadGroupNode(String workspacePath) {
    synchronized (this) {
        String filePath = workspacePath + File.separator + ".metadata" + File.separator + ".plugins" + File.separator + "org.eclipse.core.runtime" + File.separator + ".settings" + File.separator + "com.cubrid.cubridmanager.ui.prefs";
        PreferenceStore preference = new PreferenceStore(filePath);
        int size = groupNodeList.size();
        try {
            preference.load();
            String xmlString = preference.getString(COM_CUBRID_MANAGER_HOSTGROUP);
            if (xmlString == null || xmlString.trim().length() == 0) {
                return false;
            }
            ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
            IXMLMemento memento = XMLMemento.loadMemento(in);
            loadGroupNode(memento);
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
        boolean isImported = size != groupNodeList.size();
        if (isImported) {
            saveAllGroupNode();
        }
        return isImported;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) IOException(java.io.IOException) PreferenceStore(org.eclipse.jface.preference.PreferenceStore)

Example 3 with PreferenceStore

use of org.eclipse.jface.preference.PreferenceStore in project cubrid-manager by CUBRID.

the class QueryOptions method load.

/**
	 * 
	 * Load added host from file preference to be compatible for the version
	 * before 8.4.0
	 * 
	 * @param optionPath
	 *            String
	 * @param serverInfo
	 *            ServerInfo
	 * 
	 */
public static void load(String optionPath, ServerInfo serverInfo) {
    String newPrefix = getPrefix(serverInfo) + ".";
    String[] filePaths = { optionPath + File.separator + "com.cubrid.cubridmanager.core.prefs", optionPath + File.separator + "com.cubrid.cubridmanager.ui.prefs", optionPath + File.separator + "com.cubrid.common.ui.prefs" };
    for (String filePath : filePaths) {
        File file = new File(filePath);
        if (!file.exists()) {
            continue;
        }
        PreferenceStore preference = new PreferenceStore(filePath);
        try {
            preference.load();
            String[] supportedPrefixs = { "" };
            if (serverInfo != null) {
                String prefix1 = serverInfo.getHostAddress();
                String prefix2 = prefix1 + "." + serverInfo.getHostMonPort();
                String prefix3 = prefix2 + "." + serverInfo.getUserName();
                String prefix4 = serverInfo.getServerName();
                supportedPrefixs = new String[] { prefix3, prefix2, prefix1, prefix4 };
            }
            String[] keys = preference.preferenceNames();
            for (String key : keys) {
                for (String prefix : supportedPrefixs) {
                    if (key.trim().startsWith(prefix + ".")) {
                        String newKey = key.replaceAll(prefix + "\\.", newPrefix);
                        if (pref.get(newKey, null) == null) {
                            pref.put(newKey, preference.getString(key));
                        }
                        break;
                    }
                }
            }
            savePref();
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) PreferenceStore(org.eclipse.jface.preference.PreferenceStore)

Example 4 with PreferenceStore

use of org.eclipse.jface.preference.PreferenceStore in project cubrid-manager by CUBRID.

the class CMHostNodePersistManager method loadSevers.

/**
	 *
	 * Load added host from preference file path
	 *
	 * @param workspacePath String
	 * @return boolean whether import
	 *
	 */
public boolean loadSevers(String workspacePath) {
    synchronized (this) {
        String settingPath = workspacePath + File.separator + ".metadata" + File.separator + ".plugins" + File.separator + "org.eclipse.core.runtime" + File.separator + ".settings" + File.separator;
        //Load global preference setting
        QueryOptions.load(settingPath, null);
        String serverPath = settingPath + File.separator + "com.cubrid.cubridmanager.ui.prefs";
        PreferenceStore preference = new PreferenceStore(serverPath);
        int size = serverList.size();
        try {
            preference.load();
            String xmlString = preference.getString(SERVER_XML_CONTENT);
            if (xmlString == null || xmlString.trim().length() == 0) {
                return false;
            }
            ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
            IXMLMemento memento = XMLMemento.loadMemento(in);
            loadServers(memento, true, settingPath);
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
        boolean isImported = size != serverList.size();
        if (isImported) {
            saveServers();
        }
        return isImported;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) IOException(java.io.IOException) PreferenceStore(org.eclipse.jface.preference.PreferenceStore)

Example 5 with PreferenceStore

use of org.eclipse.jface.preference.PreferenceStore in project cubrid-manager by CUBRID.

the class CQBGroupNodePersistManager method loadGroupNode.

/**
	 * Load group nodes from file preference.
	 *
	 * @param workspacePath String
	 * @return boolean whether import
	 */
public boolean loadGroupNode(String workspacePath) {
    synchronized (this) {
        String filePath = workspacePath + File.separator + ".metadata" + File.separator + ".plugins" + File.separator + "org.eclipse.core.runtime" + File.separator + ".settings" + File.separator + "com.cubrid.cubridquery.ui.prefs";
        PreferenceStore preference = new PreferenceStore(filePath);
        int size = groupNodeList.size();
        try {
            preference.load();
            String xmlString = preference.getString(COM_CUBRID_QB_DBGROUP);
            if (xmlString == null || xmlString.trim().length() == 0) {
                return false;
            }
            ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
            IXMLMemento memento = XMLMemento.loadMemento(in);
            loadGroupNode(memento);
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
        boolean isImported = size != groupNodeList.size();
        if (isImported) {
            saveAllGroupNode();
        }
        return isImported;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) IOException(java.io.IOException) PreferenceStore(org.eclipse.jface.preference.PreferenceStore)

Aggregations

IOException (java.io.IOException)6 PreferenceStore (org.eclipse.jface.preference.PreferenceStore)6 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)1