Search in sources :

Example 1 with DatabaseEditorConfig

use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.

the class ExportConnectionUtil method getColumnText.

public String getColumnText(Object element, int columnIndex) {
    if (element instanceof CubridServer && columnIndex == 0) {
        CubridServer server = (CubridServer) element;
        return server.getName();
    }
    if (element instanceof CubridDatabase) {
        CubridDatabase database = (CubridDatabase) element;
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            LOGGER.warn("DatabaseInfo is a null.");
            return "";
        }
        switch(columnIndex) {
            case 0:
                return dbInfo.getDbName();
            case 1:
                return dbInfo.getBrokerIP();
            case 2:
                return dbInfo.getBrokerPort();
            case 3:
                return dbInfo.getAuthLoginedDbUserInfo().getName();
            case 4:
                DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, isCMMode);
                if (editorConfig != null) {
                    return editorConfig.getDatabaseComment() == null ? "" : editorConfig.getDatabaseComment();
                }
                return "";
            case 5:
                return NodeUtil.getJavaConnectionUrl(database.getDatabaseInfo());
            case 6:
                return NodeUtil.getPHPConnectionUrl(database.getDatabaseInfo());
        }
    }
    return null;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 2 with DatabaseEditorConfig

use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.

the class MultiDatabaseLoginFailedDialog method editHost.

public void editHost(MultiDatabaseloginFailedInfo multiDatabaseloginFailedInfo) {
    if (multiDatabaseloginFailedInfo == null) {
        return;
    }
    CubridDatabase database = multiDatabaseloginFailedInfo.getCubridDatabase();
    //if login ,can't edit
    if (database.isLogined()) {
        return;
    }
    //		CubridDatabase oldDatabase = null;
    //		try {
    //			oldDatabase = database.clone();
    //		} catch (CloneNotSupportedException e) {
    //			//Ignore
    //		}
    LoginDatabaseDialog dialog = new LoginDatabaseDialog(getShell(), database);
    int returnVal = dialog.open();
    if (returnVal == IDialogConstants.OK_ID) {
        CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
        TreeViewer treeViewer = view.getViewer();
        database.removeAllChild();
        if (database.getLoader() != null) {
            database.getLoader().setLoaded(false);
        }
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        /*Save the data*/
        DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, true);
        if (editorConfig == null) {
            editorConfig = new DatabaseEditorConfig();
        }
        editorConfig.setBackGround(dialog.getSelectedColor());
        CMDBNodePersistManager.getInstance().addDatabase(database, editorConfig);
        ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
        LayoutManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
        multiDatabaseloginFailedInfo.setErrMsg("");
    }
    databaseTable.refresh();
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 3 with DatabaseEditorConfig

use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.

the class CQBDBNodePersistManager method saveDatabases.

/**
	 *
	 * Save added database to plug-in preference
	 *
	 */
public void saveDatabases() {
    synchronized (this) {
        XMLMemento memento = XMLMemento.createWriteRoot("databases");
        Iterator<CubridDatabase> iterator = databaseList.iterator();
        while (iterator.hasNext()) {
            CubridDatabase database = (CubridDatabase) iterator.next();
            DatabaseInfo dbInfo = database.getDatabaseInfo();
            ServerInfo serverInfo = dbInfo.getServerInfo();
            DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
            IXMLMemento child = memento.createChild("database");
            child.putString("name", database.getLabel());
            child.putString("dbName", dbInfo.getDbName());
            child.putString("dbUser", dbUserInfo.getName());
            if (database.isAutoSavePassword()) {
                child.putString("dbPassword", CipherUtils.encrypt(dbUserInfo.getNoEncryptPassword()));
            } else {
                child.putString("dbPassword", "");
            }
            child.putString("savePassword", String.valueOf(database.isAutoSavePassword()));
            // [TOOLS-2425]Support shard broker
            child.putString("isShard", String.valueOf(dbInfo.isShard()));
            child.putString("shardQueryType", String.valueOf(dbInfo.getShardQueryType()));
            child.putString("jdbcDriver", serverInfo.getJdbcDriverVersion());
            child.putString("brokerIp", dbInfo.getBrokerIP());
            child.putString("brokerPort", dbInfo.getBrokerPort());
            child.putString("charset", dbInfo.getCharSet());
            child.putString("jdbcAttrs", dbInfo.getJdbcAttrs());
            /*Save the database editor config*/
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, false);
            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.CQB_UI_PLUGIN_ID, DATABASE_XML_CONTENT, memento);
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) XMLMemento(com.cubrid.cubridmanager.core.common.xml.XMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) RGB(org.eclipse.swt.graphics.RGB) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 4 with DatabaseEditorConfig

