use of com.cubrid.cubridmanager.core.cubrid.serial.task.DeleteSerialTask in project cubrid-manager by CUBRID.
the class DeleteSerialAction method run.
/**
* Delete the selected serials
*/
public void run(ISchemaNode[] nodeArray) {
if (nodeArray == null) {
LOGGER.error("The nodeArray parameter is a null.");
return;
}
final List<String> serialNameList = new ArrayList<String>();
final StringBuffer serialNames = new StringBuffer();
for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
if (!isSupported(nodeArray[i])) {
setEnabled(false);
return;
}
ISchemaNode schemaNode = (ISchemaNode) nodeArray[i];
if (i == 0) {
serialNames.append(schemaNode.getLabel());
}
serialNameList.add(schemaNode.getLabel());
}
if (nodeArray.length > 1) {
serialNames.append(", ...");
}
String cfmMsg = Messages.bind(Messages.msgConfirmDelSerial, serialNames.toString(), nodeArray.length);
boolean isDelete = CommonUITool.openConfirmBox(getShell(), cfmMsg);
if (!isDelete) {
return;
}
final Shell shell = getShell();
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
String taskName = Messages.bind(Messages.delSerialTaskName, serialNames.toString());
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
for (ITask task : taskList) {
if (task instanceof DeleteSerialTask) {
DeleteSerialTask deleteSerialTask = (DeleteSerialTask) task;
String[] serialNames = new String[serialNameList.size()];
deleteSerialTask.deleteSerial(serialNameList.toArray(serialNames));
}
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
}
return true;
}
};
ISchemaNode schemaNode = (ISchemaNode) nodeArray[0];
CubridDatabase database = schemaNode.getDatabase();
DatabaseInfo databaseInfo = database.getDatabaseInfo();
DeleteSerialTask deleteSerialTask = new DeleteSerialTask(databaseInfo);
taskExcutor.addTask(deleteSerialTask);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return;
}
ISelectionProvider provider = this.getSelectionProvider();
ICubridNode parent = schemaNode.getParent();
if (provider instanceof TreeViewer) {
TreeViewer viewer = (TreeViewer) provider;
for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
parent.removeChild((ICubridNode) nodeArray[i]);
}
viewer.remove(parent, nodeArray);
viewer.setSelection(new StructuredSelection(parent), true);
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
}
}
Aggregations