Search in sources :

Example 11 with DatabaseEditorConfig

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

the class ExportConnectionUtil method writeToXls.

/**
	 * Write to xls
	 *
	 * @throws IOException
	 * @throws RowsExceededException
	 * @throws WriteException
	 */
private void writeToXls() throws IOException, RowsExceededException, WriteException {
    // FIXME split logic and ui
    WritableWorkbook workbook = null;
    WorkbookSettings workbookSettings = new WorkbookSettings();
    workbookSettings.setEncoding("UTF-8");
    workbook = Workbook.createWorkbook(file, workbookSettings);
    WritableSheet sheet = workbook.createSheet(Messages.sheetNameConnections, 0);
    WritableFont wf = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false);
    WritableCellFormat wcf = new WritableCellFormat(wf);
    jxl.write.Label label = null;
    label = new jxl.write.Label(0, 0, Messages.nameColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(1, 0, Messages.iPColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(2, 0, Messages.portColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(3, 0, Messages.userColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(4, 0, Messages.commentColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(5, 0, Messages.javaUrlColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(6, 0, Messages.phpUrlColumn, wcf);
    sheet.addCell(label);
    int index = 1;
    for (CubridDatabase database : input) {
        if (database == null) {
            continue;
        }
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            continue;
        }
        /* name */
        sheet.addCell(new jxl.write.Label(0, index, dbInfo.getDbName()));
        /* ip */
        sheet.addCell(new jxl.write.Label(1, index, dbInfo.getBrokerIP()));
        /* port */
        sheet.addCell(new jxl.write.Label(2, index, dbInfo.getBrokerPort()));
        /* user */
        sheet.addCell(new jxl.write.Label(3, index, getDbUser(dbInfo)));
        /* comment */
        String comment = "";
        DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, managerMode);
        if (editorConfig != null && editorConfig.getDatabaseComment() != null) {
            comment = editorConfig.getDatabaseComment();
        }
        sheet.addCell(new jxl.write.Label(4, index, comment));
        /* java url */
        String javaUrl = NodeUtil.getJavaConnectionUrl(dbInfo);
        sheet.addCell(new jxl.write.Label(5, index, javaUrl));
        /* php url */
        String phpUrl = NodeUtil.getPHPConnectionUrl(dbInfo);
        sheet.addCell(new jxl.write.Label(6, index, phpUrl));
        index++;
    }
    workbook.write();
    workbook.close();
}
Also used : WritableWorkbook(jxl.write.WritableWorkbook) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WritableFont(jxl.write.WritableFont) WorkbookSettings(jxl.WorkbookSettings) WritableSheet(jxl.write.WritableSheet) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) WritableCellFormat(jxl.write.WritableCellFormat) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 12 with DatabaseEditorConfig

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

the class ExportConnectionUtil method writeToTxt.

private void writeToTxt() throws IOException {
    int[] columnMaxLength = { 0, 0, 0, 0, 0, 0, 0, 0 };
    columnMaxLength[0] = Messages.nameColumn.length();
    columnMaxLength[1] = Messages.iPColumn.length();
    columnMaxLength[2] = Messages.portColumn.length();
    columnMaxLength[3] = Messages.userColumn.length();
    columnMaxLength[4] = Messages.commentColumn.length();
    columnMaxLength[5] = Messages.javaUrlColumn.length();
    columnMaxLength[6] = Messages.phpUrlColumn.length();
    for (CubridDatabase database : input) {
        if (database == null) {
            continue;
        }
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            continue;
        }
        if (dbInfo.getDbName() != null && columnMaxLength[0] < dbInfo.getDbName().length()) {
            columnMaxLength[0] = dbInfo.getDbName().length();
        }
        if (dbInfo.getBrokerIP() != null && columnMaxLength[1] < dbInfo.getBrokerIP().length()) {
            columnMaxLength[1] = dbInfo.getBrokerIP().length();
        }
        if (dbInfo.getBrokerPort() != null && columnMaxLength[2] < dbInfo.getBrokerPort().length()) {
            columnMaxLength[2] = dbInfo.getBrokerPort().length();
        }
        if (columnMaxLength[3] < getDbUser(dbInfo).length()) {
            columnMaxLength[3] = getDbUser(dbInfo).length();
        }
        DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, managerMode);
        if (editorConfig != null && editorConfig.getDatabaseComment() != null) {
            if (columnMaxLength[4] < editorConfig.getDatabaseComment().length()) {
                columnMaxLength[4] = editorConfig.getDatabaseComment().length();
            }
        }
        String javaUrl = NodeUtil.getJavaConnectionUrl(dbInfo);
        if (javaUrl != null && columnMaxLength[5] < javaUrl.length()) {
            columnMaxLength[5] = javaUrl.length();
        }
        String phpUrl = NodeUtil.getPHPConnectionUrl(dbInfo);
        if (phpUrl != null && columnMaxLength[6] < phpUrl.length()) {
            columnMaxLength[6] = phpUrl.length();
        }
    }
    BufferedWriter fs = null;
    try {
        fs = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
        /* Write the header */
        fs.write(getWrapValue(Messages.nameColumn, columnMaxLength[0]));
        fs.write(getWrapValue(Messages.iPColumn, columnMaxLength[1]));
        fs.write(getWrapValue(Messages.portColumn, columnMaxLength[2]));
        fs.write(getWrapValue(Messages.userColumn, columnMaxLength[3]));
        fs.write(getWrapValue(Messages.commentColumn, columnMaxLength[4]));
        fs.write(getWrapValue(Messages.javaUrlColumn, columnMaxLength[5]));
        fs.write(getWrapValue(Messages.phpUrlColumn, columnMaxLength[6]));
        fs.write(StringUtil.NEWLINE);
        /* Write the data */
        for (CubridDatabase database : input) {
            if (database == null) {
                continue;
            }
            DatabaseInfo dbInfo = database.getDatabaseInfo();
            if (dbInfo == null) {
                continue;
            }
            /* name */
            fs.write(getWrapValue(dbInfo.getDbName(), columnMaxLength[0]));
            /* ip */
            fs.write(getWrapValue(dbInfo.getBrokerIP(), columnMaxLength[1]));
            /* port */
            fs.write(getWrapValue(dbInfo.getBrokerPort(), columnMaxLength[2]));
            /* user */
            fs.write(getWrapValue(getDbUser(dbInfo), columnMaxLength[3]));
            /* comment */
            String comment = "";
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, managerMode);
            if (editorConfig != null && editorConfig.getDatabaseComment() != null) {
                comment = editorConfig.getDatabaseComment();
            }
            fs.write(getWrapValue(comment, columnMaxLength[4]));
            /* java url */
            String javaUrl = NodeUtil.getJavaConnectionUrl(dbInfo);
            fs.write(getWrapValue(javaUrl == null ? "" : javaUrl, columnMaxLength[5]));
            /* php url */
            String phpUrl = NodeUtil.getPHPConnectionUrl(dbInfo);
            fs.write(getWrapValue(phpUrl == null ? "" : phpUrl, columnMaxLength[6]));
            fs.write(StringUtil.NEWLINE);
        }
        fs.flush();
    } finally {
        FileUtil.close(fs);
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig) BufferedWriter(java.io.BufferedWriter)