use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.

the class CQBDBNodePersistManager method loadDatabases.

/**
	 *
	 * Load databases from xml memento
	 *
	 * @param memento IXMLMemento
	 * @param isLoadOptions boolean
	 * @param optionPath String
	 */
protected void loadDatabases(IXMLMemento memento, boolean isLoadOptions, String optionPath) {
    //when import connections, load the global preference
    if (isLoadOptions) {
        QueryOptions.load(optionPath, null);
    }
    IXMLMemento[] children = memento == null ? null : memento.getChildren("database");
    for (int i = 0; children != null && i < children.length; i++) {
        String name = children[i].getString("name");
        String dbName = children[i].getString("dbName");
        String dbUser = children[i].getString("dbUser");
        String dbPassword = children[i].getString("dbPassword");
        String jdbcDriver = children[i].getString("jdbcDriver");
        boolean savePassword = children[i].getBoolean("savePassword");
        // [TOOLS-2425]Support shard broker
        Boolean isShardObj = children[i].getBoolean("isShard");
        boolean isShard = isShardObj == null ? false : isShardObj;
        String shardQueryTypeStr = children[i].getString("shardQueryType");
        int shardQueryType = StringUtil.intValue(shardQueryTypeStr, 0);
        if (shardQueryType == 0) {
            shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_VAL;
        }
        String brokerIp = children[i].getString("brokerIp");
        String brokerPort = children[i].getString("brokerPort");
        String charset = children[i].getString("charset");
        String jdbcAttrs = children[i].getString("jdbcAttrs");
        DatabaseEditorConfig editorConfig = null;
        IXMLMemento editorConfigElement = children[i].getChild("editorConfig");
        if (editorConfigElement != null) {
            editorConfig = new DatabaseEditorConfig();
            String strBGPos = editorConfigElement.getString("purpose-code");
            if (strBGPos == null) {
                strBGPos = "0";
            }
            int bgPos = StringUtil.intValue(strBGPos, 0);
            RGB background = EditorConstance.getRGBByPos(bgPos);
            editorConfig.setBackGround(background);
            editorConfig.setDatabaseComment(editorConfigElement.getString("database-comment"));
        }
        ServerInfo serverInfo = new ServerInfo();
        serverInfo.setServerName(name);
        serverInfo.setHostAddress(brokerIp);
        serverInfo.setHostMonPort(Integer.parseInt(brokerPort));
        serverInfo.setHostJSPort(Integer.parseInt(brokerPort) + 1);
        serverInfo.setUserName(dbName + "@" + brokerIp);
        serverInfo.setJdbcDriverVersion(jdbcDriver);
        CubridServer server = new CubridServer(name, name, null, null);
        server.setServerInfo(serverInfo);
        server.setType(NodeType.SERVER);
        DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
        dbInfo.setBrokerIP(brokerIp);
        dbInfo.setBrokerPort(brokerPort);
        dbInfo.setCharSet(charset);
        dbInfo.setJdbcAttrs(jdbcAttrs);
        dbInfo.setRunningType(DbRunningType.CS);
        // [TOOLS-2425]Support shard broker
        dbInfo.setShard(isShard);
        dbInfo.setShardQueryType(shardQueryType);
        String decDbPassword = null;
        if (dbPassword != null && dbPassword.trim().length() > 0) {
            decDbPassword = CipherUtils.decrypt(dbPassword);
        }
        DbUserInfo dbUserInfo = new DbUserInfo(dbName, dbUser, dbPassword, decDbPassword, false);
        dbInfo.setAuthLoginedDbUserInfo(dbUserInfo);
        String dbId = name + ICubridNodeLoader.NODE_SEPARATOR + name;
        if (this.getDatabase(dbId) != null) {
            continue;
        }
        CubridDatabase database = new CubridDatabase(dbId, name);
        database.setServer(server);
        database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
        database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
        database.setDatabaseInfo(dbInfo);
        CubridNodeLoader loader = new CQBDbConnectionLoader();
        loader.setLevel(ICubridNodeLoader.FIRST_LEVEL);
        database.setLoader(loader);
        database.setAutoSavePassword(savePassword);
        if (isLoadOptions) {
            QueryOptions.load(optionPath, serverInfo);
        }
        /*Save the DatabaseEditorConfig to the memory*/
        QueryOptions.putEditorConfig(database, editorConfig, false);
        databaseList.add(database);
        fireAddDatabase(database);
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CQBDbConnectionLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) CubridNodeLoader(com.cubrid.common.ui.spi.model.CubridNodeLoader) RGB(org.eclipse.swt.graphics.RGB) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 5 with DatabaseEditorConfig

use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.

the class MultiQueryConnEditDialog method cloneMultiEditQueryConnInfo.

/**
	 * clone edit database
	 *
	 * @param cloneDB
	 * @return
	 */
public CubridDatabase cloneMultiEditQueryConnInfo(CubridDatabase cloneDB) {
    CubridDatabase newCubridDatabase = new CubridDatabase(cloneDB.getId(), cloneDB.getLabel());
    DatabaseInfo cloneDBInfo = cloneDB.getDatabaseInfo();
    ServerInfo cloneServerInfo = cloneDBInfo.getServerInfo();
    String databaseName = cloneDBInfo.getDbName();
    String brokerIp = cloneDBInfo.getBrokerIP();
    String brokerPort = cloneDBInfo.getBrokerPort();
    String userName = cloneDBInfo.getAuthLoginedDbUserInfo().getName();
    String userPassword = cloneDBInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
    String charset = cloneDBInfo.getCharSet();
    String jdbcAttrs = cloneDBInfo.getJdbcAttrs();
    String jdbcVersion = cloneServerInfo.getJdbcDriverVersion();
    ServerInfo newServerInfo = new ServerInfo();
    newServerInfo.setServerName(databaseName);
    newServerInfo.setHostAddress(brokerIp);
    newServerInfo.setHostMonPort(Integer.parseInt(brokerPort));
    newServerInfo.setHostJSPort(Integer.parseInt(brokerPort) + 1);
    newServerInfo.setUserName(databaseName + "@" + brokerIp);
    newServerInfo.setJdbcDriverVersion(jdbcVersion);
    DatabaseInfo newDBInfo = new DatabaseInfo(databaseName, newServerInfo);
    newDBInfo.setBrokerIP(brokerIp);
    newDBInfo.setBrokerPort(brokerPort);
    newDBInfo.setCharSet(charset);
    newDBInfo.setJdbcAttrs(jdbcAttrs);
    DbUserInfo newUserInfo = new DbUserInfo();
    newUserInfo.setDbName(databaseName);
    newUserInfo.setName(userName);
    newUserInfo.setNoEncryptPassword(userPassword);
    newDBInfo.setAuthLoginedDbUserInfo(newUserInfo);
    newCubridDatabase.setAutoSavePassword(cloneDB.isAutoSavePassword());
    newCubridDatabase.setServer(cloneDB.getServer());
    newCubridDatabase.setDatabaseInfo(newDBInfo);
    DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(cloneDB, false);
    if (editorConfig != null) {
        newCubridDatabase.setData(COMMENTKEY, editorConfig.getDatabaseComment());
    } else {
        newCubridDatabase.setData(COMMENTKEY, "");
    }
    return newCubridDatabase;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Aggregations

DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)28 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)19 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)12 RGB (org.eclipse.swt.graphics.RGB)11 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)9 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)6 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)6 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)6 TreeViewer (org.eclipse.jface.viewers.TreeViewer)6 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)5 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)5 CubridNodeLoader (com.cubrid.common.ui.spi.model.CubridNodeLoader)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)3 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)3 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 SelectColorCombo (com.cubrid.common.ui.common.control.SelectColorCombo)2 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)2 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)2