use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class ExportERwinAction method run.
public void run() {
// FIXME logic code move to core module
int selected = 0;
int logined = 0;
Object[] objects = getSelectedObj();
if (objects instanceof Object[]) {
for (Object object : objects) {
if (object instanceof CubridDatabase) {
selected++;
CubridDatabase database = (CubridDatabase) object;
if (database.isLogined()) {
logined++;
}
}
}
}
if (selected > 1) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLeastOneDb);
return;
}
if (selected <= 0) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectExportDb);
return;
}
if (logined <= 0) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLoginedDb);
return;
}
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE | SWT.APPLICATION_MODAL);
dialog.setFilterExtensions(new String[] { "*.xml" });
String filename = dialog.open();
if (filename == null) {
return;
}
if (filename.trim().equals("")) {
CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
return;
}
for (Object obj : objects) {
if (!(obj instanceof CubridDatabase)) {
continue;
}
CubridDatabase database = (CubridDatabase) obj;
final Map<String, SchemaInfo> allSchemaInfos = new HashMap<String, SchemaInfo>();
TaskExecutor executor = new TaskExecutor() {
public boolean exec(IProgressMonitor monitor) {
for (ITask task : taskList) {
if (task instanceof ExportSchemaTask) {
ExportSchemaTask eTask = (ExportSchemaTask) task;
try {
eTask.initMarshaller();
} catch (JAXBException e) {
e.printStackTrace();
eTask.cancel();
return false;
}
monitor.setTaskName(Messages.msgGenerateInfo);
monitor.worked(50);
eTask.execute();
monitor.setTaskName(Messages.msgFinished);
monitor.worked(100);
monitor.done();
} else if (task instanceof GetAllSchemaTask) {
monitor.beginTask(Messages.msgGenerateInfo, 100);
GetAllSchemaTask gTask = (GetAllSchemaTask) task;
gTask.execute();
if (task.getErrorMsg() == null) {
allSchemaInfos.putAll(gTask.getSchemas());
}
if (allSchemaInfos.size() == 0) {
continue;
}
}
}
return true;
}
};
ExportSchemaTask task = new ExportSchemaTask(allSchemaInfos, filename);
GetAllSchemaTask schemaTask = new GetAllSchemaTask(database.getDatabaseInfo());
executor.addTask(schemaTask);
executor.addTask(task);
new ExecTaskWithProgress(executor).busyCursorWhile();
if (executor.isSuccess()) {
CommonUITool.openInformationBox(Messages.titleExportSchema, Messages.msgExportSuccess);
}
}
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class EditProcedureDialog method buttonPressed.
/**
* When press button,call it
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == BUTTON_ADD_ID) {
Map<String, String> model = new HashMap<String, String>();
try {
AddFuncParamsDialog addDlg = new AddFuncParamsDialog(getShell(), model, sqlTypeMap, javaTypeMap, true, procParamsListData, database);
if (addDlg.open() == IDialogConstants.OK_ID) {
// add
procParamsListData.add(model);
procParamsTableViewer.refresh();
for (int i = 0; i < procParamsTableViewer.getTable().getColumnCount(); i++) {
procParamsTableViewer.getTable().getColumn(i).pack();
}
}
} catch (Exception e) {
LOGGER.error("", e);
}
} else if (buttonId == BUTTON_EDIT_ID) {
// edit
int index = procParamsTable.getSelectionIndex();
if (index < 0) {
return;
}
Map<String, String> map = procParamsListData.get(index);
AddFuncParamsDialog editDlg = new AddFuncParamsDialog(getShell(), map, sqlTypeMap, javaTypeMap, false, procParamsListData, database);
if (editDlg.open() == IDialogConstants.OK_ID) {
procParamsTableViewer.refresh();
for (int i = 0; i < procParamsTableViewer.getTable().getColumnCount(); i++) {
procParamsTableViewer.getTable().getColumn(i).pack();
}
}
} else if (buttonId == BUTTON_UP_ID) {
// up
int index = procParamsTable.getSelectionIndex();
if (index <= 0) {
return;
}
Map<String, String> map = procParamsListData.get(index);
Map<String, String> preMap = procParamsListData.get(index - 1);
procParamsListData.set(index - 1, map);
procParamsListData.set(index, preMap);
procParamsTableViewer.refresh();
} else if (buttonId == BUTTON_DOWN_ID) {
// down
int index = procParamsTable.getSelectionIndex();
if (index < 0 || index >= procParamsListData.size() - 1) {
return;
}
Map<String, String> map = procParamsListData.get(index);
Map<String, String> nextMap = procParamsListData.get(index + 1);
procParamsListData.set(index + 1, map);
procParamsListData.set(index, nextMap);
procParamsTableViewer.refresh();
} else if (buttonId == BUTTON_DROP_ID) {
// drop
int index = procParamsTable.getSelectionIndex();
if (index < 0) {
return;
}
procParamsListData.remove(index);
procParamsTableViewer.refresh();
getButton(BUTTON_EDIT_ID).setEnabled(false);
getButton(BUTTON_UP_ID).setEnabled(false);
getButton(BUTTON_DOWN_ID).setEnabled(false);
getButton(BUTTON_DROP_ID).setEnabled(false);
} else if (buttonId == IDialogConstants.OK_ID) {
if (valid()) {
procedureName = procNameText.getText();
CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
if (!newFlag) {
String dropSql = "DROP PROCEDURE " + QuerySyntax.escapeKeyword(procNameText.getText());
task.addSqls(dropSql);
}
task.addSqls(getSQLScript());
execute(IDialogConstants.OK_ID, new ITask[] { task });
}
return;
}
super.buttonPressed(buttonId);
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class CreateViewDialog method buttonPressed.
protected void buttonPressed(int buttonId) {
if (buttonId == BUTTON_ADD_ID) {
// add
AddQueryDialog addDlg = new AddQueryDialog(parentComp.getShell(), true, -1, this);
if (addDlg.open() == IDialogConstants.OK_ID) {
queryTableViewer.getTable().setSelection(queryTableViewer.getTable().getItemCount() - 1);
querydescText.setText(formatSql(queryTableViewer.getTable().getItem(queryTableViewer.getTable().getItemCount() - 1).getText()));
}
queryTableViewer.getTable().getColumn(0).setWidth(200);
setButtonStatus();
valid();
return;
} else if (buttonId == BUTTON_DROP_ID) {
// delete
int index = queryTableViewer.getTable().getSelectionIndex();
queryListData.remove(index);
queryTableViewer.refresh();
if (queryListData.size() > index) {
queryTableViewer.getTable().setSelection(index);
querydescText.setText(formatSql(queryTableViewer.getTable().getItem(index).getText()));
} else if (index > 0) {
queryTableViewer.getTable().setSelection(index - 1);
querydescText.setText(formatSql(queryTableViewer.getTable().getItem(index - 1).getText()));
} else {
queryTableViewer.getTable().setSelection(index - 1);
querydescText.setText("");
}
validateResult(null, false, -1);
setButtonStatus();
valid();
return;
} else if (buttonId == BUTTON_EDIT_ID) {
StringBuffer sb = new StringBuffer();
int index = queryTableViewer.getTable().getSelectionIndex();
sb.append(queryListData.get(index).get("0"));
AddQueryDialog addDlg = new AddQueryDialog(parentComp.getShell(), false, index, this);
if (addDlg.open() == IDialogConstants.OK_ID) {
// add
queryTableViewer.getTable().setSelection(index);
String sql = queryTableViewer.getTable().getItem(index).getText();
querydescText.setText(formatSql(sql));
}
setButtonStatus();
valid();
return;
} else if (buttonId == IDialogConstants.OK_ID) {
if (!valid()) {
return;
}
DatabaseInfo databaseInfo = database.getDatabaseInfo();
owner = ownerCombo.getText();
Map<String, ClassAuthorizations> authMap = getDropViewAuthorizations();
CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
String dropSql = makeDropSQLScript();
if (dropSql.length() > 0) {
dropSql = DatabaseInfo.wrapShardQuery(databaseInfo, dropSql);
task.addSqls(dropSql);
}
String sql = makeCreateSQLScript();
sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql);
task.addSqls(sql);
DatabaseInfo dbInfo = database.getDatabaseInfo();
String ownerOld = dbInfo.getAuthLoginedDbUserInfo().getName();
String ownerNew = ownerCombo.getText();
boolean isSameOwner = StringUtil.isEqualIgnoreCase(ownerOld, ownerNew);
if (!isSameOwner) {
sql = makeChangeOwnerSQLScript();
sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql);
task.addCallSqls(sql);
}
addGrantAuthSQLScriptToTask(authMap, tableText.getText(), task);
execTask(-1, new ITask[] { task }, true, getParentShell());
if (task.getErrorMsg() != null) {
return;
}
String title = com.cubrid.common.ui.common.Messages.titleSuccess;
String message = isNewTableFlag ? Messages.msgSuccessCreateView : Messages.msgSuccessEditView;
CommonUITool.openInformationBox(title, message);
}
viewName = tableText.getText();
super.buttonPressed(buttonId);
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class CubridTriggerFolderLoader method load.
/**
*
* Load children object for parent
*
* @param parent the parent node
* @param monitor the IProgressMonitor object
*/
public void load(ICubridNode parent, final IProgressMonitor monitor) {
synchronized (this) {
if (isLoaded()) {
return;
}
CubridDatabase database = ((ISchemaNode) parent).getDatabase();
if (!database.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
database.getDatabaseInfo().setTriggerList(null);
parent.removeAllChild();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
return;
}
DatabaseInfo databaseInfo = database.getDatabaseInfo();
ITask task = null;
if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
task = new GetTriggerListTask(parent.getServer().getServerInfo());
((GetTriggerListTask) task).setDbName(database.getLabel());
} else {
task = new JDBCGetTriggerListTask(databaseInfo);
}
monitorCancel(monitor, new ITask[] { task });
task.execute();
final String errorMsg = task.getErrorMsg();
if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
parent.removeAllChild();
openErrorBox(errorMsg);
setLoaded(true);
return;
}
if (monitor.isCanceled()) {
setLoaded(true);
return;
}
parent.removeAllChild();
List<Trigger> triggerList = null;
if (task instanceof GetTriggerListTask) {
triggerList = ((GetTriggerListTask) task).getTriggerInfoList();
} else if (task instanceof JDBCGetTriggerListTask) {
triggerList = ((JDBCGetTriggerListTask) task).getTriggerInfoList();
}
if (triggerList != null && !triggerList.isEmpty()) {
for (Trigger trigger : triggerList) {
String id = parent.getId() + NODE_SEPARATOR + trigger.getName();
ICubridNode triggerNode = createTriggerNode(id, trigger);
parent.addChild(triggerNode);
}
}
databaseInfo.setTriggerList(triggerList);
Collections.sort(parent.getChildren());
setLoaded(true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class OpenTriggerDetailInfoPartProgress method run.
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DatabaseInfo databaseInfo = database.getDatabaseInfo();
ITask task = null;
if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
task = new GetTriggerListTask(database.getServer().getServerInfo());
((GetTriggerListTask) task).setDbName(database.getLabel());
} else {
task = new JDBCGetTriggerListTask(databaseInfo);
}
task.execute();
if (!task.isSuccess()) {
LOGGER.error(task.getErrorMsg());
return;
}
if (task instanceof GetTriggerListTask) {
triggerList = ((GetTriggerListTask) task).getTriggerInfoList();
} else if (task instanceof JDBCGetTriggerListTask) {
triggerList = ((JDBCGetTriggerListTask) task).getTriggerInfoList();
}
success = true;
}
Aggregations