use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.
the class ERSchemaEditor method compareTableSchemas.
public void compareTableSchemas(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, SchemaInfo> schemaInfos) {
final List<TableSchemaCompareModelInputLazy> input = new ArrayList<TableSchemaCompareModelInputLazy>();
ITask reportBugTask = new AbstractUITask() {
private boolean success = false;
public void cancel() {
}
public void finish() {
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return success;
}
public void execute(IProgressMonitor monitor) {
CubridDatabase database = erSchema.getCubridDatabase();
List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(database);
final CubridDatabase virtualDb = new CubridDatabase(modelName, modelName);
virtualDb.setVirtual(true);
DatabaseInfo info = database.getDatabaseInfo();
virtualDb.setDatabaseInfo(info);
WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info);
wrappedDatabaseInfo.addSchemaInfos(schemaInfos);
wrappedDatabaseInfo.addTableSchemas(tableSchema);
ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
TableSchemaModel leftModel = TableSchemaCompareUtil.createTableSchemaModel(leftDbTableInfoList);
TableSchemaModel rightModel = new TableSchemaModel();
rightModel.getTableSchemaMap().putAll(tableSchema);
TableSchemaComparator comparator = new TableSchemaComparator(database, virtualDb);
TableSchemaCompareModel model = comparator.compare(leftModel, rightModel);
model.setSourceDB(database);
model.setTargetDB(virtualDb);
input.add(new TableSchemaCompareModelInputLazy(model));
success = true;
}
};
TaskExecutor taskExecutor = new CommonTaskExec(com.cubrid.common.ui.common.Messages.titleSchemaComparison);
taskExecutor.addTask(reportBugTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input.get(0), TableSchemaCompareInfoPart.ID);
} catch (Exception e) {
}
}
}
use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.
the class ERSchemaEditor method syncComments.
/**
* sync table comments to db tables.
*
* @return void
*/
public void syncComments() {
DatabaseInfo info = database.getDatabaseInfo();
if (info == null) {
CommonUITool.openErrorBox(Messages.errNoDatabase);
return;
}
if (!info.isLogined()) {
CommonUITool.openErrorBox(Messages.msgDBNotLogin);
return;
}
ServerInfo serverInfo = info.getServerInfo();
if (serverInfo != null && !serverInfo.isConnected()) {
CommonUITool.openErrorBox(Messages.msgDBNotLogin);
return;
}
boolean isSupportTableComment = false;
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(info, false);
isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(info, conn);
if (!isSupportTableComment) {
CommonUITool.openErrorBox(Messages.cannotSyncComments);
return;
}
} catch (Exception e) {
LOGGER.error("", e);
} finally {
QueryUtil.freeQuery(conn);
}
if (!CommonUITool.openConfirmBox(getSite().getShell(), Messages.bind(Messages.msgConfirmSyncComments, database.getLabel()))) {
return;
}
CommonTaskExec taskJobExec = new CommonTaskExec(null);
List<UpdateDescriptionTask> updateDescTasks = getUpdateDescriptionTaskList(info);
for (UpdateDescriptionTask task : updateDescTasks) {
taskJobExec.addTask(task);
}
if (updateDescTasks.size() == 0) {
CommonUITool.openInformationBox(Messages.msgNoComments);
return;
}
new ExecTaskWithProgress(taskJobExec).exec();
Set<String> failTables = new HashSet<String>();
for (UpdateDescriptionTask task : updateDescTasks) {
if (!task.isSuccess()) {
failTables.add(task.getTableName());
}
}
if (failTables.size() == 0) {
CommonUITool.openInformationBox(Messages.msgSuccessSyncComments);
} else {
CommonUITool.openErrorBox(Messages.bind(Messages.errSyncComments, failTables.toString()));
}
}
use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.
the class QueryExecuter method createContextMenuItems.
private void createContextMenuItems() {
Menu menu = new Menu(queryEditor.getEditorSite().getShell(), SWT.POP_UP);
final MenuItem itemInsert = new MenuItem(menu, SWT.PUSH);
itemInsert.setText(Messages.insertRecord);
itemInsert.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (!getEditable()) {
CommonUITool.openErrorBox(Display.getDefault().getActiveShell(), Messages.errNotEditable);
return;
}
insertSaveItem.setEnabled(getEditable());
rollbackModifiedItem.setEnabled(getEditable());
addNewItem();
}
});
final MenuItem itemCopy = new MenuItem(menu, SWT.PUSH);
itemCopy.setText(Messages.copyClipBoard);
final MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
itemDelete.setText(Messages.delete);
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemDetail = new MenuItem(menu, SWT.PUSH);
itemDetail.setText(Messages.detailView);
itemDetail.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
List<Point> selectedList = selectableSupport.getSelectedLocations();
Point location = selectedList.get(0);
if (location == null) {
CommonUITool.openErrorBox(Messages.errShowDetailFailed);
return;
}
//Bug fixed by Kevin.Qian. FYI. allDataList is a global query result to the current query.
int pageBeginIndex = (queryInfo.getCurrentPage() - 1) * queryInfo.getPageSize();
Map<String, CellValue> map = allDataList.get(pageBeginIndex + location.y);
TableItem item = tblResult.getItem(location.y);
ColumnInfo colInfo = allColumnList.get(location.x - 1);
RowDetailDialog dialog = new RowDetailDialog(tblResult.getShell(), allColumnList, map, item, colInfo.getName(), executer);
dialog.open();
}
});
tblResult.setMenu(menu);
tblResult.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
// Point pt = new Point(event.x, event.y);
// itemOid.setEnabled(false);
int index = tblResult.getSelectionIndex();
int count = tblResult.getItemCount();
if (index < 0 || index >= count) {
return;
}
// final TableItem item = tblResult.getItem(index);
// for (int i = 0; i < tblResult.getColumnCount(); i++) {
// Rectangle rect = item.getBounds(i);
// if (rect.contains(pt)) {
// selColumnName = tblResult.getColumn(i).getText();
//// Object value = item.getData(i + "");
//// String text = item.getText(i);
//// if (!DataType.VALUE_NULL.equals(value) && containsOIDs(tblResult.getColumn(i).getText())
//// && !DataType.VALUE_NONE.equals(text)) {
//// itemOid.setEnabled(true);
//// } else {
//// itemOid.setEnabled(false);
//// }
//
// }
// }
}
});
final MenuItem itemExportAll = new MenuItem(menu, SWT.PUSH);
itemExportAll.setText(Messages.allExport);
final MenuItem itemExportSelection = new MenuItem(menu, SWT.PUSH);
itemExportSelection.setText(Messages.selectExport);
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemMakeInsertQuery = new MenuItem(menu, SWT.PUSH);
itemMakeInsertQuery.setText(Messages.makeInsertFromSelectedRecord);
itemMakeInsertQuery.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_insert.png"));
final MenuItem itemMakeUpdateQuery = new MenuItem(menu, SWT.PUSH);
itemMakeUpdateQuery.setText(Messages.makeUpdateFromSelectedRecord);
itemMakeUpdateQuery.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_update.png"));
if (isEmpty()) {
itemExportAll.setEnabled(false);
itemExportSelection.setEnabled(false);
itemDetail.setEnabled(false);
}
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent event) {
List<Point> selectedList = selectableSupport.getSelectedLocations();
TableItem[] tblItems = selectableSupport.getSelectedTableItems();
boolean selectedCol = selectableSupport.hasSelected();
boolean enableItemDetail = (selectedList != null && selectedList.size() == 1);
itemExportSelection.setEnabled(selectedCol);
itemCopy.setEnabled(selectedCol);
if (allDataList.size() > 0) {
itemExportAll.setEnabled(true);
} else {
itemExportAll.setEnabled(false);
}
if (executer.getQueryEditor() != null && executer.getQueryEditor().getDatabaseInfo() != null && executer.getQueryEditor().getDatabaseInfo().equals(executer.getDatabaseInfo())) {
itemInsert.setEnabled(isEditMode());
itemDetail.setEnabled(enableItemDetail);
itemDelete.setEnabled(getEditable() && isEditMode());
} else {
itemInsert.setEnabled(false);
itemDetail.setEnabled(false);
itemDelete.setEnabled(false);
}
for (int i = 0; i < tblItems.length; i++) {
if (isEditMode() && getEditable() && tblItems[i].getText(1).equals(DataType.VALUE_NONE)) {
itemDelete.setEnabled(false);
}
}
}
});
itemCopy.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
copySelectedItems();
}
});
itemCopy.setAccelerator(SWT.CTRL + 'c');
itemDelete.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (isEditMode()) {
deleteRecord(tblResult, null);
}
}
});
itemExportAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
ExportResultDialog dialog = new ExportResultDialog(tblResult.getShell(), database, Messages.msgExportAllResults);
if (IDialogConstants.OK_ID == dialog.open()) {
ExportQueryResultTaskExecutor task = new ExportQueryResultTaskExecutor(dialog.getFile(), dialog.getFileCharset(), allColumnList, allDataList, false);
new ExecTaskWithProgress(task).exec();
}
}
});
// itemOid.addSelectionListener(new SelectionAdapter() {
// /**
// * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
// * @param event an event containing information about the
// * selection
// */
// public void widgetSelected(SelectionEvent event) {
// openOidNavigator(button2Position);
// }
//
// });
itemExportSelection.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
ExportResultDialog dialog = new ExportResultDialog(tblResult.getShell(), database, Messages.msgExportSelectedResults);
if (IDialogConstants.OK_ID == dialog.open()) {
ExportQueryResultTaskExecutor task = new ExportQueryResultTaskExecutor(dialog.getFile(), dialog.getFileCharset(), tblResult, selectableSupport.getSelectedTableItems(), false);
new ExecTaskWithProgress(task).exec();
}
}
});
itemMakeInsertQuery.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
String text = makeInsertQueryWithSelectedRecords();
CommonUITool.copyContentToClipboard(text);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
itemMakeUpdateQuery.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
String text = makeUpdateQueryWithSelectedRecords();
CommonUITool.copyContentToClipboard(text);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.
the class UserManagementWizard method performFinish.
/**
* Called when user clicks Finish
*
* @return boolean
*/
public boolean performFinish() {
final String userId = generalInfoPage.getUserId();
final String password = generalInfoPage.getPassword();
final String dbCreationAuth = generalInfoPage.getDbCreationAuth();
final String brokerAuth = generalInfoPage.getBrokerAuth();
final String statusMonitorAuth = generalInfoPage.getStatusMonitorAuth();
final List<DatabaseInfo> authDatabaselist = new ArrayList<DatabaseInfo>();
final Shell shell = getShell();
final String taskName = Messages.bind(Messages.updateUserTaskName, userId);
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
monitor.beginTask(taskName, 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;
}
}
ServerUserInfo loginedUserInfo = server.getServerInfo().getLoginedUserInfo();
if (userInfo == null) {
userInfo = new ServerUserInfo(userId, password);
} else {
userInfo.setPassword(password);
}
if (userInfo.getUserName().equals(loginedUserInfo.getUserName())) {
loginedUserInfo.setPassword(password);
}
if (!userInfo.isAdmin()) {
if (dbCreationAuth.equals(DbCreateAuthType.AUTH_NONE.getText())) {
userInfo.setDbCreateAuthType(DbCreateAuthType.AUTH_NONE);
} else if (dbCreationAuth.equals(DbCreateAuthType.AUTH_ADMIN.getText())) {
userInfo.setDbCreateAuthType(DbCreateAuthType.AUTH_ADMIN);
}
if (brokerAuth.equals(CasAuthType.AUTH_NONE.getText())) {
userInfo.setCasAuth(CasAuthType.AUTH_NONE);
} else if (brokerAuth.equals(CasAuthType.AUTH_ADMIN.getText())) {
userInfo.setCasAuth(CasAuthType.AUTH_ADMIN);
} else if (brokerAuth.equals(CasAuthType.AUTH_MONITOR.getText())) {
userInfo.setCasAuth(CasAuthType.AUTH_MONITOR);
}
if (statusMonitorAuth.equals(StatusMonitorAuthType.AUTH_NONE.getText())) {
userInfo.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_NONE);
} else if (statusMonitorAuth.equals(StatusMonitorAuthType.AUTH_ADMIN.getText())) {
userInfo.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_ADMIN);
} else if (statusMonitorAuth.equals(StatusMonitorAuthType.AUTH_MONITOR.getText())) {
userInfo.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_MONITOR);
}
userInfo.removeAllDatabaseInfo();
userInfo.setDatabaseInfoList(authDatabaselist);
}
return true;
}
};
if (userInfo != null && userInfo.isAdmin()) {
ChangeCMUserPasswordTask changeCMUserPasswordTask = new ChangeCMUserPasswordTask(server.getServerInfo());
changeCMUserPasswordTask.setUserName(userId);
changeCMUserPasswordTask.setPassword(password);
taskExcutor.addTask(changeCMUserPasswordTask);
} else if (userInfo != null && !userInfo.isAdmin()) {
DeleteCMUserTask deleteCMUserTask = new DeleteCMUserTask(server.getServerInfo());
deleteCMUserTask.setUserId(userId);
taskExcutor.addTask(deleteCMUserTask);
}
if (userInfo == null || !userInfo.isAdmin()) {
AddCMUserTask addCMUserTask = new AddCMUserTask(server.getServerInfo());
addCMUserTask.setUserId(userId);
addCMUserTask.setPassword(password);
addCMUserTask.setDbcreate(dbCreationAuth);
addCMUserTask.setCasAuth(brokerAuth);
addCMUserTask.setStautsMonitorAuth(statusMonitorAuth);
taskExcutor.addTask(addCMUserTask);
}
ServerType serverType = server.getServerInfo().getServerType();
if ((userInfo == null || !userInfo.isAdmin()) && (serverType == ServerType.BOTH || serverType == ServerType.DATABASE)) {
List<Map<String, Object>> dbAuthInfoList = authDbInfoPage.getDbAuthInfoList();
List<String> dbNameList = new ArrayList<String>();
List<String> dbUserList = new ArrayList<String>();
List<String> dbPasswordList = new ArrayList<String>();
List<String> dbBrokerPortList = new ArrayList<String>();
if (dbAuthInfoList != null && !dbAuthInfoList.isEmpty()) {
int size = dbAuthInfoList.size();
for (int i = 0; i < size; i++) {
Map<String, Object> map = dbAuthInfoList.get(i);
String allowConnectedStr = (String) map.get("1");
if ("Yes".equals(allowConnectedStr)) {
String dbName = (String) map.get("0");
dbNameList.add(dbName);
String dbUser = (String) map.get("2");
dbUserList.add(dbUser);
String brokerIP = (String) map.get("3");
String brokerPort = (String) map.get("4");
String port = "";
if (brokerPort.matches("^\\d+$")) {
port = brokerPort;
} else {
port = brokerPort.substring(brokerPort.indexOf("[") + 1, brokerPort.indexOf("/"));
}
dbBrokerPortList.add(brokerIP + "," + port);
dbPasswordList.add("");
DatabaseInfo databaseInfo = new DatabaseInfo(dbName, server.getServerInfo());
databaseInfo.setBrokerPort(brokerPort);
databaseInfo.setBrokerIP(brokerIP);
DbUserInfo dbUserInfo = new DbUserInfo();
dbUserInfo.setName(dbUser);
databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
authDatabaselist.add(databaseInfo);
}
}
}
String[] dbNameArr = new String[dbNameList.size()];
String[] dbUserArr = new String[dbUserList.size()];
String[] dbPasswordArr = new String[dbPasswordList.size()];
String[] dbBrokerPortArr = new String[dbBrokerPortList.size()];
UpdateCMUserTask updateTask = new UpdateCMUserTask(server.getServerInfo());
updateTask.setCmUserName(userId);
updateTask.setDbAuth(dbNameList.toArray(dbNameArr), dbUserList.toArray(dbUserArr), dbPasswordList.toArray(dbPasswordArr), dbBrokerPortList.toArray(dbBrokerPortArr));
updateTask.setCasAuth(brokerAuth);
updateTask.setDbCreator(dbCreationAuth);
updateTask.setStatusMonitorAuth(statusMonitorAuth);
taskExcutor.addTask(updateTask);
}
new ExecTaskWithProgress(taskExcutor).exec(true, true);
return taskExcutor.isSuccess();
}
use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress 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);
}
Aggregations