use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class FavoriteQueryNavigatorView method getCurrentDatabase.
/**
* Return current selected database from the navigation tree.
* @return CubridDatabase
*/
private CubridDatabase getCurrentDatabase() {
CubridDatabase cubridDatabase = null;
CubridNavigatorView nav = CubridNavigatorView.findNavigationView();
if (nav != null) {
TreeItem[] items = nav.getSelectedItems();
if (items.length > 0 && items[0] != null && items[0].getData() instanceof ISchemaNode) {
ISchemaNode node = (ISchemaNode) items[0].getData();
CubridDatabase tempDatabase = node.getDatabase();
if (tempDatabase != null && tempDatabase.isLogined()) {
cubridDatabase = tempDatabase;
}
}
}
return cubridDatabase;
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class FavoriteQueryNavigatorView method executeSql.
/**
* Execute selected queries
*/
private void executeSql() {
CubridDatabase cubridDatabase = getCurrentDatabase();
if (cubridDatabase == null || cubridDatabase.getDatabaseInfo() == null) {
CommonUITool.openErrorBox(com.cubrid.common.ui.query.Messages.errNoConnectionBatchRun);
return;
}
// Judge the file is exist
int[] indexes = tv.getTable().getSelectionIndices();
List<Map<String, String>> list = FavoriteQueryPersistUtil.getInstance().getListData();
for (int i = 0; i < indexes.length; i++) {
Map<String, String> item = list.get(indexes[i]);
String filename = item.get("1");
String fullpath = item.get("4") + File.separator + filename;
if (!new File(fullpath).exists()) {
String msg = Messages.bind(com.cubrid.common.ui.query.Messages.errFileNotExist, fullpath);
CommonUITool.openErrorBox(msg);
return;
}
}
String targetDbName = cubridDatabase.getDatabaseInfo().getDbName() + "@" + cubridDatabase.getServer().getServerInfo().getHostAddress();
String msg = Messages.bind(com.cubrid.common.ui.query.Messages.msgDoYouWantExecuteSql, targetDbName);
if (!CommonUITool.openConfirmBox(msg)) {
return;
}
String charset = StringUtil.getDefaultCharset();
ImportConfig importConfig = new ImportConfig();
importConfig.setImportType(ImportConfig.IMPORT_FROM_SQL);
importConfig.setThreadCount(1);
importConfig.setCommitLine(100);
Set<String> charsets = new HashSet<String>();
for (int i = 0; i < indexes.length; i++) {
Map<String, String> item = list.get(indexes[i]);
String filename = item.get("1");
String fullpath = item.get("4") + File.separator + filename;
charset = item.get("5");
if (StringUtil.isEmpty(charset)) {
charset = StringUtil.getDefaultCharset();
} else {
charsets.add(charset);
}
TableConfig fileConfig = new TableConfig(filename);
fileConfig.setFilePath(fullpath);
fileConfig.setFileType(TableConfig.TYPE_DATA);
importConfig.addTableConfig(fileConfig);
}
importConfig.setFilesCharset(charset);
if (charsets.size() > 1) {
msg = Messages.bind(com.cubrid.common.ui.query.Messages.msgDoYouWantExecuteWithNotSameCharset, charset);
if (!CommonUITool.openConfirmBox(msg)) {
return;
}
}
ImportDataEditorInput input = new ImportDataEditorInput();
input.setDatabase(cubridDatabase);
input.setImportConfig(importConfig);
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, ImportDataViewPart.ID);
} catch (Exception e) {
CommonUITool.openErrorBox(Display.getCurrent().getActiveShell(), e.getMessage());
}
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class ExportConnectionUtil method buttonPressed.
/**
* Call this method when the button in button bar is pressed
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == COPY_CLIPBOARD_ID) {
List<CubridDatabase> databaseList = getCheckedDatabases();
if (databaseList.size() <= 0) {
CommonUITool.openErrorBox(getShell(), Messages.expConDialogCopyErrorMsg);
return;
}
StringBuilder sb = new StringBuilder();
for (CubridDatabase db : databaseList) {
if (sb.length() > 0) {
sb.append(StringUtil.NEWLINE);
}
sb.append(NodeUtil.getJavaConnectionUrl(db.getDatabaseInfo()));
}
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });
CommonUITool.openInformationBox(Messages.titleSuccess, Messages.expConDialogCopySucessMsg);
return;
} else if (buttonId == IDialogConstants.OK_ID) {
if (!verify()) {
return;
}
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE | SWT.APPLICATION_MODAL);
String[] filterExtensions = new String[] { "*.xls" };
//Windows wild cards
dialog.setFilterExtensions(filterExtensions);
String fileName = dialog.open();
if (fileName == null) {
return;
}
/*Process the file extensions*/
if (!ExportConnectionUtil.isTxtFile(fileName) && !ExportConnectionUtil.isXlsFile(fileName) && !ExportConnectionUtil.isXlsxFile(fileName)) {
int filterIndex = dialog.getFilterIndex();
if (filterIndex == 0 || filterIndex == 2) {
fileName = fileName + ".xls";
} else if (filterIndex == 1) {
fileName = fileName + ".txt";
}
}
TaskExecutor taskExec = new CommonTaskExec(Messages.nameExportConnectionTask);
File file = new File(fileName);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
LOGGER.error("Create file failed:" + e.getMessage());
}
}
ExportConnectionsTask task = new ExportConnectionsTask(getCheckedDatabases(), file);
taskExec.addTask(task);
new ExecTaskWithProgress(taskExec).busyCursorWhile();
if (taskExec.isSuccess()) {
CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgConnectionUrlExported);
super.okPressed();
}
}
super.buttonPressed(buttonId);
}
use of com.cubrid.common.ui.spi.model.CubridDatabase 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;
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class BackupDatabaseAction method run.
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
ISchemaNode node = (ISchemaNode) obj[0];
final CubridDatabase database = node.getDatabase();
final BackupDatabaseDialog dialog = new BackupDatabaseDialog(getShell());
dialog.setDatabase(database);
final Shell shell = getShell();
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
monitor.beginTask(Messages.loadDbBackupInfoTaskName, IProgressMonitor.UNKNOWN);
for (ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
if (task instanceof GetDbBackupInfoTask) {
GetDbBackupInfoTask getDbBackupInfoTask = (GetDbBackupInfoTask) task;
dialog.setDbBackupInfo(getDbBackupInfoTask.getDbBackupInfo());
} else if (task instanceof GetCubridConfParameterTask) {
GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
Map<String, String> commonParas = confParas.get(ConfConstants.COMMON_SECTION_NAME);
Map<String, String> dbParas = confParas.get("[@" + database.getLabel() + "]");
String str = dbParas == null ? null : dbParas.get(ConfConstants.REPLICATION);
boolean isReplication = "yes".equals(str);
if (!isReplication) {
str = commonParas == null ? null : commonParas.get(ConfConstants.REPLICATION);
isReplication = "yes".equals(str);
}
dialog.setReplication(isReplication);
}
}
return true;
}
};
ServerInfo serverInfo = database.getServer().getServerInfo();
GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
taskExcutor.addTask(getCubridConfParameterTask);
GetDbBackupInfoTask getDbBackupInfoTask = new GetDbBackupInfoTask(serverInfo);
getDbBackupInfoTask.setDbName(database.getLabel());
taskExcutor.addTask(getDbBackupInfoTask);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (taskExcutor.isSuccess()) {
dialog.open();
}
}
Aggregations