Search in sources :

Example 1 with ConnectDatabaseExecutor

use of com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor in project cubrid-manager by CUBRID.

the class LoginQueryEditDialog method buttonPressed.

/**
	 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
	 * @param buttonId the id of the button that was pressed (see
	 *        <code>IDialogConstants.*_ID</code> constants)
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID || buttonId == TEST_CONNECT_ID) {
        String brokerIp = connectionComp.getBrokerIpText().getText();
        CubridServer cubridServer = DatabaseNavigatorMenu.SELF_DATABASE.getServer();
        ServerInfo serverInfo = new ServerInfo();
        serverInfo.setServerName(DatabaseNavigatorMenu.SELF_DATABASE_ID);
        serverInfo.setHostAddress(brokerIp);
        cubridServer.setServerInfo(serverInfo);
        String databaseName = connectionComp.getDatabaseCombo().getText();
        DatabaseInfo dbInfo = new DatabaseInfo(databaseName, cubridServer.getServerInfo());
        dbInfo.setBrokerIP(brokerIp);
        dbInfo.setBrokerPort(connectionComp.getBrokerPortCombo().getText());
        dbInfo.getServerInfo().setJdbcDriverVersion(connectionComp.getJdbcCombo().getText());
        String userName = connectionComp.getUserNameText().getText();
        String password = connectionComp.getPasswordText().getText();
        DbUserInfo userInfo = new DbUserInfo();
        userInfo.setDbName(databaseName);
        userInfo.setName(userName);
        userInfo.setNoEncryptPassword(password);
        dbInfo.setAuthLoginedDbUserInfo(userInfo);
        int currentShardId = connectionComp.getCurShardId();
        dbInfo.setCurrentShardId(currentShardId);
        String charset = connectionComp.getCharsetCombo().getText();
        dbInfo.setCharSet(charset);
        boolean isShard = connectionComp.getBtnShard().getSelection();
        dbInfo.setShard(isShard);
        boolean sureCharset = CommonUITool.openConfirmBox(Messages.bind(com.cubrid.cubridmanager.ui.host.Messages.msgConfirmCharset, charset));
        if (!sureCharset) {
            connectionComp.getCharsetCombo().setFocus();
            return;
        }
        TaskExecutor taskExcutor = new ConnectDatabaseExecutor(dbInfo);
        new ExecTaskWithProgress(taskExcutor).exec();
        if (!taskExcutor.isSuccess()) {
            return;
        }
        if (buttonId == TEST_CONNECT_ID) {
            CommonUITool.openInformationBox(com.cubrid.cubridmanager.ui.common.Messages.titleSuccess, com.cubrid.cubridmanager.ui.host.Messages.msgTestConnSuccess);
            return;
        }
        dbInfo.setLogined(true);
        dbInfo.setRunningType(DbRunningType.CS);
        DatabaseNavigatorMenu.SELF_DATABASE.setDatabaseInfo(dbInfo);
    }
    super.buttonPressed(buttonId);
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) ConnectDatabaseExecutor(com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor)

Example 2 with ConnectDatabaseExecutor

use of com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor in project cubrid-manager by CUBRID.

the class QueryConnDialog method buttonPressed.

/**
	 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
	 * @param buttonId the id of the button that was pressed (see
	 *        <code>IDialogConstants.*_ID</code> constants)
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == TEST_CONNECT_ID || buttonId == CONNECT_ID || buttonId == SAVE_ID) {
        String name = queryConnNameText.getText();
        String dbName = connectionComp.getDatabaseText().getText();
        String brokerIp = connectionComp.getBrokerIpText().getText();
        String brokerPort = connectionComp.getBrokerPortText().getText();
        String userName = connectionComp.getUserNameText().getText();
        String password = connectionComp.getPasswordText().getText();
        String charset = connectionComp.getCharsetCombo().getText();
        String jdbcDriver = connectionComp.getJdbcCombo().getText();
        String jdbcAttrs = connectionComp.getAttrText().getText().trim();
        boolean isAutoCommit = connectionComp.isAutoCommit();
        // [TOOLS-2425]Support shard broker
        boolean isShard = connectionComp.getBtnShard().getSelection();
        int currentShardId = connectionComp.getCurShardId();
        int currentShardVal = connectionComp.getCurShardVal();
        int defaultShardQueryType = connectionComp.getShardQueryType();
        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);
        DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
        dbInfo.setBrokerIP(brokerIp);
        dbInfo.setBrokerPort(brokerPort);
        dbInfo.setCharSet(charset);
        dbInfo.setJdbcAttrs(jdbcAttrs);
        // [TOOLS-2425]Support shard broker
        dbInfo.setShard(isShard);
        dbInfo.setCurrentShardId(currentShardId);
        dbInfo.setCurrentShardVal(currentShardVal);
        dbInfo.setShardQueryType(defaultShardQueryType);
        DbUserInfo userInfo = new DbUserInfo();
        userInfo.setDbName(dbName);
        userInfo.setName(userName);
        userInfo.setNoEncryptPassword(password);
        dbInfo.setAuthLoginedDbUserInfo(userInfo);
        if (buttonId == TEST_CONNECT_ID || buttonId == CONNECT_ID) {
            TaskExecutor taskExcutor = new ConnectDatabaseExecutor(dbInfo);
            new ExecTaskWithProgress(taskExcutor).exec();
            if (!taskExcutor.isSuccess()) {
                return;
            }
            if (buttonId == TEST_CONNECT_ID) {
                CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgTestConnSuccess);
                return;
            }
        }
        if (buttonId == CONNECT_ID) {
            // check whether dba authorization
            IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
            checkTask.execute();
            userInfo.setDbaAuthority(checkTask.isDBAUser());
            dbInfo.setRunningType(DbRunningType.CS);
            dbInfo.getServerInfo().setConnected(true);
            dbInfo.setLogined(true);
            boolean userChanged = !name.equals(oldLoginUserName);
            fireLogoutEvent = oldDatabaseIsLogin && userChanged;
        }
        if (!isNewQueryConn && database != null) {
            boolean isContinue = CQBConnectionUtils.processConnectionLogout(database);
            if (!isContinue) {
                return;
            }
        }
        // If this is new connection,then warning charset setting
        if (isNewQueryConn) {
            boolean sureCharset = CommonUITool.openConfirmBox(Messages.bind(com.cubrid.cubridquery.ui.connection.Messages.msgConfirmCharset, charset));
            if (!sureCharset) {
                connectionComp.getCharsetCombo().setFocus();
                return;
            }
        }
        if (isNewQueryConn && (buttonId == CONNECT_ID || buttonId == SAVE_ID) && EditorConstance.getDefaultBackground().equals(getSelectedBackground())) {
            boolean surePurpose = CommonUITool.openConfirmBox(Messages.msgUseDefaultPurpose);
            if (!surePurpose) {
                selectColorCombo.expandMenu();
                return;
            }
        }
        CubridServer server = new CubridServer(name, name, null, null);
        server.setServerInfo(serverInfo);
        server.setType(NodeType.SERVER);
        String dbId = name + ICubridNodeLoader.NODE_SEPARATOR + name;
        if (isNewQueryConn) {
            database = new CubridDatabase(dbId, name);
        } else {
            database.setId(dbId);
            database.setLabel(name);
        }
        database.setDatabaseInfo(dbInfo);
        database.setServer(server);
        database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
        database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
        CubridNodeLoader loader = new CQBDbConnectionLoader();
        loader.setLevel(ICubridNodeLoader.FIRST_LEVEL);
        database.setLoader(loader);
        database.setAutoSavePassword(connectionComp.isAutoSavePassword());
        if (buttonId == CONNECT_ID || buttonId == SAVE_ID) {
            if (database != null) {
                DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, false);
                if (editorConfig == null) {
                    editorConfig = new DatabaseEditorConfig();
                }
                editorConfig.setBackGround(getSelectedBackground());
                editorConfig.setDatabaseComment(getDatabaseComment());
                QueryOptions.putEditorConfig(database, editorConfig, false);
            }
            newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
            if (isNewQueryConn) {
                CQBDBNodePersistManager.getInstance().fireAddDatabase(database);
            } else if (oldInfo != null) {
                CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
            }
        }
        QueryOptions.setAutoCommit(serverInfo, isAutoCommit);
    }
    setReturnCode(buttonId);
    close();
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) 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) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) IsDBAUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask) ConnectDatabaseExecutor(com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 3 with ConnectDatabaseExecutor

use of com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor in project cubrid-manager by CUBRID.

the class LoginQueryEditorDialog method buttonPressed.

/**
	 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
	 * @param buttonId the id of the button that was pressed (see
	 *        <code>IDialogConstants.*_ID</code> constants)
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == TEST_CONNECT_ID || buttonId == IDialogConstants.OK_ID) {
        String dbName = connectionComp.getDatabaseText().getText();
        String brokerIp = connectionComp.getBrokerIpText().getText();
        String brokerPort = connectionComp.getBrokerPortText().getText();
        String userName = connectionComp.getUserNameText().getText();
        String password = connectionComp.getPasswordText().getText();
        String charset = connectionComp.getCharsetCombo().getText();
        String jdbcDriver = connectionComp.getJdbcCombo().getText();
        String jdbcAttrs = connectionComp.getAttrText().getText().trim();
        boolean isShard = connectionComp.getBtnShard().getSelection();
        int currentShardId = connectionComp.getCurShardId();
        ServerInfo serverInfo = new ServerInfo();
        serverInfo.setServerName(DatabaseNavigatorMenu.SELF_DATABASE_ID);
        serverInfo.setHostAddress(brokerIp);
        serverInfo.setHostMonPort(Integer.parseInt(brokerPort));
        serverInfo.setHostJSPort(Integer.parseInt(brokerPort) + 1);
        serverInfo.setJdbcDriverVersion(jdbcDriver);
        DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
        dbInfo.setBrokerIP(brokerIp);
        dbInfo.setBrokerPort(brokerPort);
        dbInfo.setCharSet(charset);
        dbInfo.setJdbcAttrs(jdbcAttrs);
        dbInfo.setShard(isShard);
        dbInfo.setCurrentShardId(currentShardId);
        DbUserInfo userInfo = new DbUserInfo();
        userInfo.setDbName(dbName);
        userInfo.setName(userName);
        userInfo.setNoEncryptPassword(password);
        dbInfo.setAuthLoginedDbUserInfo(userInfo);
        TaskExecutor taskExcutor = new ConnectDatabaseExecutor(dbInfo);
        new ExecTaskWithProgress(taskExcutor).exec();
        if (!taskExcutor.isSuccess()) {
            return;
        }
        if (buttonId == TEST_CONNECT_ID) {
            CommonUITool.openInformationBox(com.cubrid.cubridquery.ui.connection.Messages.titleSuccess, com.cubrid.cubridquery.ui.connection.Messages.msgTestConnSuccess);
            return;
        }
        // check whether dba authorization
        IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
        checkTask.execute();
        userInfo.setDbaAuthority(checkTask.isDBAUser());
        dbInfo.setLogined(true);
        dbInfo.setRunningType(DbRunningType.CS);
        dbInfo.getServerInfo().setConnected(true);
        dbInfo.setLogined(true);
        CubridServer server = new CubridServer(DatabaseNavigatorMenu.SELF_DATABASE_ID, DatabaseNavigatorMenu.SELF_DATABASE_SELECTED_LABEL, null, null);
        server.setServerInfo(serverInfo);
        server.setType(NodeType.SERVER);
        DatabaseNavigatorMenu.SELF_DATABASE.setDatabaseInfo(dbInfo);
        DatabaseNavigatorMenu.SELF_DATABASE.setServer(server);
        DatabaseNavigatorMenu.SELF_DATABASE.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
        DatabaseNavigatorMenu.SELF_DATABASE.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
        DatabaseNavigatorMenu.SELF_DATABASE.setLoader(new CQBDbConnectionLoader());
    }
    super.buttonPressed(buttonId);
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CQBDbConnectionLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) IsDBAUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask) ConnectDatabaseExecutor(com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 4 with ConnectDatabaseExecutor

use of com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor in project cubrid-manager by CUBRID.

the class LoginDatabaseDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    final Composite composite = new Composite(parentComp, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.numColumns = 5;
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    Label userNameLabel = new Label(composite, SWT.LEFT);
    userNameLabel.setText(Messages.lblDbUserName);
    userNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    userNameText = new Text(composite, SWT.LEFT | SWT.BORDER);
    if (database != null && database.getUserName() != null) {
        userNameText.setText(database.getUserName());
    }
    userNameText.addModifyListener(this);
    userNameText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 4, 1, 100, -1));
    userNameText.setFocus();
    Label passwordLabel = new Label(composite, SWT.LEFT);
    passwordLabel.setText(Messages.lblDbPassword);
    passwordLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    passwordText = new Text(composite, SWT.LEFT | SWT.PASSWORD | SWT.BORDER);
    passwordText.setTextLimit(ValidateUtil.MAX_PASSWORD_LENGTH);
    passwordText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 4, 1, 100, -1));
    if (database != null && database.getPassword() != null && database.isAutoSavePassword()) {
        passwordText.setText(database.getPassword());
    }
    if (database != null && database.getUserName() != null) {
        passwordText.selectAll();
        passwordText.setFocus();
    }
    new Composite(composite, SWT.NONE).setLayoutData(CommonUITool.createGridData(1, 1, 0, 0));
    Button btnSavePassword = new Button(composite, SWT.CHECK);
    btnSavePassword.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_FILL, 1, 1, -1, -1));
    btnSavePassword.setText(Messages.btnSavePassword);
    if (database == null) {
        btnSavePassword.setSelection(true);
        isSavePassword = true;
    } else {
        btnSavePassword.setSelection(database.isAutoSavePassword());
        isSavePassword = database.isAutoSavePassword();
    }
    btnSavePassword.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            isSavePassword = !isSavePassword;
        }
    });
    Label backgroundLabel = new Label(composite, SWT.None);
    backgroundLabel.setText(Messages.lblBackground);
    backgroundLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, true);
    RGB selectedColor = null;
    if (editorConfig != null) {
        selectedColor = editorConfig.getBackGround();
    } else {
        selectedColor = EditorConstance.getDefaultBackground();
    }
    selectColorCombo = new SelectColorCombo(composite, SWT.BORDER, selectedColor);
    selectColorCombo.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_END, 2, 1, 110, -1));
    Label commentLabel = new Label(composite, SWT.None);
    commentLabel.setText(Messages.lblComment);
    commentLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, -1, -1));
    commentText = new Text(composite, SWT.BORDER);
    commentText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 4, 1, -1, -1));
    commentText.setTextLimit(64);
    if (editorConfig != null) {
        commentText.setText(StringUtil.nvl(editorConfig.getDatabaseComment()));
    }
    new Label(composite, SWT.None);
    Label commentDescLabel = new Label(composite, SWT.None);
    commentDescLabel.setText(Messages.lblDescComment);
    commentDescLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 4, 1, -1, -1));
    final Group brokerGroup = new Group(composite, SWT.NONE);
    {
        brokerGroup.setText(com.cubrid.common.ui.query.Messages.brokerGrp);
        brokerGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 5, 1, -1, -1));
        GridLayout brokerLayout = new GridLayout();
        brokerLayout.numColumns = 3;
        brokerLayout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        brokerLayout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        brokerLayout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        brokerLayout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        brokerGroup.setLayout(brokerLayout);
        final Label labelBrokerIp = new Label(brokerGroup, SWT.NONE);
        labelBrokerIp.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        labelBrokerIp.setText(com.cubrid.common.ui.query.Messages.brokerIP);
        brokerIpText = new Text(brokerGroup, SWT.BORDER);
        brokerIpText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
        final Label labelBrokerPort = new Label(brokerGroup, SWT.NONE);
        labelBrokerPort.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        labelBrokerPort.setText(com.cubrid.common.ui.query.Messages.brokerPort);
        brokerPortCombo = new Combo(brokerGroup, SWT.NONE);
        brokerPortCombo.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
        BrokerInfos brokerInfos = database.getServer().getServerInfo().getBrokerInfos();
        BrokerInfoList bis = brokerInfos == null ? null : brokerInfos.getBorkerInfoList();
        if (bis != null) {
            List<BrokerInfo> brokerInfoList = bis.getBrokerInfoList();
            for (BrokerInfo brokerInfo : brokerInfoList) {
                if (StringUtil.isEmpty(brokerInfo.getPort())) {
                    continue;
                }
                String status = "";
                if (!StringUtil.isEqualIgnoreCase(brokerInfos.getBrokerstatus(), "ON")) {
                    status = "OFF";
                } else {
                    status = !StringUtil.isEqualIgnoreCase(brokerInfo.getState(), "ON") ? "OFF" : "ON";
                }
                String text = brokerInfo.getName() + "[" + brokerInfo.getPort() + "/" + status + "]";
                brokerPortCombo.add(text);
                brokerPortCombo.setData(brokerInfo.getPort(), text);
                brokerPortCombo.setData(text, brokerInfo);
            }
        }
        Label charSetLbl = new Label(brokerGroup, SWT.CHECK);
        charSetLbl.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        charSetLbl.setText(com.cubrid.common.ui.query.Messages.lblCharSet);
        charsetCombo = new Combo(brokerGroup, SWT.BORDER);
        charsetCombo.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
        Button testConnectionButton = new Button(brokerGroup, SWT.None);
        testConnectionButton.setText(com.cubrid.common.ui.query.Messages.btnTestConnection);
        testConnectionButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        testConnectionButton.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                widgetDefaultSelected(e);
            }

            public void widgetDefaultSelected(SelectionEvent e) {
                final String dbUser = userNameText.getText();
                final String dbPassword = passwordText.getText();
                final DatabaseInfo dbInfo = database.getDatabaseInfo();
                final String brokerIP = brokerIpText.getText();
                final String brokerPort = getBrokerPort();
                final String dbName = dbInfo.getDbName();
                final ServerInfo serverInfo = dbInfo.getServerInfo();
                final String charset = dbInfo.getCharSet();
                final String driverVersion = serverInfo.getJdbcDriverVersion();
                // advanced jdbc settings
                final String jdbcAttrs = attrText.getText();
                final boolean isShard = dbInfo.isShard();
                TaskExecutor taskExcutor = new ConnectDatabaseExecutor(brokerIP, brokerPort, dbName, dbUser, dbPassword, charset, jdbcAttrs, driverVersion, false, isShard);
                new ExecTaskWithProgress(taskExcutor).exec();
                if (taskExcutor.isSuccess()) {
                    CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgTestConnSuccess);
                }
            }
        });
    }
    Group advancedOptionGroup = new Group(composite, SWT.NONE);
    {
        advancedOptionGroup.setText(Messages.grpAdvancedJDBC);
        advancedOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 5, 1, -1, -1));
        GridLayout brokerInfoGroupLayout = new GridLayout();
        brokerInfoGroupLayout.numColumns = 3;
        advancedOptionGroup.setLayout(brokerInfoGroupLayout);
        // JDBC attributes
        Label attrLabel = new Label(advancedOptionGroup, SWT.LEFT);
        attrLabel.setText(com.cubrid.common.ui.common.Messages.lblJdbcAttr);
        attrLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        attrText = new Text(advancedOptionGroup, SWT.LEFT | SWT.BORDER);
        attrText.setEditable(false);
        attrText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
        Button btnAttr = new Button(advancedOptionGroup, SWT.NONE);
        {
            btnAttr.setText(com.cubrid.common.ui.common.Messages.btnJdbcAttr);
            btnAttr.setLayoutData(CommonUITool.createGridData(1, 1, 80, -1));
            btnAttr.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent event) {
                    JdbcOptionDialog dialog = new JdbcOptionDialog(getShell(), attrText.getText());
                    if (IDialogConstants.OK_ID == dialog.open()) {
                        String jdbcOptions = dialog.getJdbcOptions();
                        attrText.setText(StringUtil.nvl(jdbcOptions));
                    }
                }
            });
        }
    }
    if (database != null && database.getDatabaseInfo() != null) {
        String jdbcAttrs = database.getDatabaseInfo().getJdbcAttrs();
        attrText.setText(StringUtil.nvl(jdbcAttrs));
        String brokerIp = QueryOptions.getBrokerIp(database.getDatabaseInfo());
        if (StringUtil.isEmpty(brokerIp)) {
            brokerIp = database.getServer().getHostAddress();
        }
        if (brokerIp != null) {
            brokerIpText.setText(brokerIp);
        }
        String brokerPort = QueryOptions.getBrokerPort(database.getDatabaseInfo());
        brokerPort = (String) brokerPortCombo.getData(brokerPort);
        if (brokerPort != null) {
            brokerPortCombo.setText(brokerPort);
        }
        String charset = QueryOptions.getCharset(database.getDatabaseInfo());
        charsetCombo.setItems(QueryOptions.getAllCharset(charset));
        if (charset != null && charset.trim().length() > 0) {
            charsetCombo.setText(charset);
        } else {
            charsetCombo.select(0);
        }
    }
    setTitle(Messages.titleLoginDbDialog);
    setMessage(Messages.msgLoginDbDialog);
    return parentComp;
}
Also used : Group(org.eclipse.swt.widgets.Group) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) Label(org.eclipse.swt.widgets.Label) SelectColorCombo(com.cubrid.common.ui.common.control.SelectColorCombo) Combo(org.eclipse.swt.widgets.Combo) BrokerInfoList(com.cubrid.cubridmanager.core.broker.model.BrokerInfoList) BrokerInfo(com.cubrid.cubridmanager.core.broker.model.BrokerInfo) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) BrokerInfoList(com.cubrid.cubridmanager.core.broker.model.BrokerInfoList) List(java.util.List) JdbcOptionDialog(com.cubrid.common.ui.common.dialog.JdbcOptionDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) RGB(org.eclipse.swt.graphics.RGB) SelectColorCombo(com.cubrid.common.ui.common.control.SelectColorCombo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) GridData(org.eclipse.swt.layout.GridData) ConnectDatabaseExecutor(com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)4 ConnectDatabaseExecutor (com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor)4 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)4 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)4 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)3 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)3 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)2 IsDBAUserTask (com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask)2 CQBDbConnectionLoader (com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader)2 SelectColorCombo (com.cubrid.common.ui.common.control.SelectColorCombo)1 JdbcOptionDialog (com.cubrid.common.ui.common.dialog.JdbcOptionDialog)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 CubridNodeLoader (com.cubrid.common.ui.spi.model.CubridNodeLoader)1 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)1 BrokerInfo (com.cubrid.cubridmanager.core.broker.model.BrokerInfo)1 BrokerInfoList (com.cubrid.cubridmanager.core.broker.model.BrokerInfoList)1 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)1 List (java.util.List)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1