Search in sources :

Example 36 with IXMLMemento

use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.

the class DBParameter method saveDatabases.

/**
	 *
	 * Save added database to plug-in preference
	 *
	 */
public void saveDatabases() {
    synchronized (this) {
        XMLMemento memento = XMLMemento.createWriteRoot("databases");
        for (DBParameter dbParameter : databaseMap.values()) {
            String dbName = StringUtils.defaultString(dbParameter.getDbName());
            String address = StringUtils.defaultString(dbParameter.getHostAddress());
            String port = StringUtils.defaultString(dbParameter.getMonPort());
            String dbUser = StringUtils.defaultString(dbParameter.getDBUser());
            String password = StringUtils.defaultString(dbParameter.getPassword());
            String jdbcAttrs = StringUtils.defaultString(dbParameter.getJdbcAttrs());
            boolean savePassword = dbParameter.isSavePassword();
            IXMLMemento child = memento.createChild("database");
            child.putString("dbUser", dbUser);
            child.putString("dbName", dbName);
            child.putString("address", address);
            child.putString("port", port);
            child.putString("dbPassword", CipherUtils.encrypt(password));
            child.putString("savePassword", String.valueOf(savePassword));
            child.putString("jdbcAttrs", jdbcAttrs);
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(dbUser, dbName, address, port, null, true);
            if (editorConfig != null) {
                IXMLMemento editorConfigChild = child.createChild("editorConfig");
                editorConfigChild.putString("database-comment", editorConfig.getDatabaseComment() == null ? "" : editorConfig.getDatabaseComment());
                if (editorConfig.getBackGround() != null) {
                    RGB background = editorConfig.getBackGround();
                    int bgPos = EditorConstance.getBGPos(background);
                    editorConfigChild.putInteger("purpose-code", bgPos);
                }
            }
        }
        PersistUtils.saveXMLMemento(ApplicationUtil.CM_UI_PLUGIN_ID, DATABASE_XML_CONTENT, memento);
    }
}
Also used : XMLMemento(com.cubrid.cubridmanager.core.common.xml.XMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) RGB(org.eclipse.swt.graphics.RGB) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 37 with IXMLMemento

use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.

the class CMGroupNodePersistManager method loadGroupNode.

/**
	 * Load group nodes from local preference.
	 *
	 */
private void loadGroupNode() {
    synchronized (this) {
        IXMLMemento memento = PersistUtils.getXMLMemento(ApplicationUtil.CM_UI_PLUGIN_ID, COM_CUBRID_MANAGER_HOSTGROUP);
        loadGroupNode(memento);
    }
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento)

Example 38 with IXMLMemento

use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.

the class CMGroupNodePersistManager method loadGroupNode.

/**
	 * Load group nodes from xml memento.
	 *
	 * @param memento IXMLMemento
	 *
	 */
private void loadGroupNode(IXMLMemento memento) {
    IXMLMemento[] children = memento == null ? null : memento.getChildren("group");
    groupNodeList.clear();
    for (int i = 0; children != null && i < children.length; i++) {
        String id = children[i].getString("id");
        String name = children[i].getString("name");
        CubridGroupNode cgn = getGroupById(id);
        if (cgn == null) {
            cgn = new CubridGroupNode(id, name, DEFAULT_GROUP_NODE.getIconPath());
            groupNodeList.add(cgn);
        }
        cgn.setLoader(DEFAULT_GROUP_NODE.getLoader());
        IXMLMemento[] items = children[i].getChildren("item");
        for (IXMLMemento item : items) {
            String itemId = item.getString("id");
            CubridServer cs = CMHostNodePersistManager.getInstance().getServer(itemId);
            if (cs == null) {
                continue;
            }
            cgn.addChild(cs);
        }
    }
    //groupNodeList.size >=1
    if (groupNodeList.isEmpty()) {
        try {
            groupNodeList.add((CubridGroupNode) DEFAULT_GROUP_NODE.clone());
            List<CubridServer> servers = CMHostNodePersistManager.getInstance().getAllServers();
            for (CubridServer server : servers) {
                groupNodeList.get(0).addChild(server);
            }
        } catch (CloneNotSupportedException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 39 with IXMLMemento

use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.

the class CMHostNodePersistManager method loadSevers.

/**
	 *
	 * Load added host from plugin preference
	 *
	 */
protected void loadSevers() {
    synchronized (this) {
        //			serverList.clear();
        boolean isHasLocalHost = false;
        boolean alreadyAddedLocalhostDefault = false;
        IXMLMemento memento = PersistUtils.getXMLMemento(ApplicationUtil.CM_UI_PLUGIN_ID, SERVER_XML_CONTENT);
        // For compatible for the version before 8.4.0
        URL url = Platform.getInstanceLocation().getURL();
        File file = new File(url.getFile());
        String optionsPath = file.getAbsolutePath() + File.separator + ".metadata" + File.separator + ".plugins" + File.separator + "org.eclipse.core.runtime" + File.separator + ".settings" + File.separator;
        //Load global preference setting
        QueryOptions.load(optionsPath, null);
        if (memento != null) {
            alreadyAddedLocalhostDefault = memento.getBoolean("alreadyAddedLocalhostDefault");
        }
        isHasLocalHost = loadServers(memento, true, optionsPath);
        if (!isHasLocalHost && !alreadyAddedLocalhostDefault) {
            String id = "localhost";
            String name = "localhost";
            int port = 8001;
            String userName = "admin";
            ServerInfo serverInfo = new ServerInfo();
            serverInfo.setServerName(name);
            serverInfo.setHostAddress(name);
            serverInfo.setHostMonPort(port);
            serverInfo.setHostJSPort(port + 1);
            serverInfo.setUserName(userName);
            serverInfo.setUserPassword("");
            CubridServer server = new CubridServer(id, name, "icons/navigator/host.png", "icons/navigator/host_connected.png");
            server.setServerInfo(serverInfo);
            server.setType(NodeType.SERVER);
            server.setLoader(new CubridServerLoader());
            serverList.add(0, server);
            ServerManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
            /*Save the server list*/
            saveServers();
        }
    }
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) File(java.io.File) URL(java.net.URL) CubridServerLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CubridServerLoader)

Example 40 with IXMLMemento

use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento 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)

Aggregations

IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)54 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)18 ByteArrayInputStream (java.io.ByteArrayInputStream)10 IOException (java.io.IOException)10 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)8 ArrayList (java.util.ArrayList)7 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)6 HashMap (java.util.HashMap)6 RGB (org.eclipse.swt.graphics.RGB)6 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)5 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)5 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)5 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)5 PreferenceStore (org.eclipse.jface.preference.PreferenceStore)5 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)4 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)4 SQLHistoryDetail (com.cubrid.common.ui.query.control.SQLHistoryDetail)3 QueryRecord (com.cubrid.common.ui.query.tuner.QueryRecord)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 MonitorStatistic (com.cubrid.common.ui.spi.model.MonitorStatistic)3