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();
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations