use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig 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();
}
use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.
the class EditQueryConnAction method run.
/**
* Open the query connection
*/
public void run() {
// TODO remove later
CQBGroupNodePersistManager.getInstance().fix();
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
ISelectionProvider provider = getSelectionProvider();
if (!(provider instanceof TreeViewer)) {
return;
}
CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
if (cubridDatabases.length == 0) {
return;
}
ConnectionInfo oldInfo = null;
ConnectionInfo newInfo = null;
if (cubridDatabases.length > 1) {
MultiQueryConnEditDialog dialog = new MultiQueryConnEditDialog(getShell(), Arrays.asList(cubridDatabases));
if (dialog.open() != MultiQueryConnEditDialog.SAVE_ID) {
return;
}
List<CubridDatabase> newDBList = dialog.getNewDBList();
for (int i = 0; i < cubridDatabases.length; i++) {
CubridDatabase saveCubridDatabase = cubridDatabases[i];
CubridDatabase newCubridDatabase = newDBList.get(i);
oldInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(saveCubridDatabase);
newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(newCubridDatabase);
saveCubridDatabase.setLabel(newCubridDatabase.getLabel());
saveCubridDatabase.getDatabaseInfo().setDbName(newCubridDatabase.getDatabaseInfo().getDbName());
saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setName(newCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().getName());
saveCubridDatabase.setAutoSavePassword(newCubridDatabase.isAutoSavePassword());
if (saveCubridDatabase.isAutoSavePassword()) {
saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(newCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().getNoEncryptPassword());
} else {
saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(null);
}
saveCubridDatabase.getDatabaseInfo().setBrokerIP(newCubridDatabase.getDatabaseInfo().getBrokerIP());
saveCubridDatabase.getDatabaseInfo().setBrokerPort(newCubridDatabase.getDatabaseInfo().getBrokerPort());
DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(saveCubridDatabase, false);
if (editorConfig == null) {
editorConfig = new DatabaseEditorConfig();
editorConfig.setBackGround(EditorConstance.getDefaultBackground());
} else if (editorConfig.getBackGround() == null) {
editorConfig.setBackGround(EditorConstance.getDefaultBackground());
}
if (newCubridDatabase.getData(MultiQueryConnEditDialog.COMMENTKEY) != null) {
editorConfig.setDatabaseComment((String) newCubridDatabase.getData(MultiQueryConnEditDialog.COMMENTKEY));
}
QueryOptions.putEditorConfig(saveCubridDatabase, editorConfig, false);
CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
boolean isContinue = CQBConnectionUtils.processConnectionLogout(saveCubridDatabase);
if (isContinue) {
TreeViewer viewer = (TreeViewer) provider;
viewer.refresh(saveCubridDatabase, true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(saveCubridDatabase, CubridNodeChangedEventType.DATABASE_LOGOUT));
}
}
LayoutManager.getInstance().fireSelectionChanged(getSelection());
ActionManager.getInstance().fireSelectionChanged(getSelection());
CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
CQBDBNodePersistManager.getInstance().saveDatabases();
return;
}
CubridDatabase database = (CubridDatabase) cubridDatabases[0];
if (database.getParent() == null) {
CQBGroupNodePersistManager.getInstance();
}
String preName = (database == null || database.getServer() == null) ? "" : database.getServer().getName();
ServerInfo preServerInfo = (database == null || database.getServer() == null) ? null : database.getServer().getServerInfo();
oldInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
QueryConnDialog dialog = new QueryConnDialog(getShell(), database, false);
int returnCode = dialog.open();
if (returnCode == QueryConnDialog.CONNECT_ID) {
database.removeAllChild();
newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
TreeViewer treeViewer = (TreeViewer) provider;
CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
CQBDBNodePersistManager.getInstance().saveDatabases();
if (!preName.equals(database.getServer().getName())) {
QueryOptions.removePref(preServerInfo);
}
treeViewer.refresh(database, true);
treeViewer.expandToLevel(database, 1);
ActionManager.getInstance().fireSelectionChanged(getSelection());
LayoutManager.getInstance().fireSelectionChanged(getSelection());
if (dialog.isFireLogoutEvent()) {
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT));
}
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
try {
CommonUITool.openQueryEditor(database, true);
} catch (PartInitException e) {
LOGGER.error(e.getMessage(), e);
}
} else if (returnCode == QueryConnDialog.SAVE_ID) {
TreeViewer treeViewer = (TreeViewer) provider;
treeViewer.refresh(database, true);
treeViewer.expandToLevel(database, 1);
CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
CQBDBNodePersistManager.getInstance().saveDatabases();
}
}
use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.
the class ShortSetEditorConfigAction method run.
public void run() {
DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, false);
ShortSettingEditorConfigDialog dialog = new ShortSettingEditorConfigDialog(Display.getCurrent().getActiveShell(), editorConfig);
if (IDialogConstants.OK_ID == dialog.open()) {
editorConfig = dialog.getEditorConfig();
QueryOptions.putEditorConfig(database, editorConfig, false);
CQBDBNodePersistManager.getInstance().saveDatabases();
}
}
use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.
the class QueryEditorPart method refreshQueryOptions.
// /**
// * Set query connection
// *
// * @param queryConn Connection
// */
// public void setQueryConn(Connection queryConn) {
// this.queryConn = queryConn;
// }
/**
* When query options change or database and server refresh, refresh this
* query style
*/
public void refreshQueryOptions() {
CubridDatabase database = getSelectedDatabase();
boolean enabled = (database != DatabaseNavigatorMenu.NULL_DATABASE);
if (enabled && !connection.hasConnection()) {
this.initConnection(database);
}
enabled = enabled && connection.hasConnection();
if (enabled) {
for (CombinedQueryEditorComposite combinedQueryEditorComposite : getAllCombinedQueryEditorComposite()) {
combinedQueryEditorComposite.getMultiDBQueryComp().setMainDatabase(database);
}
}
queryPlanItem.setEnabled(enabled);
setPstmtParaItem.setEnabled(enabled);
ServerInfo serverInfo = getSelectedServer() == null ? null : getSelectedServer().getServerInfo();
String fontString = QueryOptions.getFontString(serverInfo);
Font font = ResourceManager.getFont(fontString);
if (font == null) {
String[] fontData = QueryOptions.getDefaultFont();
font = ResourceManager.getFont(fontData[0], Integer.valueOf(fontData[1]), Integer.valueOf(fontData[2]));
}
int[] fontColor = QueryOptions.getFontColor(serverInfo);
final Color color = ResourceManager.getColor(fontColor[0], fontColor[1], fontColor[2]);
// Change SQL editor font
if (font != null) {
getSqlTextEditor().setFont(font);
}
getSqlTextEditor().setForeground(color);
for (CombinedQueryEditorComposite combinedQueryEditorComposite : getAllCombinedQueryEditorComposite()) {
combinedQueryEditorComposite.getSqlEditorComp().getTextViewer().refresh();
// Change the table result font
QueryResultComposite queryResultComp = combinedQueryComposite.getQueryResultComp();
if (queryResultComp == null || queryResultComp.isDisposed()) {
return;
}
Table resultTable = queryResultComp.getResultTable();
if (resultTable != null && !resultTable.isDisposed()) {
resultTable.setFont(font);
resultTable.setForeground(color);
}
// Update editor config
if (database != null) {
DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, isCMMode);
if (editorConfig != null && editorConfig.getBackGround() != null) {
setEditorBackground(ResourceManager.getColor(editorConfig.getBackGround()));
} else {
setEditorBackground(ResourceManager.getColor(EditorConstance.getDefaultBackground()));
}
}
//query plan
combinedQueryComposite.getQueryPlanResultComp().fillPlanHistory();
//sql history
combinedQueryComposite.getRecentlyUsedSQLComposite().fillRecentlyUsedSQLList();
/*Fire database changed*/
combinedQueryComposite.fireDatabaseChanged(database);
}
}
use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.
the class ExportConnectionUtil method writeToXlsx.
/**
* Write to xlsx
*
* @throws IOException
*/
private void writeToXlsx() throws IOException {
// FIXME split logic and ui
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(Messages.sheetNameConnections);
String sheetRef = sheet.getPackagePart().getPartName().getName().substring(1);
File tmp = File.createTempFile("Connections", ".xml");
Map<String, File> fileMap = new HashMap<String, File>();
fileMap.put(sheetRef, tmp);
OutputStreamWriter writer = null;
XlsxWriterHelper xlsxWriterhelper = null;
XlsxWriterHelper.SpreadsheetWriter sheetWriter = null;
try {
writer = new OutputStreamWriter(new FileOutputStream(tmp), "UTF-8");
xlsxWriterhelper = new XlsxWriterHelper();
sheetWriter = new XlsxWriterHelper.SpreadsheetWriter(writer);
sheetWriter.setCharset("UTF-8");
sheetWriter.beginSheet();
/* Write the header */
int styleIndex = ((XSSFCellStyle) xlsxWriterhelper.getStyles(workbook).get("header")).getIndex();
sheetWriter.insertRow(0);
sheetWriter.createCell(0, Messages.nameColumn, styleIndex);
sheetWriter.createCell(1, Messages.iPColumn, styleIndex);
sheetWriter.createCell(2, Messages.portColumn, styleIndex);
sheetWriter.createCell(3, Messages.userColumn, styleIndex);
sheetWriter.createCell(4, Messages.commentColumn, styleIndex);
sheetWriter.createCell(5, Messages.javaUrlColumn, styleIndex);
sheetWriter.createCell(6, Messages.phpUrlColumn, styleIndex);
sheetWriter.endRow();
/* Write the data */
int rowIndex = 1;
for (CubridDatabase database : input) {
if (database == null) {
continue;
}
DatabaseInfo dbInfo = database.getDatabaseInfo();
if (dbInfo == null) {
continue;
}
sheetWriter.insertRow(rowIndex++);
/* name */
sheetWriter.createCell(0, dbInfo.getDbName());
/* ip */
sheetWriter.createCell(1, dbInfo.getBrokerIP());
/* port */
sheetWriter.createCell(2, dbInfo.getBrokerPort());
/* user */
sheetWriter.createCell(3, getDbUser(dbInfo));
/* comment */
String comment = "";
DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, managerMode);
if (editorConfig != null && editorConfig.getDatabaseComment() != null) {
comment = editorConfig.getDatabaseComment();
}
sheetWriter.createCell(4, comment);
/* javaUrl */
String url = NodeUtil.getJavaConnectionUrl(dbInfo);
sheetWriter.createCell(5, url);
/* phpUrl */
String phpUrl = NodeUtil.getPHPConnectionUrl(dbInfo);
sheetWriter.createCell(6, phpUrl);
sheetWriter.endRow();
}
XlsxWriterHelper.writeSheetWriter(sheetWriter);
} finally {
XlsxWriterHelper.writeWorkbook(workbook, xlsxWriterhelper, fileMap, file);
}
}
Aggregations