Example 13 with DatabaseEditorConfig

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

the class DBParameter method loadDatabases.

/**
	 *
	 * Load added databases from xml memento
	 *
	 * @param memento IXMLMemento
	 */
protected void loadDatabases(IXMLMemento memento) {
    IXMLMemento[] children = memento == null ? null : memento.getChildren("database");
    for (int i = 0; children != null && i < children.length; i++) {
        String address = children[i].getString("address");
        String port = children[i].getString("port");
        String dbName = children[i].getString("dbName");
        String dbUser = children[i].getString("dbUser");
        String encryptPassword = children[i].getString("dbPassword");
        String dbPassword = "";
        if (!StringUtil.isEmpty(encryptPassword)) {
            dbPassword = CipherUtils.decrypt(encryptPassword);
        }
        String jdbcAttrs = children[i].getString("jdbcAttrs");
        if (jdbcAttrs == null)
            jdbcAttrs = "";
        boolean savePassword = children[i].getBoolean("savePassword");
        String key = getMapKey(dbUser, dbName, address, port);
        DBParameter dbParameter = databaseMap.get(key);
        if (dbParameter == null) {
            dbParameter = new DBParameter(dbName, address, port, dbUser, dbPassword, jdbcAttrs, savePassword);
            databaseMap.put(key, dbParameter);
        }
        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"));
        }
        QueryOptions.putEditorConfig(dbUser, dbName, address, port, null, editorConfig, true);
    }
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) RGB(org.eclipse.swt.graphics.RGB) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 14 with DatabaseEditorConfig

use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig 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 15 with DatabaseEditorConfig

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

the class ShortSetEditorConfigAction method run.

@Override
public void run() {
    boolean isCMMode = PerspectiveManager.getInstance().isManagerMode();
    DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, isCMMode);
    ShortSettingEditorConfigDialog dialog = new ShortSettingEditorConfigDialog(Display.getCurrent().getActiveShell(), editorConfig);
    if (IDialogConstants.OK_ID == dialog.open()) {
        editorConfig = dialog.getEditorConfig();
        QueryOptions.putEditorConfig(database, editorConfig, isCMMode);
        CMDBNodePersistManager.getInstance().addDatabase(database, editorConfig);
    }
}
Also used : ShortSettingEditorConfigDialog(com.cubrid.cubridmanager.ui.common.dialog.ShortSettingEditorConfigDialog) 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