Search in sources :

Example 6 with CubridServerLoader

use of com.cubrid.cubridmanager.ui.spi.model.loader.CubridServerLoader 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 7 with CubridServerLoader

use of com.cubrid.cubridmanager.ui.spi.model.loader.CubridServerLoader in project cubrid-manager by CUBRID.

the class CMHostNodePersistManager method loadServers.

private boolean loadServers(List<CubridServer> servers, IXMLMemento memento, boolean isLoadOptions, String optionPath, boolean allowDuplicate) {
    boolean isHasLocalHost = false;
    IXMLMemento[] children = memento == null ? null : memento.getChildren("host");
    for (int i = 0; children != null && i < children.length; i++) {
        String id = children[i].getString("id");
        String name = children[i].getString("name");
        if ("localhost".equals(name)) {
            isHasLocalHost = true;
        }
        String address = children[i].getString("address");
        String port = children[i].getString("port");
        String user = children[i].getString("user");
        String userPasword = children[i].getString("password");
        String jdbcDriver = children[i].getString("jdbcDriver");
        boolean savePassword = children[i].getBoolean("savePassword");
        String strSoTimeOut = children[i].getString("soTimeOut");
        int soTimeOut = StringUtil.intValue(strSoTimeOut, SocketTask.SOCKET_IO_TIMEOUT_MSEC);
        // duplicate entry check: memento -- current workspace
        if (!allowDuplicate) {
            if (getServer(id) != null && isContainedByHostAddress(address, port, null)) {
                continue;
            }
        }
        String strCheckCert = children[i].getString("isCheckCert");
        ServerInfo serverInfo = new ServerInfo();
        serverInfo.setServerName(name);
        serverInfo.setHostAddress(address);
        serverInfo.setHostMonPort(Integer.parseInt(port));
        serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
        serverInfo.setUserName(user);
        serverInfo.setUserPassword(CipherUtils.decrypt(userPasword));
        serverInfo.setJdbcDriverVersion(jdbcDriver);
        serverInfo.setSoTimeOut(soTimeOut);
        if (!StringUtil.isEmpty(strCheckCert)) {
            serverInfo.setCheckCertStatus(StringUtil.booleanValue(strCheckCert));
        }
        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());
        server.setAutoSavePassword(savePassword);
        if (isLoadOptions) {
            QueryOptions.load(optionPath, serverInfo);
        }
        servers.add(server);
        ServerManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
    }
    return isHasLocalHost;
}
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) CubridServerLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CubridServerLoader)

Aggregations

CubridServer (com.cubrid.common.ui.spi.model.CubridServer)7 CubridServerLoader (com.cubrid.cubridmanager.ui.spi.model.loader.CubridServerLoader)7 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)6 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)2 HostDialog (com.cubrid.cubridmanager.ui.host.dialog.HostDialog)2 Shell (org.eclipse.swt.widgets.Shell)2 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)1 File (java.io.File)1 URL (java.net.URL)1